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