| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkMatrix.h" | 8 #include "SkMatrix.h" |
| 9 #include "gl/GrGLProgramDataManager.h" | 9 #include "gl/GrGLProgramDataManager.h" |
| 10 #include "gl/GrGLGpu.h" | 10 #include "gl/GrGLGpu.h" |
| 11 #include "glsl/GrGLSLUniformHandler.h" | 11 #include "glsl/GrGLSLUniformHandler.h" |
| 12 | 12 |
| 13 #define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(UNI, COUNT) \ | 13 #define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(UNI, COUNT) \ |
| 14 SkASSERT(arrayCount <= uni.fArrayCount || \ | 14 SkASSERT((COUNT) <= (UNI).fArrayCount || \ |
| 15 (1 == arrayCount && GrGLSLShaderVar::kNonArray == uni.fArrayCo
unt)) | 15 (1 == (COUNT) && GrGLSLShaderVar::kNonArray == (UNI).fArrayCou
nt)) |
| 16 | 16 |
| 17 GrGLProgramDataManager::GrGLProgramDataManager(GrGLGpu* gpu, GrGLuint programID, | 17 GrGLProgramDataManager::GrGLProgramDataManager(GrGLGpu* gpu, GrGLuint programID, |
| 18 const UniformInfoArray& uniforms, | 18 const UniformInfoArray& uniforms, |
| 19 const VaryingInfoArray& pathProcV
aryings) | 19 const VaryingInfoArray& pathProcV
aryings) |
| 20 : fGpu(gpu) | 20 : fGpu(gpu) |
| 21 , fProgramID(programID) { | 21 , fProgramID(programID) { |
| 22 int count = uniforms.count(); | 22 int count = uniforms.count(); |
| 23 fUniforms.push_back_n(count); | 23 fUniforms.push_back_n(count); |
| 24 for (int i = 0; i < count; i++) { | 24 for (int i = 0; i < count; i++) { |
| 25 Uniform& uniform = fUniforms[i]; | 25 Uniform& uniform = fUniforms[i]; |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); | 194 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
| 195 SkDEBUGCODE(this->printUnused(uni);) | 195 SkDEBUGCODE(this->printUnused(uni);) |
| 196 if (kUnusedUniform != uni.fFSLocation) { | 196 if (kUnusedUniform != uni.fFSLocation) { |
| 197 GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fFSLocation, arrayCount,
v)); | 197 GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fFSLocation, arrayCount,
v)); |
| 198 } | 198 } |
| 199 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 199 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
| 200 GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fVSLocation, arrayCount,
v)); | 200 GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fVSLocation, arrayCount,
v)); |
| 201 } | 201 } |
| 202 } | 202 } |
| 203 | 203 |
| 204 void GrGLProgramDataManager::setMatrix2f(UniformHandle u, const float matrix[])
const { |
| 205 this->setMatrices<2>(u, 1, matrix); |
| 206 } |
| 207 |
| 204 void GrGLProgramDataManager::setMatrix3f(UniformHandle u, const float matrix[])
const { | 208 void GrGLProgramDataManager::setMatrix3f(UniformHandle u, const float matrix[])
const { |
| 205 const Uniform& uni = fUniforms[u.toIndex()]; | 209 this->setMatrices<3>(u, 1, matrix); |
| 206 SkASSERT(uni.fType == kMat33f_GrSLType); | |
| 207 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); | |
| 208 SkDEBUGCODE(this->printUnused(uni);) | |
| 209 if (kUnusedUniform != uni.fFSLocation) { | |
| 210 GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fFSLocation, 1, fal
se, matrix)); | |
| 211 } | |
| 212 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | |
| 213 GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fVSLocation, 1, fal
se, matrix)); | |
| 214 } | |
| 215 } | 210 } |
| 216 | 211 |
| 217 void GrGLProgramDataManager::setMatrix4f(UniformHandle u, const float matrix[])
const { | 212 void GrGLProgramDataManager::setMatrix4f(UniformHandle u, const float matrix[])
const { |
| 218 const Uniform& uni = fUniforms[u.toIndex()]; | 213 this->setMatrices<4>(u, 1, matrix); |
| 219 SkASSERT(uni.fType == kMat44f_GrSLType); | |
| 220 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); | |
| 221 SkDEBUGCODE(this->printUnused(uni);) | |
| 222 if (kUnusedUniform != uni.fFSLocation) { | |
| 223 GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fFSLocation, 1, fal
se, matrix)); | |
| 224 } | |
| 225 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | |
| 226 GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fVSLocation, 1, fal
se, matrix)); | |
| 227 } | |
| 228 } | 214 } |
| 229 | 215 |
| 230 void GrGLProgramDataManager::setMatrix3fv(UniformHandle u, | 216 void GrGLProgramDataManager::setMatrix2fv(UniformHandle u, int arrayCount, const
float m[]) const { |
| 231 int arrayCount, | 217 this->setMatrices<2>(u, arrayCount, m); |
| 232 const float matrices[]) const { | 218 } |
| 219 |
| 220 void GrGLProgramDataManager::setMatrix3fv(UniformHandle u, int arrayCount, const
float m[]) const { |
| 221 this->setMatrices<3>(u, arrayCount, m); |
| 222 } |
| 223 |
| 224 void GrGLProgramDataManager::setMatrix4fv(UniformHandle u, int arrayCount, const
float m[]) const { |
| 225 this->setMatrices<4>(u, arrayCount, m); |
| 226 } |
| 227 |
| 228 template<int N> struct set_uniform_matrix; |
| 229 |
| 230 template<int N> inline void GrGLProgramDataManager::setMatrices(UniformHandle u, |
| 231 int arrayCount, |
| 232 const float matr
ices[]) const { |
| 233 const Uniform& uni = fUniforms[u.toIndex()]; | 233 const Uniform& uni = fUniforms[u.toIndex()]; |
| 234 SkASSERT(uni.fType == kMat33f_GrSLType); | 234 SkASSERT(uni.fType == kMat22f_GrSLType + (N - 2)); |
| 235 SkASSERT(arrayCount > 0); | 235 SkASSERT(arrayCount > 0); |
| 236 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); | 236 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
| 237 SkDEBUGCODE(this->printUnused(uni);) | 237 SkDEBUGCODE(this->printUnused(uni);) |
| 238 if (kUnusedUniform != uni.fFSLocation) { | 238 if (kUnusedUniform != uni.fFSLocation) { |
| 239 GR_GL_CALL(fGpu->glInterface(), | 239 set_uniform_matrix<N>::set(fGpu->glInterface(), uni.fFSLocation, arrayCo
unt, matrices); |
| 240 UniformMatrix3fv(uni.fFSLocation, arrayCount, false, matrices
)); | |
| 241 } | 240 } |
| 242 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 241 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
| 243 GR_GL_CALL(fGpu->glInterface(), | 242 set_uniform_matrix<N>::set(fGpu->glInterface(), uni.fVSLocation, arrayCo
unt, matrices); |
| 244 UniformMatrix3fv(uni.fVSLocation, arrayCount, false, matrices
)); | |
| 245 } | 243 } |
| 246 } | 244 } |
| 247 | 245 |
| 248 void GrGLProgramDataManager::setMatrix4fv(UniformHandle u, | 246 template<> struct set_uniform_matrix<2> { |
| 249 int arrayCount, | 247 inline static void set(const GrGLInterface* gli, const GrGLint loc, int cnt,
const float m[]) { |
| 250 const float matrices[]) const { | 248 GR_GL_CALL(gli, UniformMatrix2fv(loc, cnt, false, m)); |
| 251 const Uniform& uni = fUniforms[u.toIndex()]; | |
| 252 SkASSERT(uni.fType == kMat44f_GrSLType); | |
| 253 SkASSERT(arrayCount > 0); | |
| 254 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); | |
| 255 SkDEBUGCODE(this->printUnused(uni);) | |
| 256 if (kUnusedUniform != uni.fFSLocation) { | |
| 257 GR_GL_CALL(fGpu->glInterface(), | |
| 258 UniformMatrix4fv(uni.fFSLocation, arrayCount, false, matrices
)); | |
| 259 } | 249 } |
| 260 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 250 }; |
| 261 GR_GL_CALL(fGpu->glInterface(), | 251 |
| 262 UniformMatrix4fv(uni.fVSLocation, arrayCount, false, matrices
)); | 252 template<> struct set_uniform_matrix<3> { |
| 253 inline static void set(const GrGLInterface* gli, const GrGLint loc, int cnt,
const float m[]) { |
| 254 GR_GL_CALL(gli, UniformMatrix3fv(loc, cnt, false, m)); |
| 263 } | 255 } |
| 264 } | 256 }; |
| 257 |
| 258 template<> struct set_uniform_matrix<4> { |
| 259 inline static void set(const GrGLInterface* gli, const GrGLint loc, int cnt,
const float m[]) { |
| 260 GR_GL_CALL(gli, UniformMatrix4fv(loc, cnt, false, m)); |
| 261 } |
| 262 }; |
| 265 | 263 |
| 266 void GrGLProgramDataManager::setPathFragmentInputTransform(VaryingHandle u, | 264 void GrGLProgramDataManager::setPathFragmentInputTransform(VaryingHandle u, |
| 267 int components, | 265 int components, |
| 268 const SkMatrix& matri
x) const { | 266 const SkMatrix& matri
x) const { |
| 269 SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport()); | 267 SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport()); |
| 270 const PathProcVarying& fragmentInput = fPathProcVaryings[u.toIndex()]; | 268 const PathProcVarying& fragmentInput = fPathProcVaryings[u.toIndex()]; |
| 271 | 269 |
| 272 SkASSERT((components == 2 && fragmentInput.fType == kVec2f_GrSLType) || | 270 SkASSERT((components == 2 && fragmentInput.fType == kVec2f_GrSLType) || |
| 273 (components == 3 && fragmentInput.fType == kVec3f_GrSLType)); | 271 (components == 3 && fragmentInput.fType == kVec3f_GrSLType)); |
| 274 | 272 |
| 275 fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID, | 273 fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID, |
| 276 fragmentInput.
fLocation, | 274 fragmentInput.
fLocation, |
| 277 GR_GL_OBJECT_L
INEAR, | 275 GR_GL_OBJECT_L
INEAR, |
| 278 components, | 276 components, |
| 279 matrix); | 277 matrix); |
| 280 } | 278 } |
| 281 | 279 |
| 282 #ifdef SK_DEBUG | 280 #ifdef SK_DEBUG |
| 283 void GrGLProgramDataManager::printUnused(const Uniform& uni) const { | 281 void GrGLProgramDataManager::printUnused(const Uniform& uni) const { |
| 284 if (kUnusedUniform == uni.fFSLocation && kUnusedUniform == uni.fVSLocation)
{ | 282 if (kUnusedUniform == uni.fFSLocation && kUnusedUniform == uni.fVSLocation)
{ |
| 285 GrCapsDebugf(fGpu->caps(), "Unused uniform in shader\n"); | 283 GrCapsDebugf(fGpu->caps(), "Unused uniform in shader\n"); |
| 286 } | 284 } |
| 287 } | 285 } |
| 288 #endif | 286 #endif |
| OLD | NEW |