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