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 | |
| 14 | #define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(UNI, OFFSET, COUNT) \ |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 15 | SkASSERT(offset + arrayCount <= uni.fArrayCount || \ |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 16 | (0 == offset && 1 == arrayCount && GrGLShaderVar::kNonArray == uni.fArrayCount)) |
| 17 | |
| 18 | GrGLUniformManager::UniformHandle GrGLUniformManager::appendUniform(GrSLType type, int arrayCount) { |
| 19 | int idx = fUniforms.count(); |
| 20 | Uniform& uni = fUniforms.push_back(); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 21 | SkASSERT(GrGLShaderVar::kNonArray == arrayCount || arrayCount > 0); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 22 | uni.fArrayCount = arrayCount; |
| 23 | uni.fType = type; |
| 24 | uni.fVSLocation = kUnusedUniform; |
| 25 | uni.fFSLocation = kUnusedUniform; |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 26 | return GrGLUniformManager::UniformHandle::CreateFromUniformIndex(idx); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | void GrGLUniformManager::setSampler(UniformHandle u, GrGLint texUnit) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 30 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 31 | SkASSERT(uni.fType == kSampler2D_GrSLType); |
| 32 | SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
bsalomon@google.com | 0982d35 | 2012-07-31 15:33:25 +0000 | [diff] [blame] | 33 | // FIXME: We still insert a single sampler uniform for every stage. If the shader does not |
| 34 | // reference the sampler then the compiler may have optimized it out. Uncomment this assert |
| 35 | // once stages insert their own samplers. |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 36 | // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 37 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 38 | GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fFSLocation, texUnit)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 39 | } |
| 40 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 41 | GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fVSLocation, texUnit)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | |
| 45 | void GrGLUniformManager::set1f(UniformHandle u, GrGLfloat v0) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 46 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 47 | SkASSERT(uni.fType == kFloat_GrSLType); |
| 48 | SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
| 49 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 50 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 51 | GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fFSLocation, v0)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 52 | } |
| 53 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 54 | GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fVSLocation, v0)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | |
| 58 | void GrGLUniformManager::set1fv(UniformHandle u, |
| 59 | int offset, |
| 60 | int arrayCount, |
| 61 | const GrGLfloat v[]) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 62 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 63 | SkASSERT(uni.fType == kFloat_GrSLType); |
| 64 | SkASSERT(arrayCount > 0); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 65 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount); |
| 66 | // This assert fires in some instances of the two-pt gradient for its VSParams. |
| 67 | // Once the uniform manager is responsible for inserting the duplicate uniform |
| 68 | // 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] | 69 | //SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 70 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 71 | GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fFSLocation + offset, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 72 | } |
| 73 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 74 | GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fVSLocation + offset, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
| 78 | void GrGLUniformManager::set2f(UniformHandle u, GrGLfloat v0, GrGLfloat v1) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 79 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 80 | SkASSERT(uni.fType == kVec2f_GrSLType); |
| 81 | SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
| 82 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 83 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 84 | GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fFSLocation, v0, v1)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 85 | } |
| 86 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 87 | GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fVSLocation, v0, v1)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | |
| 91 | void GrGLUniformManager::set2fv(UniformHandle u, |
| 92 | int offset, |
| 93 | int arrayCount, |
| 94 | const GrGLfloat v[]) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 95 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 96 | SkASSERT(uni.fType == kVec2f_GrSLType); |
| 97 | SkASSERT(arrayCount > 0); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 98 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 99 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 100 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 101 | GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fFSLocation + offset, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 102 | } |
| 103 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 104 | GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fVSLocation + offset, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | |
| 108 | void GrGLUniformManager::set3f(UniformHandle u, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 109 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 110 | SkASSERT(uni.fType == kVec3f_GrSLType); |
| 111 | SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
| 112 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 113 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 114 | GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fFSLocation, v0, v1, v2)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 115 | } |
| 116 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 117 | GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fVSLocation, v0, v1, v2)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | |
| 121 | void GrGLUniformManager::set3fv(UniformHandle u, |
| 122 | int offset, |
| 123 | int arrayCount, |
| 124 | const GrGLfloat v[]) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 125 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 126 | SkASSERT(uni.fType == kVec3f_GrSLType); |
| 127 | SkASSERT(arrayCount > 0); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 128 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 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(), Uniform3fv(uni.fFSLocation + offset, arrayCount, v)); |
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(), Uniform3fv(uni.fVSLocation + offset, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | |
| 138 | void GrGLUniformManager::set4f(UniformHandle u, |
| 139 | GrGLfloat v0, |
| 140 | GrGLfloat v1, |
| 141 | GrGLfloat v2, |
| 142 | GrGLfloat v3) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 143 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 144 | SkASSERT(uni.fType == kVec4f_GrSLType); |
| 145 | SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
| 146 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 147 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 148 | 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] | 149 | } |
| 150 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 151 | 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] | 152 | } |
| 153 | } |
| 154 | |
| 155 | void GrGLUniformManager::set4fv(UniformHandle u, |
| 156 | int offset, |
| 157 | int arrayCount, |
| 158 | const GrGLfloat v[]) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 159 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 160 | SkASSERT(uni.fType == kVec4f_GrSLType); |
| 161 | SkASSERT(arrayCount > 0); |
| 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(), Uniform4fv(uni.fFSLocation + offset, arrayCount, v)); |
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(), Uniform4fv(uni.fVSLocation + offset, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | |
| 171 | void GrGLUniformManager::setMatrix3f(UniformHandle u, const GrGLfloat matrix[]) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 172 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 173 | SkASSERT(uni.fType == kMat33f_GrSLType); |
| 174 | SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
bsalomon@google.com | 8ea78d8 | 2012-10-24 20:11:30 +0000 | [diff] [blame] | 175 | // 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] | 176 | // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 177 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 178 | GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fFSLocation, 1, false, matrix)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 179 | } |
| 180 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 181 | GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fVSLocation, 1, false, matrix)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
| 185 | void GrGLUniformManager::setMatrix4f(UniformHandle u, const GrGLfloat matrix[]) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 186 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 187 | SkASSERT(uni.fType == kMat44f_GrSLType); |
| 188 | SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
| 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(), UniformMatrix4fv(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(), UniformMatrix4fv(uni.fVSLocation, 1, false, matrix)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | |
| 198 | void GrGLUniformManager::setMatrix3fv(UniformHandle u, |
| 199 | int offset, |
| 200 | int arrayCount, |
| 201 | const GrGLfloat matrices[]) const { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 202 | const Uniform& uni = fUniforms[u.toUniformIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 203 | SkASSERT(uni.fType == kMat33f_GrSLType); |
| 204 | SkASSERT(arrayCount > 0); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 205 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 206 | SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 207 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 208 | GR_GL_CALL(fGpu->glInterface(), |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 209 | UniformMatrix3fv(uni.fFSLocation + offset, arrayCount, false, matrices)); |
| 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(), |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 213 | UniformMatrix3fv(uni.fVSLocation + offset, arrayCount, false, matrices)); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | void GrGLUniformManager::setMatrix4fv(UniformHandle u, |
| 218 | int offset, |
| 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); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 224 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, 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(), |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 228 | UniformMatrix4fv(uni.fFSLocation + offset, arrayCount, false, matrices)); |
| 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(), |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 232 | UniformMatrix4fv(uni.fVSLocation + offset, arrayCount, false, matrices)); |
| 233 | } |
| 234 | } |
| 235 | |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 236 | void GrGLUniformManager::setSkMatrix(UniformHandle u, const SkMatrix& matrix) const { |
robertphillips@google.com | e41fee9 | 2012-11-01 22:18:10 +0000 | [diff] [blame] | 237 | // GR_STATIC_ASSERT(SK_SCALAR_IS_FLOAT); |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 238 | GrGLfloat mt[] = { |
| 239 | matrix.get(SkMatrix::kMScaleX), |
| 240 | matrix.get(SkMatrix::kMSkewY), |
| 241 | matrix.get(SkMatrix::kMPersp0), |
| 242 | matrix.get(SkMatrix::kMSkewX), |
| 243 | matrix.get(SkMatrix::kMScaleY), |
| 244 | matrix.get(SkMatrix::kMPersp1), |
| 245 | matrix.get(SkMatrix::kMTransX), |
| 246 | matrix.get(SkMatrix::kMTransY), |
| 247 | matrix.get(SkMatrix::kMPersp2), |
| 248 | }; |
| 249 | this->setMatrix3f(u, mt); |
| 250 | } |
| 251 | |
| 252 | |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 253 | void GrGLUniformManager::getUniformLocations(GrGLuint programID, const BuilderUniformArray& uniforms) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 254 | SkASSERT(uniforms.count() == fUniforms.count()); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 255 | int count = fUniforms.count(); |
| 256 | for (int i = 0; i < count; ++i) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 257 | SkASSERT(uniforms[i].fVariable.getType() == fUniforms[i].fType); |
| 258 | SkASSERT(uniforms[i].fVariable.getArrayCount() == fUniforms[i].fArrayCount); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 259 | GrGLint location; |
| 260 | // TODO: Move the Xoom uniform array in both FS and VS bug workaround here. |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 261 | GR_GL_CALL_RET(fGpu->glInterface(), location, |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 262 | GetUniformLocation(programID, uniforms[i].fVariable.c_str())); |
commit-bot@chromium.org | 74a3a21 | 2013-08-30 19:43:59 +0000 | [diff] [blame] | 263 | if (GrGLShaderBuilder::kVertex_Visibility & uniforms[i].fVisibility) { |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 264 | fUniforms[i].fVSLocation = location; |
| 265 | } |
commit-bot@chromium.org | 74a3a21 | 2013-08-30 19:43:59 +0000 | [diff] [blame] | 266 | if (GrGLShaderBuilder::kFragment_Visibility & uniforms[i].fVisibility) { |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 267 | fUniforms[i].fFSLocation = location; |
| 268 | } |
| 269 | } |
| 270 | } |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 271 | |
| 272 | const GrGLUniformManager::BuilderUniform& |
| 273 | GrGLUniformManager::getBuilderUniform(const BuilderUniformArray& array, UniformHandle handle) const { |
| 274 | return array[handle.toUniformIndex()]; |
| 275 | } |