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 | |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 8 | #include "SkMatrix.h" |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 9 | #include "gl/GrGLProgramDataManager.h" |
| 10 | #include "gl/GrGLGpu.h" |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 11 | #include "glsl/GrGLSLUniformHandler.h" |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 12 | |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 13 | #define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(UNI, COUNT) \ |
| 14 | SkASSERT(arrayCount <= uni.fArrayCount || \ |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 15 | (1 == arrayCount && GrGLSLShaderVar::kNonArray == uni.fArrayCount)) |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 16 | |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 17 | GrGLProgramDataManager::GrGLProgramDataManager(GrGLGpu* gpu, GrGLuint programID, |
| 18 | const UniformInfoArray& uniforms, |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 19 | const VaryingInfoArray& pathProcVaryings) |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 20 | : fGpu(gpu) |
| 21 | , fProgramID(programID) { |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 22 | int count = uniforms.count(); |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 23 | fUniforms.push_back_n(count); |
| 24 | for (int i = 0; i < count; i++) { |
| 25 | Uniform& uniform = fUniforms[i]; |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 26 | const UniformInfo& builderUniform = uniforms[i]; |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 27 | SkASSERT(GrGLSLShaderVar::kNonArray == builderUniform.fVariable.getArrayCount() || |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 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 | |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 35 | if (GrGLSLUniformHandler::kVertex_Visibility & builderUniform.fVisibility) { |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 36 | uniform.fVSLocation = builderUniform.fLocation; |
| 37 | } else { |
| 38 | uniform.fVSLocation = kUnusedUniform; |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 39 | } |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 40 | if (GrGLSLUniformHandler::kFragment_Visibility & builderUniform.fVisibility) { |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 41 | uniform.fFSLocation = builderUniform.fLocation; |
| 42 | } else { |
| 43 | uniform.fFSLocation = kUnusedUniform; |
| 44 | } |
| 45 | } |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 46 | |
| 47 | // NVPR programs have separable varyings |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 48 | count = pathProcVaryings.count(); |
| 49 | fPathProcVaryings.push_back_n(count); |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 50 | for (int i = 0; i < count; i++) { |
| 51 | SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport()); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 52 | PathProcVarying& pathProcVarying = fPathProcVaryings[i]; |
| 53 | const VaryingInfo& builderPathProcVarying = pathProcVaryings[i]; |
| 54 | SkASSERT(GrGLSLShaderVar::kNonArray == builderPathProcVarying.fVariable.getArrayCount() || |
| 55 | builderPathProcVarying.fVariable.getArrayCount() > 0); |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 56 | SkDEBUGCODE( |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 57 | pathProcVarying.fArrayCount = builderPathProcVarying.fVariable.getArrayCount(); |
| 58 | pathProcVarying.fType = builderPathProcVarying.fVariable.getType(); |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 59 | ); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 60 | pathProcVarying.fLocation = builderPathProcVarying.fLocation; |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 61 | } |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 62 | } |
| 63 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 64 | void GrGLProgramDataManager::setSampler(UniformHandle u, int texUnit) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 65 | const Uniform& uni = fUniforms[u.toIndex()]; |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 66 | SkASSERT(uni.fType == kSampler2D_GrSLType || uni.fType == kSamplerExternal_GrSLType || |
| 67 | uni.fType == kSampler2DRect_GrSLType); |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 68 | SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); |
bsalomon@google.com | 0982d35 | 2012-07-31 15:33:25 +0000 | [diff] [blame] | 69 | // FIXME: We still insert a single sampler uniform for every stage. If the shader does not |
| 70 | // reference the sampler then the compiler may have optimized it out. Uncomment this assert |
| 71 | // once stages insert their own samplers. |
joshualitt | af2d56d | 2015-05-11 06:21:34 -0700 | [diff] [blame] | 72 | // this->printUnused(uni); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 73 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 74 | GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fFSLocation, texUnit)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 75 | } |
| 76 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 77 | GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fVSLocation, texUnit)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 81 | void GrGLProgramDataManager::set1f(UniformHandle u, float v0) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 82 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 83 | SkASSERT(uni.fType == kFloat_GrSLType); |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 84 | SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 85 | SkDEBUGCODE(this->printUnused(uni);) |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 86 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 87 | GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fFSLocation, v0)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 88 | } |
| 89 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 90 | GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fVSLocation, v0)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 94 | void GrGLProgramDataManager::set1fv(UniformHandle u, |
| 95 | int arrayCount, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 96 | const float v[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 97 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 98 | SkASSERT(uni.fType == kFloat_GrSLType); |
| 99 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 100 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 101 | // This assert fires in some instances of the two-pt gradient for its VSParams. |
| 102 | // Once the uniform manager is responsible for inserting the duplicate uniform |
| 103 | // arrays in VS and FS driver bug workaround, this can be enabled. |
joshualitt | af2d56d | 2015-05-11 06:21:34 -0700 | [diff] [blame] | 104 | // this->printUni(uni); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 105 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 106 | GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fFSLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 107 | } |
| 108 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 109 | GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fVSLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 110 | } |
| 111 | } |
| 112 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 113 | void GrGLProgramDataManager::set2f(UniformHandle u, float v0, float v1) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 114 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 115 | SkASSERT(uni.fType == kVec2f_GrSLType); |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 116 | SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 117 | SkDEBUGCODE(this->printUnused(uni);) |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 118 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 119 | GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fFSLocation, v0, v1)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 120 | } |
| 121 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 122 | GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fVSLocation, v0, v1)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 126 | void GrGLProgramDataManager::set2fv(UniformHandle u, |
| 127 | int arrayCount, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 128 | const float v[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 129 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 130 | SkASSERT(uni.fType == kVec2f_GrSLType); |
| 131 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 132 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 133 | SkDEBUGCODE(this->printUnused(uni);) |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 134 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 135 | GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fFSLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 136 | } |
| 137 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 138 | GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fVSLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 142 | void GrGLProgramDataManager::set3f(UniformHandle u, float v0, float v1, float v2) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 143 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 144 | SkASSERT(uni.fType == kVec3f_GrSLType); |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 145 | SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 146 | SkDEBUGCODE(this->printUnused(uni);) |
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(), Uniform3f(uni.fFSLocation, v0, v1, v2)); |
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(), Uniform3f(uni.fVSLocation, v0, v1, v2)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 155 | void GrGLProgramDataManager::set3fv(UniformHandle u, |
| 156 | int arrayCount, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 157 | const float v[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 158 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 159 | SkASSERT(uni.fType == kVec3f_GrSLType); |
| 160 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 161 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 162 | SkDEBUGCODE(this->printUnused(uni);) |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 163 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 164 | GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fFSLocation, 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 | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 167 | GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fVSLocation, arrayCount, v)); |
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::set4f(UniformHandle u, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 172 | float v0, |
| 173 | float v1, |
| 174 | float v2, |
| 175 | float v3) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 176 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 177 | SkASSERT(uni.fType == kVec4f_GrSLType); |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 178 | SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 179 | SkDEBUGCODE(this->printUnused(uni);) |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 180 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 181 | 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] | 182 | } |
| 183 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 184 | 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] | 185 | } |
| 186 | } |
| 187 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 188 | void GrGLProgramDataManager::set4fv(UniformHandle u, |
| 189 | int arrayCount, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 190 | const float v[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 191 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 192 | SkASSERT(uni.fType == kVec4f_GrSLType); |
| 193 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 194 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 195 | SkDEBUGCODE(this->printUnused(uni);) |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 196 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 197 | GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fFSLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 198 | } |
| 199 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 200 | GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fVSLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 204 | void GrGLProgramDataManager::setMatrix3f(UniformHandle u, const float matrix[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 205 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 206 | SkASSERT(uni.fType == kMat33f_GrSLType); |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 207 | SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 208 | SkDEBUGCODE(this->printUnused(uni);) |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 209 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 210 | GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fFSLocation, 1, false, matrix)); |
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(), UniformMatrix3fv(uni.fVSLocation, 1, false, matrix)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 217 | void GrGLProgramDataManager::setMatrix4f(UniformHandle u, const float matrix[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 218 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 219 | SkASSERT(uni.fType == kMat44f_GrSLType); |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 220 | SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 221 | SkDEBUGCODE(this->printUnused(uni);) |
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(), UniformMatrix4fv(uni.fFSLocation, 1, false, matrix)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 224 | } |
| 225 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 226 | GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fVSLocation, 1, false, matrix)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 230 | void GrGLProgramDataManager::setMatrix3fv(UniformHandle u, |
| 231 | int arrayCount, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 232 | const float matrices[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 233 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 234 | SkASSERT(uni.fType == kMat33f_GrSLType); |
| 235 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 236 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 237 | SkDEBUGCODE(this->printUnused(uni);) |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 238 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 239 | GR_GL_CALL(fGpu->glInterface(), |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 240 | UniformMatrix3fv(uni.fFSLocation, arrayCount, false, matrices)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 241 | } |
| 242 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 243 | GR_GL_CALL(fGpu->glInterface(), |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 244 | UniformMatrix3fv(uni.fVSLocation, arrayCount, false, matrices)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 248 | void GrGLProgramDataManager::setMatrix4fv(UniformHandle u, |
| 249 | int arrayCount, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 250 | const float matrices[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 251 | const Uniform& uni = fUniforms[u.toIndex()]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 252 | SkASSERT(uni.fType == kMat44f_GrSLType); |
| 253 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 254 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 255 | SkDEBUGCODE(this->printUnused(uni);) |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 256 | if (kUnusedUniform != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 257 | GR_GL_CALL(fGpu->glInterface(), |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 258 | UniformMatrix4fv(uni.fFSLocation, arrayCount, false, matrices)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 259 | } |
| 260 | if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 261 | GR_GL_CALL(fGpu->glInterface(), |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 262 | UniformMatrix4fv(uni.fVSLocation, arrayCount, false, matrices)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 266 | void GrGLProgramDataManager::setPathFragmentInputTransform(VaryingHandle u, |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 267 | int components, |
| 268 | const SkMatrix& matrix) const { |
| 269 | SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport()); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 270 | const PathProcVarying& fragmentInput = fPathProcVaryings[u.toIndex()]; |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 271 | |
| 272 | SkASSERT((components == 2 && fragmentInput.fType == kVec2f_GrSLType) || |
| 273 | (components == 3 && fragmentInput.fType == kVec3f_GrSLType)); |
| 274 | |
| 275 | fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID, |
| 276 | fragmentInput.fLocation, |
| 277 | GR_GL_OBJECT_LINEAR, |
| 278 | components, |
| 279 | matrix); |
| 280 | } |
| 281 | |
joshualitt | af2d56d | 2015-05-11 06:21:34 -0700 | [diff] [blame] | 282 | #ifdef SK_DEBUG |
| 283 | void GrGLProgramDataManager::printUnused(const Uniform& uni) const { |
| 284 | if (kUnusedUniform == uni.fFSLocation && kUnusedUniform == uni.fVSLocation) { |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 285 | GrCapsDebugf(fGpu->caps(), "Unused uniform in shader\n"); |
joshualitt | af2d56d | 2015-05-11 06:21:34 -0700 | [diff] [blame] | 286 | } |
| 287 | } |
| 288 | #endif |