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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 const char* name, | 220 const char* name, |
222 const char** outName = NULL) { | 221 const char** outName = NULL) { |
223 return this->addUniformArray(visibility, type, name, GrGLShaderVar::kNon
Array, outName); | 222 return this->addUniformArray(visibility, type, name, GrGLShaderVar::kNon
Array, outName); |
224 } | 223 } |
225 GrGLUniformManager::UniformHandle addUniformArray(uint32_t visibility, | 224 GrGLUniformManager::UniformHandle addUniformArray(uint32_t visibility, |
226 GrSLType type, | 225 GrSLType type, |
227 const char* name, | 226 const char* name, |
228 int arrayCount, | 227 int arrayCount, |
229 const char** outName = NUL
L); | 228 const char** outName = NUL
L); |
230 | 229 |
231 const GrGLShaderVar& getUniformVariable(GrGLUniformManager::UniformHandle) c
onst; | 230 const GrGLShaderVar& getUniformVariable(GrGLUniformManager::UniformHandle u)
const { |
| 231 return fUniformManager.getBuilderUniform(fUniforms, u).fVariable; |
| 232 } |
232 | 233 |
233 /** | 234 /** |
234 * Shortcut for getUniformVariable(u).c_str() | 235 * Shortcut for getUniformVariable(u).c_str() |
235 */ | 236 */ |
236 const char* getUniformCStr(GrGLUniformManager::UniformHandle u) const { | 237 const char* getUniformCStr(GrGLUniformManager::UniformHandle u) const { |
237 return this->getUniformVariable(u).c_str(); | 238 return this->getUniformVariable(u).c_str(); |
238 } | 239 } |
239 | 240 |
240 /** Add a vertex attribute to the current program that is passed in from the
vertex data. | 241 /** Add a vertex attribute to the current program that is passed in from the
vertex data. |
241 Returns false if the attribute was already there, true otherwise. */ | 242 Returns false if the attribute was already there, true otherwise. */ |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 bool fTopLeftFragPosRead; | 459 bool fTopLeftFragPosRead; |
459 | 460 |
460 SkSTArray<10, AttributePair, true> fEffectAttributes; | 461 SkSTArray<10, AttributePair, true> fEffectAttributes; |
461 | 462 |
462 GrGLShaderVar* fPositionVar; | 463 GrGLShaderVar* fPositionVar; |
463 GrGLShaderVar* fLocalCoordsVar; | 464 GrGLShaderVar* fLocalCoordsVar; |
464 | 465 |
465 }; | 466 }; |
466 | 467 |
467 #endif | 468 #endif |
OLD | NEW |