Chromium Code Reviews| 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 |
| 11 #include "GrAllocator.h" | 11 #include "GrAllocator.h" |
| 12 #include "GrBackendEffectFactory.h" | 12 #include "GrBackendEffectFactory.h" |
| 13 #include "GrColor.h" | |
| 13 #include "GrEffect.h" | 14 #include "GrEffect.h" |
| 14 #include "gl/GrGLSL.h" | 15 #include "gl/GrGLSL.h" |
| 15 #include "gl/GrGLUniformManager.h" | 16 #include "gl/GrGLUniformManager.h" |
| 16 | 17 |
| 17 #include <stdarg.h> | 18 #include <stdarg.h> |
| 18 | 19 |
| 19 class GrGLContextInfo; | 20 class GrGLContextInfo; |
| 20 class GrEffectStage; | 21 class GrEffectStage; |
| 21 | 22 |
| 22 /** | 23 /** |
| 23 Contains all the incremental state of a shader as it is being built,as well as helpers to | 24 Contains all the incremental state of a shader as it is being built,as well as helpers to |
| 24 manipulate that state. | 25 manipulate that state. |
| 25 */ | 26 */ |
| 26 class GrGLShaderBuilder { | 27 class GrGLShaderBuilder { |
| 27 public: | 28 public: |
| 28 /** | 29 /** |
| 29 * Passed to GrGLEffects to add texture reads to their shader code. | 30 * Passed to GrGLEffects to add texture reads to their shader code. |
| 30 */ | 31 */ |
| 31 class TextureSampler { | 32 class TextureSampler { |
| 32 public: | 33 public: |
| 33 TextureSampler() | 34 TextureSampler() |
| 34 : fTextureAccess(NULL) | 35 : fConfigComponentMask(0) |
| 35 , fSamplerUniform(GrGLUniformManager::kInvalidUniformHandle) {} | 36 , fSamplerUniform(GrGLUniformManager::kInvalidUniformHandle) { |
| 37 // we will memcpy the first 4 bytes from passed in swizzle. This ens ures the string is | |
| 38 // terminated. | |
|
robertphillips
2013/03/28 13:38:29
very minor: Do we want to use '\0' rather than 0 t
bsalomon
2013/03/28 13:46:00
Done
| |
| 39 fSwizzle[4] = 0; | |
| 40 } | |
| 36 | 41 |
| 37 TextureSampler(const TextureSampler& other) { *this = other; } | 42 TextureSampler(const TextureSampler& other) { *this = other; } |
| 38 | 43 |
| 39 TextureSampler& operator= (const TextureSampler& other) { | 44 TextureSampler& operator= (const TextureSampler& other) { |
| 40 GrAssert(NULL == fTextureAccess); | 45 GrAssert(0 == fConfigComponentMask); |
| 41 GrAssert(GrGLUniformManager::kInvalidUniformHandle == fSamplerUnifor m); | 46 GrAssert(GrGLUniformManager::kInvalidUniformHandle == fSamplerUnifor m); |
| 42 | 47 |
| 43 fTextureAccess = other.fTextureAccess; | 48 fConfigComponentMask = other.fConfigComponentMask; |
| 44 fSamplerUniform = other.fSamplerUniform; | 49 fSamplerUniform = other.fSamplerUniform; |
| 45 return *this; | 50 return *this; |
| 46 } | 51 } |
| 47 | 52 |
| 48 const GrTextureAccess* textureAccess() const { return fTextureAccess; } | 53 // bitfield of GrColorComponentFlags present in the texture's config. |
| 54 uint32_t configComponentMask() const { return fConfigComponentMask; } | |
| 55 | |
| 56 const char* swizzle() const { return fSwizzle; } | |
| 49 | 57 |
| 50 private: | 58 private: |
| 51 // The idx param is used to ensure multiple samplers within a single eff ect have unique | 59 // The idx param is used to ensure multiple samplers within a single eff ect have unique |
| 52 // uniform names. | 60 // uniform names. swizzle is a four char max string made up of chars 'r' , 'g', 'b', and 'a'. |
| 53 void init(GrGLShaderBuilder* builder, const GrTextureAccess* access, int idx) { | 61 void init(GrGLShaderBuilder* builder, |
| 54 GrAssert(NULL == fTextureAccess); | 62 uint32_t configComponentMask, |
| 63 const char* swizzle, | |
| 64 int idx) { | |
| 65 GrAssert(0 == fConfigComponentMask); | |
| 55 GrAssert(GrGLUniformManager::kInvalidUniformHandle == fSamplerUnifor m); | 66 GrAssert(GrGLUniformManager::kInvalidUniformHandle == fSamplerUnifor m); |
| 56 | 67 |
| 57 GrAssert(NULL != builder); | 68 GrAssert(NULL != builder); |
| 58 GrAssert(NULL != access); | |
| 59 SkString name; | 69 SkString name; |
| 60 name.printf("Sampler%d_", idx); | 70 name.printf("Sampler%d_", idx); |
| 61 fSamplerUniform = builder->addUniform(GrGLShaderBuilder::kFragment_S haderType, | 71 fSamplerUniform = builder->addUniform(GrGLShaderBuilder::kFragment_S haderType, |
| 62 kSampler2D_GrSLType, | 72 kSampler2D_GrSLType, |
| 63 name.c_str()); | 73 name.c_str()); |
| 64 GrAssert(GrGLUniformManager::kInvalidUniformHandle != fSamplerUnifor m); | 74 GrAssert(GrGLUniformManager::kInvalidUniformHandle != fSamplerUnifor m); |
| 65 | 75 |
| 66 fTextureAccess = access; | 76 fConfigComponentMask = configComponentMask; |
| 77 memcpy(fSwizzle, swizzle, 4); | |
| 67 } | 78 } |
| 68 | 79 |
| 69 const GrTextureAccess* fTextureAccess; | 80 void init(GrGLShaderBuilder* builder, const GrTextureAccess* access, int idx) { |
| 81 GrAssert(NULL != access); | |
| 82 this->init(builder, | |
| 83 GrPixelConfigComponentMask(access->getTexture()->config() ), | |
| 84 access->getSwizzle(), | |
| 85 idx); | |
| 86 } | |
| 87 | |
| 88 uint32_t fConfigComponentMask; | |
| 89 char fSwizzle[5]; | |
| 70 GrGLUniformManager::UniformHandle fSamplerUniform; | 90 GrGLUniformManager::UniformHandle fSamplerUniform; |
| 71 | 91 |
| 72 friend class GrGLShaderBuilder; // to access fSamplerUniform | 92 friend class GrGLShaderBuilder; // to call init(). |
| 73 friend class GrGLProgram; // to construct these and access fSample rUniform. | |
| 74 }; | 93 }; |
| 75 | 94 |
| 76 typedef SkTArray<TextureSampler> TextureSamplerArray; | 95 typedef SkTArray<TextureSampler> TextureSamplerArray; |
| 77 | 96 |
| 78 enum ShaderType { | 97 enum ShaderType { |
| 79 kVertex_ShaderType = 0x1, | 98 kVertex_ShaderType = 0x1, |
| 80 kGeometry_ShaderType = 0x2, | 99 kGeometry_ShaderType = 0x2, |
| 81 kFragment_ShaderType = 0x4, | 100 kFragment_ShaderType = 0x4, |
| 82 }; | 101 }; |
| 83 | 102 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 GrGLUniformManager::UniformHandle fRTHeightUniform; | 317 GrGLUniformManager::UniformHandle fRTHeightUniform; |
| 299 | 318 |
| 300 SkSTArray<10, AttributePair, true> fEffectAttributes; | 319 SkSTArray<10, AttributePair, true> fEffectAttributes; |
| 301 | 320 |
| 302 GrGLShaderVar* fPositionVar; | 321 GrGLShaderVar* fPositionVar; |
| 303 GrGLShaderVar* fLocalCoordsVar; | 322 GrGLShaderVar* fLocalCoordsVar; |
| 304 | 323 |
| 305 }; | 324 }; |
| 306 | 325 |
| 307 #endif | 326 #endif |
| OLD | NEW |