| 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 23 matching lines...) Expand all Loading... |
| 34 typedef GrGLProgramEffects::TextureSampler TextureSampler; | 34 typedef GrGLProgramEffects::TextureSampler TextureSampler; |
| 35 typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray; | 35 typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray; |
| 36 typedef GrGLUniformManager::BuilderUniform BuilderUniform; | 36 typedef GrGLUniformManager::BuilderUniform BuilderUniform; |
| 37 | 37 |
| 38 enum ShaderVisibility { | 38 enum ShaderVisibility { |
| 39 kVertex_Visibility = 0x1, | 39 kVertex_Visibility = 0x1, |
| 40 kGeometry_Visibility = 0x2, | 40 kGeometry_Visibility = 0x2, |
| 41 kFragment_Visibility = 0x4, | 41 kFragment_Visibility = 0x4, |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 GrGLShaderBuilder(GrGpuGL*, GrGLUniformManager&, const GrGLProgramDesc&); | 44 typedef GrGLUniformManager::UniformHandle UniformHandle; |
| 45 |
| 46 // Handles for program uniforms (other than per-effect uniforms) |
| 47 struct UniformHandles { |
| 48 UniformHandle fViewMatrixUni; |
| 49 UniformHandle fRTAdjustmentUni; |
| 50 UniformHandle fColorUni; |
| 51 UniformHandle fCoverageUni; |
| 52 |
| 53 // We use the render target height to provide a y-down frag coord when s
pecifying |
| 54 // origin_upper_left is not supported. |
| 55 UniformHandle fRTHeightUni; |
| 56 |
| 57 // Uniforms for computing texture coords to do the dst-copy lookup |
| 58 UniformHandle fDstCopyTopLeftUni; |
| 59 UniformHandle fDstCopyScaleUni; |
| 60 UniformHandle fDstCopySamplerUni; |
| 61 }; |
| 62 |
| 63 struct GenProgramOutput { |
| 64 GrGLProgramEffects* fColorEffects; |
| 65 GrGLProgramEffects* fCoverageEffects; |
| 66 UniformHandles fUniformHandles; |
| 67 bool fHasVS; |
| 68 int fNumTexCoordSets; |
| 69 GrGLuint fProgramID; |
| 70 }; |
| 71 |
| 72 static bool GenProgram(GrGpuGL* gpu, |
| 73 GrGLUniformManager& uman, |
| 74 const GrGLProgramDesc& desc, |
| 75 const GrEffectStage* inColorStages[], |
| 76 const GrEffectStage* inCoverageStages[], |
| 77 GenProgramOutput* output); |
| 78 |
| 45 virtual ~GrGLShaderBuilder() {} | 79 virtual ~GrGLShaderBuilder() {} |
| 46 | 80 |
| 47 /** | 81 /** |
| 48 * Use of these features may require a GLSL extension to be enabled. Shaders
may not compile | 82 * Use of these features may require a GLSL extension to be enabled. Shaders
may not compile |
| 49 * if code is added that uses one of these features without calling enableFe
ature() | 83 * if code is added that uses one of these features without calling enableFe
ature() |
| 50 */ | 84 */ |
| 51 enum GLSLFeature { | 85 enum GLSLFeature { |
| 52 kStandardDerivatives_GLSLFeature = 0, | 86 kStandardDerivatives_GLSLFeature = 0, |
| 53 | 87 |
| 54 kLastGLSLFeature = kStandardDerivatives_GLSLFeature | 88 kLastGLSLFeature = kStandardDerivatives_GLSLFeature |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 } | 255 } |
| 222 | 256 |
| 223 ~FSBlock() { | 257 ~FSBlock() { |
| 224 fBuilder->fsCodeAppend("\t}\n"); | 258 fBuilder->fsCodeAppend("\t}\n"); |
| 225 } | 259 } |
| 226 private: | 260 private: |
| 227 GrGLShaderBuilder* fBuilder; | 261 GrGLShaderBuilder* fBuilder; |
| 228 }; | 262 }; |
| 229 | 263 |
| 230 protected: | 264 protected: |
| 265 GrGLShaderBuilder(GrGpuGL*, GrGLUniformManager&, const GrGLProgramDesc&); |
| 266 |
| 231 GrGpuGL* gpu() const { return fGpu; } | 267 GrGpuGL* gpu() const { return fGpu; } |
| 232 | 268 |
| 269 const GrGLProgramDesc& desc() const { return fDesc; } |
| 270 |
| 233 void setInputColor(const GrGLSLExpr4& inputColor) { fInputColor = inputColor
; } | 271 void setInputColor(const GrGLSLExpr4& inputColor) { fInputColor = inputColor
; } |
| 234 void setInputCoverage(const GrGLSLExpr4& inputCoverage) { fInputCoverage = i
nputCoverage; } | 272 void setInputCoverage(const GrGLSLExpr4& inputCoverage) { fInputCoverage = i
nputCoverage; } |
| 235 | 273 |
| 236 /** Add input/output variable declarations (i.e. 'varying') to the fragment
shader. */ | 274 /** Add input/output variable declarations (i.e. 'varying') to the fragment
shader. */ |
| 237 GrGLShaderVar& fsInputAppend() { return fFSInputs.push_back(); } | 275 GrGLShaderVar& fsInputAppend() { return fFSInputs.push_back(); } |
| 238 | 276 |
| 239 // Generates a name for a variable. The generated string will be name prefix
ed by the prefix | 277 // Generates a name for a variable. The generated string will be name prefix
ed by the prefix |
| 240 // char (unless the prefix is '\0'). It also mangles the name to be stage-sp
ecific if we're | 278 // char (unless the prefix is '\0'). It also mangles the name to be stage-sp
ecific if we're |
| 241 // generating stage code. | 279 // generating stage code. |
| 242 void nameVariable(SkString* out, char prefix, const char* name); | 280 void nameVariable(SkString* out, char prefix, const char* name); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 int fSavedIndex; | 337 int fSavedIndex; |
| 300 const GrEffectStage* fSavedEffectStage; | 338 const GrEffectStage* fSavedEffectStage; |
| 301 }; | 339 }; |
| 302 private: | 340 private: |
| 303 void validate() const { SkASSERT((NULL == fEffectStage) == (-1 == fCurre
ntIndex)); } | 341 void validate() const { SkASSERT((NULL == fEffectStage) == (-1 == fCurre
ntIndex)); } |
| 304 int fNextIndex; | 342 int fNextIndex; |
| 305 int fCurrentIndex; | 343 int fCurrentIndex; |
| 306 const GrEffectStage* fEffectStage; | 344 const GrEffectStage* fEffectStage; |
| 307 } fCodeStage; | 345 } fCodeStage; |
| 308 | 346 |
| 347 bool genProgram(const GrEffectStage* colorStages[], |
| 348 const GrEffectStage* coverageStages[], |
| 349 GenProgramOutput* output); |
| 350 |
| 309 /** | 351 /** |
| 310 * Features that should only be enabled by GrGLShaderBuilder itself. | 352 * Features that should only be enabled by GrGLShaderBuilder itself. |
| 311 */ | 353 */ |
| 312 enum GLSLPrivateFeature { | 354 enum GLSLPrivateFeature { |
| 313 kFragCoordConventions_GLSLPrivateFeature = kLastGLSLFeature + 1, | 355 kFragCoordConventions_GLSLPrivateFeature = kLastGLSLFeature + 1, |
| 314 kEXTShaderFramebufferFetch_GLSLPrivateFeature, | 356 kEXTShaderFramebufferFetch_GLSLPrivateFeature, |
| 315 kNVShaderFramebufferFetch_GLSLPrivateFeature, | 357 kNVShaderFramebufferFetch_GLSLPrivateFeature, |
| 316 }; | 358 }; |
| 317 bool enablePrivateFeature(GLSLPrivateFeature); | 359 bool enablePrivateFeature(GLSLPrivateFeature); |
| 318 | 360 |
| 319 // If we ever have VS/GS features we can expand this to take a bitmask of Sh
aderVisibility and | 361 // If we ever have VS/GS features we can expand this to take a bitmask of Sh
aderVisibility and |
| 320 // track the enables separately for each shader. | 362 // track the enables separately for each shader. |
| 321 void addFSFeature(uint32_t featureBit, const char* extensionName); | 363 void addFSFeature(uint32_t featureBit, const char* extensionName); |
| 322 | 364 |
| 323 // Interpretation of DstReadKey when generating code | 365 // Interpretation of DstReadKey when generating code |
| 324 enum { | 366 enum { |
| 325 kNoDstRead_DstReadKey = 0, | 367 kNoDstRead_DstReadKey = 0, |
| 326 kYesDstRead_DstReadKeyBit = 0x1, // Set if we do a dst-copy-read. | 368 kYesDstRead_DstReadKeyBit = 0x1, // Set if we do a dst-copy-read. |
| 327 kUseAlphaConfig_DstReadKeyBit = 0x2, // Set if dst-copy config is alpha
only. | 369 kUseAlphaConfig_DstReadKeyBit = 0x2, // Set if dst-copy config is alpha
only. |
| 328 kTopLeftOrigin_DstReadKeyBit = 0x4, // Set if dst-copy origin is top-le
ft. | 370 kTopLeftOrigin_DstReadKeyBit = 0x4, // Set if dst-copy origin is top-le
ft. |
| 329 }; | 371 }; |
| 330 | 372 |
| 331 enum { | 373 enum { |
| 332 kNoFragPosRead_FragPosKey = 0, // The fragment positition wil
l not be needed. | 374 kNoFragPosRead_FragPosKey = 0, // The fragment positition wil
l not be needed. |
| 333 kTopLeftFragPosRead_FragPosKey = 0x1,// Read frag pos relative to t
op-left. | 375 kTopLeftFragPosRead_FragPosKey = 0x1,// Read frag pos relative to t
op-left. |
| 334 kBottomLeftFragPosRead_FragPosKey = 0x2,// Read frag pos relative to b
ottom-left. | 376 kBottomLeftFragPosRead_FragPosKey = 0x2,// Read frag pos relative to b
ottom-left. |
| 335 }; | 377 }; |
| 336 | 378 |
| 379 const GrGLProgramDesc& fDesc; |
| 337 GrGpuGL* fGpu; | 380 GrGpuGL* fGpu; |
| 338 GrGLUniformManager& fUniformManager; | 381 GrGLUniformManager& fUniformManager; |
| 339 uint32_t fFSFeaturesAddedMask; | 382 uint32_t fFSFeaturesAddedMask; |
| 340 SkString fFSFunctions; | 383 SkString fFSFunctions; |
| 341 SkString fFSExtensions; | 384 SkString fFSExtensions; |
| 342 VarArray fFSInputs; | 385 VarArray fFSInputs; |
| 343 VarArray fFSOutputs; | 386 VarArray fFSOutputs; |
| 344 GrGLUniformManager::BuilderUniformArray fUniforms; | 387 GrGLUniformManager::BuilderUniformArray fUniforms; |
| 345 | 388 |
| 346 SkString fFSCode; | 389 SkString fFSCode; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 | 469 |
| 427 GrGLUniformManager::UniformHandle getRTAdjustmentVecUniform() const { | 470 GrGLUniformManager::UniformHandle getRTAdjustmentVecUniform() const { |
| 428 return fRTAdustmentVecUniform; | 471 return fRTAdustmentVecUniform; |
| 429 } | 472 } |
| 430 | 473 |
| 431 protected: | 474 protected: |
| 432 virtual bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>
* shaderIds) const SK_OVERRIDE; | 475 virtual bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>
* shaderIds) const SK_OVERRIDE; |
| 433 virtual void bindProgramLocations(GrGLuint programId) const SK_OVERRIDE; | 476 virtual void bindProgramLocations(GrGLuint programId) const SK_OVERRIDE; |
| 434 | 477 |
| 435 private: | 478 private: |
| 436 const GrGLProgramDesc& fDesc; | |
| 437 VarArray fVSAttrs; | 479 VarArray fVSAttrs; |
| 438 VarArray fVSOutputs; | 480 VarArray fVSOutputs; |
| 439 VarArray fGSInputs; | 481 VarArray fGSInputs; |
| 440 VarArray fGSOutputs; | 482 VarArray fGSOutputs; |
| 441 | 483 |
| 442 SkString fVSCode; | 484 SkString fVSCode; |
| 443 | 485 |
| 444 struct AttributePair { | 486 struct AttributePair { |
| 445 void set(int index, const SkString& name) { | 487 void set(int index, const SkString& name) { |
| 446 fIndex = index; fName = name; | 488 fIndex = index; fName = name; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 473 int effectCnt, | 515 int effectCnt, |
| 474 GrGLSLExpr4* inOutFSColor) SK_OVERRIDE; | 516 GrGLSLExpr4* inOutFSColor) SK_OVERRIDE; |
| 475 | 517 |
| 476 private: | 518 private: |
| 477 int fNumTexCoordSets; | 519 int fNumTexCoordSets; |
| 478 | 520 |
| 479 typedef GrGLShaderBuilder INHERITED; | 521 typedef GrGLShaderBuilder INHERITED; |
| 480 }; | 522 }; |
| 481 | 523 |
| 482 #endif | 524 #endif |
| OLD | NEW |