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 GrGLProgramBuilder_DEFINED | 8 #ifndef GrGLProgramBuilder_DEFINED |
9 #define GrGLProgramBuilder_DEFINED | 9 #define GrGLProgramBuilder_DEFINED |
10 | 10 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 GrGLFragmentShaderBuilder* getFragmentShaderBuilder() { return &fFS; } | 142 GrGLFragmentShaderBuilder* getFragmentShaderBuilder() { return &fFS; } |
143 GrGpuGL* gpu() const { return fGpu; } | 143 GrGpuGL* gpu() const { return fGpu; } |
144 | 144 |
145 protected: | 145 protected: |
146 typedef GrTAllocator<GrGLShaderVar> VarArray; | 146 typedef GrTAllocator<GrGLShaderVar> VarArray; |
147 GrGLProgramBuilder(GrGpuGL*, const GrGLProgramDesc&); | 147 GrGLProgramBuilder(GrGpuGL*, const GrGLProgramDesc&); |
148 | 148 |
149 const GrGLProgramDesc& desc() const { return fDesc; } | 149 const GrGLProgramDesc& desc() const { return fDesc; } |
150 | 150 |
151 // Helper for emitEffects(). | 151 // Helper for emitEffects(). |
152 void createAndEmitEffects(GrGLProgramEffectsBuilder*, | 152 void createAndEmitEffects(const GrEffectStage* effectStages[], |
153 const GrEffectStage* effectStages[], | |
154 int effectCnt, | 153 int effectCnt, |
155 const GrGLProgramDesc::EffectKeyProvider&, | 154 const GrGLProgramDesc::EffectKeyProvider&, |
156 GrGLSLExpr4* inOutFSColor); | 155 GrGLSLExpr4* inOutFSColor); |
157 | 156 |
| 157 /* |
| 158 * A helper function called to emit the geometry processor as well as indivi
dual coverage |
| 159 * and color stages. this will call into subclasses emit effect |
| 160 */ |
| 161 void emitEffect(const GrEffectStage& effectStage, |
| 162 int effectIndex, |
| 163 const GrGLProgramDesc::EffectKeyProvider& keyProvider, |
| 164 GrGLSLExpr4* inColor, |
| 165 GrGLSLExpr4* outColor); |
| 166 |
| 167 /** |
| 168 * Helper for emitEffect() in subclasses. Emits uniforms for an effect's tex
ture accesses and |
| 169 * appends the necessary data to the TextureSamplerArray* object so effects
can add texture |
| 170 * lookups to their code. This method is only meant to be called during the
construction phase. |
| 171 */ |
| 172 void emitSamplers(const GrEffect& effect, GrGLEffect::TextureSamplerArray* o
utSamplers); |
| 173 |
158 // Generates a name for a variable. The generated string will be name prefix
ed by the prefix | 174 // Generates a name for a variable. The generated string will be name prefix
ed by the prefix |
159 // char (unless the prefix is '\0'). It also mangles the name to be stage-sp
ecific if we're | 175 // char (unless the prefix is '\0'). It also mangles the name to be stage-sp
ecific if we're |
160 // generating stage code. | 176 // generating stage code. |
161 void nameVariable(SkString* out, char prefix, const char* name); | 177 void nameVariable(SkString* out, char prefix, const char* name); |
162 | 178 |
163 virtual bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>
* shaderIds) const; | 179 virtual bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>
* shaderIds) const; |
164 | 180 |
165 virtual void bindProgramLocations(GrGLuint programId); | 181 virtual void bindProgramLocations(GrGLuint programId); |
166 void resolveProgramLocations(GrGLuint programId); | 182 void resolveProgramLocations(GrGLuint programId); |
167 | 183 |
168 void appendDecls(const VarArray&, SkString*) const; | 184 void appendDecls(const VarArray&, SkString*) const; |
169 void appendUniformDecls(ShaderVisibility, SkString*) const; | 185 void appendUniformDecls(ShaderVisibility, SkString*) const; |
170 | 186 |
171 SkAutoTUnref<GrGLProgramEffects> fGeometryProcessor; | |
172 SkAutoTUnref<GrGLProgramEffects> fColorEffects; | |
173 SkAutoTUnref<GrGLProgramEffects> fCoverageEffects; | |
174 BuiltinUniformHandles fUniformHandles; | |
175 bool fFragOnly; | |
176 int fTexCoordSetCnt; | |
177 GrGLuint fProgramID; | |
178 GrGLFragmentShaderBuilder fFS; | |
179 SeparableVaryingInfoArray fSeparableVaryingInfos; | |
180 | |
181 class CodeStage : SkNoncopyable { | 187 class CodeStage : SkNoncopyable { |
182 public: | 188 public: |
183 CodeStage() : fNextIndex(0), fCurrentIndex(-1), fEffectStage(NULL) {} | 189 CodeStage() : fNextIndex(0), fCurrentIndex(-1), fEffectStage(NULL) {} |
184 | 190 |
185 bool inStageCode() const { | 191 bool inStageCode() const { |
186 this->validate(); | 192 this->validate(); |
187 return SkToBool(fEffectStage); | 193 return SkToBool(fEffectStage); |
188 } | 194 } |
189 | 195 |
190 const GrEffectStage* effectStage() const { | 196 const GrEffectStage* effectStage() const { |
(...skipping 29 matching lines...) Expand all Loading... |
220 private: | 226 private: |
221 CodeStage* fCodeStage; | 227 CodeStage* fCodeStage; |
222 int fSavedIndex; | 228 int fSavedIndex; |
223 const GrEffectStage* fSavedEffectStage; | 229 const GrEffectStage* fSavedEffectStage; |
224 }; | 230 }; |
225 private: | 231 private: |
226 void validate() const { SkASSERT((NULL == fEffectStage) == (-1 == fCurre
ntIndex)); } | 232 void validate() const { SkASSERT((NULL == fEffectStage) == (-1 == fCurre
ntIndex)); } |
227 int fNextIndex; | 233 int fNextIndex; |
228 int fCurrentIndex; | 234 int fCurrentIndex; |
229 const GrEffectStage* fEffectStage; | 235 const GrEffectStage* fEffectStage; |
230 } fCodeStage; | 236 }; |
| 237 |
| 238 CodeStage fCodeStage; |
| 239 SkAutoTUnref<GrGLProgramEffects> fGeometryProcessor; |
| 240 SkAutoTUnref<GrGLProgramEffects> fColorEffects; |
| 241 SkAutoTUnref<GrGLProgramEffects> fCoverageEffects; |
| 242 BuiltinUniformHandles fUniformHandles; |
| 243 bool fFragOnly; |
| 244 int fTexCoordSetCnt; |
| 245 GrGLuint fProgramID; |
| 246 GrGLFragmentShaderBuilder fFS; |
| 247 SeparableVaryingInfoArray fSeparableVaryingInfos; |
231 | 248 |
232 private: | 249 private: |
233 | 250 virtual void createAndEmitEffects(const GrEffectStage* geometryProcessor, |
234 /** | 251 const GrEffectStage* colorStages[], |
235 * The base class will emit the fragment code that precedes the per-effect c
ode and then call | 252 const GrEffectStage* coverageStages[], |
236 * this function. The subclass can use it to insert additional fragment code
that should | 253 GrGLSLExpr4* inputColor, |
237 * execute before the effects' code and/or emit other shaders (e.g. geometry
, vertex). | 254 GrGLSLExpr4* inputCoverage) = 0; |
238 * | 255 /* |
239 * The subclass can modify the initial color or coverage | 256 * Subclasses override emitEffect below to emit data and code for a specific
single effect |
240 */ | 257 */ |
241 virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, | 258 virtual void emitEffect(const GrEffectStage&, |
242 GrGLSLExpr4* coverage) = 0; | 259 const GrEffectKey&, |
| 260 const char* outColor, |
| 261 const char* inColor, |
| 262 int stageIndex) = 0; |
243 | 263 |
244 /* | 264 /* |
245 * Full shader builder needs to emit code after the color stages and before
the coverage stages | 265 * Because we have fragment only builders, and those builders need to implem
ent a subclass |
| 266 * of program effects, we have to have base classes overload the program eff
ects here |
246 */ | 267 */ |
247 virtual void emitGeometryProcessor(const GrEffectStage* geometryProcessor, | 268 virtual GrGLProgramEffects* getProgramEffects() = 0; |
248 GrGLSLExpr4* coverage) = 0; | |
249 | |
250 /** | |
251 * Adds code for effects and returns a GrGLProgramEffects* object. The caller
is responsible for | |
252 * deleting it when finished. effectStages contains the effects to add. The e
ffect key provider | |
253 * is used to communicate the key each effect created in its GenKey function.
inOutFSColor | |
254 * specifies the input color to the first stage and is updated to be the outp
ut color of the | |
255 * last stage. The handles to texture samplers for effectStage[i] are added t
o | |
256 * effectSamplerHandles[i]. | |
257 */ | |
258 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], | |
259 int effectCnt, | |
260 const GrGLProgramDesc::Effe
ctKeyProvider&, | |
261 GrGLSLExpr4* inOutFSColor)
= 0; | |
262 | |
263 /** | |
264 * Similar to emitCodeBeforeEffects() but called after per-effect code is em
itted. | |
265 */ | |
266 virtual void emitCodeAfterEffects() = 0; | |
267 | 269 |
268 /** | 270 /** |
269 * Compiles all the shaders, links them into a program, and writes the progr
am id to the output | 271 * Compiles all the shaders, links them into a program, and writes the progr
am id to the output |
270 * struct. | 272 * struct. |
271 **/ | 273 **/ |
272 bool finish(); | 274 bool finish(); |
273 | 275 |
274 const GrGLProgramDesc& fDesc; | 276 const GrGLProgramDesc& fDesc; |
275 GrGpuGL* fGpu; | 277 GrGpuGL* fGpu; |
276 UniformInfoArray fUniforms; | 278 UniformInfoArray fUniforms; |
277 | 279 |
278 friend class GrGLShaderBuilder; | 280 friend class GrGLShaderBuilder; |
279 friend class GrGLVertexShaderBuilder; | 281 friend class GrGLVertexShaderBuilder; |
280 friend class GrGLFragmentShaderBuilder; | 282 friend class GrGLFragmentShaderBuilder; |
281 friend class GrGLGeometryShaderBuilder; | 283 friend class GrGLGeometryShaderBuilder; |
282 }; | 284 }; |
283 | 285 |
284 #endif | 286 #endif |
OLD | NEW |