OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "GrAllocator.h" | 11 #include "GrAllocator.h" |
12 #include "GrBackendEffectFactory.h" | 12 #include "GrBackendEffectFactory.h" |
13 #include "GrColor.h" | 13 #include "GrColor.h" |
14 #include "GrEffect.h" | 14 #include "GrEffect.h" |
15 #include "SkTypes.h" | 15 #include "SkTypes.h" |
| 16 #include "gl/GrGLProgramDesc.h" |
16 #include "gl/GrGLProgramEffects.h" | 17 #include "gl/GrGLProgramEffects.h" |
17 #include "gl/GrGLSL.h" | 18 #include "gl/GrGLSL.h" |
18 #include "gl/GrGLUniformManager.h" | 19 #include "gl/GrGLUniformManager.h" |
19 | 20 |
20 #include <stdarg.h> | 21 #include <stdarg.h> |
21 | 22 |
22 class GrGLContextInfo; | 23 class GrGLContextInfo; |
23 class GrEffectStage; | 24 class GrEffectStage; |
24 class GrGLProgramDesc; | 25 class GrGLProgramDesc; |
25 | 26 |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 GrGpuGL* gpu() const { return fGpu; } | 247 GrGpuGL* gpu() const { return fGpu; } |
247 | 248 |
248 const GrGLProgramDesc& desc() const { return fDesc; } | 249 const GrGLProgramDesc& desc() const { return fDesc; } |
249 | 250 |
250 /** Add input/output variable declarations (i.e. 'varying') to the fragment
shader. */ | 251 /** Add input/output variable declarations (i.e. 'varying') to the fragment
shader. */ |
251 GrGLShaderVar& fsInputAppend() { return fFSInputs.push_back(); } | 252 GrGLShaderVar& fsInputAppend() { return fFSInputs.push_back(); } |
252 | 253 |
253 // Helper for emitEffects(). | 254 // Helper for emitEffects(). |
254 void createAndEmitEffects(GrGLProgramEffectsBuilder*, | 255 void createAndEmitEffects(GrGLProgramEffectsBuilder*, |
255 const GrEffectStage* effectStages[], | 256 const GrEffectStage* effectStages[], |
256 const EffectKey effectKeys[], | |
257 int effectCnt, | 257 int effectCnt, |
| 258 const GrGLProgramDesc::EffectKeyProvider&, |
258 GrGLSLExpr4* inOutFSColor); | 259 GrGLSLExpr4* inOutFSColor); |
259 | 260 |
260 // Generates a name for a variable. The generated string will be name prefix
ed by the prefix | 261 // Generates a name for a variable. The generated string will be name prefix
ed by the prefix |
261 // char (unless the prefix is '\0'). It also mangles the name to be stage-sp
ecific if we're | 262 // char (unless the prefix is '\0'). It also mangles the name to be stage-sp
ecific if we're |
262 // generating stage code. | 263 // generating stage code. |
263 void nameVariable(SkString* out, char prefix, const char* name); | 264 void nameVariable(SkString* out, char prefix, const char* name); |
264 | 265 |
265 virtual bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>
* shaderIds) const; | 266 virtual bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>
* shaderIds) const; |
266 | 267 |
267 virtual void bindProgramLocations(GrGLuint programId) const; | 268 virtual void bindProgramLocations(GrGLuint programId) const; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 * The base class will emit the fragment code that precedes the per-effect c
ode and then call | 332 * The base class will emit the fragment code that precedes the per-effect c
ode and then call |
332 * this function. The subclass can use it to insert additional fragment code
that should | 333 * this function. The subclass can use it to insert additional fragment code
that should |
333 * execute before the effects' code and/or emit other shaders (e.g. geometry
, vertex). | 334 * execute before the effects' code and/or emit other shaders (e.g. geometry
, vertex). |
334 * | 335 * |
335 * The subclass can modify the initial color or coverage | 336 * The subclass can modify the initial color or coverage |
336 */ | 337 */ |
337 virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr4* coverage
) = 0; | 338 virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr4* coverage
) = 0; |
338 | 339 |
339 /** | 340 /** |
340 * Adds code for effects and returns a GrGLProgramEffects* object. The caller
is responsible for | 341 * Adds code for effects and returns a GrGLProgramEffects* object. The caller
is responsible for |
341 * deleting it when finished. effectStages contains the effects to add. effec
tKeys[i] is the key | 342 * deleting it when finished. effectStages contains the effects to add. The e
ffect key provider |
342 * generated from effectStages[i]. inOutFSColor specifies the input color to
the first stage and | 343 * is used to communicate the key each effect created in its GenKey function.
inOutFSColor |
343 * is updated to be the output color of the last stage. | 344 * specifies the input color to the first stage and is updated to be the outp
ut color of the |
344 * The handles to texture samplers for effectStage[i] are added to | 345 * last stage. The handles to texture samplers for effectStage[i] are added t
o |
345 * effectSamplerHandles[i]. | 346 * effectSamplerHandles[i]. |
346 */ | 347 */ |
347 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], | 348 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], |
348 const EffectKey effectKeys[
], | |
349 int effectCnt, | 349 int effectCnt, |
| 350 const GrGLProgramDesc::Effe
ctKeyProvider&, |
350 GrGLSLExpr4* inOutFSColor)
= 0; | 351 GrGLSLExpr4* inOutFSColor)
= 0; |
351 | 352 |
352 /** | 353 /** |
353 * Similar to emitCodeBeforeEffects() but called after per-effect code is em
itted. | 354 * Similar to emitCodeBeforeEffects() but called after per-effect code is em
itted. |
354 */ | 355 */ |
355 virtual void emitCodeAfterEffects() = 0; | 356 virtual void emitCodeAfterEffects() = 0; |
356 | 357 |
357 /** Enables using the secondary color output and returns the name of the var
in which it is | 358 /** Enables using the secondary color output and returns the name of the var
in which it is |
358 to be stored */ | 359 to be stored */ |
359 const char* enableSecondaryOutput(); | 360 const char* enableSecondaryOutput(); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 */ | 459 */ |
459 bool hasExplicitLocalCoords() const { return (fLocalCoordsVar != fPositionVa
r); } | 460 bool hasExplicitLocalCoords() const { return (fLocalCoordsVar != fPositionVa
r); } |
460 | 461 |
461 bool addEffectAttribute(int attributeIndex, GrSLType type, const SkString& n
ame); | 462 bool addEffectAttribute(int attributeIndex, GrSLType type, const SkString& n
ame); |
462 const SkString* getEffectAttributeName(int attributeIndex) const; | 463 const SkString* getEffectAttributeName(int attributeIndex) const; |
463 | 464 |
464 private: | 465 private: |
465 virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr4* coverage
) SK_OVERRIDE; | 466 virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr4* coverage
) SK_OVERRIDE; |
466 | 467 |
467 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], | 468 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], |
468 const EffectKey effectKeys[
], | |
469 int effectCnt, | 469 int effectCnt, |
| 470 const GrGLProgramDesc::Effe
ctKeyProvider&, |
470 GrGLSLExpr4* inOutFSColor)
SK_OVERRIDE; | 471 GrGLSLExpr4* inOutFSColor)
SK_OVERRIDE; |
471 | 472 |
472 virtual void emitCodeAfterEffects() SK_OVERRIDE; | 473 virtual void emitCodeAfterEffects() SK_OVERRIDE; |
473 | 474 |
474 virtual bool compileAndAttachShaders(GrGLuint programId, | 475 virtual bool compileAndAttachShaders(GrGLuint programId, |
475 SkTDArray<GrGLuint>* shaderIds) const S
K_OVERRIDE; | 476 SkTDArray<GrGLuint>* shaderIds) const S
K_OVERRIDE; |
476 | 477 |
477 virtual void bindProgramLocations(GrGLuint programId) const SK_OVERRIDE; | 478 virtual void bindProgramLocations(GrGLuint programId) const SK_OVERRIDE; |
478 | 479 |
479 VarArray fVSAttrs; | 480 VarArray fVSAttrs; |
(...skipping 23 matching lines...) Expand all Loading... |
503 class GrGLFragmentOnlyShaderBuilder : public GrGLShaderBuilder { | 504 class GrGLFragmentOnlyShaderBuilder : public GrGLShaderBuilder { |
504 public: | 505 public: |
505 GrGLFragmentOnlyShaderBuilder(GrGpuGL*, GrGLUniformManager*, const GrGLProgr
amDesc&); | 506 GrGLFragmentOnlyShaderBuilder(GrGpuGL*, GrGLUniformManager*, const GrGLProgr
amDesc&); |
506 | 507 |
507 int addTexCoordSets(int count); | 508 int addTexCoordSets(int count); |
508 | 509 |
509 private: | 510 private: |
510 virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr4* coverage
) SK_OVERRIDE {} | 511 virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr4* coverage
) SK_OVERRIDE {} |
511 | 512 |
512 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], | 513 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], |
513 const EffectKey effectKeys[
], | |
514 int effectCnt, | 514 int effectCnt, |
| 515 const GrGLProgramDesc::Effe
ctKeyProvider&, |
515 GrGLSLExpr4* inOutFSColor)
SK_OVERRIDE; | 516 GrGLSLExpr4* inOutFSColor)
SK_OVERRIDE; |
516 | 517 |
517 virtual void emitCodeAfterEffects() SK_OVERRIDE {} | 518 virtual void emitCodeAfterEffects() SK_OVERRIDE {} |
518 | 519 |
519 typedef GrGLShaderBuilder INHERITED; | 520 typedef GrGLShaderBuilder INHERITED; |
520 }; | 521 }; |
521 | 522 |
522 #endif | 523 #endif |
OLD | NEW |