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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 void init(GrGLShaderBuilder* builder, | 64 void init(GrGLShaderBuilder* builder, |
65 uint32_t configComponentMask, | 65 uint32_t configComponentMask, |
66 const char* swizzle, | 66 const char* swizzle, |
67 int idx) { | 67 int idx) { |
68 GrAssert(!this->isInitialized()); | 68 GrAssert(!this->isInitialized()); |
69 GrAssert(0 != configComponentMask); | 69 GrAssert(0 != configComponentMask); |
70 GrAssert(GrGLUniformManager::kInvalidUniformHandle == fSamplerUnifor m); | 70 GrAssert(GrGLUniformManager::kInvalidUniformHandle == fSamplerUnifor m); |
71 | 71 |
72 GrAssert(NULL != builder); | 72 GrAssert(NULL != builder); |
73 SkString name; | 73 SkString name; |
74 name.printf("Sampler%d_", idx); | 74 name.printf("Sampler%d", idx); |
75 fSamplerUniform = builder->addUniform(GrGLShaderBuilder::kFragment_S haderType, | 75 fSamplerUniform = builder->addUniform(GrGLShaderBuilder::kFragment_S haderType, |
76 kSampler2D_GrSLType, | 76 kSampler2D_GrSLType, |
77 name.c_str()); | 77 name.c_str()); |
78 GrAssert(GrGLUniformManager::kInvalidUniformHandle != fSamplerUnifor m); | 78 GrAssert(GrGLUniformManager::kInvalidUniformHandle != fSamplerUnifor m); |
79 | 79 |
80 fConfigComponentMask = configComponentMask; | 80 fConfigComponentMask = configComponentMask; |
81 memcpy(fSwizzle, swizzle, 4); | 81 memcpy(fSwizzle, swizzle, 4); |
82 } | 82 } |
83 | 83 |
84 void init(GrGLShaderBuilder* builder, const GrTextureAccess* access, int idx) { | 84 void init(GrGLShaderBuilder* builder, const GrTextureAccess* access, int idx) { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 | 268 |
269 /** | 269 /** |
270 * Interfaces used by GrGLProgram. | 270 * Interfaces used by GrGLProgram. |
271 * TODO: Hide these from the GrEffects using friend or splitting this into t wo related classes. | 271 * TODO: Hide these from the GrEffects using friend or splitting this into t wo related classes. |
272 * Also, GrGLProgram's shader string construction should be moved to this cl ass. | 272 * Also, GrGLProgram's shader string construction should be moved to this cl ass. |
273 */ | 273 */ |
274 | 274 |
275 /** Called after building is complete to get the final shader string. */ | 275 /** Called after building is complete to get the final shader string. */ |
276 void getShader(ShaderType, SkString*) const; | 276 void getShader(ShaderType, SkString*) const; |
277 | 277 |
278 void setCurrentStage(int stageIdx) { fCurrentStageIdx = stageIdx; } | 278 /** |
279 void setNonStage() { fCurrentStageIdx = kNonStageIdx; } | 279 * Adds code for effects. effectStages contains the effects to add. effectKe ys[i] is the key |
280 // TODO: move remainder of shader code generation to this class and call thi s privately | 280 * generated from effectStages[i]. An entry in effectStages can be NULL, in which case it is |
281 // Handles of sampler uniforms generated for the effect are appended to samp lerHandles. | 281 * skipped. inOutFSColor specifies the input color to the first stage and is updated to be the |
282 GrGLEffect* createAndEmitGLEffect( | 282 * output color of the last stage. fsInOutColorKnownValue specifies whether the input color |
283 const GrEffectStage& stage, | 283 * has a known constant value and is updated to refer to the status of the o utput color. |
284 GrBackendEffectFactory::EffectKey key, | 284 * The handles to texture samplers for effectStage[i] are added to effectSam plerHandles[i]. The |
285 const char* fsInColor, // NULL means no incoming color | 285 * glEffects array is updated to contain the GrGLEffect generated for each e ntry in |
286 const char* fsOutColor, | 286 * effectStages. |
287 SkTArray<GrGLUniformManager::UniformHandle, true >* samplerHandles); | 287 */ |
288 void emitEffects(const GrEffectStage* effectStages[], | |
289 const GrBackendEffectFactory::EffectKey effectKeys[], | |
290 int effectCnt, | |
robertphillips
2013/05/08 19:56:33
xtra space here?
| |
291 SkString* inOutFSColor, | |
292 GrSLConstantVec* fsInOutColorKnownValue, | |
293 SkTArray<GrGLUniformManager::UniformHandle, true>* effectSa mplerHandles[], | |
294 GrGLEffect* glEffects[]); | |
288 | 295 |
289 GrGLUniformManager::UniformHandle getRTHeightUniform() const { return fRTHei ghtUniform; } | 296 GrGLUniformManager::UniformHandle getRTHeightUniform() const { return fRTHei ghtUniform; } |
290 GrGLUniformManager::UniformHandle getDstCopyTopLeftUniform() const { | 297 GrGLUniformManager::UniformHandle getDstCopyTopLeftUniform() const { |
291 return fDstCopyTopLeftUniform; | 298 return fDstCopyTopLeftUniform; |
292 } | 299 } |
293 GrGLUniformManager::UniformHandle getDstCopyScaleUniform() const { | 300 GrGLUniformManager::UniformHandle getDstCopyScaleUniform() const { |
294 return fDstCopyScaleUniform; | 301 return fDstCopyScaleUniform; |
295 } | 302 } |
296 GrGLUniformManager::UniformHandle getDstCopySamplerUniform() const { | 303 GrGLUniformManager::UniformHandle getDstCopySamplerUniform() const { |
297 return fDstCopySampler.fSamplerUniform; | 304 return fDstCopySampler.fSamplerUniform; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 | 338 |
332 VarArray fVSAttrs; | 339 VarArray fVSAttrs; |
333 VarArray fVSOutputs; | 340 VarArray fVSOutputs; |
334 VarArray fGSInputs; | 341 VarArray fGSInputs; |
335 VarArray fGSOutputs; | 342 VarArray fGSOutputs; |
336 VarArray fFSInputs; | 343 VarArray fFSInputs; |
337 SkString fGSHeader; // layout qualifiers specific to GS | 344 SkString fGSHeader; // layout qualifiers specific to GS |
338 VarArray fFSOutputs; | 345 VarArray fFSOutputs; |
339 | 346 |
340 private: | 347 private: |
341 enum { | 348 class CodeStage : GrNoncopyable { |
342 kNonStageIdx = -1, | 349 public: |
343 }; | 350 CodeStage() : fNextIndex(0), fCurrentIndex(-1), fEffectStage(NULL) {} |
351 | |
352 bool inStageCode() const { | |
353 this->validate(); | |
354 return NULL != fEffectStage; | |
355 } | |
356 | |
357 const GrEffectStage* effectStage() const { | |
358 this->validate(); | |
359 return fEffectStage; | |
360 } | |
361 | |
362 int stageIndex() const { | |
363 this->validate(); | |
364 return fCurrentIndex; | |
365 } | |
366 | |
robertphillips
2013/05/08 19:56:33
AutoStageRestore?
bsalomon
2013/05/08 20:38:54
Done.
| |
367 class AutoRestore : GrNoncopyable { | |
368 public: | |
369 AutoRestore(CodeStage* codeStage, const GrEffectStage* newStage) { | |
370 GrAssert(NULL != codeStage); | |
371 fSavedIndex = codeStage->fCurrentIndex; | |
372 fSavedEffectStage = codeStage->fEffectStage; | |
373 | |
374 if (NULL == newStage) { | |
375 codeStage->fCurrentIndex = -1; | |
376 } else { | |
377 codeStage->fCurrentIndex = codeStage->fNextIndex++; | |
378 } | |
379 codeStage->fEffectStage = newStage; | |
380 | |
381 fCodeStage = codeStage; | |
382 } | |
383 ~AutoRestore() { | |
384 fCodeStage->fCurrentIndex = fSavedIndex; | |
385 fCodeStage->fEffectStage = fSavedEffectStage; | |
386 } | |
387 private: | |
388 CodeStage* fCodeStage; | |
389 int fSavedIndex; | |
390 const GrEffectStage* fSavedEffectStage; | |
391 }; | |
392 private: | |
393 void validate() const { GrAssert((NULL == fEffectStage) == (-1 == fCurre ntIndex)); } | |
394 int fNextIndex; | |
395 int fCurrentIndex; | |
396 const GrEffectStage* fEffectStage; | |
397 } fCodeStage; | |
344 | 398 |
345 /** | 399 /** |
346 * Features that should only be enabled by GrGLShaderBuilder itself. | 400 * Features that should only be enabled by GrGLShaderBuilder itself. |
347 */ | 401 */ |
348 enum GLSLPrivateFeature { | 402 enum GLSLPrivateFeature { |
349 kFragCoordConventions_GLSLPrivateFeature = kLastGLSLFeature + 1, | 403 kFragCoordConventions_GLSLPrivateFeature = kLastGLSLFeature + 1, |
350 kEXTShaderFramebufferFetch_GLSLPrivateFeature, | 404 kEXTShaderFramebufferFetch_GLSLPrivateFeature, |
351 kNVShaderFramebufferFetch_GLSLPrivateFeature, | 405 kNVShaderFramebufferFetch_GLSLPrivateFeature, |
352 }; | 406 }; |
353 bool enablePrivateFeature(GLSLPrivateFeature); | 407 bool enablePrivateFeature(GLSLPrivateFeature); |
354 | 408 |
355 // If we ever have VS/GS features we can expand this to take a bitmask of Sh aderType and track | 409 // If we ever have VS/GS features we can expand this to take a bitmask of Sh aderType and track |
356 // the enables separately for each shader. | 410 // the enables separately for each shader. |
357 void addFSFeature(uint32_t featureBit, const char* extensionName); | 411 void addFSFeature(uint32_t featureBit, const char* extensionName); |
358 | 412 |
413 // Generates a name for a variable. The generated string will be name prefix ed by the prefix | |
414 // char (unless the prefix is '\0') and with _Stage<stage-num> appended if i n stage code. | |
415 void nameVariable(SkString* out, char prefix, const char* name); | |
416 | |
359 // Interpretation of DstReadKey when generating code | 417 // Interpretation of DstReadKey when generating code |
360 enum { | 418 enum { |
361 kNoDstRead_DstReadKey = 0, | 419 kNoDstRead_DstReadKey = 0, |
362 kYesDstRead_DstReadKeyBit = 0x1, // Set if we do a dst-copy-read. | 420 kYesDstRead_DstReadKeyBit = 0x1, // Set if we do a dst-copy-read. |
363 kUseAlphaConfig_DstReadKeyBit = 0x2, // Set if dst-copy config is alpha only. | 421 kUseAlphaConfig_DstReadKeyBit = 0x2, // Set if dst-copy config is alpha only. |
364 kTopLeftOrigin_DstReadKeyBit = 0x4, // Set if dst-copy origin is top-le ft. | 422 kTopLeftOrigin_DstReadKeyBit = 0x4, // Set if dst-copy origin is top-le ft. |
365 }; | 423 }; |
366 | 424 |
367 const GrGLContextInfo& fCtxInfo; | 425 const GrGLContextInfo& fCtxInfo; |
368 GrGLUniformManager& fUniformManager; | 426 GrGLUniformManager& fUniformManager; |
369 int fCurrentStageIdx; | |
370 uint32_t fFSFeaturesAddedMask; | 427 uint32_t fFSFeaturesAddedMask; |
371 SkString fFSFunctions; | 428 SkString fFSFunctions; |
372 SkString fFSExtensions; | 429 SkString fFSExtensions; |
373 | 430 |
374 bool fUsesGS; | 431 bool fUsesGS; |
375 | 432 |
376 SkString fFSCode; | 433 SkString fFSCode; |
377 SkString fVSCode; | 434 SkString fVSCode; |
378 SkString fGSCode; | 435 SkString fGSCode; |
379 | 436 |
380 bool fSetupFragPosition; | 437 bool fSetupFragPosition; |
381 TextureSampler fDstCopySampler; | 438 TextureSampler fDstCopySampler; |
382 | 439 |
383 GrGLUniformManager::UniformHandle fRTHeightUniform; | 440 GrGLUniformManager::UniformHandle fRTHeightUniform; |
384 GrGLUniformManager::UniformHandle fDstCopyTopLeftUniform; | 441 GrGLUniformManager::UniformHandle fDstCopyTopLeftUniform; |
385 GrGLUniformManager::UniformHandle fDstCopyScaleUniform; | 442 GrGLUniformManager::UniformHandle fDstCopyScaleUniform; |
386 | 443 |
387 SkSTArray<10, AttributePair, true> fEffectAttributes; | 444 SkSTArray<10, AttributePair, true> fEffectAttributes; |
388 | 445 |
389 GrGLShaderVar* fPositionVar; | 446 GrGLShaderVar* fPositionVar; |
390 GrGLShaderVar* fLocalCoordsVar; | 447 GrGLShaderVar* fLocalCoordsVar; |
391 | 448 |
392 }; | 449 }; |
393 | 450 |
394 #endif | 451 #endif |
OLD | NEW |