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