blob: 2c8ec0d8ca741206b88f06ce4b7716d6c231fb0c [file] [log] [blame]
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gl/GrGLShaderBuilder.h"
9#include "gl/GrGLProgram.h"
10#include "gl/GrGLUniformHandle.h"
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000011#include "gl/GrGpuGL.h"
bsalomon@google.comd8b5fac2012-11-01 17:02:46 +000012#include "SkMatrix.h"
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000013
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +000014#define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(UNI, COUNT) \
15 SkASSERT(arrayCount <= uni.fArrayCount || \
16 (1 == arrayCount && GrGLShaderVar::kNonArray == uni.fArrayCount))
17
kkinnunen7510b222014-07-30 00:04:16 -070018GrGLProgramDataManager::GrGLProgramDataManager(GrGpuGL* gpu) : fGpu(gpu) {
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +000019 // skbug.com/2056
20 fUsingBindUniform = fGpu->glInterface()->fFunctions.fBindUniformLocation != NULL;
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +000021}
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000022
kkinnunen7510b222014-07-30 00:04:16 -070023GrGLProgramDataManager::UniformHandle GrGLProgramDataManager::appendUniform(GrSLType type, int arrayCount) {
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000024 int idx = fUniforms.count();
25 Uniform& uni = fUniforms.push_back();
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000026 SkASSERT(GrGLShaderVar::kNonArray == arrayCount || arrayCount > 0);
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000027 uni.fArrayCount = arrayCount;
28 uni.fType = type;
29 uni.fVSLocation = kUnusedUniform;
30 uni.fFSLocation = kUnusedUniform;
kkinnunen7510b222014-07-30 00:04:16 -070031 return GrGLProgramDataManager::UniformHandle::CreateFromUniformIndex(idx);
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000032}
33
kkinnunen7510b222014-07-30 00:04:16 -070034void GrGLProgramDataManager::setSampler(UniformHandle u, GrGLint texUnit) const {
commit-bot@chromium.org7425c122013-08-14 18:14:19 +000035 const Uniform& uni = fUniforms[u.toUniformIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000036 SkASSERT(uni.fType == kSampler2D_GrSLType);
37 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
bsalomon@google.com0982d352012-07-31 15:33:25 +000038 // FIXME: We still insert a single sampler uniform for every stage. If the shader does not
39 // reference the sampler then the compiler may have optimized it out. Uncomment this assert
40 // once stages insert their own samplers.
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000041 // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000042 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000043 GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fFSLocation, texUnit));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000044 }
45 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000046 GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fVSLocation, texUnit));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000047 }
48}
49
kkinnunen7510b222014-07-30 00:04:16 -070050void GrGLProgramDataManager::set1f(UniformHandle u, GrGLfloat v0) const {
commit-bot@chromium.org7425c122013-08-14 18:14:19 +000051 const Uniform& uni = fUniforms[u.toUniformIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000052 SkASSERT(uni.fType == kFloat_GrSLType);
53 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
54 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000055 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000056 GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fFSLocation, v0));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000057 }
58 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000059 GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fVSLocation, v0));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000060 }
61}
62
kkinnunen7510b222014-07-30 00:04:16 -070063void GrGLProgramDataManager::set1fv(UniformHandle u,
64 int arrayCount,
65 const GrGLfloat v[]) const {
commit-bot@chromium.org7425c122013-08-14 18:14:19 +000066 const Uniform& uni = fUniforms[u.toUniformIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000067 SkASSERT(uni.fType == kFloat_GrSLType);
68 SkASSERT(arrayCount > 0);
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +000069 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000070 // This assert fires in some instances of the two-pt gradient for its VSParams.
71 // Once the uniform manager is responsible for inserting the duplicate uniform
72 // arrays in VS and FS driver bug workaround, this can be enabled.
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000073 //SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000074 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +000075 GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fFSLocation, arrayCount, v));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000076 }
77 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +000078 GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fVSLocation, arrayCount, v));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000079 }
80}
81
kkinnunen7510b222014-07-30 00:04:16 -070082void GrGLProgramDataManager::set2f(UniformHandle u, GrGLfloat v0, GrGLfloat v1) const {
commit-bot@chromium.org7425c122013-08-14 18:14:19 +000083 const Uniform& uni = fUniforms[u.toUniformIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000084 SkASSERT(uni.fType == kVec2f_GrSLType);
85 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
86 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000087 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000088 GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fFSLocation, v0, v1));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000089 }
90 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000091 GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fVSLocation, v0, v1));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000092 }
93}
94
kkinnunen7510b222014-07-30 00:04:16 -070095void GrGLProgramDataManager::set2fv(UniformHandle u,
96 int arrayCount,
97 const GrGLfloat v[]) const {
commit-bot@chromium.org7425c122013-08-14 18:14:19 +000098 const Uniform& uni = fUniforms[u.toUniformIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000099 SkASSERT(uni.fType == kVec2f_GrSLType);
100 SkASSERT(arrayCount > 0);
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000101 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000102 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000103 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000104 GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fFSLocation, arrayCount, v));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000105 }
106 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000107 GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fVSLocation, arrayCount, v));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000108 }
109}
110
kkinnunen7510b222014-07-30 00:04:16 -0700111void GrGLProgramDataManager::set3f(UniformHandle u, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2) const {
commit-bot@chromium.org7425c122013-08-14 18:14:19 +0000112 const Uniform& uni = fUniforms[u.toUniformIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000113 SkASSERT(uni.fType == kVec3f_GrSLType);
114 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
115 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000116 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000117 GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fFSLocation, v0, v1, v2));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000118 }
119 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000120 GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fVSLocation, v0, v1, v2));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000121 }
122}
123
kkinnunen7510b222014-07-30 00:04:16 -0700124void GrGLProgramDataManager::set3fv(UniformHandle u,
125 int arrayCount,
126 const GrGLfloat v[]) const {
commit-bot@chromium.org7425c122013-08-14 18:14:19 +0000127 const Uniform& uni = fUniforms[u.toUniformIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000128 SkASSERT(uni.fType == kVec3f_GrSLType);
129 SkASSERT(arrayCount > 0);
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000130 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000131 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000132 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000133 GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fFSLocation, arrayCount, v));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000134 }
135 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000136 GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fVSLocation, arrayCount, v));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000137 }
138}
139
kkinnunen7510b222014-07-30 00:04:16 -0700140void GrGLProgramDataManager::set4f(UniformHandle u,
141 GrGLfloat v0,
142 GrGLfloat v1,
143 GrGLfloat v2,
144 GrGLfloat v3) const {
commit-bot@chromium.org7425c122013-08-14 18:14:19 +0000145 const Uniform& uni = fUniforms[u.toUniformIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000146 SkASSERT(uni.fType == kVec4f_GrSLType);
147 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
148 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000149 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000150 GR_GL_CALL(fGpu->glInterface(), Uniform4f(uni.fFSLocation, v0, v1, v2, v3));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000151 }
152 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000153 GR_GL_CALL(fGpu->glInterface(), Uniform4f(uni.fVSLocation, v0, v1, v2, v3));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000154 }
155}
156
kkinnunen7510b222014-07-30 00:04:16 -0700157void GrGLProgramDataManager::set4fv(UniformHandle u,
158 int arrayCount,
159 const GrGLfloat v[]) const {
commit-bot@chromium.org7425c122013-08-14 18:14:19 +0000160 const Uniform& uni = fUniforms[u.toUniformIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000161 SkASSERT(uni.fType == kVec4f_GrSLType);
162 SkASSERT(arrayCount > 0);
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000163 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000164 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000165 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000166 GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fFSLocation, arrayCount, v));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000167 }
168 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000169 GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fVSLocation, arrayCount, v));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000170 }
171}
172
kkinnunen7510b222014-07-30 00:04:16 -0700173void GrGLProgramDataManager::setMatrix3f(UniformHandle u, const GrGLfloat matrix[]) const {
commit-bot@chromium.org7425c122013-08-14 18:14:19 +0000174 const Uniform& uni = fUniforms[u.toUniformIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000175 SkASSERT(uni.fType == kMat33f_GrSLType);
176 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
bsalomon@google.com8ea78d82012-10-24 20:11:30 +0000177 // TODO: Re-enable this assert once texture matrices aren't forced on all effects
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000178 // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000179 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000180 GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fFSLocation, 1, false, matrix));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000181 }
182 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000183 GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fVSLocation, 1, false, matrix));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000184 }
185}
186
kkinnunen7510b222014-07-30 00:04:16 -0700187void GrGLProgramDataManager::setMatrix4f(UniformHandle u, const GrGLfloat matrix[]) const {
commit-bot@chromium.org7425c122013-08-14 18:14:19 +0000188 const Uniform& uni = fUniforms[u.toUniformIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000189 SkASSERT(uni.fType == kMat44f_GrSLType);
190 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
191 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000192 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000193 GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fFSLocation, 1, false, matrix));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000194 }
195 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000196 GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fVSLocation, 1, false, matrix));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000197 }
198}
199
kkinnunen7510b222014-07-30 00:04:16 -0700200void GrGLProgramDataManager::setMatrix3fv(UniformHandle u,
201 int arrayCount,
202 const GrGLfloat matrices[]) const {
commit-bot@chromium.org7425c122013-08-14 18:14:19 +0000203 const Uniform& uni = fUniforms[u.toUniformIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000204 SkASSERT(uni.fType == kMat33f_GrSLType);
205 SkASSERT(arrayCount > 0);
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000206 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000207 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000208 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000209 GR_GL_CALL(fGpu->glInterface(),
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000210 UniformMatrix3fv(uni.fFSLocation, arrayCount, false, matrices));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000211 }
212 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000213 GR_GL_CALL(fGpu->glInterface(),
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000214 UniformMatrix3fv(uni.fVSLocation, arrayCount, false, matrices));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000215 }
216}
217
kkinnunen7510b222014-07-30 00:04:16 -0700218void GrGLProgramDataManager::setMatrix4fv(UniformHandle u,
219 int arrayCount,
220 const GrGLfloat matrices[]) const {
commit-bot@chromium.org7425c122013-08-14 18:14:19 +0000221 const Uniform& uni = fUniforms[u.toUniformIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000222 SkASSERT(uni.fType == kMat44f_GrSLType);
223 SkASSERT(arrayCount > 0);
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000224 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000225 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000226 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000227 GR_GL_CALL(fGpu->glInterface(),
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000228 UniformMatrix4fv(uni.fFSLocation, arrayCount, false, matrices));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000229 }
230 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000231 GR_GL_CALL(fGpu->glInterface(),
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000232 UniformMatrix4fv(uni.fVSLocation, arrayCount, false, matrices));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000233 }
234}
235
kkinnunen7510b222014-07-30 00:04:16 -0700236void GrGLProgramDataManager::setSkMatrix(UniformHandle u, const SkMatrix& matrix) const {
bsalomon@google.comd8b5fac2012-11-01 17:02:46 +0000237 GrGLfloat mt[] = {
238 matrix.get(SkMatrix::kMScaleX),
239 matrix.get(SkMatrix::kMSkewY),
240 matrix.get(SkMatrix::kMPersp0),
241 matrix.get(SkMatrix::kMSkewX),
242 matrix.get(SkMatrix::kMScaleY),
243 matrix.get(SkMatrix::kMPersp1),
244 matrix.get(SkMatrix::kMTransX),
245 matrix.get(SkMatrix::kMTransY),
246 matrix.get(SkMatrix::kMPersp2),
247 };
248 this->setMatrix3f(u, mt);
249}
250
251
kkinnunen7510b222014-07-30 00:04:16 -0700252void GrGLProgramDataManager::getUniformLocations(GrGLuint programID, const BuilderUniformArray& uniforms) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000253 SkASSERT(uniforms.count() == fUniforms.count());
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000254 int count = fUniforms.count();
255 for (int i = 0; i < count; ++i) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000256 SkASSERT(uniforms[i].fVariable.getType() == fUniforms[i].fType);
257 SkASSERT(uniforms[i].fVariable.getArrayCount() == fUniforms[i].fArrayCount);
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000258 GrGLint location;
259 // TODO: Move the Xoom uniform array in both FS and VS bug workaround here.
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000260 if (fUsingBindUniform) {
261 location = i;
262 GR_GL_CALL(fGpu->glInterface(),
263 BindUniformLocation(programID, location, uniforms[i].fVariable.c_str()));
264 } else {
265 GR_GL_CALL_RET(fGpu->glInterface(), location,
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000266 GetUniformLocation(programID, uniforms[i].fVariable.c_str()));
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000267 }
commit-bot@chromium.org74a3a212013-08-30 19:43:59 +0000268 if (GrGLShaderBuilder::kVertex_Visibility & uniforms[i].fVisibility) {
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000269 fUniforms[i].fVSLocation = location;
270 }
commit-bot@chromium.org74a3a212013-08-30 19:43:59 +0000271 if (GrGLShaderBuilder::kFragment_Visibility & uniforms[i].fVisibility) {
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000272 fUniforms[i].fFSLocation = location;
273 }
274 }
275}
commit-bot@chromium.org7425c122013-08-14 18:14:19 +0000276
kkinnunen7510b222014-07-30 00:04:16 -0700277const GrGLProgramDataManager::BuilderUniform&
278GrGLProgramDataManager::getBuilderUniform(const BuilderUniformArray& array, UniformHandle handle) const {
commit-bot@chromium.org7425c122013-08-14 18:14:19 +0000279 return array[handle.toUniformIndex()];
280}