blob: a03f1b292230df64ed0bb9d66594a4ab7ddbb57f [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
bsalomon@google.comd8b5fac2012-11-01 17:02:46 +00008#include "SkMatrix.h"
joshualitte7afc2d2015-09-11 10:44:13 -07009#include "gl/GrGLProgramDataManager.h"
10#include "gl/GrGLGpu.h"
egdaniel7ea439b2015-12-03 09:20:44 -080011#include "glsl/GrGLSLUniformHandler.h"
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000012
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +000013#define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(UNI, COUNT) \
14 SkASSERT(arrayCount <= uni.fArrayCount || \
egdaniel0d3f0612015-10-21 10:45:48 -070015 (1 == arrayCount && GrGLSLShaderVar::kNonArray == uni.fArrayCount))
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +000016
joshualittd8dd47b2015-09-11 11:45:01 -070017GrGLProgramDataManager::GrGLProgramDataManager(GrGLGpu* gpu, GrGLuint programID,
18 const UniformInfoArray& uniforms,
egdaniel0eafe792015-11-20 14:01:22 -080019 const VaryingInfoArray& pathProcVaryings)
joshualittd8dd47b2015-09-11 11:45:01 -070020 : fGpu(gpu)
21 , fProgramID(programID) {
joshualitt47bb3822014-10-07 16:43:25 -070022 int count = uniforms.count();
kkinnunendddc18a2014-08-03 23:19:46 -070023 fUniforms.push_back_n(count);
24 for (int i = 0; i < count; i++) {
25 Uniform& uniform = fUniforms[i];
joshualitt47bb3822014-10-07 16:43:25 -070026 const UniformInfo& builderUniform = uniforms[i];
egdaniel0d3f0612015-10-21 10:45:48 -070027 SkASSERT(GrGLSLShaderVar::kNonArray == builderUniform.fVariable.getArrayCount() ||
kkinnunendddc18a2014-08-03 23:19:46 -070028 builderUniform.fVariable.getArrayCount() > 0);
29 SkDEBUGCODE(
30 uniform.fArrayCount = builderUniform.fVariable.getArrayCount();
31 uniform.fType = builderUniform.fVariable.getType();
32 );
33 // TODO: Move the Xoom uniform array in both FS and VS bug workaround here.
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000034
egdaniel7ea439b2015-12-03 09:20:44 -080035 if (GrGLSLUniformHandler::kVertex_Visibility & builderUniform.fVisibility) {
kkinnunendddc18a2014-08-03 23:19:46 -070036 uniform.fVSLocation = builderUniform.fLocation;
37 } else {
38 uniform.fVSLocation = kUnusedUniform;
joshualitt47bb3822014-10-07 16:43:25 -070039 }
egdaniel7ea439b2015-12-03 09:20:44 -080040 if (GrGLSLUniformHandler::kFragment_Visibility & builderUniform.fVisibility) {
kkinnunendddc18a2014-08-03 23:19:46 -070041 uniform.fFSLocation = builderUniform.fLocation;
42 } else {
43 uniform.fFSLocation = kUnusedUniform;
44 }
45 }
joshualittd8dd47b2015-09-11 11:45:01 -070046
47 // NVPR programs have separable varyings
egdaniel0eafe792015-11-20 14:01:22 -080048 count = pathProcVaryings.count();
49 fPathProcVaryings.push_back_n(count);
joshualittd8dd47b2015-09-11 11:45:01 -070050 for (int i = 0; i < count; i++) {
51 SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport());
egdaniel0eafe792015-11-20 14:01:22 -080052 PathProcVarying& pathProcVarying = fPathProcVaryings[i];
53 const VaryingInfo& builderPathProcVarying = pathProcVaryings[i];
54 SkASSERT(GrGLSLShaderVar::kNonArray == builderPathProcVarying.fVariable.getArrayCount() ||
55 builderPathProcVarying.fVariable.getArrayCount() > 0);
joshualittd8dd47b2015-09-11 11:45:01 -070056 SkDEBUGCODE(
egdaniel0eafe792015-11-20 14:01:22 -080057 pathProcVarying.fArrayCount = builderPathProcVarying.fVariable.getArrayCount();
58 pathProcVarying.fType = builderPathProcVarying.fVariable.getType();
joshualittd8dd47b2015-09-11 11:45:01 -070059 );
egdaniel0eafe792015-11-20 14:01:22 -080060 pathProcVarying.fLocation = builderPathProcVarying.fLocation;
joshualittd8dd47b2015-09-11 11:45:01 -070061 }
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000062}
63
egdaniel018fb622015-10-28 07:26:40 -070064void GrGLProgramDataManager::setSampler(UniformHandle u, int texUnit) const {
joshualitte7afc2d2015-09-11 10:44:13 -070065 const Uniform& uni = fUniforms[u.toIndex()];
bsalomone5286e02016-01-14 09:24:09 -080066 SkASSERT(uni.fType == kSampler2D_GrSLType || uni.fType == kSamplerExternal_GrSLType ||
67 uni.fType == kSampler2DRect_GrSLType);
egdaniel0d3f0612015-10-21 10:45:48 -070068 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount);
bsalomon@google.com0982d352012-07-31 15:33:25 +000069 // FIXME: We still insert a single sampler uniform for every stage. If the shader does not
70 // reference the sampler then the compiler may have optimized it out. Uncomment this assert
71 // once stages insert their own samplers.
joshualittaf2d56d2015-05-11 06:21:34 -070072 // this->printUnused(uni);
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000073 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000074 GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fFSLocation, texUnit));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000075 }
76 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000077 GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fVSLocation, texUnit));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000078 }
79}
80
egdaniel018fb622015-10-28 07:26:40 -070081void GrGLProgramDataManager::set1f(UniformHandle u, float v0) const {
joshualitte7afc2d2015-09-11 10:44:13 -070082 const Uniform& uni = fUniforms[u.toIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000083 SkASSERT(uni.fType == kFloat_GrSLType);
egdaniel0d3f0612015-10-21 10:45:48 -070084 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount);
joshualitt7d022d62015-05-12 12:03:50 -070085 SkDEBUGCODE(this->printUnused(uni);)
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000086 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000087 GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fFSLocation, v0));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000088 }
89 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000090 GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fVSLocation, v0));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000091 }
92}
93
kkinnunen7510b222014-07-30 00:04:16 -070094void GrGLProgramDataManager::set1fv(UniformHandle u,
95 int arrayCount,
egdaniel018fb622015-10-28 07:26:40 -070096 const float v[]) const {
joshualitte7afc2d2015-09-11 10:44:13 -070097 const Uniform& uni = fUniforms[u.toIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000098 SkASSERT(uni.fType == kFloat_GrSLType);
99 SkASSERT(arrayCount > 0);
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000100 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000101 // This assert fires in some instances of the two-pt gradient for its VSParams.
102 // Once the uniform manager is responsible for inserting the duplicate uniform
103 // arrays in VS and FS driver bug workaround, this can be enabled.
joshualittaf2d56d2015-05-11 06:21:34 -0700104 // this->printUni(uni);
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000105 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000106 GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fFSLocation, arrayCount, v));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000107 }
108 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000109 GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fVSLocation, arrayCount, v));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000110 }
111}
112
egdaniel018fb622015-10-28 07:26:40 -0700113void GrGLProgramDataManager::set2f(UniformHandle u, float v0, float v1) const {
joshualitte7afc2d2015-09-11 10:44:13 -0700114 const Uniform& uni = fUniforms[u.toIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000115 SkASSERT(uni.fType == kVec2f_GrSLType);
egdaniel0d3f0612015-10-21 10:45:48 -0700116 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount);
joshualitt7d022d62015-05-12 12:03:50 -0700117 SkDEBUGCODE(this->printUnused(uni);)
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000118 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000119 GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fFSLocation, v0, v1));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000120 }
121 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000122 GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fVSLocation, v0, v1));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000123 }
124}
125
kkinnunen7510b222014-07-30 00:04:16 -0700126void GrGLProgramDataManager::set2fv(UniformHandle u,
127 int arrayCount,
egdaniel018fb622015-10-28 07:26:40 -0700128 const float v[]) const {
joshualitte7afc2d2015-09-11 10:44:13 -0700129 const Uniform& uni = fUniforms[u.toIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000130 SkASSERT(uni.fType == kVec2f_GrSLType);
131 SkASSERT(arrayCount > 0);
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000132 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
joshualitt7d022d62015-05-12 12:03:50 -0700133 SkDEBUGCODE(this->printUnused(uni);)
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000134 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000135 GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fFSLocation, arrayCount, v));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000136 }
137 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000138 GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fVSLocation, arrayCount, v));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000139 }
140}
141
egdaniel018fb622015-10-28 07:26:40 -0700142void GrGLProgramDataManager::set3f(UniformHandle u, float v0, float v1, float v2) const {
joshualitte7afc2d2015-09-11 10:44:13 -0700143 const Uniform& uni = fUniforms[u.toIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000144 SkASSERT(uni.fType == kVec3f_GrSLType);
egdaniel0d3f0612015-10-21 10:45:48 -0700145 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount);
joshualitt7d022d62015-05-12 12:03:50 -0700146 SkDEBUGCODE(this->printUnused(uni);)
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000147 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000148 GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fFSLocation, v0, v1, v2));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000149 }
150 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000151 GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fVSLocation, v0, v1, v2));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000152 }
153}
154
kkinnunen7510b222014-07-30 00:04:16 -0700155void GrGLProgramDataManager::set3fv(UniformHandle u,
156 int arrayCount,
egdaniel018fb622015-10-28 07:26:40 -0700157 const float v[]) const {
joshualitte7afc2d2015-09-11 10:44:13 -0700158 const Uniform& uni = fUniforms[u.toIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000159 SkASSERT(uni.fType == kVec3f_GrSLType);
160 SkASSERT(arrayCount > 0);
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000161 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
joshualitt7d022d62015-05-12 12:03:50 -0700162 SkDEBUGCODE(this->printUnused(uni);)
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000163 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000164 GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fFSLocation, arrayCount, v));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000165 }
166 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000167 GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fVSLocation, arrayCount, v));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000168 }
169}
170
kkinnunen7510b222014-07-30 00:04:16 -0700171void GrGLProgramDataManager::set4f(UniformHandle u,
egdaniel018fb622015-10-28 07:26:40 -0700172 float v0,
173 float v1,
174 float v2,
175 float v3) const {
joshualitte7afc2d2015-09-11 10:44:13 -0700176 const Uniform& uni = fUniforms[u.toIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000177 SkASSERT(uni.fType == kVec4f_GrSLType);
egdaniel0d3f0612015-10-21 10:45:48 -0700178 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount);
joshualitt7d022d62015-05-12 12:03:50 -0700179 SkDEBUGCODE(this->printUnused(uni);)
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000180 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000181 GR_GL_CALL(fGpu->glInterface(), Uniform4f(uni.fFSLocation, v0, v1, v2, v3));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000182 }
183 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000184 GR_GL_CALL(fGpu->glInterface(), Uniform4f(uni.fVSLocation, v0, v1, v2, v3));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000185 }
186}
187
kkinnunen7510b222014-07-30 00:04:16 -0700188void GrGLProgramDataManager::set4fv(UniformHandle u,
189 int arrayCount,
egdaniel018fb622015-10-28 07:26:40 -0700190 const float v[]) const {
joshualitte7afc2d2015-09-11 10:44:13 -0700191 const Uniform& uni = fUniforms[u.toIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000192 SkASSERT(uni.fType == kVec4f_GrSLType);
193 SkASSERT(arrayCount > 0);
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000194 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
joshualitt7d022d62015-05-12 12:03:50 -0700195 SkDEBUGCODE(this->printUnused(uni);)
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000196 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000197 GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fFSLocation, arrayCount, v));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000198 }
199 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000200 GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fVSLocation, arrayCount, v));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000201 }
202}
203
egdaniel018fb622015-10-28 07:26:40 -0700204void GrGLProgramDataManager::setMatrix3f(UniformHandle u, const float matrix[]) const {
joshualitte7afc2d2015-09-11 10:44:13 -0700205 const Uniform& uni = fUniforms[u.toIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000206 SkASSERT(uni.fType == kMat33f_GrSLType);
egdaniel0d3f0612015-10-21 10:45:48 -0700207 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount);
joshualitt7d022d62015-05-12 12:03:50 -0700208 SkDEBUGCODE(this->printUnused(uni);)
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000209 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000210 GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fFSLocation, 1, false, matrix));
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(), UniformMatrix3fv(uni.fVSLocation, 1, false, matrix));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000214 }
215}
216
egdaniel018fb622015-10-28 07:26:40 -0700217void GrGLProgramDataManager::setMatrix4f(UniformHandle u, const float matrix[]) const {
joshualitte7afc2d2015-09-11 10:44:13 -0700218 const Uniform& uni = fUniforms[u.toIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000219 SkASSERT(uni.fType == kMat44f_GrSLType);
egdaniel0d3f0612015-10-21 10:45:48 -0700220 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount);
joshualitt7d022d62015-05-12 12:03:50 -0700221 SkDEBUGCODE(this->printUnused(uni);)
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000222 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000223 GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fFSLocation, 1, false, matrix));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000224 }
225 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000226 GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fVSLocation, 1, false, matrix));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000227 }
228}
229
kkinnunen7510b222014-07-30 00:04:16 -0700230void GrGLProgramDataManager::setMatrix3fv(UniformHandle u,
231 int arrayCount,
egdaniel018fb622015-10-28 07:26:40 -0700232 const float matrices[]) const {
joshualitte7afc2d2015-09-11 10:44:13 -0700233 const Uniform& uni = fUniforms[u.toIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000234 SkASSERT(uni.fType == kMat33f_GrSLType);
235 SkASSERT(arrayCount > 0);
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000236 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
joshualitt7d022d62015-05-12 12:03:50 -0700237 SkDEBUGCODE(this->printUnused(uni);)
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000238 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000239 GR_GL_CALL(fGpu->glInterface(),
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000240 UniformMatrix3fv(uni.fFSLocation, arrayCount, false, matrices));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000241 }
242 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000243 GR_GL_CALL(fGpu->glInterface(),
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000244 UniformMatrix3fv(uni.fVSLocation, arrayCount, false, matrices));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000245 }
246}
247
kkinnunen7510b222014-07-30 00:04:16 -0700248void GrGLProgramDataManager::setMatrix4fv(UniformHandle u,
249 int arrayCount,
egdaniel018fb622015-10-28 07:26:40 -0700250 const float matrices[]) const {
joshualitte7afc2d2015-09-11 10:44:13 -0700251 const Uniform& uni = fUniforms[u.toIndex()];
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000252 SkASSERT(uni.fType == kMat44f_GrSLType);
253 SkASSERT(arrayCount > 0);
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000254 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
joshualitt7d022d62015-05-12 12:03:50 -0700255 SkDEBUGCODE(this->printUnused(uni);)
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000256 if (kUnusedUniform != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000257 GR_GL_CALL(fGpu->glInterface(),
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000258 UniformMatrix4fv(uni.fFSLocation, arrayCount, false, matrices));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000259 }
260 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000261 GR_GL_CALL(fGpu->glInterface(),
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +0000262 UniformMatrix4fv(uni.fVSLocation, arrayCount, false, matrices));
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000263 }
264}
265
egdaniel0eafe792015-11-20 14:01:22 -0800266void GrGLProgramDataManager::setPathFragmentInputTransform(VaryingHandle u,
joshualittd8dd47b2015-09-11 11:45:01 -0700267 int components,
268 const SkMatrix& matrix) const {
269 SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport());
egdaniel0eafe792015-11-20 14:01:22 -0800270 const PathProcVarying& fragmentInput = fPathProcVaryings[u.toIndex()];
joshualittd8dd47b2015-09-11 11:45:01 -0700271
272 SkASSERT((components == 2 && fragmentInput.fType == kVec2f_GrSLType) ||
273 (components == 3 && fragmentInput.fType == kVec3f_GrSLType));
274
275 fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID,
276 fragmentInput.fLocation,
277 GR_GL_OBJECT_LINEAR,
278 components,
279 matrix);
280}
281
joshualittaf2d56d2015-05-11 06:21:34 -0700282#ifdef SK_DEBUG
283void GrGLProgramDataManager::printUnused(const Uniform& uni) const {
284 if (kUnusedUniform == uni.fFSLocation && kUnusedUniform == uni.fVSLocation) {
bsalomon682c2692015-05-22 14:01:46 -0700285 GrCapsDebugf(fGpu->caps(), "Unused uniform in shader\n");
joshualittaf2d56d2015-05-11 06:21:34 -0700286 }
287}
288#endif