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