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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkMatrix.h" |
| 9 | #include "src/gpu/gl/GrGLGpu.h" |
| 10 | #include "src/gpu/gl/GrGLProgramDataManager.h" |
| 11 | #include "src/gpu/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(); |
Brian Salomon | 2335644 | 2018-11-30 15:33:19 -0500 | [diff] [blame] | 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(); |
Brian Salomon | 2335644 | 2018-11-30 15:33:19 -0500 | [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 | |
fmenozzi | 497e9e2 | 2016-06-21 09:42:12 -0700 | [diff] [blame] | 64 | void GrGLProgramDataManager::set1i(UniformHandle u, int32_t i) const { |
| 65 | const Uniform& uni = fUniforms[u.toIndex()]; |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 66 | SkASSERT(uni.fType == kInt_GrSLType || uni.fType == kShort_GrSLType); |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 67 | SkASSERT(GrShaderVar::kNonArray == uni.fArrayCount); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 68 | if (kUnusedUniform != uni.fLocation) { |
| 69 | GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fLocation, i)); |
fmenozzi | 497e9e2 | 2016-06-21 09:42:12 -0700 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
fmenozzi | 35a98c7 | 2016-07-20 08:26:12 -0700 | [diff] [blame] | 73 | void GrGLProgramDataManager::set1iv(UniformHandle u, |
| 74 | int arrayCount, |
Michael Ludwig | 779ed02 | 2018-08-28 17:20:07 -0400 | [diff] [blame] | 75 | const int32_t v[]) const { |
fmenozzi | 35a98c7 | 2016-07-20 08:26:12 -0700 | [diff] [blame] | 76 | const Uniform& uni = fUniforms[u.toIndex()]; |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 77 | SkASSERT(uni.fType == kInt_GrSLType || uni.fType == kShort_GrSLType); |
fmenozzi | 35a98c7 | 2016-07-20 08:26:12 -0700 | [diff] [blame] | 78 | SkASSERT(arrayCount > 0); |
| 79 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 80 | if (kUnusedUniform != uni.fLocation) { |
| 81 | GR_GL_CALL(fGpu->glInterface(), Uniform1iv(uni.fLocation, arrayCount, v)); |
fmenozzi | 35a98c7 | 2016-07-20 08:26:12 -0700 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 85 | void GrGLProgramDataManager::set1f(UniformHandle u, float v0) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 86 | const Uniform& uni = fUniforms[u.toIndex()]; |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 87 | SkASSERT(uni.fType == kFloat_GrSLType || uni.fType == kHalf_GrSLType); |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 88 | SkASSERT(GrShaderVar::kNonArray == uni.fArrayCount); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 89 | if (kUnusedUniform != uni.fLocation) { |
| 90 | GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fLocation, 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()]; |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 98 | SkASSERT(uni.fType == kFloat_GrSLType || uni.fType == kHalf_GrSLType); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 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); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 105 | if (kUnusedUniform != uni.fLocation) { |
| 106 | GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | |
Michael Ludwig | 779ed02 | 2018-08-28 17:20:07 -0400 | [diff] [blame] | 110 | void GrGLProgramDataManager::set2i(UniformHandle u, int32_t i0, int32_t i1) const { |
| 111 | const Uniform& uni = fUniforms[u.toIndex()]; |
| 112 | SkASSERT(uni.fType == kInt2_GrSLType || uni.fType == kShort2_GrSLType); |
| 113 | SkASSERT(GrShaderVar::kNonArray == uni.fArrayCount); |
| 114 | if (kUnusedUniform != uni.fLocation) { |
| 115 | GR_GL_CALL(fGpu->glInterface(), Uniform2i(uni.fLocation, i0, i1)); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | void GrGLProgramDataManager::set2iv(UniformHandle u, |
| 120 | int arrayCount, |
| 121 | const int32_t v[]) const { |
| 122 | const Uniform& uni = fUniforms[u.toIndex()]; |
| 123 | SkASSERT(uni.fType == kInt2_GrSLType || uni.fType == kShort2_GrSLType); |
| 124 | SkASSERT(arrayCount > 0); |
| 125 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
| 126 | if (kUnusedUniform != uni.fLocation) { |
| 127 | GR_GL_CALL(fGpu->glInterface(), Uniform2iv(uni.fLocation, arrayCount, v)); |
| 128 | } |
| 129 | } |
| 130 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 131 | void GrGLProgramDataManager::set2f(UniformHandle u, float v0, float v1) 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); |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 134 | SkASSERT(GrShaderVar::kNonArray == uni.fArrayCount); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 135 | if (kUnusedUniform != uni.fLocation) { |
| 136 | GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fLocation, v0, v1)); |
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::set2fv(UniformHandle u, |
| 141 | int arrayCount, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 142 | const float v[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 143 | const Uniform& uni = fUniforms[u.toIndex()]; |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 144 | SkASSERT(uni.fType == kFloat2_GrSLType || uni.fType == kHalf2_GrSLType); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 145 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 146 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 147 | if (kUnusedUniform != uni.fLocation) { |
| 148 | GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | |
Michael Ludwig | 779ed02 | 2018-08-28 17:20:07 -0400 | [diff] [blame] | 152 | void GrGLProgramDataManager::set3i(UniformHandle u, int32_t i0, int32_t i1, int32_t i2) const { |
| 153 | const Uniform& uni = fUniforms[u.toIndex()]; |
| 154 | SkASSERT(uni.fType == kInt3_GrSLType || uni.fType == kShort3_GrSLType); |
| 155 | SkASSERT(GrShaderVar::kNonArray == uni.fArrayCount); |
| 156 | if (kUnusedUniform != uni.fLocation) { |
| 157 | GR_GL_CALL(fGpu->glInterface(), Uniform3i(uni.fLocation, i0, i1, i2)); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | void GrGLProgramDataManager::set3iv(UniformHandle u, |
| 162 | int arrayCount, |
| 163 | const int32_t v[]) const { |
| 164 | const Uniform& uni = fUniforms[u.toIndex()]; |
| 165 | SkASSERT(uni.fType == kInt3_GrSLType || uni.fType == kShort3_GrSLType); |
| 166 | SkASSERT(arrayCount > 0); |
| 167 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
| 168 | if (kUnusedUniform != uni.fLocation) { |
| 169 | GR_GL_CALL(fGpu->glInterface(), Uniform3iv(uni.fLocation, arrayCount, v)); |
| 170 | } |
| 171 | } |
| 172 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 173 | void GrGLProgramDataManager::set3f(UniformHandle u, float v0, float v1, float v2) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 174 | const Uniform& uni = fUniforms[u.toIndex()]; |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 175 | SkASSERT(uni.fType == kFloat3_GrSLType || uni.fType == kHalf3_GrSLType); |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 176 | SkASSERT(GrShaderVar::kNonArray == uni.fArrayCount); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 177 | if (kUnusedUniform != uni.fLocation) { |
| 178 | GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fLocation, v0, v1, v2)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 182 | void GrGLProgramDataManager::set3fv(UniformHandle u, |
| 183 | int arrayCount, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 184 | const float v[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 185 | const Uniform& uni = fUniforms[u.toIndex()]; |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 186 | SkASSERT(uni.fType == kFloat3_GrSLType || uni.fType == kHalf3_GrSLType); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 187 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 188 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 189 | if (kUnusedUniform != uni.fLocation) { |
| 190 | GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | |
Michael Ludwig | 779ed02 | 2018-08-28 17:20:07 -0400 | [diff] [blame] | 194 | void GrGLProgramDataManager::set4i(UniformHandle u, |
| 195 | int32_t i0, |
| 196 | int32_t i1, |
| 197 | int32_t i2, |
| 198 | int32_t i3) const { |
| 199 | const Uniform& uni = fUniforms[u.toIndex()]; |
| 200 | SkASSERT(uni.fType == kInt4_GrSLType || uni.fType == kShort4_GrSLType); |
| 201 | SkASSERT(GrShaderVar::kNonArray == uni.fArrayCount); |
| 202 | if (kUnusedUniform != uni.fLocation) { |
| 203 | GR_GL_CALL(fGpu->glInterface(), Uniform4i(uni.fLocation, i0, i1, i2, i3)); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | void GrGLProgramDataManager::set4iv(UniformHandle u, |
| 208 | int arrayCount, |
| 209 | const int32_t v[]) const { |
| 210 | const Uniform& uni = fUniforms[u.toIndex()]; |
| 211 | SkASSERT(uni.fType == kInt4_GrSLType || uni.fType == kShort4_GrSLType); |
| 212 | SkASSERT(arrayCount > 0); |
| 213 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
| 214 | if (kUnusedUniform != uni.fLocation) { |
| 215 | GR_GL_CALL(fGpu->glInterface(), Uniform4iv(uni.fLocation, arrayCount, v)); |
| 216 | } |
| 217 | } |
| 218 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 219 | void GrGLProgramDataManager::set4f(UniformHandle u, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 220 | float v0, |
| 221 | float v1, |
| 222 | float v2, |
| 223 | float v3) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 224 | const Uniform& uni = fUniforms[u.toIndex()]; |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 225 | SkASSERT(uni.fType == kFloat4_GrSLType || uni.fType == kHalf4_GrSLType); |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 226 | SkASSERT(GrShaderVar::kNonArray == uni.fArrayCount); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 227 | if (kUnusedUniform != uni.fLocation) { |
| 228 | 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] | 229 | } |
| 230 | } |
| 231 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 232 | void GrGLProgramDataManager::set4fv(UniformHandle u, |
| 233 | int arrayCount, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 234 | const float v[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 235 | const Uniform& uni = fUniforms[u.toIndex()]; |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 236 | SkASSERT(uni.fType == kFloat4_GrSLType || uni.fType == kHalf4_GrSLType); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 237 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 238 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 239 | if (kUnusedUniform != uni.fLocation) { |
| 240 | GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fLocation, arrayCount, v)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 244 | void GrGLProgramDataManager::setMatrix2f(UniformHandle u, const float matrix[]) const { |
| 245 | this->setMatrices<2>(u, 1, matrix); |
| 246 | } |
| 247 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 248 | void GrGLProgramDataManager::setMatrix3f(UniformHandle u, const float matrix[]) const { |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 249 | this->setMatrices<3>(u, 1, matrix); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 250 | } |
| 251 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 252 | void GrGLProgramDataManager::setMatrix4f(UniformHandle u, const float matrix[]) const { |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 253 | this->setMatrices<4>(u, 1, matrix); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 254 | } |
| 255 | |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 256 | void GrGLProgramDataManager::setMatrix2fv(UniformHandle u, int arrayCount, const float m[]) const { |
| 257 | this->setMatrices<2>(u, arrayCount, m); |
| 258 | } |
| 259 | |
| 260 | void GrGLProgramDataManager::setMatrix3fv(UniformHandle u, int arrayCount, const float m[]) const { |
| 261 | this->setMatrices<3>(u, arrayCount, m); |
| 262 | } |
| 263 | |
| 264 | void GrGLProgramDataManager::setMatrix4fv(UniformHandle u, int arrayCount, const float m[]) const { |
| 265 | this->setMatrices<4>(u, arrayCount, m); |
| 266 | } |
| 267 | |
| 268 | template<int N> struct set_uniform_matrix; |
| 269 | |
| 270 | template<int N> inline void GrGLProgramDataManager::setMatrices(UniformHandle u, |
| 271 | int arrayCount, |
| 272 | const float matrices[]) const { |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 273 | const Uniform& uni = fUniforms[u.toIndex()]; |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 274 | SkASSERT(uni.fType == kFloat2x2_GrSLType + (N - 2) || |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 275 | uni.fType == kHalf2x2_GrSLType + (N - 2)); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 276 | SkASSERT(arrayCount > 0); |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 277 | ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 278 | if (kUnusedUniform != uni.fLocation) { |
| 279 | set_uniform_matrix<N>::set(fGpu->glInterface(), uni.fLocation, arrayCount, matrices); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 283 | template<> struct set_uniform_matrix<2> { |
| 284 | inline static void set(const GrGLInterface* gli, const GrGLint loc, int cnt, const float m[]) { |
| 285 | GR_GL_CALL(gli, UniformMatrix2fv(loc, cnt, false, m)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 286 | } |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 287 | }; |
| 288 | |
| 289 | template<> struct set_uniform_matrix<3> { |
| 290 | inline static void set(const GrGLInterface* gli, const GrGLint loc, int cnt, const float m[]) { |
| 291 | GR_GL_CALL(gli, UniformMatrix3fv(loc, cnt, false, m)); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 292 | } |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 293 | }; |
| 294 | |
| 295 | template<> struct set_uniform_matrix<4> { |
| 296 | inline static void set(const GrGLInterface* gli, const GrGLint loc, int cnt, const float m[]) { |
| 297 | GR_GL_CALL(gli, UniformMatrix4fv(loc, cnt, false, m)); |
| 298 | } |
| 299 | }; |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 300 | |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 301 | void GrGLProgramDataManager::setPathFragmentInputTransform(VaryingHandle u, |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 302 | int components, |
| 303 | const SkMatrix& matrix) const { |
| 304 | SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport()); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 305 | const PathProcVarying& fragmentInput = fPathProcVaryings[u.toIndex()]; |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 306 | |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 307 | SkASSERT((components == 2 && (fragmentInput.fType == kFloat2_GrSLType || |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 308 | fragmentInput.fType == kHalf2_GrSLType)) || |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 309 | (components == 3 && (fragmentInput.fType == kFloat3_GrSLType || |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 310 | fragmentInput.fType == kHalf3_GrSLType))); |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 311 | |
| 312 | fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID, |
| 313 | fragmentInput.fLocation, |
| 314 | GR_GL_OBJECT_LINEAR, |
| 315 | components, |
| 316 | matrix); |
| 317 | } |