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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 typedef GrTAllocator<SeparableVaryingInfo> SeparableVaryingInfoArray; | 78 typedef GrTAllocator<SeparableVaryingInfo> SeparableVaryingInfoArray; |
79 | 79 |
80 /** Generates a shader program. | 80 /** Generates a shader program. |
81 * | 81 * |
82 * The program implements what is specified in the stages given as input. | 82 * The program implements what is specified in the stages given as input. |
83 * After successful generation, the builder result objects are available | 83 * After successful generation, the builder result objects are available |
84 * to be used. | 84 * to be used. |
85 * @return true if generation was successful. | 85 * @return true if generation was successful. |
86 */ | 86 */ |
87 bool genProgram(const GrEffectStage* inColorStages[], | 87 |
| 88 bool genProgram(const GrEffectStage* inGeometryProcessor, |
| 89 const GrEffectStage* inColorStages[], |
88 const GrEffectStage* inCoverageStages[]); | 90 const GrEffectStage* inCoverageStages[]); |
89 | 91 |
90 // Below are the results of the shader generation. | 92 GrGLProgramEffects* getGeometryProcessor() const { |
91 | 93 SkASSERT(fProgramID); return fGeometryProcessor.get(); |
| 94 } |
92 GrGLProgramEffects* getColorEffects() const { SkASSERT(fProgramID); return f
ColorEffects.get(); } | 95 GrGLProgramEffects* getColorEffects() const { SkASSERT(fProgramID); return f
ColorEffects.get(); } |
93 GrGLProgramEffects* getCoverageEffects() const { SkASSERT(fProgramID); retur
n fCoverageEffects.get(); } | 96 GrGLProgramEffects* getCoverageEffects() const { SkASSERT(fProgramID); retur
n fCoverageEffects.get(); } |
94 const BuiltinUniformHandles& getBuiltinUniformHandles() const { | 97 const BuiltinUniformHandles& getBuiltinUniformHandles() const { |
95 SkASSERT(fProgramID); | 98 SkASSERT(fProgramID); |
96 return fUniformHandles; | 99 return fUniformHandles; |
97 } | 100 } |
98 GrGLuint getProgramID() const { SkASSERT(fProgramID); return fProgramID; } | 101 GrGLuint getProgramID() const { SkASSERT(fProgramID); return fProgramID; } |
99 bool hasVertexShader() const { SkASSERT(fProgramID); return !fFragOnly; } | 102 bool hasVertexShader() const { SkASSERT(fProgramID); return !fFragOnly; } |
100 int getTexCoordSetCount() const { SkASSERT(fProgramID); return fTexCoordSetC
nt; } | 103 int getTexCoordSetCount() const { SkASSERT(fProgramID); return fTexCoordSetC
nt; } |
101 const UniformInfoArray& getUniformInfos() const { return fUniforms; } | 104 const UniformInfoArray& getUniformInfos() const { return fUniforms; } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 void nameVariable(SkString* out, char prefix, const char* name); | 161 void nameVariable(SkString* out, char prefix, const char* name); |
159 | 162 |
160 virtual bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>
* shaderIds) const; | 163 virtual bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>
* shaderIds) const; |
161 | 164 |
162 virtual void bindProgramLocations(GrGLuint programId); | 165 virtual void bindProgramLocations(GrGLuint programId); |
163 void resolveProgramLocations(GrGLuint programId); | 166 void resolveProgramLocations(GrGLuint programId); |
164 | 167 |
165 void appendDecls(const VarArray&, SkString*) const; | 168 void appendDecls(const VarArray&, SkString*) const; |
166 void appendUniformDecls(ShaderVisibility, SkString*) const; | 169 void appendUniformDecls(ShaderVisibility, SkString*) const; |
167 | 170 |
| 171 SkAutoTUnref<GrGLProgramEffects> fGeometryProcessor; |
168 SkAutoTUnref<GrGLProgramEffects> fColorEffects; | 172 SkAutoTUnref<GrGLProgramEffects> fColorEffects; |
169 SkAutoTUnref<GrGLProgramEffects> fCoverageEffects; | 173 SkAutoTUnref<GrGLProgramEffects> fCoverageEffects; |
170 BuiltinUniformHandles fUniformHandles; | 174 BuiltinUniformHandles fUniformHandles; |
171 bool fFragOnly; | 175 bool fFragOnly; |
172 int fTexCoordSetCnt; | 176 int fTexCoordSetCnt; |
173 GrGLuint fProgramID; | 177 GrGLuint fProgramID; |
174 GrGLFragmentShaderBuilder fFS; | 178 GrGLFragmentShaderBuilder fFS; |
175 SeparableVaryingInfoArray fSeparableVaryingInfos; | 179 SeparableVaryingInfoArray fSeparableVaryingInfos; |
176 private: | 180 |
177 class CodeStage : SkNoncopyable { | 181 class CodeStage : SkNoncopyable { |
178 public: | 182 public: |
179 CodeStage() : fNextIndex(0), fCurrentIndex(-1), fEffectStage(NULL) {} | 183 CodeStage() : fNextIndex(0), fCurrentIndex(-1), fEffectStage(NULL) {} |
180 | 184 |
181 bool inStageCode() const { | 185 bool inStageCode() const { |
182 this->validate(); | 186 this->validate(); |
183 return NULL != fEffectStage; | 187 return NULL != fEffectStage; |
184 } | 188 } |
185 | 189 |
186 const GrEffectStage* effectStage() const { | 190 const GrEffectStage* effectStage() const { |
(...skipping 30 matching lines...) Expand all Loading... |
217 CodeStage* fCodeStage; | 221 CodeStage* fCodeStage; |
218 int fSavedIndex; | 222 int fSavedIndex; |
219 const GrEffectStage* fSavedEffectStage; | 223 const GrEffectStage* fSavedEffectStage; |
220 }; | 224 }; |
221 private: | 225 private: |
222 void validate() const { SkASSERT((NULL == fEffectStage) == (-1 == fCurre
ntIndex)); } | 226 void validate() const { SkASSERT((NULL == fEffectStage) == (-1 == fCurre
ntIndex)); } |
223 int fNextIndex; | 227 int fNextIndex; |
224 int fCurrentIndex; | 228 int fCurrentIndex; |
225 const GrEffectStage* fEffectStage; | 229 const GrEffectStage* fEffectStage; |
226 } fCodeStage; | 230 } fCodeStage; |
| 231 private: |
227 | 232 |
228 /** | 233 /** |
229 * The base class will emit the fragment code that precedes the per-effect c
ode and then call | 234 * The base class will emit the fragment code that precedes the per-effect c
ode and then call |
230 * this function. The subclass can use it to insert additional fragment code
that should | 235 * this function. The subclass can use it to insert additional fragment code
that should |
231 * execute before the effects' code and/or emit other shaders (e.g. geometry
, vertex). | 236 * execute before the effects' code and/or emit other shaders (e.g. geometry
, vertex). |
232 * | 237 * |
233 * The subclass can modify the initial color or coverage | 238 * The subclass can modify the initial color or coverage |
234 */ | 239 */ |
235 virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr4* coverage
) = 0; | 240 virtual void emitCodeBeforeEffects(const GrEffectStage* geometryProcessor, |
| 241 GrGLSLExpr4* color, |
| 242 GrGLSLExpr4* coverage) = 0; |
236 | 243 |
237 /** | 244 /** |
238 * Adds code for effects and returns a GrGLProgramEffects* object. The caller
is responsible for | 245 * Adds code for effects and returns a GrGLProgramEffects* object. The caller
is responsible for |
239 * deleting it when finished. effectStages contains the effects to add. The e
ffect key provider | 246 * deleting it when finished. effectStages contains the effects to add. The e
ffect key provider |
240 * is used to communicate the key each effect created in its GenKey function.
inOutFSColor | 247 * is used to communicate the key each effect created in its GenKey function.
inOutFSColor |
241 * specifies the input color to the first stage and is updated to be the outp
ut color of the | 248 * specifies the input color to the first stage and is updated to be the outp
ut color of the |
242 * last stage. The handles to texture samplers for effectStage[i] are added t
o | 249 * last stage. The handles to texture samplers for effectStage[i] are added t
o |
243 * effectSamplerHandles[i]. | 250 * effectSamplerHandles[i]. |
244 */ | 251 */ |
245 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], | 252 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 * populate the variable. The APIs can refer to the variable through the ret
urned handle. | 297 * populate the variable. The APIs can refer to the variable through the ret
urned handle. |
291 */ | 298 */ |
292 VaryingHandle addSeparableVarying(GrSLType type, | 299 VaryingHandle addSeparableVarying(GrSLType type, |
293 const char* name, | 300 const char* name, |
294 const char** vsOutName, | 301 const char** vsOutName, |
295 const char** fsInName); | 302 const char** fsInName); |
296 | 303 |
297 GrGLVertexShaderBuilder* getVertexShaderBuilder() { return &fVS; } | 304 GrGLVertexShaderBuilder* getVertexShaderBuilder() { return &fVS; } |
298 | 305 |
299 private: | 306 private: |
300 virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr4* coverage
) SK_OVERRIDE; | 307 virtual void emitCodeBeforeEffects(const GrEffectStage* geometryProcessor, |
| 308 GrGLSLExpr4* color, |
| 309 GrGLSLExpr4* coverage) SK_OVERRIDE; |
301 | 310 |
302 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], | 311 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], |
303 int effectCnt, | 312 int effectCnt, |
304 const GrGLProgramDesc::Effe
ctKeyProvider&, | 313 const GrGLProgramDesc::Effe
ctKeyProvider&, |
305 GrGLSLExpr4* inOutFSColor)
SK_OVERRIDE; | 314 GrGLSLExpr4* inOutFSColor)
SK_OVERRIDE; |
306 | 315 |
| 316 /* |
| 317 * These functions are temporary and will eventually operate not on effects
but on |
| 318 * geometry processors |
| 319 */ |
| 320 void createAndEmitEffect(GrGLProgramEffectsBuilder*, |
| 321 const GrEffectStage* effectStage, |
| 322 const GrGLProgramDesc::EffectKeyProvider&, |
| 323 GrGLSLExpr4* inOutFSColor); |
| 324 |
| 325 GrGLProgramEffects* createAndEmitEffect(const GrEffectStage* geometryProcess
or, |
| 326 const GrGLProgramDesc::EffectKeyProv
ider&, |
| 327 GrGLSLExpr4* inOutFSColor); |
| 328 |
307 virtual void emitCodeAfterEffects() SK_OVERRIDE; | 329 virtual void emitCodeAfterEffects() SK_OVERRIDE; |
308 | 330 |
309 virtual bool compileAndAttachShaders(GrGLuint programId, | 331 virtual bool compileAndAttachShaders(GrGLuint programId, |
310 SkTDArray<GrGLuint>* shaderIds) const S
K_OVERRIDE; | 332 SkTDArray<GrGLuint>* shaderIds) const S
K_OVERRIDE; |
311 | 333 |
312 virtual void bindProgramLocations(GrGLuint programId) SK_OVERRIDE; | 334 virtual void bindProgramLocations(GrGLuint programId) SK_OVERRIDE; |
313 | 335 |
314 GrGLGeometryShaderBuilder fGS; | 336 GrGLGeometryShaderBuilder fGS; |
315 GrGLVertexShaderBuilder fVS; | 337 GrGLVertexShaderBuilder fVS; |
316 | 338 |
317 typedef GrGLProgramBuilder INHERITED; | 339 typedef GrGLProgramBuilder INHERITED; |
318 }; | 340 }; |
319 | 341 |
320 //////////////////////////////////////////////////////////////////////////////// | 342 //////////////////////////////////////////////////////////////////////////////// |
321 | 343 |
322 class GrGLFragmentOnlyProgramBuilder : public GrGLProgramBuilder { | 344 class GrGLFragmentOnlyProgramBuilder : public GrGLProgramBuilder { |
323 public: | 345 public: |
324 GrGLFragmentOnlyProgramBuilder(GrGpuGL*, const GrGLProgramDesc&); | 346 GrGLFragmentOnlyProgramBuilder(GrGpuGL*, const GrGLProgramDesc&); |
325 | 347 |
326 int addTexCoordSets(int count); | 348 int addTexCoordSets(int count); |
327 | 349 |
328 private: | 350 private: |
329 virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr4* coverage
) SK_OVERRIDE {} | 351 virtual void emitCodeBeforeEffects(const GrEffectStage*, |
| 352 GrGLSLExpr4* color, |
| 353 GrGLSLExpr4* coverage) SK_OVERRIDE {} |
330 | 354 |
331 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], | 355 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], |
332 int effectCnt, | 356 int effectCnt, |
333 const GrGLProgramDesc::Effe
ctKeyProvider&, | 357 const GrGLProgramDesc::Effe
ctKeyProvider&, |
334 GrGLSLExpr4* inOutFSColor)
SK_OVERRIDE; | 358 GrGLSLExpr4* inOutFSColor)
SK_OVERRIDE; |
335 | 359 |
336 virtual void emitCodeAfterEffects() SK_OVERRIDE {} | 360 virtual void emitCodeAfterEffects() SK_OVERRIDE {} |
337 | 361 |
338 typedef GrGLProgramBuilder INHERITED; | 362 typedef GrGLProgramBuilder INHERITED; |
339 }; | 363 }; |
340 | 364 |
341 #endif | 365 #endif |
OLD | NEW |