OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "gl/GrGLUniformHandler.h" | 8 #include "gl/GrGLUniformHandler.h" |
9 | 9 |
10 #include "gl/GrGLCaps.h" | 10 #include "gl/GrGLCaps.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 uni.fVariable.setArrayCount(arrayCount); | 45 uni.fVariable.setArrayCount(arrayCount); |
46 uni.fVisibility = visibility; | 46 uni.fVisibility = visibility; |
47 uni.fVariable.setPrecision(precision); | 47 uni.fVariable.setPrecision(precision); |
48 | 48 |
49 if (outName) { | 49 if (outName) { |
50 *outName = uni.fVariable.c_str(); | 50 *outName = uni.fVariable.c_str(); |
51 } | 51 } |
52 return GrGLSLUniformHandler::UniformHandle(fUniforms.count() - 1); | 52 return GrGLSLUniformHandler::UniformHandle(fUniforms.count() - 1); |
53 } | 53 } |
54 | 54 |
55 GrGLSLUniformHandler::SamplerHandle GrGLUniformHandler::internalAddSampler(uint3
2_t visibility, | |
56 GrPix
elConfig config, | |
57 GrSLT
ype type, | |
58 GrSLP
recision precision, | |
59 const
char* name) { | |
60 SkASSERT(name && strlen(name)); | |
61 SkDEBUGCODE(static const uint32_t kVisMask = kVertex_GrShaderFlag | kFragmen
t_GrShaderFlag); | |
62 SkASSERT(0 == (~kVisMask & visibility)); | |
63 SkASSERT(0 != visibility); | |
64 SkString mangleName; | |
65 char prefix = 'u'; | |
66 fProgramBuilder->nameVariable(&mangleName, prefix, name, true); | |
67 fSamplers.emplace_back(visibility, config, type, precision, mangleName.c_str
()); | |
68 return GrGLSLUniformHandler::SamplerHandle(fSamplers.count() - 1); | |
69 } | |
70 | |
71 void GrGLUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString*
out) const { | 55 void GrGLUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString*
out) const { |
72 for (int i = 0; i < fUniforms.count(); ++i) { | 56 for (int i = 0; i < fUniforms.count(); ++i) { |
73 if (fUniforms[i].fVisibility & visibility) { | 57 if (fUniforms[i].fVisibility & visibility) { |
74 fUniforms[i].fVariable.appendDecl(fProgramBuilder->glslCaps(), out); | 58 fUniforms[i].fVariable.appendDecl(fProgramBuilder->glslCaps(), out); |
75 out->append(";\n"); | 59 out->append(";\n"); |
76 } | 60 } |
77 } | 61 } |
78 for (int i = 0; i < fSamplers.count(); ++i) { | |
79 if (fSamplers[i].visibility() & visibility) { | |
80 fSamplers[i].fShaderVar.appendDecl(fProgramBuilder->glslCaps(), out)
; | |
81 out->append(";\n"); | |
82 } | |
83 } | |
84 } | 62 } |
85 | 63 |
86 void GrGLUniformHandler::bindUniformLocations(GrGLuint programID, const GrGLCaps
& caps) { | 64 void GrGLUniformHandler::bindUniformLocations(GrGLuint programID, const GrGLCaps
& caps) { |
87 if (caps.bindUniformLocationSupport()) { | 65 if (caps.bindUniformLocationSupport()) { |
88 int count = fUniforms.count(); | 66 int count = fUniforms.count(); |
89 for (int i = 0; i < count; ++i) { | 67 for (int i = 0; i < count; ++i) { |
90 GL_CALL(BindUniformLocation(programID, i, fUniforms[i].fVariable.c_s
tr())); | 68 GL_CALL(BindUniformLocation(programID, i, fUniforms[i].fVariable.c_s
tr())); |
91 fUniforms[i].fLocation = i; | 69 fUniforms[i].fLocation = i; |
92 } | 70 } |
93 for (int i = 0; i < fSamplers.count(); ++i) { | |
94 GL_CALL(BindUniformLocation(programID, i, fSamplers[i].fShaderVar.c_
str())); | |
95 fSamplers[i].fLocation = i; | |
96 } | |
97 } | 71 } |
98 } | 72 } |
99 | 73 |
100 void GrGLUniformHandler::getUniformLocations(GrGLuint programID, const GrGLCaps&
caps) { | 74 void GrGLUniformHandler::getUniformLocations(GrGLuint programID, const GrGLCaps&
caps) { |
101 if (!caps.bindUniformLocationSupport()) { | 75 if (!caps.bindUniformLocationSupport()) { |
102 int count = fUniforms.count(); | 76 int count = fUniforms.count(); |
103 for (int i = 0; i < count; ++i) { | 77 for (int i = 0; i < count; ++i) { |
104 GrGLint location; | 78 GrGLint location; |
105 GL_CALL_RET(location, GetUniformLocation(programID, fUniforms[i].fVa
riable.c_str())); | 79 GL_CALL_RET(location, GetUniformLocation(programID, fUniforms[i].fVa
riable.c_str())); |
106 fUniforms[i].fLocation = location; | 80 fUniforms[i].fLocation = location; |
107 } | 81 } |
108 for (int i = 0; i < fSamplers.count(); ++i) { | |
109 GrGLint location; | |
110 GL_CALL_RET(location, GetUniformLocation(programID, fSamplers[i].fSh
aderVar.c_str())); | |
111 fSamplers[i].fLocation = location; | |
112 } | |
113 } | 82 } |
114 } | 83 } |
115 | 84 |
116 const GrGLGpu* GrGLUniformHandler::glGpu() const { | 85 const GrGLGpu* GrGLUniformHandler::glGpu() const { |
117 GrGLProgramBuilder* glPB = (GrGLProgramBuilder*) fProgramBuilder; | 86 GrGLProgramBuilder* glPB = (GrGLProgramBuilder*) fProgramBuilder; |
118 return glPB->gpu(); | 87 return glPB->gpu(); |
119 } | 88 } |
OLD | NEW |