| 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 #ifndef GrGLShaderBuilder_DEFINED | 8 #ifndef GrGLShaderBuilder_DEFINED |
| 9 #define GrGLShaderBuilder_DEFINED | 9 #define GrGLShaderBuilder_DEFINED |
| 10 | 10 |
| 11 #include "SkTArray.h" |
| 11 #include "gl/GrGLProcessor.h" | 12 #include "gl/GrGLProcessor.h" |
| 12 #include "gl/GrGLProgramDesc.h" | 13 #include "gl/GrGLProgramDesc.h" |
| 13 #include "gl/GrGLProgramDataManager.h" | 14 #include "gl/GrGLProgramDataManager.h" |
| 14 | 15 |
| 15 #include <stdarg.h> | 16 #include <stdarg.h> |
| 16 | 17 |
| 17 class GrGLContextInfo; | 18 class GrGLContextInfo; |
| 18 class GrGLProgramBuilder; | 19 class GrGLProgramBuilder; |
| 19 | 20 |
| 20 /** | 21 /** |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 /** If texture swizzling is available using tex parameters then it is prefer
red over mangling | 67 /** If texture swizzling is available using tex parameters then it is prefer
red over mangling |
| 67 the generated shader code. This potentially allows greater reuse of cach
ed shaders. */ | 68 the generated shader code. This potentially allows greater reuse of cach
ed shaders. */ |
| 68 static const GrGLenum* GetTexParamSwizzle(GrPixelConfig config, const GrGLCa
ps& caps); | 69 static const GrGLenum* GetTexParamSwizzle(GrPixelConfig config, const GrGLCa
ps& caps); |
| 69 | 70 |
| 70 /** | 71 /** |
| 71 * Called by GrGLProcessors to add code to one of the shaders. | 72 * Called by GrGLProcessors to add code to one of the shaders. |
| 72 */ | 73 */ |
| 73 void codeAppendf(const char format[], ...) SK_PRINTF_LIKE(2, 3) { | 74 void codeAppendf(const char format[], ...) SK_PRINTF_LIKE(2, 3) { |
| 74 va_list args; | 75 va_list args; |
| 75 va_start(args, format); | 76 va_start(args, format); |
| 76 fCode.appendVAList(format, args); | 77 this->code().appendVAList(format, args); |
| 77 va_end(args); | 78 va_end(args); |
| 78 } | 79 } |
| 79 | 80 |
| 80 void codeAppend(const char* str) { fCode.append(str); } | 81 void codeAppend(const char* str) { this->code().append(str); } |
| 81 | 82 |
| 82 void codePrependf(const char format[], ...) SK_PRINTF_LIKE(2, 3) { | 83 void codePrependf(const char format[], ...) SK_PRINTF_LIKE(2, 3) { |
| 83 va_list args; | 84 va_list args; |
| 84 va_start(args, format); | 85 va_start(args, format); |
| 85 fCode.prependVAList(format, args); | 86 this->code().prependVAList(format, args); |
| 86 va_end(args); | 87 va_end(args); |
| 87 } | 88 } |
| 88 | 89 |
| 89 /** | 90 /** |
| 90 * Appends a variable declaration to one of the shaders | 91 * Appends a variable declaration to one of the shaders |
| 91 */ | 92 */ |
| 92 void declAppend(const GrGLShaderVar& var); | 93 void declAppend(const GrGLShaderVar& var); |
| 93 | 94 |
| 94 /** Emits a helper function outside of main() in the fragment shader. */ | 95 /** Emits a helper function outside of main() in the fragment shader. */ |
| 95 void emitFunction(GrSLType returnType, | 96 void emitFunction(GrSLType returnType, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 void appendTextureLookup(const char* samplerName, | 132 void appendTextureLookup(const char* samplerName, |
| 132 const char* coordName, | 133 const char* coordName, |
| 133 uint32_t configComponentMask, | 134 uint32_t configComponentMask, |
| 134 const char* swizzle); | 135 const char* swizzle); |
| 135 | 136 |
| 136 /* | 137 /* |
| 137 * A general function which enables an extension in a shader if the feature
bit is not present | 138 * A general function which enables an extension in a shader if the feature
bit is not present |
| 138 */ | 139 */ |
| 139 void addFeature(uint32_t featureBit, const char* extensionName); | 140 void addFeature(uint32_t featureBit, const char* extensionName); |
| 140 | 141 |
| 142 void nextStage() { |
| 143 fShaderStrings.push_back(); |
| 144 fCompilerStrings.push_back(this->code().c_str()); |
| 145 fCompilerStringLengths.push_back((int)this->code().size()); |
| 146 fCodeIndex++; |
| 147 } |
| 148 |
| 149 SkString& versionDecl() { return fShaderStrings[kVersionDecl]; } |
| 150 SkString& extensions() { return fShaderStrings[kExtensions]; } |
| 151 SkString& precisionQualifier() { return fShaderStrings[kPrecisionQualifier];
} |
| 152 SkString& uniforms() { return fShaderStrings[kUniforms]; } |
| 153 SkString& inputs() { return fShaderStrings[kInputs]; } |
| 154 SkString& outputs() { return fShaderStrings[kOutputs]; } |
| 155 SkString& functions() { return fShaderStrings[kFunctions]; } |
| 156 SkString& main() { return fShaderStrings[kMain]; } |
| 157 SkString& code() { return fShaderStrings[fCodeIndex]; } |
| 158 bool finalize(GrGLuint programId, GrGLenum type, SkTDArray<GrGLuint>* shader
Ids); |
| 159 |
| 160 enum { |
| 161 kVersionDecl, |
| 162 kExtensions, |
| 163 kPrecisionQualifier, |
| 164 kUniforms, |
| 165 kInputs, |
| 166 kOutputs, |
| 167 kFunctions, |
| 168 kMain, |
| 169 kCode, |
| 170 }; |
| 171 |
| 141 GrGLProgramBuilder* fProgramBuilder; | 172 GrGLProgramBuilder* fProgramBuilder; |
| 142 | 173 SkSTArray<kCode, const char*, true> fCompilerStrings; |
| 174 SkSTArray<kCode, int, true> fCompilerStringLengths; |
| 175 SkSTArray<kCode, SkString> fShaderStrings; |
| 143 SkString fCode; | 176 SkString fCode; |
| 144 SkString fFunctions; | 177 SkString fFunctions; |
| 145 SkString fExtensions; | 178 SkString fExtensions; |
| 146 | 179 |
| 147 VarArray fInputs; | 180 VarArray fInputs; |
| 148 VarArray fOutputs; | 181 VarArray fOutputs; |
| 149 uint32_t fFeaturesAddedMask; | 182 uint32_t fFeaturesAddedMask; |
| 183 int fCodeIndex; |
| 184 bool fFinalized; |
| 185 |
| 186 friend class GrGLProgramBuilder; |
| 150 }; | 187 }; |
| 151 #endif | 188 #endif |
| OLD | NEW |