| 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 15 matching lines...) Expand all Loading... |
| 26 manipulate that state. | 26 manipulate that state. |
| 27 */ | 27 */ |
| 28 class GrGLShaderBuilder { | 28 class GrGLShaderBuilder { |
| 29 public: | 29 public: |
| 30 /** | 30 /** |
| 31 * Passed to GrGLEffects to add texture reads to their shader code. | 31 * Passed to GrGLEffects to add texture reads to their shader code. |
| 32 */ | 32 */ |
| 33 class TextureSampler { | 33 class TextureSampler { |
| 34 public: | 34 public: |
| 35 TextureSampler() | 35 TextureSampler() |
| 36 : fConfigComponentMask(0) | 36 : fConfigComponentMask(0) { |
| 37 , fSamplerUniform(GrGLUniformManager::kInvalidUniformHandle) { | |
| 38 // 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 |
| 39 // terminated. | 38 // terminated. |
| 40 fSwizzle[4] = '\0'; | 39 fSwizzle[4] = '\0'; |
| 41 } | 40 } |
| 42 | 41 |
| 43 TextureSampler(const TextureSampler& other) { *this = other; } | 42 TextureSampler(const TextureSampler& other) { *this = other; } |
| 44 | 43 |
| 45 TextureSampler& operator= (const TextureSampler& other) { | 44 TextureSampler& operator= (const TextureSampler& other) { |
| 46 GrAssert(0 == fConfigComponentMask); | 45 GrAssert(0 == fConfigComponentMask); |
| 47 GrAssert(GrGLUniformManager::kInvalidUniformHandle == fSamplerUnifor
m); | 46 GrAssert(!fSamplerUniform.isValid()); |
| 48 | 47 |
| 49 fConfigComponentMask = other.fConfigComponentMask; | 48 fConfigComponentMask = other.fConfigComponentMask; |
| 50 fSamplerUniform = other.fSamplerUniform; | 49 fSamplerUniform = other.fSamplerUniform; |
| 51 return *this; | 50 return *this; |
| 52 } | 51 } |
| 53 | 52 |
| 54 // bitfield of GrColorComponentFlags present in the texture's config. | 53 // bitfield of GrColorComponentFlags present in the texture's config. |
| 55 uint32_t configComponentMask() const { return fConfigComponentMask; } | 54 uint32_t configComponentMask() const { return fConfigComponentMask; } |
| 56 | 55 |
| 57 const char* swizzle() const { return fSwizzle; } | 56 const char* swizzle() const { return fSwizzle; } |
| 58 | 57 |
| 59 bool isInitialized() const { return 0 != fConfigComponentMask; } | 58 bool isInitialized() const { return 0 != fConfigComponentMask; } |
| 60 | 59 |
| 61 private: | 60 private: |
| 62 // 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 |
| 63 // 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'. |
| 64 void init(GrGLShaderBuilder* builder, | 63 void init(GrGLShaderBuilder* builder, |
| 65 uint32_t configComponentMask, | 64 uint32_t configComponentMask, |
| 66 const char* swizzle, | 65 const char* swizzle, |
| 67 int idx) { | 66 int idx) { |
| 68 GrAssert(!this->isInitialized()); | 67 GrAssert(!this->isInitialized()); |
| 69 GrAssert(0 != configComponentMask); | 68 GrAssert(0 != configComponentMask); |
| 70 GrAssert(GrGLUniformManager::kInvalidUniformHandle == fSamplerUnifor
m); | 69 GrAssert(!fSamplerUniform.isValid()); |
| 71 | 70 |
| 72 GrAssert(NULL != builder); | 71 GrAssert(NULL != builder); |
| 73 SkString name; | 72 SkString name; |
| 74 name.printf("Sampler%d", idx); | 73 name.printf("Sampler%d", idx); |
| 75 fSamplerUniform = builder->addUniform(GrGLShaderBuilder::kFragment_S
haderType, | 74 fSamplerUniform = builder->addUniform(GrGLShaderBuilder::kFragment_S
haderType, |
| 76 kSampler2D_GrSLType, | 75 kSampler2D_GrSLType, |
| 77 name.c_str()); | 76 name.c_str()); |
| 78 GrAssert(GrGLUniformManager::kInvalidUniformHandle != fSamplerUnifor
m); | 77 GrAssert(fSamplerUniform.isValid()); |
| 79 | 78 |
| 80 fConfigComponentMask = configComponentMask; | 79 fConfigComponentMask = configComponentMask; |
| 81 memcpy(fSwizzle, swizzle, 4); | 80 memcpy(fSwizzle, swizzle, 4); |
| 82 } | 81 } |
| 83 | 82 |
| 84 void init(GrGLShaderBuilder* builder, const GrTextureAccess* access, int
idx) { | 83 void init(GrGLShaderBuilder* builder, const GrTextureAccess* access, int
idx) { |
| 85 GrAssert(NULL != access); | 84 GrAssert(NULL != access); |
| 86 this->init(builder, | 85 this->init(builder, |
| 87 GrPixelConfigComponentMask(access->getTexture()->config()
), | 86 GrPixelConfigComponentMask(access->getTexture()->config()
), |
| 88 access->getSwizzle(), | 87 access->getSwizzle(), |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 bool fTopLeftFragPosRead; | 457 bool fTopLeftFragPosRead; |
| 459 | 458 |
| 460 SkSTArray<10, AttributePair, true> fEffectAttributes; | 459 SkSTArray<10, AttributePair, true> fEffectAttributes; |
| 461 | 460 |
| 462 GrGLShaderVar* fPositionVar; | 461 GrGLShaderVar* fPositionVar; |
| 463 GrGLShaderVar* fLocalCoordsVar; | 462 GrGLShaderVar* fLocalCoordsVar; |
| 464 | 463 |
| 465 }; | 464 }; |
| 466 | 465 |
| 467 #endif | 466 #endif |
| OLD | NEW |