diff options
author | twiz@google.com <twiz@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-08-02 15:15:16 +0000 |
---|---|---|
committer | twiz@google.com <twiz@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-08-02 15:15:16 +0000 |
commit | a5e65ec434fed44dc616e4f64950b835b541181b (patch) | |
tree | ffe3592179c7c3ce78db8e5e485c641900042015 /include/gpu | |
parent | eb7ad4a8b9c67743d6aa4e71b82e32f4cf1c8a9f (diff) |
Introduction of set of functions to manage generation of texture fetch shader code.
A new set of routines have been added to GrGLShaderBuilder to emit texture fetches, taking into consideration the format of the texture to be accessed, and the channel swizzle.
Review URL: https://codereview.appspot.com/6446072
git-svn-id: http://skia.googlecode.com/svn/trunk@4919 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/gpu')
-rw-r--r-- | include/gpu/GrCustomStage.h | 29 | ||||
-rw-r--r-- | include/gpu/GrProgramStageFactory.h | 27 |
2 files changed, 45 insertions, 11 deletions
diff --git a/include/gpu/GrCustomStage.h b/include/gpu/GrCustomStage.h index 906076656a..a13ecd469e 100644 --- a/include/gpu/GrCustomStage.h +++ b/include/gpu/GrCustomStage.h @@ -14,6 +14,27 @@ class GrContext; class GrTexture; +class SkString; + +/** A class representing the swizzle access pattern for a texture. + */ +class GrTextureAccess { +public: + typedef char Swizzle[4]; + + GrTextureAccess(const GrTexture* texture, const SkString& swizzle); + + const GrTexture* getTexture() const { return fTexture; } + const Swizzle& getSwizzle() const { return fSwizzle; } + + bool referencesAlpha() const { + return fSwizzle[0] == 'a' || fSwizzle[1] == 'a' || fSwizzle[2] == 'a' || fSwizzle[3] == 'a'; + } + +private: + const GrTexture* fTexture; + Swizzle fSwizzle; +}; /** Provides custom vertex shader, fragment shader, uniform data for a particular stage of the Ganesh shading pipeline. @@ -74,13 +95,17 @@ public: */ virtual bool isEqual(const GrCustomStage&) const; - /** Human-meaningful string to identify this effect; may be embedded - in generated shader code. */ + /** Human-meaningful string to identify this effect; may be embedded + in generated shader code. */ const char* name() const { return this->getFactory().name(); } virtual unsigned int numTextures() const; virtual GrTexture* texture(unsigned int index) const; + /** Returns the access pattern for the texture at index. Returns NULL if index is + unused. */ + virtual const GrTextureAccess* textureAccess(unsigned int index) const; + void* operator new(size_t size); void operator delete(void* target); diff --git a/include/gpu/GrProgramStageFactory.h b/include/gpu/GrProgramStageFactory.h index f2b4f5fc90..90f6b32851 100644 --- a/include/gpu/GrProgramStageFactory.h +++ b/include/gpu/GrProgramStageFactory.h @@ -19,15 +19,18 @@ class GrCustomStage; class GrGLProgramStage; +class GrGLCaps; class GrProgramStageFactory : public GrNoncopyable { public: - typedef uint16_t StageKey; + typedef uint32_t StageKey; enum { kProgramStageKeyBits = 10, + kTexturingStageKeyBits = 6 }; - virtual StageKey glStageKey(const GrCustomStage& stage) const = 0; + virtual StageKey glStageKey(const GrCustomStage& stage, + const GrGLCaps& caps ) const = 0; virtual GrGLProgramStage* createGLInstance( const GrCustomStage& stage) const = 0; @@ -68,7 +71,7 @@ template <typename StageClass> class GrTProgramStageFactory : public GrProgramStageFactory { public: - typedef typename StageClass::GLProgramStage GLProgramStage; + typedef typename StageClass::GLProgramStage GLProgramStage; /** Returns a human-readable name that is accessible via GrCustomStage or GrGLProgramStage and is consistent between the two of them. @@ -80,20 +83,26 @@ public: id identifies the GrCustomShader subclass. The remainder is based on the aspects of the GrCustomStage object's configuration that affect GLSL code generation. */ - virtual StageKey glStageKey(const GrCustomStage& stage) const SK_OVERRIDE { + virtual StageKey glStageKey(const GrCustomStage& stage, + const GrGLCaps& caps) const SK_OVERRIDE { GrAssert(kIllegalStageClassID != fStageClassID); - StageKey stageID = GLProgramStage::GenKey(stage); + StageKey stageID = GLProgramStage::GenKey(stage, caps); + StageKey textureKey = GLProgramStage::GenTextureKey(stage, caps); #if GR_DEBUG static const StageKey kIllegalIDMask = (uint16_t) (~((1U << kProgramStageKeyBits) - 1)); GrAssert(!(kIllegalIDMask & stageID)); + + static const StageKey kIllegalTextureKeyMask = + (uint16_t) (~((1U << kTexturingStageKeyBits) - 1)); + GrAssert(!(kIllegalTextureKeyMask & textureKey)); #endif - return fStageClassID | stageID; + return fStageClassID | (textureKey << kProgramStageKeyBits) | stageID; } /** Returns a new instance of the appropriate *GL* implementation class - for the given GrCustomStage; caller is responsible for deleting - the object. */ + for the given GrCustomStage; caller is responsible for deleting + the object. */ virtual GLProgramStage* createGLInstance( const GrCustomStage& stage) const SK_OVERRIDE { return SkNEW_ARGS(GLProgramStage, (*this, stage)); @@ -113,7 +122,7 @@ public: protected: GrTProgramStageFactory() { - fStageClassID = GenID() << kProgramStageKeyBits; + fStageClassID = GenID() << (kProgramStageKeyBits + kTexturingStageKeyBits) ; } }; |