Torque3D Documentation / _generateds / gfxGLStateCache.h

gfxGLStateCache.h

Engine/source/gfx/gl/gfxGLStateCache.h

More...

Classes:

class

GFXGLStateCache store OpenGL state to avoid performance penalities of glGet* calls GL_TEXTURE_1D/2D/3D, GL_FRAMEBUFFER, GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER.

Detailed Description

  1
  2#ifndef GFX_GL_STATE_CACHE
  3#define GFX_GL_STATE_CACHE
  4
  5
  6/// GFXGLStateCache store OpenGL state to avoid performance penalities of glGet* calls
  7/// GL_TEXTURE_1D/2D/3D, GL_FRAMEBUFFER, GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER
  8class GFXGLStateCache
  9{
 10public:
 11   GFXGLStateCache()
 12   {      
 13      mActiveTexture = 0;      
 14      mBindedVBO = 0;
 15      mBindedIBO = 0;
 16      mBindedFBO_W = 0;
 17      mBindedFBO_R = 0;
 18      mVertexAttribActive = 0;
 19   }
 20
 21   class TextureUnit
 22   {
 23   public:
 24      TextureUnit() :  mTexture1D(0), mTexture2D(0), mTexture3D(0), mTextureCube(0)
 25      {
 26
 27      }
 28      GLuint mTexture1D, mTexture2D, mTexture3D, mTextureCube;
 29   };
 30
 31   /// after glBindTexture
 32   void setCacheBindedTex(U32 texUnit, GLenum biding, GLuint handle)
 33   { 
 34      mActiveTexture = texUnit;
 35      switch (biding)
 36      {
 37      case GL_TEXTURE_2D:
 38         mTextureUnits[mActiveTexture].mTexture2D = handle;
 39         break;
 40      case GL_TEXTURE_3D:
 41         mTextureUnits[mActiveTexture].mTexture3D = handle;
 42         break;
 43      case GL_TEXTURE_1D:
 44         mTextureUnits[mActiveTexture].mTexture1D = handle;
 45         break;
 46      case GL_TEXTURE_CUBE_MAP:
 47         mTextureUnits[mActiveTexture].mTextureCube = handle;
 48         break;
 49      default:
 50         AssertFatal(0, avar("GFXGLStateCache::setCacheBindedTex - binding (%x) not supported.", biding) );
 51         return;
 52      }
 53   }
 54
 55   /// after opengl object binded
 56   void setCacheBinded(GLenum biding, GLuint handle) 
 57   { 
 58      switch (biding)
 59      {
 60      case GL_TEXTURE_2D:
 61         mTextureUnits[mActiveTexture].mTexture2D = handle;
 62         break;
 63      case GL_TEXTURE_3D:
 64         mTextureUnits[mActiveTexture].mTexture3D = handle;
 65         break;
 66      case GL_TEXTURE_1D:
 67         mTextureUnits[mActiveTexture].mTexture1D = handle;
 68         break;
 69      case GL_TEXTURE_CUBE_MAP:
 70         mTextureUnits[mActiveTexture].mTextureCube = handle;
 71         break;
 72      case GL_FRAMEBUFFER:
 73         mBindedFBO_W = mBindedFBO_R = handle;
 74         break;
 75      case GL_DRAW_FRAMEBUFFER:
 76         mBindedFBO_W = handle;
 77         break;
 78      case GL_READ_FRAMEBUFFER:
 79         mBindedFBO_R = handle;
 80         break;
 81      case GL_ARRAY_BUFFER:
 82         mBindedVBO = handle;
 83         break;
 84      case GL_ELEMENT_ARRAY_BUFFER:
 85         mBindedIBO = handle;
 86         break;
 87      default:
 88         AssertFatal(0, avar("GFXGLStateCache::setCacheBinded - binding (%x) not supported.", biding) );
 89         break;
 90      }
 91   }
 92
 93   GLuint getCacheBinded(GLenum biding) const
 94   {
 95      switch (biding)
 96      {
 97      case GL_TEXTURE_2D:
 98         return mTextureUnits[mActiveTexture].mTexture2D;
 99      case GL_TEXTURE_3D:
100         return mTextureUnits[mActiveTexture].mTexture3D;
101      case GL_TEXTURE_1D:
102         return mTextureUnits[mActiveTexture].mTexture1D;
103      case GL_TEXTURE_CUBE_MAP:
104         return mTextureUnits[mActiveTexture].mTextureCube;
105      case GL_DRAW_FRAMEBUFFER:
106         return mBindedFBO_W;
107      case GL_READ_FRAMEBUFFER:
108         return mBindedFBO_R;
109      case GL_ARRAY_BUFFER:
110         return mBindedVBO;
111      case GL_ELEMENT_ARRAY_BUFFER:
112         return mBindedIBO;
113      default:
114         AssertFatal(0, avar("GFXGLStateCache::getCacheBinded - binding (%x) not supported.", biding) );
115         return 0;
116      }
117   }
118
119   /// after glActiveTexture
120   void setCacheActiveTexture(U32 unit) { mActiveTexture = unit; }
121   U32 getCacheActiveTexture() const { return mActiveTexture;  }
122
123   /// for cache glEnableVertexAttribArray / glDisableVertexAttribArray
124   void setCacheVertexAttribActive(U32 activeMask) { mVertexAttribActive = activeMask; }
125   U32 getCacheVertexAttribActive() const { return mVertexAttribActive;  }
126
127protected:   
128   GLuint mActiveTexture, mBindedVBO, mBindedIBO, mBindedFBO_W, mBindedFBO_R;
129   TextureUnit mTextureUnits[TEXTURE_STAGE_COUNT];
130   U32 mVertexAttribActive;
131};
132
133
134#endif
135