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 "GrAllocator.h" |
12 #include "gl/GrGLFragmentProcessor.h" | 12 #include "glsl/GrGLSLShaderVar.h" |
13 #include "gl/GrGLProgramDesc.h" | 13 #include "SkTDArray.h" |
14 #include "gl/GrGLProgramDataManager.h" | |
15 #include "gl/GrGLTypes.h" | |
16 | 14 |
17 #include <stdarg.h> | 15 #include <stdarg.h> |
18 | 16 |
19 class GrGLCaps; | |
20 class GrGLContextInfo; | |
21 class GrGLProgramBuilder; | 17 class GrGLProgramBuilder; |
22 class GrGLSLTextureSampler; | 18 class GrGLSLTextureSampler; |
23 | 19 |
24 /** | 20 /** |
25 base class for all shaders builders | 21 base class for all shaders builders |
26 */ | 22 */ |
27 class GrGLShaderBuilder { | 23 class GrGLShaderBuilder { |
28 public: | 24 public: |
29 GrGLShaderBuilder(GrGLProgramBuilder* program); | 25 GrGLShaderBuilder(GrGLProgramBuilder* program); |
| 26 virtual ~GrGLShaderBuilder() {} |
30 | 27 |
31 void addInput(const GrGLSLShaderVar& input) { fInputs.push_back(input); } | 28 void addInput(const GrGLSLShaderVar& input) { fInputs.push_back(input); } |
32 void addOutput(const GrGLSLShaderVar& output) { fOutputs.push_back(output);
} | 29 void addOutput(const GrGLSLShaderVar& output) { fOutputs.push_back(output);
} |
33 | 30 |
34 /* | 31 /* |
35 * We put texture lookups in the base class because it is TECHNICALLY possib
le to do texture | 32 * We put texture lookups in the base class because it is TECHNICALLY possib
le to do texture |
36 * lookups in any kind of shader. However, for the time being using these c
alls on non-fragment | 33 * lookups in any kind of shader. However, for the time being using these c
alls on non-fragment |
37 * shaders will result in a shader compilation error as texture sampler unif
orms are only | 34 * shaders will result in a shader compilation error as texture sampler unif
orms are only |
38 * visible to the fragment shader. It would not be hard to change this beha
vior, if someone | 35 * visible to the fragment shader. It would not be hard to change this beha
vior, if someone |
39 * actually wants to do texture lookups in a non-fragment shader | 36 * actually wants to do texture lookups in a non-fragment shader |
(...skipping 18 matching lines...) Expand all Loading... |
58 | 55 |
59 /** Does the work of appendTextureLookup and modulates the result by modulat
ion. The result is | 56 /** Does the work of appendTextureLookup and modulates the result by modulat
ion. The result is |
60 always a vec4. modulation and the swizzle specified by GrGLSLTextureSamp
ler must both be | 57 always a vec4. modulation and the swizzle specified by GrGLSLTextureSamp
ler must both be |
61 vec4 or float. If modulation is "" or nullptr it this function acts as t
hough | 58 vec4 or float. If modulation is "" or nullptr it this function acts as t
hough |
62 appendTextureLookup were called. */ | 59 appendTextureLookup were called. */ |
63 void appendTextureLookupAndModulate(const char* modulation, | 60 void appendTextureLookupAndModulate(const char* modulation, |
64 const GrGLSLTextureSampler&, | 61 const GrGLSLTextureSampler&, |
65 const char* coordName, | 62 const char* coordName, |
66 GrSLType coordType = kVec2f_GrSLType); | 63 GrSLType coordType = kVec2f_GrSLType); |
67 | 64 |
68 /** If texture swizzling is available using tex parameters then it is prefer
red over mangling | |
69 the generated shader code. This potentially allows greater reuse of cach
ed shaders. */ | |
70 static const GrGLenum* GetTexParamSwizzle(GrPixelConfig config, const GrGLCa
ps& caps); | |
71 | |
72 /** | 65 /** |
73 * Called by GrGLProcessors to add code to one of the shaders. | 66 * Called by GrGLProcessors to add code to one of the shaders. |
74 */ | 67 */ |
75 void codeAppendf(const char format[], ...) SK_PRINTF_LIKE(2, 3) { | 68 void codeAppendf(const char format[], ...) SK_PRINTF_LIKE(2, 3) { |
76 va_list args; | 69 va_list args; |
77 va_start(args, format); | 70 va_start(args, format); |
78 this->code().appendVAList(format, args); | 71 this->code().appendVAList(format, args); |
79 va_end(args); | 72 va_end(args); |
80 } | 73 } |
81 | 74 |
(...skipping 13 matching lines...) Expand all Loading... |
95 | 88 |
96 /** Emits a helper function outside of main() in the fragment shader. */ | 89 /** Emits a helper function outside of main() in the fragment shader. */ |
97 void emitFunction(GrSLType returnType, | 90 void emitFunction(GrSLType returnType, |
98 const char* name, | 91 const char* name, |
99 int argCnt, | 92 int argCnt, |
100 const GrGLSLShaderVar* args, | 93 const GrGLSLShaderVar* args, |
101 const char* body, | 94 const char* body, |
102 SkString* outName); | 95 SkString* outName); |
103 | 96 |
104 /* | 97 /* |
| 98 * Combines the various parts of the shader to create a single finalized sha
der string. |
| 99 */ |
| 100 void finalize(uint32_t visibility); |
| 101 |
| 102 /* |
105 * Get parent builder for adding uniforms | 103 * Get parent builder for adding uniforms |
106 */ | 104 */ |
107 GrGLProgramBuilder* getProgramBuilder() { return fProgramBuilder; } | 105 GrGLProgramBuilder* getProgramBuilder() { return fProgramBuilder; } |
108 | 106 |
109 /** | 107 /** |
110 * Helper for begining and ending a block in the shader code. | 108 * Helper for begining and ending a block in the shader code. |
111 */ | 109 */ |
112 class ShaderBlock { | 110 class ShaderBlock { |
113 public: | 111 public: |
114 ShaderBlock(GrGLShaderBuilder* builder) : fBuilder(builder) { | 112 ShaderBlock(GrGLShaderBuilder* builder) : fBuilder(builder) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 SkString& versionDecl() { return fShaderStrings[kVersionDecl]; } | 164 SkString& versionDecl() { return fShaderStrings[kVersionDecl]; } |
167 SkString& extensions() { return fShaderStrings[kExtensions]; } | 165 SkString& extensions() { return fShaderStrings[kExtensions]; } |
168 SkString& precisionQualifier() { return fShaderStrings[kPrecisionQualifier];
} | 166 SkString& precisionQualifier() { return fShaderStrings[kPrecisionQualifier];
} |
169 SkString& layoutQualifiers() { return fShaderStrings[kLayoutQualifiers]; } | 167 SkString& layoutQualifiers() { return fShaderStrings[kLayoutQualifiers]; } |
170 SkString& uniforms() { return fShaderStrings[kUniforms]; } | 168 SkString& uniforms() { return fShaderStrings[kUniforms]; } |
171 SkString& inputs() { return fShaderStrings[kInputs]; } | 169 SkString& inputs() { return fShaderStrings[kInputs]; } |
172 SkString& outputs() { return fShaderStrings[kOutputs]; } | 170 SkString& outputs() { return fShaderStrings[kOutputs]; } |
173 SkString& functions() { return fShaderStrings[kFunctions]; } | 171 SkString& functions() { return fShaderStrings[kFunctions]; } |
174 SkString& main() { return fShaderStrings[kMain]; } | 172 SkString& main() { return fShaderStrings[kMain]; } |
175 SkString& code() { return fShaderStrings[fCodeIndex]; } | 173 SkString& code() { return fShaderStrings[fCodeIndex]; } |
176 bool finalize(GrGLuint programId, GrGLenum type, SkTDArray<GrGLuint>* shader
Ids); | 174 |
| 175 virtual void onFinalize() = 0; |
177 | 176 |
178 enum { | 177 enum { |
179 kVersionDecl, | 178 kVersionDecl, |
180 kExtensions, | 179 kExtensions, |
181 kPrecisionQualifier, | 180 kPrecisionQualifier, |
182 kLayoutQualifiers, | 181 kLayoutQualifiers, |
183 kUniforms, | 182 kUniforms, |
184 kInputs, | 183 kInputs, |
185 kOutputs, | 184 kOutputs, |
186 kFunctions, | 185 kFunctions, |
(...skipping 13 matching lines...) Expand all Loading... |
200 VarArray fOutputs; | 199 VarArray fOutputs; |
201 uint32_t fFeaturesAddedMask; | 200 uint32_t fFeaturesAddedMask; |
202 SkSTArray<1, SkString> fLayoutParams[kLastInterfaceQualifier + 1]; | 201 SkSTArray<1, SkString> fLayoutParams[kLastInterfaceQualifier + 1]; |
203 int fCodeIndex; | 202 int fCodeIndex; |
204 bool fFinalized; | 203 bool fFinalized; |
205 | 204 |
206 friend class GrGLProgramBuilder; | 205 friend class GrGLProgramBuilder; |
207 friend class GrGLPathProgramBuilder; // to access fInputs. | 206 friend class GrGLPathProgramBuilder; // to access fInputs. |
208 }; | 207 }; |
209 #endif | 208 #endif |
OLD | NEW |