OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "GrGLShaderBuilder.h" | 8 #include "GrGLShaderBuilder.h" |
9 #include "gl/builders/GrGLProgramBuilder.h" | |
10 #include "glsl/GrGLSLCaps.h" | 9 #include "glsl/GrGLSLCaps.h" |
11 #include "glsl/GrGLSLShaderVar.h" | 10 #include "glsl/GrGLSLShaderVar.h" |
12 #include "glsl/GrGLSLTextureSampler.h" | 11 #include "glsl/GrGLSLTextureSampler.h" |
| 12 #include "glsl/GrGLSLProgramBuilder.h" |
13 | 13 |
14 static void map_swizzle(const char* swizzleMap, const char* swizzle, char* mangl
edSwizzle) { | 14 static void map_swizzle(const char* swizzleMap, const char* swizzle, char* mangl
edSwizzle) { |
15 int i; | 15 int i; |
16 for (i = 0; '\0' != swizzle[i]; ++i) { | 16 for (i = 0; '\0' != swizzle[i]; ++i) { |
17 switch (swizzle[i]) { | 17 switch (swizzle[i]) { |
18 case 'r': | 18 case 'r': |
19 mangledSwizzle[i] = swizzleMap[0]; | 19 mangledSwizzle[i] = swizzleMap[0]; |
20 break; | 20 break; |
21 case 'g': | 21 case 'g': |
22 mangledSwizzle[i] = swizzleMap[1]; | 22 mangledSwizzle[i] = swizzleMap[1]; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 swizzle = mangledSwizzle; | 62 swizzle = mangledSwizzle; |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 // For shader prettiness we omit the swizzle rather than appending ".rgba". | 66 // For shader prettiness we omit the swizzle rather than appending ".rgba". |
67 if (memcmp(swizzle, "rgba", 4)) { | 67 if (memcmp(swizzle, "rgba", 4)) { |
68 out->appendf(".%s", swizzle); | 68 out->appendf(".%s", swizzle); |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 GrGLShaderBuilder::GrGLShaderBuilder(GrGLProgramBuilder* program) | 72 GrGLShaderBuilder::GrGLShaderBuilder(GrGLSLProgramBuilder* program) |
73 : fProgramBuilder(program) | 73 : fProgramBuilder(program) |
74 , fInputs(GrGLProgramBuilder::kVarsPerBlock) | 74 , fInputs(GrGLSLProgramBuilder::kVarsPerBlock) |
75 , fOutputs(GrGLProgramBuilder::kVarsPerBlock) | 75 , fOutputs(GrGLSLProgramBuilder::kVarsPerBlock) |
76 , fFeaturesAddedMask(0) | 76 , fFeaturesAddedMask(0) |
77 , fCodeIndex(kCode) | 77 , fCodeIndex(kCode) |
78 , fFinalized(false) { | 78 , fFinalized(false) { |
79 // We push back some dummy pointers which will later become our header | 79 // We push back some dummy pointers which will later become our header |
80 for (int i = 0; i <= kCode; i++) { | 80 for (int i = 0; i <= kCode; i++) { |
81 fShaderStrings.push_back(); | 81 fShaderStrings.push_back(); |
82 fCompilerStrings.push_back(nullptr); | 82 fCompilerStrings.push_back(nullptr); |
83 fCompilerStringLengths.push_back(0); | 83 fCompilerStringLengths.push_back(0); |
84 } | 84 } |
85 | 85 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 180 |
181 GR_STATIC_ASSERT(0 == GrGLShaderBuilder::kOut_InterfaceQualifier); | 181 GR_STATIC_ASSERT(0 == GrGLShaderBuilder::kOut_InterfaceQualifier); |
182 GR_STATIC_ASSERT(SK_ARRAY_COUNT(interfaceQualifierNames) == kLastInterfaceQu
alifier + 1); | 182 GR_STATIC_ASSERT(SK_ARRAY_COUNT(interfaceQualifierNames) == kLastInterfaceQu
alifier + 1); |
183 } | 183 } |
184 | 184 |
185 void GrGLShaderBuilder::finalize(uint32_t visibility) { | 185 void GrGLShaderBuilder::finalize(uint32_t visibility) { |
186 SkASSERT(!fFinalized); | 186 SkASSERT(!fFinalized); |
187 this->versionDecl() = fProgramBuilder->glslCaps()->versionDeclString(); | 187 this->versionDecl() = fProgramBuilder->glslCaps()->versionDeclString(); |
188 this->compileAndAppendLayoutQualifiers(); | 188 this->compileAndAppendLayoutQualifiers(); |
189 SkASSERT(visibility); | 189 SkASSERT(visibility); |
190 fProgramBuilder->appendUniformDecls((GrGLProgramBuilder::ShaderVisibility) v
isibility, | 190 fProgramBuilder->appendUniformDecls((GrGLSLProgramBuilder::ShaderVisibility)
visibility, |
191 &this->uniforms()); | 191 &this->uniforms()); |
192 this->appendDecls(fInputs, &this->inputs()); | 192 this->appendDecls(fInputs, &this->inputs()); |
193 // We should not have any outputs in the fragment shader when using version
1.10 | 193 // We should not have any outputs in the fragment shader when using version
1.10 |
194 SkASSERT(GrGLProgramBuilder::kFragment_Visibility != visibility || | 194 SkASSERT(GrGLSLProgramBuilder::kFragment_Visibility != visibility || |
195 k110_GrGLSLGeneration != fProgramBuilder->glslCaps()->generation()
|| | 195 k110_GrGLSLGeneration != fProgramBuilder->glslCaps()->generation()
|| |
196 fOutputs.empty()); | 196 fOutputs.empty()); |
197 this->appendDecls(fOutputs, &this->outputs()); | 197 this->appendDecls(fOutputs, &this->outputs()); |
198 this->onFinalize(); | 198 this->onFinalize(); |
199 // append the 'footer' to code | 199 // append the 'footer' to code |
200 this->code().append("}"); | 200 this->code().append("}"); |
201 | 201 |
202 for (int i = 0; i <= fCodeIndex; i++) { | 202 for (int i = 0; i <= fCodeIndex; i++) { |
203 fCompilerStrings[i] = fShaderStrings[i].c_str(); | 203 fCompilerStrings[i] = fShaderStrings[i].c_str(); |
204 fCompilerStringLengths[i] = (int)fShaderStrings[i].size(); | 204 fCompilerStringLengths[i] = (int)fShaderStrings[i].size(); |
205 } | 205 } |
206 | 206 |
207 fFinalized = true; | 207 fFinalized = true; |
208 } | 208 } |
209 | 209 |
OLD | NEW |