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" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 SkASSERT(GrGLSLShaderVar::kNonArray == builderPathProcVarying.fVariable.
getArrayCount() || | 54 SkASSERT(GrGLSLShaderVar::kNonArray == builderPathProcVarying.fVariable.
getArrayCount() || |
55 builderPathProcVarying.fVariable.getArrayCount() > 0); | 55 builderPathProcVarying.fVariable.getArrayCount() > 0); |
56 SkDEBUGCODE( | 56 SkDEBUGCODE( |
57 pathProcVarying.fArrayCount = builderPathProcVarying.fVariable.getAr
rayCount(); | 57 pathProcVarying.fArrayCount = builderPathProcVarying.fVariable.getAr
rayCount(); |
58 pathProcVarying.fType = builderPathProcVarying.fVariable.getType(); | 58 pathProcVarying.fType = builderPathProcVarying.fVariable.getType(); |
59 ); | 59 ); |
60 pathProcVarying.fLocation = builderPathProcVarying.fLocation; | 60 pathProcVarying.fLocation = builderPathProcVarying.fLocation; |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 void GrGLProgramDataManager::setSamplers(const SkTArray<GrGLSampler>& samplers)
const { | 64 void GrGLProgramDataManager::setSampler(UniformHandle u, int texUnit) const { |
65 for (int i = 0; i < samplers.count(); ++i) { | 65 const Uniform& uni = fUniforms[u.toIndex()]; |
66 GrGLint vsLocation; | 66 SkASSERT(GrSLTypeIsSamplerType(uni.fType)); |
67 GrGLint fsLocation; | 67 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); |
68 const GrGLSampler& sampler = samplers[i]; | 68 // FIXME: We still insert a single sampler uniform for every stage. If the s
hader does not |
69 if (kVertex_GrShaderFlag & sampler.visibility()) { | 69 // reference the sampler then the compiler may have optimized it out. Uncomm
ent this assert |
70 vsLocation = sampler.location(); | 70 // once stages insert their own samplers. |
71 } else { | 71 // this->printUnused(uni); |
72 vsLocation = kUnusedUniform; | 72 if (kUnusedUniform != uni.fFSLocation) { |
73 } | 73 GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fFSLocation, texUnit)); |
74 if (kFragment_GrShaderFlag & sampler.visibility()) { | 74 } |
75 fsLocation = sampler.location(); | 75 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
76 } else { | 76 GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fVSLocation, texUnit)); |
77 fsLocation = kUnusedUniform; | |
78 } | |
79 // FIXME: We still insert a single sampler uniform for every stage. If t
he shader does not | |
80 // reference the sampler then the compiler may have optimized it out. Un
comment this assert | |
81 // once stages insert their own samplers. | |
82 // this->printUnused(uni); | |
83 if (kUnusedUniform != fsLocation) { | |
84 GR_GL_CALL(fGpu->glInterface(), Uniform1i(fsLocation, i)); | |
85 } | |
86 if (kUnusedUniform != vsLocation && vsLocation != fsLocation) { | |
87 GR_GL_CALL(fGpu->glInterface(), Uniform1i(vsLocation, i)); | |
88 } | |
89 } | 77 } |
90 } | 78 } |
91 | 79 |
92 void GrGLProgramDataManager::set1f(UniformHandle u, float v0) const { | 80 void GrGLProgramDataManager::set1f(UniformHandle u, float v0) const { |
93 const Uniform& uni = fUniforms[u.toIndex()]; | 81 const Uniform& uni = fUniforms[u.toIndex()]; |
94 SkASSERT(uni.fType == kFloat_GrSLType); | 82 SkASSERT(uni.fType == kFloat_GrSLType); |
95 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); | 83 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); |
96 SkDEBUGCODE(this->printUnused(uni);) | 84 SkDEBUGCODE(this->printUnused(uni);) |
97 if (kUnusedUniform != uni.fFSLocation) { | 85 if (kUnusedUniform != uni.fFSLocation) { |
98 GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fFSLocation, v0)); | 86 GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fFSLocation, v0)); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 matrix); | 276 matrix); |
289 } | 277 } |
290 | 278 |
291 #ifdef SK_DEBUG | 279 #ifdef SK_DEBUG |
292 void GrGLProgramDataManager::printUnused(const Uniform& uni) const { | 280 void GrGLProgramDataManager::printUnused(const Uniform& uni) const { |
293 if (kUnusedUniform == uni.fFSLocation && kUnusedUniform == uni.fVSLocation)
{ | 281 if (kUnusedUniform == uni.fFSLocation && kUnusedUniform == uni.fVSLocation)
{ |
294 GrCapsDebugf(fGpu->caps(), "Unused uniform in shader\n"); | 282 GrCapsDebugf(fGpu->caps(), "Unused uniform in shader\n"); |
295 } | 283 } |
296 } | 284 } |
297 #endif | 285 #endif |
OLD | NEW |