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" |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 10 | #include "gl/GrGpuGL.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 | |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame^] | 17 | GrGLProgramDataManager::GrGLProgramDataManager(GrGpuGL* gpu, const UniformInfoArray& uniforms) |
| 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. |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 52 | // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
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); |
| 65 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
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. |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 84 | //SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
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); |
| 97 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
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); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 113 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
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); |
| 126 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
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); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 142 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
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); |
| 159 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
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); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 175 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
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); |
bsalomon@google.com | 8ea78d8 | 2012-10-24 20:11:30 +0000 | [diff] [blame] | 188 | // TODO: Re-enable this assert once texture matrices aren't forced on all effects |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 189 | // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 190 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 191 | GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fFSLocation, 1, false, matrix)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 192 | } |
| 193 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 194 | GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fVSLocation, 1, false, matrix)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 198 | void GrGLProgramDataManager::setMatrix4f(UniformHandle u, const GrGLfloat matrix[]) const { |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 199 | const Uniform& uni = fUniforms[u.toProgramDataIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 200 | SkASSERT(uni.fType == kMat44f_GrSLType); |
| 201 | SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
| 202 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 203 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 204 | GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fFSLocation, 1, false, matrix)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 205 | } |
| 206 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 207 | GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fVSLocation, 1, false, matrix)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 211 | void GrGLProgramDataManager::setMatrix3fv(UniformHandle u, |
| 212 | int arrayCount, |
| 213 | const GrGLfloat matrices[]) const { |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 214 | const Uniform& uni = fUniforms[u.toProgramDataIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 215 | SkASSERT(uni.fType == kMat33f_GrSLType); |
| 216 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 217 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 218 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 219 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 220 | GR_GL_CALL(fGpu->glInterface(), |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 221 | UniformMatrix3fv(uni.fFSLocation, arrayCount, false, matrices)); |
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(), |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 225 | UniformMatrix3fv(uni.fVSLocation, arrayCount, false, matrices)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 229 | void GrGLProgramDataManager::setMatrix4fv(UniformHandle u, |
| 230 | int arrayCount, |
| 231 | const GrGLfloat matrices[]) const { |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 232 | const Uniform& uni = fUniforms[u.toProgramDataIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 233 | SkASSERT(uni.fType == kMat44f_GrSLType); |
| 234 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 235 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 236 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 237 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 238 | GR_GL_CALL(fGpu->glInterface(), |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 239 | UniformMatrix4fv(uni.fFSLocation, arrayCount, false, matrices)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 240 | } |
| 241 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 242 | GR_GL_CALL(fGpu->glInterface(), |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 243 | UniformMatrix4fv(uni.fVSLocation, arrayCount, false, matrices)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 247 | void GrGLProgramDataManager::setSkMatrix(UniformHandle u, const SkMatrix& matrix) const { |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 248 | GrGLfloat mt[] = { |
| 249 | matrix.get(SkMatrix::kMScaleX), |
| 250 | matrix.get(SkMatrix::kMSkewY), |
| 251 | matrix.get(SkMatrix::kMPersp0), |
| 252 | matrix.get(SkMatrix::kMSkewX), |
| 253 | matrix.get(SkMatrix::kMScaleY), |
| 254 | matrix.get(SkMatrix::kMPersp1), |
| 255 | matrix.get(SkMatrix::kMTransX), |
| 256 | matrix.get(SkMatrix::kMTransY), |
| 257 | matrix.get(SkMatrix::kMPersp2), |
| 258 | }; |
| 259 | this->setMatrix3f(u, mt); |
| 260 | } |