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 24 matching lines...) Expand all Loading... |
35 TextureSampler() | 35 TextureSampler() |
36 : fConfigComponentMask(0) { | 36 : fConfigComponentMask(0) { |
37 // we will memcpy the first 4 bytes from passed in swizzle. This ens
ures the string is | 37 // we will memcpy the first 4 bytes from passed in swizzle. This ens
ures the string is |
38 // terminated. | 38 // terminated. |
39 fSwizzle[4] = '\0'; | 39 fSwizzle[4] = '\0'; |
40 } | 40 } |
41 | 41 |
42 TextureSampler(const TextureSampler& other) { *this = other; } | 42 TextureSampler(const TextureSampler& other) { *this = other; } |
43 | 43 |
44 TextureSampler& operator= (const TextureSampler& other) { | 44 TextureSampler& operator= (const TextureSampler& other) { |
45 GrAssert(0 == fConfigComponentMask); | 45 SkASSERT(0 == fConfigComponentMask); |
46 GrAssert(!fSamplerUniform.isValid()); | 46 SkASSERT(!fSamplerUniform.isValid()); |
47 | 47 |
48 fConfigComponentMask = other.fConfigComponentMask; | 48 fConfigComponentMask = other.fConfigComponentMask; |
49 fSamplerUniform = other.fSamplerUniform; | 49 fSamplerUniform = other.fSamplerUniform; |
50 return *this; | 50 return *this; |
51 } | 51 } |
52 | 52 |
53 // bitfield of GrColorComponentFlags present in the texture's config. | 53 // bitfield of GrColorComponentFlags present in the texture's config. |
54 uint32_t configComponentMask() const { return fConfigComponentMask; } | 54 uint32_t configComponentMask() const { return fConfigComponentMask; } |
55 | 55 |
56 const char* swizzle() const { return fSwizzle; } | 56 const char* swizzle() const { return fSwizzle; } |
57 | 57 |
58 bool isInitialized() const { return 0 != fConfigComponentMask; } | 58 bool isInitialized() const { return 0 != fConfigComponentMask; } |
59 | 59 |
60 private: | 60 private: |
61 // The idx param is used to ensure multiple samplers within a single eff
ect have unique | 61 // The idx param is used to ensure multiple samplers within a single eff
ect have unique |
62 // uniform names. swizzle is a four char max string made up of chars 'r'
, 'g', 'b', and 'a'. | 62 // uniform names. swizzle is a four char max string made up of chars 'r'
, 'g', 'b', and 'a'. |
63 void init(GrGLShaderBuilder* builder, | 63 void init(GrGLShaderBuilder* builder, |
64 uint32_t configComponentMask, | 64 uint32_t configComponentMask, |
65 const char* swizzle, | 65 const char* swizzle, |
66 int idx) { | 66 int idx) { |
67 GrAssert(!this->isInitialized()); | 67 SkASSERT(!this->isInitialized()); |
68 GrAssert(0 != configComponentMask); | 68 SkASSERT(0 != configComponentMask); |
69 GrAssert(!fSamplerUniform.isValid()); | 69 SkASSERT(!fSamplerUniform.isValid()); |
70 | 70 |
71 GrAssert(NULL != builder); | 71 SkASSERT(NULL != builder); |
72 SkString name; | 72 SkString name; |
73 name.printf("Sampler%d", idx); | 73 name.printf("Sampler%d", idx); |
74 fSamplerUniform = builder->addUniform(GrGLShaderBuilder::kFragment_S
haderType, | 74 fSamplerUniform = builder->addUniform(GrGLShaderBuilder::kFragment_S
haderType, |
75 kSampler2D_GrSLType, | 75 kSampler2D_GrSLType, |
76 name.c_str()); | 76 name.c_str()); |
77 GrAssert(fSamplerUniform.isValid()); | 77 SkASSERT(fSamplerUniform.isValid()); |
78 | 78 |
79 fConfigComponentMask = configComponentMask; | 79 fConfigComponentMask = configComponentMask; |
80 memcpy(fSwizzle, swizzle, 4); | 80 memcpy(fSwizzle, swizzle, 4); |
81 } | 81 } |
82 | 82 |
83 void init(GrGLShaderBuilder* builder, const GrTextureAccess* access, int
idx) { | 83 void init(GrGLShaderBuilder* builder, const GrTextureAccess* access, int
idx) { |
84 GrAssert(NULL != access); | 84 SkASSERT(NULL != access); |
85 this->init(builder, | 85 this->init(builder, |
86 GrPixelConfigComponentMask(access->getTexture()->config()
), | 86 GrPixelConfigComponentMask(access->getTexture()->config()
), |
87 access->getSwizzle(), | 87 access->getSwizzle(), |
88 idx); | 88 idx); |
89 } | 89 } |
90 | 90 |
91 uint32_t fConfigComponentMask; | 91 uint32_t fConfigComponentMask; |
92 char fSwizzle[5]; | 92 char fSwizzle[5]; |
93 GrGLUniformManager::UniformHandle fSamplerUniform; | 93 GrGLUniformManager::UniformHandle fSamplerUniform; |
94 | 94 |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 } | 368 } |
369 | 369 |
370 int stageIndex() const { | 370 int stageIndex() const { |
371 this->validate(); | 371 this->validate(); |
372 return fCurrentIndex; | 372 return fCurrentIndex; |
373 } | 373 } |
374 | 374 |
375 class AutoStageRestore : GrNoncopyable { | 375 class AutoStageRestore : GrNoncopyable { |
376 public: | 376 public: |
377 AutoStageRestore(CodeStage* codeStage, const GrEffectStage* newStage
) { | 377 AutoStageRestore(CodeStage* codeStage, const GrEffectStage* newStage
) { |
378 GrAssert(NULL != codeStage); | 378 SkASSERT(NULL != codeStage); |
379 fSavedIndex = codeStage->fCurrentIndex; | 379 fSavedIndex = codeStage->fCurrentIndex; |
380 fSavedEffectStage = codeStage->fEffectStage; | 380 fSavedEffectStage = codeStage->fEffectStage; |
381 | 381 |
382 if (NULL == newStage) { | 382 if (NULL == newStage) { |
383 codeStage->fCurrentIndex = -1; | 383 codeStage->fCurrentIndex = -1; |
384 } else { | 384 } else { |
385 codeStage->fCurrentIndex = codeStage->fNextIndex++; | 385 codeStage->fCurrentIndex = codeStage->fNextIndex++; |
386 } | 386 } |
387 codeStage->fEffectStage = newStage; | 387 codeStage->fEffectStage = newStage; |
388 | 388 |
389 fCodeStage = codeStage; | 389 fCodeStage = codeStage; |
390 } | 390 } |
391 ~AutoStageRestore() { | 391 ~AutoStageRestore() { |
392 fCodeStage->fCurrentIndex = fSavedIndex; | 392 fCodeStage->fCurrentIndex = fSavedIndex; |
393 fCodeStage->fEffectStage = fSavedEffectStage; | 393 fCodeStage->fEffectStage = fSavedEffectStage; |
394 } | 394 } |
395 private: | 395 private: |
396 CodeStage* fCodeStage; | 396 CodeStage* fCodeStage; |
397 int fSavedIndex; | 397 int fSavedIndex; |
398 const GrEffectStage* fSavedEffectStage; | 398 const GrEffectStage* fSavedEffectStage; |
399 }; | 399 }; |
400 private: | 400 private: |
401 void validate() const { GrAssert((NULL == fEffectStage) == (-1 == fCurre
ntIndex)); } | 401 void validate() const { SkASSERT((NULL == fEffectStage) == (-1 == fCurre
ntIndex)); } |
402 int fNextIndex; | 402 int fNextIndex; |
403 int fCurrentIndex; | 403 int fCurrentIndex; |
404 const GrEffectStage* fEffectStage; | 404 const GrEffectStage* fEffectStage; |
405 } fCodeStage; | 405 } fCodeStage; |
406 | 406 |
407 /** | 407 /** |
408 * Features that should only be enabled by GrGLShaderBuilder itself. | 408 * Features that should only be enabled by GrGLShaderBuilder itself. |
409 */ | 409 */ |
410 enum GLSLPrivateFeature { | 410 enum GLSLPrivateFeature { |
411 kFragCoordConventions_GLSLPrivateFeature = kLastGLSLFeature + 1, | 411 kFragCoordConventions_GLSLPrivateFeature = kLastGLSLFeature + 1, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 bool fTopLeftFragPosRead; | 459 bool fTopLeftFragPosRead; |
460 | 460 |
461 SkSTArray<10, AttributePair, true> fEffectAttributes; | 461 SkSTArray<10, AttributePair, true> fEffectAttributes; |
462 | 462 |
463 GrGLShaderVar* fPositionVar; | 463 GrGLShaderVar* fPositionVar; |
464 GrGLShaderVar* fLocalCoordsVar; | 464 GrGLShaderVar* fLocalCoordsVar; |
465 | 465 |
466 }; | 466 }; |
467 | 467 |
468 #endif | 468 #endif |
OLD | NEW |