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) \ |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 14 | SkASSERT((COUNT) <= (UNI).fArrayCount || \ |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 15 | (1 == (COUNT) && GrShaderVar::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]; |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 27 | SkASSERT(GrShaderVar::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 | ); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 33 | uniform.fLocation = builderUniform.fLocation; |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 34 | } |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 35 | |
| 36 | // NVPR programs have separable varyings |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 37 | count = pathProcVaryings.count(); |
| 38 | fPathProcVaryings.push_back_n(count); |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 39 | for (int i = 0; i < count; i++) { |
| 40 | SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport()); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 41 | PathProcVarying& pathProcVarying = fPathProcVaryings[i]; |
| 42 | const VaryingInfo& builderPathProcVarying = pathProcVaryings[i]; |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 43 | SkASSERT(GrShaderVar::kNonArray == builderPathProcVarying.fVariable.getArrayCount() || |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 44 | builderPathProcVarying.fVariable.getArrayCount() > 0); |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 45 | SkDEBUGCODE( |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 46 | pathProcVarying.fArrayCount = builderPathProcVarying.fVariable.getArrayCount(); |
| 47 | pathProcVarying.fType = builderPathProcVarying.fVariable.getType(); |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 48 | ); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 49 | pathProcVarying.fLocation = builderPathProcVarying.fLocation; |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 50 | } |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Greg Daniel | bc5d4d7 | 2017-05-05 10:28:42 -0400 | [diff] [blame] | 53 | void GrGLProgramDataManager::setSamplerUniforms(const UniformInfoArray& samplers, |
| 54 | int startUnit) const { |
egdaniel | 09aa1fc | 2016-04-20 07:09:46 -0700 | [diff] [blame] | 55 | for (int i = 0; i < samplers.count(); ++i) { |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 56 | const UniformInfo& sampler = samplers[i]; |
| 57 | SkASSERT(sampler.fVisibility); |
| 58 | if (kUnusedUniform != sampler.fLocation) { |
Greg Daniel | bc5d4d7 | 2017-05-05 10:28:42 -0400 | [diff] [blame] | 59 | GR_GL_CALL(fGpu->glInterface(), Uniform1i(sampler.fLocation, i + startUnit)); |
egdaniel | 09aa1fc | 2016-04-20 07:09:46 -0700 | [diff] [blame] | 60 | } |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 64 | void GrGLProgramDataManager::setImageStorages(const UniformInfoArray& images) const { |
| 65 | for (int i = 0; i < images.count(); ++i) { |
| 66 | const UniformInfo& image = images[i]; |
| 67 | SkASSERT(image.fVisibility); |
| 68 | if (kUnusedUniform != image.fLocation) { |
| 69 | GR_GL_CALL(fGpu->glInterface(), Uniform1i(image.fLocation, i)); |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
fmenozzi | 497e9e2 | 2016-06-21 09:42:12 -0700 | [diff] [blame] | 74 | void GrGLProgramDataManager::set1i(UniformHandle u, int32_t i) const { |
| 75 | const Uniform& uni = fUniforms[u.toIndex()]; |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 76 | SkASSERT(uni.fType == kInt_GrSLType || uni.fType == kShort_GrSLType); |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 77 | SkASSERT(GrShaderVar::kNonArray == uni.fArrayCount); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 78 | if (kUnusedUniform != uni.fLocation) { |
| 79 | GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fLocation, i)); |
fmenozzi | 497e9e2 | 2016-06-21 09:42:12 -0700 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |
fmenozzi | 35a98c7 | 2016-07-20 08:26:12 -0700 | [diff] [blame] | 83 | void GrGLProgramDataManager::set1iv(UniformHandle u, |
| 84 | int arrayCount, |
| 85 | const int v[]) const { |
| 86 | const Uniform& uni = fUniforms[u.toIndex()]; |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 87 | SkASSERT(uni.fType == kInt_GrSLType || uni.fType == kShort_GrSLType); |
fmenozzi | 35a98c7 | 2016-07-20 08:26:12 -0700 | [diff] [blame] | 88 | SkASSERT(arrayCount > 0); |
| 89 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 90 | if (kUnusedUniform != uni.fLocation) { |
| 91 | GR_GL_CALL(fGpu->glInterface(), Uniform1iv(uni.fLocation, arrayCount, v)); |
fmenozzi | 35a98c7 | 2016-07-20 08:26:12 -0700 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 95 | void GrGLProgramDataManager::set1f(UniformHandle u, float v0) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 96 | const Uniform& uni = fUniforms[u.toIndex()]; |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 97 | SkASSERT(uni.fType == kFloat_GrSLType || uni.fType == kHalf_GrSLType); |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 98 | SkASSERT(GrShaderVar::kNonArray == uni.fArrayCount); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 99 | if (kUnusedUniform != uni.fLocation) { |
| 100 | GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fLocation, v0)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 104 | void GrGLProgramDataManager::set1fv(UniformHandle u, |
| 105 | int arrayCount, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 106 | const float v[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 107 | const Uniform& uni = fUniforms[u.toIndex()]; |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 108 | SkASSERT(uni.fType == kFloat_GrSLType || uni.fType == kHalf_GrSLType); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 109 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 110 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 111 | // This assert fires in some instances of the two-pt gradient for its VSParams. |
| 112 | // Once the uniform manager is responsible for inserting the duplicate uniform |
| 113 | // arrays in VS and FS driver bug workaround, this can be enabled. |
joshualitt | af2d56d | 2015-05-11 06:21:34 -0700 | [diff] [blame] | 114 | // this->printUni(uni); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 115 | if (kUnusedUniform != uni.fLocation) { |
| 116 | GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 120 | void GrGLProgramDataManager::set2f(UniformHandle u, float v0, float v1) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 121 | const Uniform& uni = fUniforms[u.toIndex()]; |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 122 | SkASSERT(uni.fType == kFloat2_GrSLType || uni.fType == kHalf2_GrSLType); |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 123 | SkASSERT(GrShaderVar::kNonArray == uni.fArrayCount); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 124 | if (kUnusedUniform != uni.fLocation) { |
| 125 | GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fLocation, v0, v1)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 129 | void GrGLProgramDataManager::set2fv(UniformHandle u, |
| 130 | int arrayCount, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 131 | const float v[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 132 | const Uniform& uni = fUniforms[u.toIndex()]; |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 133 | SkASSERT(uni.fType == kFloat2_GrSLType || uni.fType == kHalf2_GrSLType); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 134 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 135 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 136 | if (kUnusedUniform != uni.fLocation) { |
| 137 | GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 141 | void GrGLProgramDataManager::set3f(UniformHandle u, float v0, float v1, float v2) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 142 | const Uniform& uni = fUniforms[u.toIndex()]; |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 143 | SkASSERT(uni.fType == kFloat3_GrSLType || uni.fType == kHalf3_GrSLType); |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 144 | SkASSERT(GrShaderVar::kNonArray == uni.fArrayCount); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 145 | if (kUnusedUniform != uni.fLocation) { |
| 146 | GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fLocation, v0, v1, v2)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 150 | void GrGLProgramDataManager::set3fv(UniformHandle u, |
| 151 | int arrayCount, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 152 | const float v[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 153 | const Uniform& uni = fUniforms[u.toIndex()]; |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 154 | SkASSERT(uni.fType == kFloat3_GrSLType || uni.fType == kHalf3_GrSLType); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 155 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 156 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 157 | if (kUnusedUniform != uni.fLocation) { |
| 158 | GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 162 | void GrGLProgramDataManager::set4f(UniformHandle u, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 163 | float v0, |
| 164 | float v1, |
| 165 | float v2, |
| 166 | float v3) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 167 | const Uniform& uni = fUniforms[u.toIndex()]; |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 168 | SkASSERT(uni.fType == kFloat4_GrSLType || uni.fType == kHalf4_GrSLType); |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 169 | SkASSERT(GrShaderVar::kNonArray == uni.fArrayCount); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 170 | if (kUnusedUniform != uni.fLocation) { |
| 171 | GR_GL_CALL(fGpu->glInterface(), Uniform4f(uni.fLocation, v0, v1, v2, v3)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 175 | void GrGLProgramDataManager::set4fv(UniformHandle u, |
| 176 | int arrayCount, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 177 | const float v[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 178 | const Uniform& uni = fUniforms[u.toIndex()]; |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 179 | SkASSERT(uni.fType == kFloat4_GrSLType || uni.fType == kHalf4_GrSLType); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 180 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 181 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 182 | if (kUnusedUniform != uni.fLocation) { |
| 183 | GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 187 | void GrGLProgramDataManager::setMatrix2f(UniformHandle u, const float matrix[]) const { |
| 188 | this->setMatrices<2>(u, 1, matrix); |
| 189 | } |
| 190 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 191 | void GrGLProgramDataManager::setMatrix3f(UniformHandle u, const float matrix[]) const { |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 192 | this->setMatrices<3>(u, 1, matrix); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 193 | } |
| 194 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 195 | void GrGLProgramDataManager::setMatrix4f(UniformHandle u, const float matrix[]) const { |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 196 | this->setMatrices<4>(u, 1, matrix); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 197 | } |
| 198 | |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 199 | void GrGLProgramDataManager::setMatrix2fv(UniformHandle u, int arrayCount, const float m[]) const { |
| 200 | this->setMatrices<2>(u, arrayCount, m); |
| 201 | } |
| 202 | |
| 203 | void GrGLProgramDataManager::setMatrix3fv(UniformHandle u, int arrayCount, const float m[]) const { |
| 204 | this->setMatrices<3>(u, arrayCount, m); |
| 205 | } |
| 206 | |
| 207 | void GrGLProgramDataManager::setMatrix4fv(UniformHandle u, int arrayCount, const float m[]) const { |
| 208 | this->setMatrices<4>(u, arrayCount, m); |
| 209 | } |
| 210 | |
| 211 | template<int N> struct set_uniform_matrix; |
| 212 | |
| 213 | template<int N> inline void GrGLProgramDataManager::setMatrices(UniformHandle u, |
| 214 | int arrayCount, |
| 215 | const float matrices[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 216 | const Uniform& uni = fUniforms[u.toIndex()]; |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 217 | SkASSERT(uni.fType == kFloat2x2_GrSLType + (N - 2) || |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 218 | uni.fType == kHalf2x2_GrSLType + (N - 2)); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 219 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 220 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 221 | if (kUnusedUniform != uni.fLocation) { |
| 222 | set_uniform_matrix<N>::set(fGpu->glInterface(), uni.fLocation, arrayCount, matrices); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 226 | template<> struct set_uniform_matrix<2> { |
| 227 | inline static void set(const GrGLInterface* gli, const GrGLint loc, int cnt, const float m[]) { |
| 228 | GR_GL_CALL(gli, UniformMatrix2fv(loc, cnt, false, m)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 229 | } |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 230 | }; |
| 231 | |
| 232 | template<> struct set_uniform_matrix<3> { |
| 233 | inline static void set(const GrGLInterface* gli, const GrGLint loc, int cnt, const float m[]) { |
| 234 | GR_GL_CALL(gli, UniformMatrix3fv(loc, cnt, false, m)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 235 | } |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 236 | }; |
| 237 | |
| 238 | template<> struct set_uniform_matrix<4> { |
| 239 | inline static void set(const GrGLInterface* gli, const GrGLint loc, int cnt, const float m[]) { |
| 240 | GR_GL_CALL(gli, UniformMatrix4fv(loc, cnt, false, m)); |
| 241 | } |
| 242 | }; |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 243 | |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 244 | void GrGLProgramDataManager::setPathFragmentInputTransform(VaryingHandle u, |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 245 | int components, |
| 246 | const SkMatrix& matrix) const { |
| 247 | SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport()); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 248 | const PathProcVarying& fragmentInput = fPathProcVaryings[u.toIndex()]; |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 249 | |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 250 | SkASSERT((components == 2 && (fragmentInput.fType == kFloat2_GrSLType || |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 251 | fragmentInput.fType == kHalf2_GrSLType)) || |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 252 | (components == 3 && (fragmentInput.fType == kFloat3_GrSLType || |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 253 | fragmentInput.fType == kHalf3_GrSLType))); |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 254 | |
| 255 | fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID, |
| 256 | fragmentInput.fLocation, |
| 257 | GR_GL_OBJECT_LINEAR, |
| 258 | components, |
| 259 | matrix); |
| 260 | } |