| 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 "GrGLProgramBuilder.h" | 9 #include "GrGLProgramBuilder.h" |
| 10 #include "GrGLShaderStringBuilder.h" | 10 #include "GrGLShaderStringBuilder.h" |
| 11 #include "../GrGLGpu.h" | 11 #include "gl/GrGLCaps.h" |
| 12 #include "../GrGLShaderVar.h" | 12 #include "gl/GrGLContext.h" |
| 13 #include "gl/GrGLGpu.h" |
| 14 #include "gl/GrGLShaderVar.h" |
| 13 #include "glsl/GrGLSLCaps.h" | 15 #include "glsl/GrGLSLCaps.h" |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 void append_texture_lookup(SkString* out, | 18 void append_texture_lookup(SkString* out, |
| 17 GrGLGpu* gpu, | 19 GrGLGpu* gpu, |
| 18 const char* samplerName, | 20 const char* samplerName, |
| 19 const char* coordName, | 21 const char* coordName, |
| 20 uint32_t configComponentMask, | 22 uint32_t configComponentMask, |
| 21 const char* swizzle, | 23 const char* swizzle, |
| 22 GrSLType varyingType = kVec2f_GrSLType) { | 24 GrSLType varyingType = kVec2f_GrSLType) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 fShaderStrings.push_back(); | 62 fShaderStrings.push_back(); |
| 61 fCompilerStrings.push_back(nullptr); | 63 fCompilerStrings.push_back(nullptr); |
| 62 fCompilerStringLengths.push_back(0); | 64 fCompilerStringLengths.push_back(0); |
| 63 } | 65 } |
| 64 | 66 |
| 65 this->main() = "void main() {"; | 67 this->main() = "void main() {"; |
| 66 } | 68 } |
| 67 | 69 |
| 68 void GrGLShaderBuilder::declAppend(const GrGLShaderVar& var) { | 70 void GrGLShaderBuilder::declAppend(const GrGLShaderVar& var) { |
| 69 SkString tempDecl; | 71 SkString tempDecl; |
| 70 var.appendDecl(fProgramBuilder->ctxInfo(), &tempDecl); | 72 var.appendDecl(fProgramBuilder->glslCaps(), &tempDecl); |
| 71 this->codeAppendf("%s;", tempDecl.c_str()); | 73 this->codeAppendf("%s;", tempDecl.c_str()); |
| 72 } | 74 } |
| 73 | 75 |
| 74 void GrGLShaderBuilder::emitFunction(GrSLType returnType, | 76 void GrGLShaderBuilder::emitFunction(GrSLType returnType, |
| 75 const char* name, | 77 const char* name, |
| 76 int argCnt, | 78 int argCnt, |
| 77 const GrGLShaderVar* args, | 79 const GrGLShaderVar* args, |
| 78 const char* body, | 80 const char* body, |
| 79 SkString* outName) { | 81 SkString* outName) { |
| 80 this->functions().append(GrGLSLTypeString(returnType)); | 82 this->functions().append(GrGLSLTypeString(returnType)); |
| 81 fProgramBuilder->nameVariable(outName, '\0', name); | 83 fProgramBuilder->nameVariable(outName, '\0', name); |
| 82 this->functions().appendf(" %s", outName->c_str()); | 84 this->functions().appendf(" %s", outName->c_str()); |
| 83 this->functions().append("("); | 85 this->functions().append("("); |
| 84 const GrGLContextInfo& ctxInfo = fProgramBuilder->gpu()->ctxInfo(); | |
| 85 for (int i = 0; i < argCnt; ++i) { | 86 for (int i = 0; i < argCnt; ++i) { |
| 86 args[i].appendDecl(ctxInfo, &this->functions()); | 87 args[i].appendDecl(fProgramBuilder->glslCaps(), &this->functions()); |
| 87 if (i < argCnt - 1) { | 88 if (i < argCnt - 1) { |
| 88 this->functions().append(", "); | 89 this->functions().append(", "); |
| 89 } | 90 } |
| 90 } | 91 } |
| 91 this->functions().append(") {\n"); | 92 this->functions().append(") {\n"); |
| 92 this->functions().append(body); | 93 this->functions().append(body); |
| 93 this->functions().append("}\n\n"); | 94 this->functions().append("}\n\n"); |
| 94 } | 95 } |
| 95 | 96 |
| 96 void GrGLShaderBuilder::appendTextureLookup(SkString* out, | 97 void GrGLShaderBuilder::appendTextureLookup(SkString* out, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 | 141 |
| 141 void GrGLShaderBuilder::addFeature(uint32_t featureBit, const char* extensionNam
e) { | 142 void GrGLShaderBuilder::addFeature(uint32_t featureBit, const char* extensionNam
e) { |
| 142 if (!(featureBit & fFeaturesAddedMask)) { | 143 if (!(featureBit & fFeaturesAddedMask)) { |
| 143 this->extensions().appendf("#extension %s: require\n", extensionName); | 144 this->extensions().appendf("#extension %s: require\n", extensionName); |
| 144 fFeaturesAddedMask |= featureBit; | 145 fFeaturesAddedMask |= featureBit; |
| 145 } | 146 } |
| 146 } | 147 } |
| 147 | 148 |
| 148 void GrGLShaderBuilder::appendDecls(const VarArray& vars, SkString* out) const { | 149 void GrGLShaderBuilder::appendDecls(const VarArray& vars, SkString* out) const { |
| 149 for (int i = 0; i < vars.count(); ++i) { | 150 for (int i = 0; i < vars.count(); ++i) { |
| 150 vars[i].appendDecl(fProgramBuilder->ctxInfo(), out); | 151 vars[i].appendDecl(fProgramBuilder->glslCaps(), out); |
| 151 out->append(";\n"); | 152 out->append(";\n"); |
| 152 } | 153 } |
| 153 } | 154 } |
| 154 | 155 |
| 155 void GrGLShaderBuilder::appendTextureLookup(const char* samplerName, | 156 void GrGLShaderBuilder::appendTextureLookup(const char* samplerName, |
| 156 const char* coordName, | 157 const char* coordName, |
| 157 uint32_t configComponentMask, | 158 uint32_t configComponentMask, |
| 158 const char* swizzle) { | 159 const char* swizzle) { |
| 159 append_texture_lookup(&this->code(), | 160 append_texture_lookup(&this->code(), |
| 160 fProgramBuilder->gpu(), | 161 fProgramBuilder->gpu(), |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 fFinalized = true; | 216 fFinalized = true; |
| 216 | 217 |
| 217 if (!shaderId) { | 218 if (!shaderId) { |
| 218 return false; | 219 return false; |
| 219 } | 220 } |
| 220 | 221 |
| 221 *shaderIds->append() = shaderId; | 222 *shaderIds->append() = shaderId; |
| 222 | 223 |
| 223 return true; | 224 return true; |
| 224 } | 225 } |
| OLD | NEW |