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 | |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 8 | #include "gl/builders/GrGLProgramBuilder.h" |
kkinnunen | ec56e45 | 2014-08-25 22:21:16 -0700 | [diff] [blame^] | 9 | #include "gl/GrGLPathRendering.h" |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 10 | #include "gl/GrGLProgram.h" |
| 11 | #include "gl/GrGLUniformHandle.h" |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 12 | #include "gl/GrGpuGL.h" |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 13 | #include "SkMatrix.h" |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 14 | |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 15 | #define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(UNI, COUNT) \ |
| 16 | SkASSERT(arrayCount <= uni.fArrayCount || \ |
| 17 | (1 == arrayCount && GrGLShaderVar::kNonArray == uni.fArrayCount)) |
| 18 | |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 19 | GrGLProgramDataManager::GrGLProgramDataManager(GrGpuGL* gpu, |
kkinnunen | ec56e45 | 2014-08-25 22:21:16 -0700 | [diff] [blame^] | 20 | GrGLProgram* program, |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 21 | const GrGLProgramBuilder& builder) |
kkinnunen | ec56e45 | 2014-08-25 22:21:16 -0700 | [diff] [blame^] | 22 | : fGpu(gpu), |
| 23 | fProgram(program) { |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 24 | int count = builder.getUniformInfos().count(); |
| 25 | fUniforms.push_back_n(count); |
| 26 | for (int i = 0; i < count; i++) { |
| 27 | Uniform& uniform = fUniforms[i]; |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 28 | const GrGLProgramBuilder::UniformInfo& builderUniform = builder.getUniformInfos()[i]; |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 29 | SkASSERT(GrGLShaderVar::kNonArray == builderUniform.fVariable.getArrayCount() || |
| 30 | builderUniform.fVariable.getArrayCount() > 0); |
| 31 | SkDEBUGCODE( |
| 32 | uniform.fArrayCount = builderUniform.fVariable.getArrayCount(); |
| 33 | uniform.fType = builderUniform.fVariable.getType(); |
| 34 | ); |
| 35 | // 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] | 36 | |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 37 | if (GrGLProgramBuilder::kVertex_Visibility & builderUniform.fVisibility) { |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 38 | uniform.fVSLocation = builderUniform.fLocation; |
| 39 | } else { |
| 40 | uniform.fVSLocation = kUnusedUniform; |
| 41 | } |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 42 | if (GrGLProgramBuilder::kFragment_Visibility & builderUniform.fVisibility) { |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 43 | uniform.fFSLocation = builderUniform.fLocation; |
| 44 | } else { |
| 45 | uniform.fFSLocation = kUnusedUniform; |
| 46 | } |
| 47 | } |
kkinnunen | ec56e45 | 2014-08-25 22:21:16 -0700 | [diff] [blame^] | 48 | |
| 49 | count = builder.getSeparableVaryingInfos().count(); |
| 50 | fVaryings.push_back_n(count); |
| 51 | for (int i = 0; i < count; i++) { |
| 52 | Varying& varying = fVaryings[i]; |
| 53 | const GrGLProgramBuilder::SeparableVaryingInfo& builderVarying = |
| 54 | builder.getSeparableVaryingInfos()[i]; |
| 55 | SkASSERT(GrGLShaderVar::kNonArray == builderVarying.fVariable.getArrayCount()); |
| 56 | SkDEBUGCODE( |
| 57 | varying.fType = builderVarying.fVariable.getType(); |
| 58 | ); |
| 59 | varying.fLocation = builderVarying.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 { |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 64 | const Uniform& uni = fUniforms[u.toProgramDataIndex()]; |
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. |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 70 | // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
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 { |
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(GrGLShaderVar::kNonArray == uni.fArrayCount); |
| 83 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
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 { |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 95 | const Uniform& uni = fUniforms[u.toProgramDataIndex()]; |
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. |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 102 | //SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
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 { |
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(GrGLShaderVar::kNonArray == uni.fArrayCount); |
| 115 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
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 { |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 127 | const Uniform& uni = fUniforms[u.toProgramDataIndex()]; |
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); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 131 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
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 { |
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(GrGLShaderVar::kNonArray == uni.fArrayCount); |
| 144 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
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 { |
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 == 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); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 160 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
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 { |
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(GrGLShaderVar::kNonArray == uni.fArrayCount); |
| 177 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
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 { |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 189 | const Uniform& uni = fUniforms[u.toProgramDataIndex()]; |
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); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 193 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
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 { |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 203 | const Uniform& uni = fUniforms[u.toProgramDataIndex()]; |
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); |
bsalomon@google.com | 8ea78d8 | 2012-10-24 20:11:30 +0000 | [diff] [blame] | 206 | // 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] | 207 | // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 208 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 209 | GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fFSLocation, 1, false, matrix)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 210 | } |
| 211 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 212 | GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fVSLocation, 1, false, matrix)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 213 | } |
| 214 | } |
| 215 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 216 | void GrGLProgramDataManager::setMatrix4f(UniformHandle u, const GrGLfloat matrix[]) 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 == kMat44f_GrSLType); |
| 219 | SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
| 220 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 221 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 222 | GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fFSLocation, 1, false, matrix)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 223 | } |
| 224 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 225 | GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fVSLocation, 1, false, matrix)); |
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::setMatrix3fv(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 == kMat33f_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 | UniformMatrix3fv(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 | UniformMatrix3fv(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::setMatrix4fv(UniformHandle u, |
| 248 | int arrayCount, |
| 249 | const GrGLfloat matrices[]) const { |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 250 | const Uniform& uni = fUniforms[u.toProgramDataIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 251 | SkASSERT(uni.fType == kMat44f_GrSLType); |
| 252 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 253 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 254 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 255 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 256 | GR_GL_CALL(fGpu->glInterface(), |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 257 | UniformMatrix4fv(uni.fFSLocation, arrayCount, false, matrices)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 258 | } |
| 259 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 260 | GR_GL_CALL(fGpu->glInterface(), |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 261 | UniformMatrix4fv(uni.fVSLocation, arrayCount, false, matrices)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 265 | void GrGLProgramDataManager::setSkMatrix(UniformHandle u, const SkMatrix& matrix) const { |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 266 | GrGLfloat mt[] = { |
| 267 | matrix.get(SkMatrix::kMScaleX), |
| 268 | matrix.get(SkMatrix::kMSkewY), |
| 269 | matrix.get(SkMatrix::kMPersp0), |
| 270 | matrix.get(SkMatrix::kMSkewX), |
| 271 | matrix.get(SkMatrix::kMScaleY), |
| 272 | matrix.get(SkMatrix::kMPersp1), |
| 273 | matrix.get(SkMatrix::kMTransX), |
| 274 | matrix.get(SkMatrix::kMTransY), |
| 275 | matrix.get(SkMatrix::kMPersp2), |
| 276 | }; |
| 277 | this->setMatrix3f(u, mt); |
| 278 | } |
kkinnunen | ec56e45 | 2014-08-25 22:21:16 -0700 | [diff] [blame^] | 279 | |
| 280 | void GrGLProgramDataManager::setProgramPathFragmentInputTransform(VaryingHandle i, |
| 281 | unsigned components, |
| 282 | const SkMatrix& matrix) const { |
| 283 | const Varying& fragmentInput = fVaryings[i.toProgramDataIndex()]; |
| 284 | fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgram->programID(), |
| 285 | fragmentInput.fLocation, |
| 286 | GR_GL_OBJECT_LINEAR, |
| 287 | components, |
| 288 | matrix); |
| 289 | } |