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" |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 11 | |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 12 | #define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(UNI, COUNT) \ |
| 13 | SkASSERT(arrayCount <= uni.fArrayCount || \ |
| 14 | (1 == arrayCount && GrGLShaderVar::kNonArray == uni.fArrayCount)) |
| 15 | |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame^] | 16 | GrGLProgramDataManager::GrGLProgramDataManager(GrGLGpu* gpu, GrGLuint programID, |
| 17 | const UniformInfoArray& uniforms, |
| 18 | const SeparableVaryingInfoArray& separableVaryings) |
| 19 | : fGpu(gpu) |
| 20 | , fProgramID(programID) { |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 21 | int count = uniforms.count(); |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 22 | fUniforms.push_back_n(count); |
| 23 | for (int i = 0; i < count; i++) { |
| 24 | Uniform& uniform = fUniforms[i]; |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 25 | const UniformInfo& builderUniform = uniforms[i]; |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 26 | SkASSERT(GrGLShaderVar::kNonArray == builderUniform.fVariable.getArrayCount() || |
| 27 | builderUniform.fVariable.getArrayCount() > 0); |
| 28 | SkDEBUGCODE( |
| 29 | uniform.fArrayCount = builderUniform.fVariable.getArrayCount(); |
| 30 | uniform.fType = builderUniform.fVariable.getType(); |
| 31 | ); |
| 32 | // 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] | 33 | |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 34 | if (GrGLProgramBuilder::kVertex_Visibility & builderUniform.fVisibility) { |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 35 | uniform.fVSLocation = builderUniform.fLocation; |
| 36 | } else { |
| 37 | uniform.fVSLocation = kUnusedUniform; |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 38 | } |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 39 | if (GrGLProgramBuilder::kFragment_Visibility & builderUniform.fVisibility) { |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 40 | uniform.fFSLocation = builderUniform.fLocation; |
| 41 | } else { |
| 42 | uniform.fFSLocation = kUnusedUniform; |
| 43 | } |
| 44 | } |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame^] | 45 | |
| 46 | // NVPR programs have separable varyings |
| 47 | count = separableVaryings.count(); |
| 48 | fSeparableVaryings.push_back_n(count); |
| 49 | for (int i = 0; i < count; i++) { |
| 50 | SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport()); |
| 51 | SeparableVarying& separableVarying = fSeparableVaryings[i]; |
| 52 | const SeparableVaryingInfo& builderSeparableVarying = separableVaryings[i]; |
| 53 | SkASSERT(GrGLShaderVar::kNonArray == builderSeparableVarying.fVariable.getArrayCount() || |
| 54 | builderSeparableVarying.fVariable.getArrayCount() > 0); |
| 55 | SkDEBUGCODE( |
| 56 | separableVarying.fArrayCount = builderSeparableVarying.fVariable.getArrayCount(); |
| 57 | separableVarying.fType = builderSeparableVarying.fVariable.getType(); |
| 58 | ); |
| 59 | separableVarying.fLocation = builderSeparableVarying.fLocation; |
| 60 | } |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 61 | } |
| 62 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 63 | void GrGLProgramDataManager::setSampler(UniformHandle u, GrGLint texUnit) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 64 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 65 | SkASSERT(uni.fType == kSampler2D_GrSLType); |
| 66 | SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
bsalomon@google.com | 0982d35 | 2012-07-31 15:33:25 +0000 | [diff] [blame] | 67 | // FIXME: We still insert a single sampler uniform for every stage. If the shader does not |
| 68 | // reference the sampler then the compiler may have optimized it out. Uncomment this assert |
| 69 | // once stages insert their own samplers. |
joshualitt | af2d56d | 2015-05-11 06:21:34 -0700 | [diff] [blame] | 70 | // this->printUnused(uni); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 71 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 72 | GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fFSLocation, texUnit)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 73 | } |
| 74 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 75 | GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fVSLocation, texUnit)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 79 | void GrGLProgramDataManager::set1f(UniformHandle u, GrGLfloat v0) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 80 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 81 | SkASSERT(uni.fType == kFloat_GrSLType); |
| 82 | SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 83 | SkDEBUGCODE(this->printUnused(uni);) |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 84 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 85 | GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fFSLocation, v0)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 86 | } |
| 87 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 88 | GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fVSLocation, v0)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 89 | } |
| 90 | } |
| 91 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 92 | void GrGLProgramDataManager::set1fv(UniformHandle u, |
| 93 | int arrayCount, |
| 94 | const GrGLfloat v[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 95 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 96 | SkASSERT(uni.fType == kFloat_GrSLType); |
| 97 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 98 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 99 | // This assert fires in some instances of the two-pt gradient for its VSParams. |
| 100 | // Once the uniform manager is responsible for inserting the duplicate uniform |
| 101 | // arrays in VS and FS driver bug workaround, this can be enabled. |
joshualitt | af2d56d | 2015-05-11 06:21:34 -0700 | [diff] [blame] | 102 | // this->printUni(uni); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 103 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 104 | GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fFSLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 105 | } |
| 106 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 107 | GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fVSLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 108 | } |
| 109 | } |
| 110 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 111 | void GrGLProgramDataManager::set2f(UniformHandle u, GrGLfloat v0, GrGLfloat v1) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 112 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 113 | SkASSERT(uni.fType == kVec2f_GrSLType); |
| 114 | SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 115 | SkDEBUGCODE(this->printUnused(uni);) |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 116 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 117 | GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fFSLocation, v0, v1)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 118 | } |
| 119 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 120 | GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fVSLocation, v0, v1)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 124 | void GrGLProgramDataManager::set2fv(UniformHandle u, |
| 125 | int arrayCount, |
| 126 | const GrGLfloat v[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 127 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 128 | SkASSERT(uni.fType == kVec2f_GrSLType); |
| 129 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 130 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 131 | SkDEBUGCODE(this->printUnused(uni);) |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 132 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 133 | GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fFSLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 134 | } |
| 135 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 136 | GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fVSLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 140 | void GrGLProgramDataManager::set3f(UniformHandle u, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 141 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 142 | SkASSERT(uni.fType == kVec3f_GrSLType); |
| 143 | SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 144 | SkDEBUGCODE(this->printUnused(uni);) |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 145 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 146 | GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fFSLocation, v0, v1, v2)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 147 | } |
| 148 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 149 | GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fVSLocation, v0, v1, v2)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 153 | void GrGLProgramDataManager::set3fv(UniformHandle u, |
| 154 | int arrayCount, |
| 155 | const GrGLfloat v[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 156 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 157 | SkASSERT(uni.fType == kVec3f_GrSLType); |
| 158 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 159 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 160 | SkDEBUGCODE(this->printUnused(uni);) |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 161 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 162 | GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fFSLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 163 | } |
| 164 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 165 | GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fVSLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 169 | void GrGLProgramDataManager::set4f(UniformHandle u, |
| 170 | GrGLfloat v0, |
| 171 | GrGLfloat v1, |
| 172 | GrGLfloat v2, |
| 173 | GrGLfloat v3) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 174 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 175 | SkASSERT(uni.fType == kVec4f_GrSLType); |
| 176 | SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 177 | SkDEBUGCODE(this->printUnused(uni);) |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 178 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 179 | 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] | 180 | } |
| 181 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 182 | 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] | 183 | } |
| 184 | } |
| 185 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 186 | void GrGLProgramDataManager::set4fv(UniformHandle u, |
| 187 | int arrayCount, |
| 188 | const GrGLfloat v[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 189 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 190 | SkASSERT(uni.fType == kVec4f_GrSLType); |
| 191 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 192 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 193 | SkDEBUGCODE(this->printUnused(uni);) |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 194 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 195 | GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fFSLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 196 | } |
| 197 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 198 | GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fVSLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 199 | } |
| 200 | } |
| 201 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 202 | void GrGLProgramDataManager::setMatrix3f(UniformHandle u, const GrGLfloat matrix[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 203 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 204 | SkASSERT(uni.fType == kMat33f_GrSLType); |
| 205 | SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 206 | SkDEBUGCODE(this->printUnused(uni);) |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 207 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 208 | GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fFSLocation, 1, false, matrix)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 209 | } |
| 210 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 211 | GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fVSLocation, 1, false, matrix)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 215 | void GrGLProgramDataManager::setMatrix4f(UniformHandle u, const GrGLfloat matrix[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 216 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 217 | SkASSERT(uni.fType == kMat44f_GrSLType); |
| 218 | SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
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 | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 221 | GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fFSLocation, 1, false, matrix)); |
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 | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 224 | GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fVSLocation, 1, false, matrix)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 228 | void GrGLProgramDataManager::setMatrix3fv(UniformHandle u, |
| 229 | int arrayCount, |
| 230 | const GrGLfloat matrices[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 231 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 232 | SkASSERT(uni.fType == kMat33f_GrSLType); |
| 233 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 234 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 235 | SkDEBUGCODE(this->printUnused(uni);) |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 236 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 237 | GR_GL_CALL(fGpu->glInterface(), |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 238 | UniformMatrix3fv(uni.fFSLocation, arrayCount, false, matrices)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 239 | } |
| 240 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 241 | GR_GL_CALL(fGpu->glInterface(), |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 242 | UniformMatrix3fv(uni.fVSLocation, arrayCount, false, matrices)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 246 | void GrGLProgramDataManager::setMatrix4fv(UniformHandle u, |
| 247 | int arrayCount, |
| 248 | const GrGLfloat matrices[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 249 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 250 | SkASSERT(uni.fType == kMat44f_GrSLType); |
| 251 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 252 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 253 | SkDEBUGCODE(this->printUnused(uni);) |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 254 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 255 | GR_GL_CALL(fGpu->glInterface(), |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 256 | UniformMatrix4fv(uni.fFSLocation, arrayCount, false, matrices)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 257 | } |
| 258 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 259 | GR_GL_CALL(fGpu->glInterface(), |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 260 | UniformMatrix4fv(uni.fVSLocation, arrayCount, false, matrices)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 264 | void GrGLProgramDataManager::setSkMatrix(UniformHandle u, const SkMatrix& matrix) const { |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 265 | GrGLfloat mt[] = { |
| 266 | matrix.get(SkMatrix::kMScaleX), |
| 267 | matrix.get(SkMatrix::kMSkewY), |
| 268 | matrix.get(SkMatrix::kMPersp0), |
| 269 | matrix.get(SkMatrix::kMSkewX), |
| 270 | matrix.get(SkMatrix::kMScaleY), |
| 271 | matrix.get(SkMatrix::kMPersp1), |
| 272 | matrix.get(SkMatrix::kMTransX), |
| 273 | matrix.get(SkMatrix::kMTransY), |
| 274 | matrix.get(SkMatrix::kMPersp2), |
| 275 | }; |
| 276 | this->setMatrix3f(u, mt); |
| 277 | } |
joshualitt | af2d56d | 2015-05-11 06:21:34 -0700 | [diff] [blame] | 278 | |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame^] | 279 | void GrGLProgramDataManager::setPathFragmentInputTransform(SeparableVaryingHandle u, |
| 280 | int components, |
| 281 | const SkMatrix& matrix) const { |
| 282 | SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport()); |
| 283 | const SeparableVarying& fragmentInput = fSeparableVaryings[u.toIndex()]; |
| 284 | |
| 285 | SkASSERT((components == 2 && fragmentInput.fType == kVec2f_GrSLType) || |
| 286 | (components == 3 && fragmentInput.fType == kVec3f_GrSLType)); |
| 287 | |
| 288 | fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID, |
| 289 | fragmentInput.fLocation, |
| 290 | GR_GL_OBJECT_LINEAR, |
| 291 | components, |
| 292 | matrix); |
| 293 | } |
| 294 | |
joshualitt | af2d56d | 2015-05-11 06:21:34 -0700 | [diff] [blame] | 295 | #ifdef SK_DEBUG |
| 296 | void GrGLProgramDataManager::printUnused(const Uniform& uni) const { |
| 297 | if (kUnusedUniform == uni.fFSLocation && kUnusedUniform == uni.fVSLocation) { |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 298 | GrCapsDebugf(fGpu->caps(), "Unused uniform in shader\n"); |
joshualitt | af2d56d | 2015-05-11 06:21:34 -0700 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | #endif |