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 "gl/GrGLProgramDesc.h" | 11 #include "gl/GrGLProgramDesc.h" |
12 #include "gl/GrGLProgramEffects.h" | |
13 #include "gl/GrGLSL.h" | |
14 #include "gl/GrGLProgramDataManager.h" | 12 #include "gl/GrGLProgramDataManager.h" |
15 #include "GrBackendProcessorFactory.h" | |
16 #include "GrColor.h" | |
17 #include "GrProcessor.h" | |
18 #include "SkTypes.h" | |
19 | 13 |
20 #include <stdarg.h> | 14 #include <stdarg.h> |
21 | 15 |
22 class GrGLContextInfo; | 16 class GrGLContextInfo; |
23 class GrProcessorStage; | |
24 class GrGLProgramDesc; | |
25 class GrGLProgramBuilder; | 17 class GrGLProgramBuilder; |
26 class GrGLFullProgramBuilder; | |
27 | 18 |
28 /** | 19 /** |
29 base class for all shaders builders | 20 base class for all shaders builders |
30 */ | 21 */ |
31 class GrGLShaderBuilder { | 22 class GrGLShaderBuilder { |
32 public: | 23 public: |
33 typedef GrGLProcessor::TransformedCoordsArray TransformedCoordsArray; | 24 typedef GrGLProcessor::TransformedCoordsArray TransformedCoordsArray; |
34 typedef GrGLProcessor::TextureSampler TextureSampler; | 25 typedef GrGLProcessor::TextureSampler TextureSampler; |
| 26 |
35 GrGLShaderBuilder(GrGLProgramBuilder* program); | 27 GrGLShaderBuilder(GrGLProgramBuilder* program); |
36 | 28 |
37 void addInput(GrGLShaderVar i) { fInputs.push_back(i); } | 29 void addInput(GrGLShaderVar i) { fInputs.push_back(i); } |
38 void addOutput(GrGLShaderVar i) { fOutputs.push_back(i); } | 30 void addOutput(GrGLShaderVar i) { fOutputs.push_back(i); } |
39 | 31 |
40 /* | 32 /* |
41 * We put texture lookups in the base class because it is TECHNICALLY possib
le to do texture | 33 * We put texture lookups in the base class because it is TECHNICALLY possib
le to do texture |
42 * lookups in any kind of shader. However, for the time being using these c
alls on non-fragment | 34 * lookups in any kind of shader. However, for the time being using these c
alls on non-fragment |
43 * shaders will result in a shader compilation error as texture sampler unif
orms are only | 35 * shaders will result in a shader compilation error as texture sampler unif
orms are only |
44 * visible to the fragment shader. It would not be hard to change this beha
vior, if someone | 36 * visible to the fragment shader. It would not be hard to change this beha
vior, if someone |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 const GrGLShaderVar* args, | 97 const GrGLShaderVar* args, |
106 const char* body, | 98 const char* body, |
107 SkString* outName); | 99 SkString* outName); |
108 | 100 |
109 /* | 101 /* |
110 * Get parent builder for adding uniforms | 102 * Get parent builder for adding uniforms |
111 */ | 103 */ |
112 GrGLProgramBuilder* getProgramBuilder() { return fProgramBuilder; } | 104 GrGLProgramBuilder* getProgramBuilder() { return fProgramBuilder; } |
113 | 105 |
114 /** | 106 /** |
115 * Helper for begining and ending a block in the fragment code. | 107 * Helper for begining and ending a block in the shader code. |
116 */ | 108 */ |
117 class ShaderBlock { | 109 class ShaderBlock { |
118 public: | 110 public: |
119 ShaderBlock(GrGLShaderBuilder* builder) : fBuilder(builder) { | 111 ShaderBlock(GrGLShaderBuilder* builder) : fBuilder(builder) { |
120 SkASSERT(builder); | 112 SkASSERT(builder); |
121 fBuilder->codeAppend("{"); | 113 fBuilder->codeAppend("{"); |
122 } | 114 } |
123 | 115 |
124 ~ShaderBlock() { | 116 ~ShaderBlock() { |
125 fBuilder->codeAppend("}"); | 117 fBuilder->codeAppend("}"); |
126 } | 118 } |
127 private: | 119 private: |
128 GrGLShaderBuilder* fBuilder; | 120 GrGLShaderBuilder* fBuilder; |
129 }; | 121 }; |
| 122 |
130 protected: | 123 protected: |
| 124 typedef GrTAllocator<GrGLShaderVar> VarArray; |
| 125 void appendDecls(const VarArray& vars, SkString* out) const; |
131 | 126 |
132 /* | 127 /* |
133 * this super low level function is just for use internally to builders | 128 * this super low level function is just for use internally to builders |
134 */ | 129 */ |
135 void appendTextureLookup(const char* samplerName, | 130 void appendTextureLookup(const char* samplerName, |
136 const char* coordName, | 131 const char* coordName, |
137 uint32_t configComponentMask, | 132 uint32_t configComponentMask, |
138 const char* swizzle); | 133 const char* swizzle); |
139 | 134 |
140 /* | 135 /* |
141 * A general function which enables an extension in a shader if the feature
bit is not present | 136 * A general function which enables an extension in a shader if the feature
bit is not present |
142 */ | 137 */ |
143 void addFeature(uint32_t featureBit, const char* extensionName); | 138 void addFeature(uint32_t featureBit, const char* extensionName); |
144 | 139 |
145 typedef GrTAllocator<GrGLShaderVar> VarArray; | |
146 | |
147 GrGLProgramBuilder* fProgramBuilder; | 140 GrGLProgramBuilder* fProgramBuilder; |
148 | 141 |
149 SkString fCode; | 142 SkString fCode; |
150 SkString fFunctions; | 143 SkString fFunctions; |
151 SkString fExtensions; | 144 SkString fExtensions; |
152 | 145 |
153 VarArray fInputs; | 146 VarArray fInputs; |
154 VarArray fOutputs; | 147 VarArray fOutputs; |
155 uint32_t fFeaturesAddedMask; | 148 uint32_t fFeaturesAddedMask; |
156 }; | 149 }; |
157 | |
158 | |
159 /* | |
160 * Full Shader builder is the base class for shaders which are only accessible t
hrough full program | |
161 * builder, ie vertex, geometry, and later TCU / TES. Using this base class, th
ey can access the | |
162 * full program builder functionality through the full program pointer | |
163 */ | |
164 class GrGLFullShaderBuilder : public GrGLShaderBuilder { | |
165 public: | |
166 GrGLFullShaderBuilder(GrGLFullProgramBuilder* program); | |
167 | |
168 GrGLFullProgramBuilder* fullProgramBuilder() { return fFullProgramBuilder; } | |
169 protected: | |
170 GrGLFullProgramBuilder* fFullProgramBuilder; | |
171 private: | |
172 typedef GrGLShaderBuilder INHERITED; | |
173 }; | |
174 #endif | 150 #endif |
OLD | NEW |