bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 1 | /* |
| 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.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 8 | #include "SkMatrix.h" |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 9 | #include "gl/GrGLProgramDataManager.h" |
| 10 | #include "gl/GrGLGpu.h" |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 11 | #include "glsl/GrGLSLUniformHandler.h" |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 12 | |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 13 | #define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(UNI, COUNT) \ |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 14 | SkASSERT((COUNT) <= (UNI).fArrayCount || \ |
| 15 | (1 == (COUNT) && GrGLSLShaderVar::kNonArray == (UNI).fArrayCount)) |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 16 | |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 17 | GrGLProgramDataManager::GrGLProgramDataManager(GrGLGpu* gpu, GrGLuint programID, |
| 18 | const UniformInfoArray& uniforms, |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 19 | const VaryingInfoArray& pathProcVaryings) |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 20 | : fGpu(gpu) |
| 21 | , fProgramID(programID) { |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 22 | int count = uniforms.count(); |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 23 | fUniforms.push_back_n(count); |
| 24 | for (int i = 0; i < count; i++) { |
| 25 | Uniform& uniform = fUniforms[i]; |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 26 | const UniformInfo& builderUniform = uniforms[i]; |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 27 | SkASSERT(GrGLSLShaderVar::kNonArray == builderUniform.fVariable.getArrayCount() || |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 28 | builderUniform.fVariable.getArrayCount() > 0); |
| 29 | SkDEBUGCODE( |
| 30 | uniform.fArrayCount = builderUniform.fVariable.getArrayCount(); |
| 31 | uniform.fType = builderUniform.fVariable.getType(); |
| 32 | ); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame^] | 33 | uniform.fLocation = builderUniform.fLocation; |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 34 | } |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 35 | |
| 36 | // NVPR programs have separable varyings |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 37 | count = pathProcVaryings.count(); |
| 38 | fPathProcVaryings.push_back_n(count); |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 39 | for (int i = 0; i < count; i++) { |
| 40 | SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport()); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 41 | PathProcVarying& pathProcVarying = fPathProcVaryings[i]; |
| 42 | const VaryingInfo& builderPathProcVarying = pathProcVaryings[i]; |
| 43 | SkASSERT(GrGLSLShaderVar::kNonArray == builderPathProcVarying.fVariable.getArrayCount() || |
| 44 | builderPathProcVarying.fVariable.getArrayCount() > 0); |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 45 | SkDEBUGCODE( |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 46 | pathProcVarying.fArrayCount = builderPathProcVarying.fVariable.getArrayCount(); |
| 47 | pathProcVarying.fType = builderPathProcVarying.fVariable.getType(); |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 48 | ); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 49 | pathProcVarying.fLocation = builderPathProcVarying.fLocation; |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 50 | } |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame^] | 53 | void GrGLProgramDataManager::setSamplers(const UniformInfoArray& samplers) const { |
egdaniel | 09aa1fc | 2016-04-20 07:09:46 -0700 | [diff] [blame] | 54 | for (int i = 0; i < samplers.count(); ++i) { |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame^] | 55 | const UniformInfo& sampler = samplers[i]; |
| 56 | SkASSERT(sampler.fVisibility); |
| 57 | if (kUnusedUniform != sampler.fLocation) { |
| 58 | GR_GL_CALL(fGpu->glInterface(), Uniform1i(sampler.fLocation, i)); |
egdaniel | 09aa1fc | 2016-04-20 07:09:46 -0700 | [diff] [blame] | 59 | } else { |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame^] | 60 | // FIXME: We still insert a single sampler uniform for every stage. If the shader does |
| 61 | // not reference the sampler then the compiler may have optimized it out. Uncomment this |
| 62 | // assert once stages insert their own samplers. |
| 63 | // this->printUnused(uni); |
egdaniel | 09aa1fc | 2016-04-20 07:09:46 -0700 | [diff] [blame] | 64 | } |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 65 | } |
| 66 | } |
| 67 | |
fmenozzi | 497e9e2 | 2016-06-21 09:42:12 -0700 | [diff] [blame] | 68 | void GrGLProgramDataManager::set1i(UniformHandle u, int32_t i) const { |
| 69 | const Uniform& uni = fUniforms[u.toIndex()]; |
| 70 | SkASSERT(uni.fType == kInt_GrSLType); |
| 71 | SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); |
| 72 | SkDEBUGCODE(this->printUnused(uni)); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame^] | 73 | if (kUnusedUniform != uni.fLocation) { |
| 74 | GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fLocation, i)); |
fmenozzi | 497e9e2 | 2016-06-21 09:42:12 -0700 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
fmenozzi | 35a98c7 | 2016-07-20 08:26:12 -0700 | [diff] [blame] | 78 | void GrGLProgramDataManager::set1iv(UniformHandle u, |
| 79 | int arrayCount, |
| 80 | const int v[]) const { |
| 81 | const Uniform& uni = fUniforms[u.toIndex()]; |
| 82 | SkASSERT(uni.fType == kInt_GrSLType); |
| 83 | SkASSERT(arrayCount > 0); |
| 84 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame^] | 85 | if (kUnusedUniform != uni.fLocation) { |
| 86 | GR_GL_CALL(fGpu->glInterface(), Uniform1iv(uni.fLocation, arrayCount, v)); |
fmenozzi | 35a98c7 | 2016-07-20 08:26:12 -0700 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 90 | void GrGLProgramDataManager::set1f(UniformHandle u, float v0) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 91 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 92 | SkASSERT(uni.fType == kFloat_GrSLType); |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 93 | SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 94 | SkDEBUGCODE(this->printUnused(uni);) |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame^] | 95 | if (kUnusedUniform != uni.fLocation) { |
| 96 | GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fLocation, v0)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 100 | void GrGLProgramDataManager::set1fv(UniformHandle u, |
| 101 | int arrayCount, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 102 | const float v[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 103 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 104 | SkASSERT(uni.fType == kFloat_GrSLType); |
| 105 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 106 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 107 | // This assert fires in some instances of the two-pt gradient for its VSParams. |
| 108 | // Once the uniform manager is responsible for inserting the duplicate uniform |
| 109 | // arrays in VS and FS driver bug workaround, this can be enabled. |
joshualitt | af2d56d | 2015-05-11 06:21:34 -0700 | [diff] [blame] | 110 | // this->printUni(uni); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame^] | 111 | if (kUnusedUniform != uni.fLocation) { |
| 112 | GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 116 | void GrGLProgramDataManager::set2f(UniformHandle u, float v0, float v1) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 117 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 118 | SkASSERT(uni.fType == kVec2f_GrSLType); |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 119 | SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 120 | SkDEBUGCODE(this->printUnused(uni);) |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame^] | 121 | if (kUnusedUniform != uni.fLocation) { |
| 122 | GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fLocation, v0, v1)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 126 | void GrGLProgramDataManager::set2fv(UniformHandle u, |
| 127 | int arrayCount, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 128 | const float v[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 129 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 130 | SkASSERT(uni.fType == kVec2f_GrSLType); |
| 131 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 132 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 133 | SkDEBUGCODE(this->printUnused(uni);) |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame^] | 134 | if (kUnusedUniform != uni.fLocation) { |
| 135 | GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 139 | void GrGLProgramDataManager::set3f(UniformHandle u, float v0, float v1, float v2) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 140 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 141 | SkASSERT(uni.fType == kVec3f_GrSLType); |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 142 | SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 143 | SkDEBUGCODE(this->printUnused(uni);) |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame^] | 144 | if (kUnusedUniform != uni.fLocation) { |
| 145 | GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fLocation, v0, v1, v2)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 149 | void GrGLProgramDataManager::set3fv(UniformHandle u, |
| 150 | int arrayCount, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 151 | const float v[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 152 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 153 | SkASSERT(uni.fType == kVec3f_GrSLType); |
| 154 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 155 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 156 | SkDEBUGCODE(this->printUnused(uni);) |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame^] | 157 | if (kUnusedUniform != uni.fLocation) { |
| 158 | GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 162 | void GrGLProgramDataManager::set4f(UniformHandle u, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 163 | float v0, |
| 164 | float v1, |
| 165 | float v2, |
| 166 | float v3) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 167 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 168 | SkASSERT(uni.fType == kVec4f_GrSLType); |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 169 | SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 170 | SkDEBUGCODE(this->printUnused(uni);) |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame^] | 171 | if (kUnusedUniform != uni.fLocation) { |
| 172 | GR_GL_CALL(fGpu->glInterface(), Uniform4f(uni.fLocation, v0, v1, v2, v3)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 173 | } |
| 174 | } |
| 175 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 176 | void GrGLProgramDataManager::set4fv(UniformHandle u, |
| 177 | int arrayCount, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 178 | const float v[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 179 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 180 | SkASSERT(uni.fType == kVec4f_GrSLType); |
| 181 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 182 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 183 | SkDEBUGCODE(this->printUnused(uni);) |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame^] | 184 | if (kUnusedUniform != uni.fLocation) { |
| 185 | GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 189 | void GrGLProgramDataManager::setMatrix2f(UniformHandle u, const float matrix[]) const { |
| 190 | this->setMatrices<2>(u, 1, matrix); |
| 191 | } |
| 192 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 193 | void GrGLProgramDataManager::setMatrix3f(UniformHandle u, const float matrix[]) const { |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 194 | this->setMatrices<3>(u, 1, matrix); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 195 | } |
| 196 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 197 | void GrGLProgramDataManager::setMatrix4f(UniformHandle u, const float matrix[]) const { |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 198 | this->setMatrices<4>(u, 1, matrix); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 199 | } |
| 200 | |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 201 | void GrGLProgramDataManager::setMatrix2fv(UniformHandle u, int arrayCount, const float m[]) const { |
| 202 | this->setMatrices<2>(u, arrayCount, m); |
| 203 | } |
| 204 | |
| 205 | void GrGLProgramDataManager::setMatrix3fv(UniformHandle u, int arrayCount, const float m[]) const { |
| 206 | this->setMatrices<3>(u, arrayCount, m); |
| 207 | } |
| 208 | |
| 209 | void GrGLProgramDataManager::setMatrix4fv(UniformHandle u, int arrayCount, const float m[]) const { |
| 210 | this->setMatrices<4>(u, arrayCount, m); |
| 211 | } |
| 212 | |
| 213 | template<int N> struct set_uniform_matrix; |
| 214 | |
| 215 | template<int N> inline void GrGLProgramDataManager::setMatrices(UniformHandle u, |
| 216 | int arrayCount, |
| 217 | const float matrices[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 218 | const Uniform& uni = fUniforms[u.toIndex()]; |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 219 | SkASSERT(uni.fType == kMat22f_GrSLType + (N - 2)); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 220 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 221 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 222 | SkDEBUGCODE(this->printUnused(uni);) |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame^] | 223 | if (kUnusedUniform != uni.fLocation) { |
| 224 | set_uniform_matrix<N>::set(fGpu->glInterface(), uni.fLocation, arrayCount, matrices); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 228 | template<> struct set_uniform_matrix<2> { |
| 229 | inline static void set(const GrGLInterface* gli, const GrGLint loc, int cnt, const float m[]) { |
| 230 | GR_GL_CALL(gli, UniformMatrix2fv(loc, cnt, false, m)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 231 | } |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 232 | }; |
| 233 | |
| 234 | template<> struct set_uniform_matrix<3> { |
| 235 | inline static void set(const GrGLInterface* gli, const GrGLint loc, int cnt, const float m[]) { |
| 236 | GR_GL_CALL(gli, UniformMatrix3fv(loc, cnt, false, m)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 237 | } |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 238 | }; |
| 239 | |
| 240 | template<> struct set_uniform_matrix<4> { |
| 241 | inline static void set(const GrGLInterface* gli, const GrGLint loc, int cnt, const float m[]) { |
| 242 | GR_GL_CALL(gli, UniformMatrix4fv(loc, cnt, false, m)); |
| 243 | } |
| 244 | }; |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 245 | |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 246 | void GrGLProgramDataManager::setPathFragmentInputTransform(VaryingHandle u, |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 247 | int components, |
| 248 | const SkMatrix& matrix) const { |
| 249 | SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport()); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 250 | const PathProcVarying& fragmentInput = fPathProcVaryings[u.toIndex()]; |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 251 | |
| 252 | SkASSERT((components == 2 && fragmentInput.fType == kVec2f_GrSLType) || |
| 253 | (components == 3 && fragmentInput.fType == kVec3f_GrSLType)); |
| 254 | |
| 255 | fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID, |
| 256 | fragmentInput.fLocation, |
| 257 | GR_GL_OBJECT_LINEAR, |
| 258 | components, |
| 259 | matrix); |
| 260 | } |
| 261 | |
joshualitt | af2d56d | 2015-05-11 06:21:34 -0700 | [diff] [blame] | 262 | #ifdef SK_DEBUG |
| 263 | void GrGLProgramDataManager::printUnused(const Uniform& uni) const { |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame^] | 264 | if (kUnusedUniform == uni.fLocation) { |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 265 | GrCapsDebugf(fGpu->caps(), "Unused uniform in shader\n"); |
joshualitt | af2d56d | 2015-05-11 06:21:34 -0700 | [diff] [blame] | 266 | } |
| 267 | } |
| 268 | #endif |