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 | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame^] | 18 | GrGLProgramDataManager::GrGLProgramDataManager(GrGpuGL* gpu) : fGpu(gpu) { |
commit-bot@chromium.org | c72425a | 2014-01-21 16:09:18 +0000 | [diff] [blame] | 19 | // skbug.com/2056 |
| 20 | fUsingBindUniform = fGpu->glInterface()->fFunctions.fBindUniformLocation != NULL; |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 21 | } |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 22 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame^] | 23 | GrGLProgramDataManager::UniformHandle GrGLProgramDataManager::appendUniform(GrSLType type, int arrayCount) { |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 24 | int idx = fUniforms.count(); |
| 25 | Uniform& uni = fUniforms.push_back(); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 26 | SkASSERT(GrGLShaderVar::kNonArray == arrayCount || arrayCount > 0); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 27 | uni.fArrayCount = arrayCount; |
| 28 | uni.fType = type; |
| 29 | uni.fVSLocation = kUnusedUniform; |
| 30 | uni.fFSLocation = kUnusedUniform; |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame^] | 31 | return GrGLProgramDataManager::UniformHandle::CreateFromUniformIndex(idx); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 32 | } |
| 33 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame^] | 34 | void GrGLProgramDataManager::setSampler(UniformHandle u, GrGLint texUnit) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 35 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 36 | SkASSERT(uni.fType == kSampler2D_GrSLType); |
| 37 | SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
bsalomon@google.com | 0982d35 | 2012-07-31 15:33:25 +0000 | [diff] [blame] | 38 | // FIXME: We still insert a single sampler uniform for every stage. If the shader does not |
| 39 | // reference the sampler then the compiler may have optimized it out. Uncomment this assert |
| 40 | // once stages insert their own samplers. |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 41 | // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 42 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 43 | GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fFSLocation, texUnit)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 44 | } |
| 45 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 46 | GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fVSLocation, texUnit)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame^] | 50 | void GrGLProgramDataManager::set1f(UniformHandle u, GrGLfloat v0) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 51 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 52 | SkASSERT(uni.fType == kFloat_GrSLType); |
| 53 | SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
| 54 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 55 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 56 | GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fFSLocation, v0)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 57 | } |
| 58 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 59 | GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fVSLocation, v0)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame^] | 63 | void GrGLProgramDataManager::set1fv(UniformHandle u, |
| 64 | int arrayCount, |
| 65 | const GrGLfloat v[]) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 66 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 67 | SkASSERT(uni.fType == kFloat_GrSLType); |
| 68 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 69 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 70 | // This assert fires in some instances of the two-pt gradient for its VSParams. |
| 71 | // Once the uniform manager is responsible for inserting the duplicate uniform |
| 72 | // 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] | 73 | //SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 74 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 75 | GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fFSLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 76 | } |
| 77 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 78 | GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fVSLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame^] | 82 | void GrGLProgramDataManager::set2f(UniformHandle u, GrGLfloat v0, GrGLfloat v1) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 83 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 84 | SkASSERT(uni.fType == kVec2f_GrSLType); |
| 85 | SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
| 86 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 87 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 88 | GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fFSLocation, v0, v1)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 89 | } |
| 90 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 91 | GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fVSLocation, v0, v1)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame^] | 95 | void GrGLProgramDataManager::set2fv(UniformHandle u, |
| 96 | int arrayCount, |
| 97 | const GrGLfloat v[]) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 98 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 99 | SkASSERT(uni.fType == kVec2f_GrSLType); |
| 100 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 101 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
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(), Uniform2fv(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(), Uniform2fv(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::set3f(UniformHandle u, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 112 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 113 | SkASSERT(uni.fType == kVec3f_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(), Uniform3f(uni.fFSLocation, v0, v1, v2)); |
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(), Uniform3f(uni.fVSLocation, v0, v1, v2)); |
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::set3fv(UniformHandle u, |
| 125 | int arrayCount, |
| 126 | const GrGLfloat v[]) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 127 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 128 | SkASSERT(uni.fType == kVec3f_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(), Uniform3fv(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(), Uniform3fv(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::set4f(UniformHandle u, |
| 141 | GrGLfloat v0, |
| 142 | GrGLfloat v1, |
| 143 | GrGLfloat v2, |
| 144 | GrGLfloat v3) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 145 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 146 | SkASSERT(uni.fType == kVec4f_GrSLType); |
| 147 | SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
| 148 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 149 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 150 | 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] | 151 | } |
| 152 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 153 | 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] | 154 | } |
| 155 | } |
| 156 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame^] | 157 | void GrGLProgramDataManager::set4fv(UniformHandle u, |
| 158 | int arrayCount, |
| 159 | const GrGLfloat v[]) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 160 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 161 | SkASSERT(uni.fType == kVec4f_GrSLType); |
| 162 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 163 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 164 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 165 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 166 | GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fFSLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 167 | } |
| 168 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 169 | GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fVSLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 170 | } |
| 171 | } |
| 172 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame^] | 173 | void GrGLProgramDataManager::setMatrix3f(UniformHandle u, const GrGLfloat matrix[]) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 174 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 175 | SkASSERT(uni.fType == kMat33f_GrSLType); |
| 176 | SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
bsalomon@google.com | 8ea78d8 | 2012-10-24 20:11:30 +0000 | [diff] [blame] | 177 | // 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] | 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 | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 180 | GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fFSLocation, 1, false, matrix)); |
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 | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 183 | GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fVSLocation, 1, false, matrix)); |
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::setMatrix4f(UniformHandle u, const GrGLfloat matrix[]) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 188 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 189 | SkASSERT(uni.fType == kMat44f_GrSLType); |
| 190 | SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
| 191 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 192 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 193 | GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fFSLocation, 1, false, matrix)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 194 | } |
| 195 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 196 | GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fVSLocation, 1, false, matrix)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 197 | } |
| 198 | } |
| 199 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame^] | 200 | void GrGLProgramDataManager::setMatrix3fv(UniformHandle u, |
| 201 | int arrayCount, |
| 202 | const GrGLfloat matrices[]) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 203 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 204 | SkASSERT(uni.fType == kMat33f_GrSLType); |
| 205 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 206 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
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(), |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 210 | UniformMatrix3fv(uni.fFSLocation, arrayCount, false, matrices)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 211 | } |
| 212 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 213 | GR_GL_CALL(fGpu->glInterface(), |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 214 | UniformMatrix3fv(uni.fVSLocation, arrayCount, false, matrices)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame^] | 218 | void GrGLProgramDataManager::setMatrix4fv(UniformHandle u, |
| 219 | int arrayCount, |
| 220 | const GrGLfloat matrices[]) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 221 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 222 | SkASSERT(uni.fType == kMat44f_GrSLType); |
| 223 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 224 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 225 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 226 | if (kUnusedUniform != 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 | UniformMatrix4fv(uni.fFSLocation, arrayCount, false, matrices)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 229 | } |
| 230 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 231 | GR_GL_CALL(fGpu->glInterface(), |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 232 | UniformMatrix4fv(uni.fVSLocation, arrayCount, false, matrices)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame^] | 236 | void GrGLProgramDataManager::setSkMatrix(UniformHandle u, const SkMatrix& matrix) const { |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 237 | GrGLfloat mt[] = { |
| 238 | matrix.get(SkMatrix::kMScaleX), |
| 239 | matrix.get(SkMatrix::kMSkewY), |
| 240 | matrix.get(SkMatrix::kMPersp0), |
| 241 | matrix.get(SkMatrix::kMSkewX), |
| 242 | matrix.get(SkMatrix::kMScaleY), |
| 243 | matrix.get(SkMatrix::kMPersp1), |
| 244 | matrix.get(SkMatrix::kMTransX), |
| 245 | matrix.get(SkMatrix::kMTransY), |
| 246 | matrix.get(SkMatrix::kMPersp2), |
| 247 | }; |
| 248 | this->setMatrix3f(u, mt); |
| 249 | } |
| 250 | |
| 251 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame^] | 252 | void GrGLProgramDataManager::getUniformLocations(GrGLuint programID, const BuilderUniformArray& uniforms) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 253 | SkASSERT(uniforms.count() == fUniforms.count()); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 254 | int count = fUniforms.count(); |
| 255 | for (int i = 0; i < count; ++i) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 256 | SkASSERT(uniforms[i].fVariable.getType() == fUniforms[i].fType); |
| 257 | SkASSERT(uniforms[i].fVariable.getArrayCount() == fUniforms[i].fArrayCount); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 258 | GrGLint location; |
| 259 | // TODO: Move the Xoom uniform array in both FS and VS bug workaround here. |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 260 | if (fUsingBindUniform) { |
| 261 | location = i; |
| 262 | GR_GL_CALL(fGpu->glInterface(), |
| 263 | BindUniformLocation(programID, location, uniforms[i].fVariable.c_str())); |
| 264 | } else { |
| 265 | GR_GL_CALL_RET(fGpu->glInterface(), location, |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 266 | GetUniformLocation(programID, uniforms[i].fVariable.c_str())); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 267 | } |
commit-bot@chromium.org | 74a3a21 | 2013-08-30 19:43:59 +0000 | [diff] [blame] | 268 | if (GrGLShaderBuilder::kVertex_Visibility & uniforms[i].fVisibility) { |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 269 | fUniforms[i].fVSLocation = location; |
| 270 | } |
commit-bot@chromium.org | 74a3a21 | 2013-08-30 19:43:59 +0000 | [diff] [blame] | 271 | if (GrGLShaderBuilder::kFragment_Visibility & uniforms[i].fVisibility) { |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 272 | fUniforms[i].fFSLocation = location; |
| 273 | } |
| 274 | } |
| 275 | } |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 276 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame^] | 277 | const GrGLProgramDataManager::BuilderUniform& |
| 278 | GrGLProgramDataManager::getBuilderUniform(const BuilderUniformArray& array, UniformHandle handle) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 279 | return array[handle.toUniformIndex()]; |
| 280 | } |