| 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 |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 GrGLShaderBuilder* fBuilder; | 226 GrGLShaderBuilder* fBuilder; |
| 227 }; | 227 }; |
| 228 | 228 |
| 229 protected: | 229 protected: |
| 230 GrGLShaderBuilder(GrGpuGL*, GrGLUniformManager*, const GrGLProgramDesc&); | 230 GrGLShaderBuilder(GrGpuGL*, GrGLUniformManager*, const GrGLProgramDesc&); |
| 231 | 231 |
| 232 GrGpuGL* gpu() const { return fGpu; } | 232 GrGpuGL* gpu() const { return fGpu; } |
| 233 | 233 |
| 234 const GrGLProgramDesc& desc() const { return fDesc; } | 234 const GrGLProgramDesc& desc() const { return fDesc; } |
| 235 | 235 |
| 236 void setInputColor(const GrGLSLExpr4& inputColor) { fInputColor = inputColor
; } | |
| 237 void setInputCoverage(const GrGLSLExpr4& inputCoverage) { fInputCoverage = i
nputCoverage; } | |
| 238 | |
| 239 /** Add input/output variable declarations (i.e. 'varying') to the fragment
shader. */ | 236 /** Add input/output variable declarations (i.e. 'varying') to the fragment
shader. */ |
| 240 GrGLShaderVar& fsInputAppend() { return fFSInputs.push_back(); } | 237 GrGLShaderVar& fsInputAppend() { return fFSInputs.push_back(); } |
| 241 | 238 |
| 242 // Helper for emitEffects(). | 239 // Helper for emitEffects(). |
| 243 void createAndEmitEffects(GrGLProgramEffectsBuilder*, | 240 void createAndEmitEffects(GrGLProgramEffectsBuilder*, |
| 244 const GrEffectStage* effectStages[], | 241 const GrEffectStage* effectStages[], |
| 245 const EffectKey effectKeys[], | 242 const EffectKey effectKeys[], |
| 246 int effectCnt, | 243 int effectCnt, |
| 247 GrGLSLExpr4* inOutFSColor); | 244 GrGLSLExpr4* inOutFSColor); |
| 248 | 245 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 private: | 307 private: |
| 311 void validate() const { SkASSERT((NULL == fEffectStage) == (-1 == fCurre
ntIndex)); } | 308 void validate() const { SkASSERT((NULL == fEffectStage) == (-1 == fCurre
ntIndex)); } |
| 312 int fNextIndex; | 309 int fNextIndex; |
| 313 int fCurrentIndex; | 310 int fCurrentIndex; |
| 314 const GrEffectStage* fEffectStage; | 311 const GrEffectStage* fEffectStage; |
| 315 } fCodeStage; | 312 } fCodeStage; |
| 316 | 313 |
| 317 bool genProgram(const GrEffectStage* colorStages[], const GrEffectStage* cov
erageStages[]); | 314 bool genProgram(const GrEffectStage* colorStages[], const GrEffectStage* cov
erageStages[]); |
| 318 | 315 |
| 319 /** | 316 /** |
| 317 * The base class will emit the fragment code that precedes the per-effect c
ode and then call |
| 318 * this function. The subclass can use it to insert additional fragment code
that should |
| 319 * execute before the effects' code and/or emit other shaders (e.g. geometry
, vertex). |
| 320 * |
| 321 * The subclass can modify the initial color or coverage |
| 322 */ |
| 323 virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr4* coverage
) = 0; |
| 324 |
| 325 /** |
| 320 * Adds code for effects and returns a GrGLProgramEffects* object. The caller
is responsible for | 326 * Adds code for effects and returns a GrGLProgramEffects* object. The caller
is responsible for |
| 321 * deleting it when finished. effectStages contains the effects to add. effec
tKeys[i] is the key | 327 * deleting it when finished. effectStages contains the effects to add. effec
tKeys[i] is the key |
| 322 * generated from effectStages[i]. inOutFSColor specifies the input color to
the first stage and | 328 * generated from effectStages[i]. inOutFSColor specifies the input color to
the first stage and |
| 323 * is updated to be the output color of the last stage. | 329 * is updated to be the output color of the last stage. |
| 324 * The handles to texture samplers for effectStage[i] are added to | 330 * The handles to texture samplers for effectStage[i] are added to |
| 325 * effectSamplerHandles[i]. | 331 * effectSamplerHandles[i]. |
| 326 */ | 332 */ |
| 327 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], | 333 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], |
| 328 const EffectKey effectKeys[
], | 334 const EffectKey effectKeys[
], |
| 329 int effectCnt, | 335 int effectCnt, |
| 330 GrGLSLExpr4* inOutFSColor)
= 0; | 336 GrGLSLExpr4* inOutFSColor)
= 0; |
| 331 | 337 |
| 338 /** |
| 339 * Similar to emitCodeBeforeEffects() but called after per-effect code is em
itted. |
| 340 */ |
| 341 virtual void emitCodeAfterEffects() = 0; |
| 342 |
| 332 /** Enables using the secondary color output and returns the name of the var
in which it is | 343 /** Enables using the secondary color output and returns the name of the var
in which it is |
| 333 to be stored */ | 344 to be stored */ |
| 334 const char* enableSecondaryOutput(); | 345 const char* enableSecondaryOutput(); |
| 335 /** Gets the name of the primary color output. */ | 346 /** Gets the name of the primary color output. */ |
| 336 const char* getColorOutputName() const; | 347 const char* getColorOutputName() const; |
| 337 | 348 |
| 338 /** | 349 /** |
| 339 * Compiles all the shaders, links them into a program, and writes the progr
am id to the output | 350 * Compiles all the shaders, links them into a program, and writes the progr
am id to the output |
| 340 * struct. | 351 * struct. |
| 341 **/ | 352 **/ |
| 342 bool finish(); | 353 bool finish(); |
| 343 | 354 |
| 344 const GrGLSLExpr4& getInputColor() const { | |
| 345 return fInputColor; | |
| 346 } | |
| 347 | |
| 348 const GrGLSLExpr4& getInputCoverage() const { | |
| 349 return fInputCoverage; | |
| 350 } | |
| 351 | |
| 352 /** | 355 /** |
| 353 * Features that should only be enabled by GrGLShaderBuilder itself. | 356 * Features that should only be enabled by GrGLShaderBuilder itself. |
| 354 */ | 357 */ |
| 355 enum GLSLPrivateFeature { | 358 enum GLSLPrivateFeature { |
| 356 kFragCoordConventions_GLSLPrivateFeature = kLastGLSLFeature + 1, | 359 kFragCoordConventions_GLSLPrivateFeature = kLastGLSLFeature + 1, |
| 357 kEXTShaderFramebufferFetch_GLSLPrivateFeature, | 360 kEXTShaderFramebufferFetch_GLSLPrivateFeature, |
| 358 kNVShaderFramebufferFetch_GLSLPrivateFeature, | 361 kNVShaderFramebufferFetch_GLSLPrivateFeature, |
| 359 }; | 362 }; |
| 360 bool enablePrivateFeature(GLSLPrivateFeature); | 363 bool enablePrivateFeature(GLSLPrivateFeature); |
| 361 | 364 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 385 SkString fFSExtensions; | 388 SkString fFSExtensions; |
| 386 VarArray fFSInputs; | 389 VarArray fFSInputs; |
| 387 VarArray fFSOutputs; | 390 VarArray fFSOutputs; |
| 388 GrGLUniformManager::BuilderUniformArray fUniforms; | 391 GrGLUniformManager::BuilderUniformArray fUniforms; |
| 389 | 392 |
| 390 SkString fFSCode; | 393 SkString fFSCode; |
| 391 | 394 |
| 392 bool fSetupFragPosition; | 395 bool fSetupFragPosition; |
| 393 bool fTopLeftFragPosRead; | 396 bool fTopLeftFragPosRead; |
| 394 | 397 |
| 395 GrGLSLExpr4 fInputColor; | |
| 396 GrGLSLExpr4 fInputCoverage; | |
| 397 | |
| 398 bool fHasCustomColorOutput; | 398 bool fHasCustomColorOutput; |
| 399 bool fHasSecondaryOutput; | 399 bool fHasSecondaryOutput; |
| 400 }; | 400 }; |
| 401 | 401 |
| 402 //////////////////////////////////////////////////////////////////////////////// | 402 //////////////////////////////////////////////////////////////////////////////// |
| 403 | 403 |
| 404 class GrGLFullShaderBuilder : public GrGLShaderBuilder { | 404 class GrGLFullShaderBuilder : public GrGLShaderBuilder { |
| 405 public: | 405 public: |
| 406 GrGLFullShaderBuilder(GrGpuGL*, GrGLUniformManager*, const GrGLProgramDesc&)
; | 406 GrGLFullShaderBuilder(GrGpuGL*, GrGLUniformManager*, const GrGLProgramDesc&)
; |
| 407 | 407 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 | 441 |
| 442 /** | 442 /** |
| 443 * Are explicit local coordinates provided as input to the vertex shader. | 443 * Are explicit local coordinates provided as input to the vertex shader. |
| 444 */ | 444 */ |
| 445 bool hasExplicitLocalCoords() const { return (fLocalCoordsVar != fPositionVa
r); } | 445 bool hasExplicitLocalCoords() const { return (fLocalCoordsVar != fPositionVa
r); } |
| 446 | 446 |
| 447 bool addEffectAttribute(int attributeIndex, GrSLType type, const SkString& n
ame); | 447 bool addEffectAttribute(int attributeIndex, GrSLType type, const SkString& n
ame); |
| 448 const SkString* getEffectAttributeName(int attributeIndex) const; | 448 const SkString* getEffectAttributeName(int attributeIndex) const; |
| 449 | 449 |
| 450 private: | 450 private: |
| 451 virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr4* coverage
) SK_OVERRIDE; |
| 452 |
| 451 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], | 453 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], |
| 452 const EffectKey effectKeys[
], | 454 const EffectKey effectKeys[
], |
| 453 int effectCnt, | 455 int effectCnt, |
| 454 GrGLSLExpr4* inOutFSColor)
SK_OVERRIDE; | 456 GrGLSLExpr4* inOutFSColor)
SK_OVERRIDE; |
| 457 |
| 458 virtual void emitCodeAfterEffects() SK_OVERRIDE; |
| 459 |
| 455 virtual bool compileAndAttachShaders(GrGLuint programId, | 460 virtual bool compileAndAttachShaders(GrGLuint programId, |
| 456 SkTDArray<GrGLuint>* shaderIds) const S
K_OVERRIDE; | 461 SkTDArray<GrGLuint>* shaderIds) const S
K_OVERRIDE; |
| 457 | 462 |
| 458 virtual void bindProgramLocations(GrGLuint programId) const SK_OVERRIDE; | 463 virtual void bindProgramLocations(GrGLuint programId) const SK_OVERRIDE; |
| 459 | 464 |
| 460 VarArray fVSAttrs; | 465 VarArray fVSAttrs; |
| 461 VarArray fVSOutputs; | 466 VarArray fVSOutputs; |
| 462 VarArray fGSInputs; | 467 VarArray fGSInputs; |
| 463 VarArray fGSOutputs; | 468 VarArray fGSOutputs; |
| 464 | 469 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 481 | 486 |
| 482 //////////////////////////////////////////////////////////////////////////////// | 487 //////////////////////////////////////////////////////////////////////////////// |
| 483 | 488 |
| 484 class GrGLFragmentOnlyShaderBuilder : public GrGLShaderBuilder { | 489 class GrGLFragmentOnlyShaderBuilder : public GrGLShaderBuilder { |
| 485 public: | 490 public: |
| 486 GrGLFragmentOnlyShaderBuilder(GrGpuGL*, GrGLUniformManager*, const GrGLProgr
amDesc&); | 491 GrGLFragmentOnlyShaderBuilder(GrGpuGL*, GrGLUniformManager*, const GrGLProgr
amDesc&); |
| 487 | 492 |
| 488 int addTexCoordSets(int count); | 493 int addTexCoordSets(int count); |
| 489 | 494 |
| 490 private: | 495 private: |
| 496 virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr4* coverage
) SK_OVERRIDE {} |
| 491 | 497 |
| 492 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], | 498 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], |
| 493 const EffectKey effectKeys[
], | 499 const EffectKey effectKeys[
], |
| 494 int effectCnt, | 500 int effectCnt, |
| 495 GrGLSLExpr4* inOutFSColor)
SK_OVERRIDE; | 501 GrGLSLExpr4* inOutFSColor)
SK_OVERRIDE; |
| 496 | 502 |
| 503 virtual void emitCodeAfterEffects() SK_OVERRIDE {} |
| 504 |
| 497 typedef GrGLShaderBuilder INHERITED; | 505 typedef GrGLShaderBuilder INHERITED; |
| 498 }; | 506 }; |
| 499 | 507 |
| 500 #endif | 508 #endif |
| OLD | NEW |