OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreGLStateCacheManagerImp.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 
29 #ifndef __GLStateCacheManagerImp_H__
30 #define __GLStateCacheManagerImp_H__
31 
32 #include "OgreGLPrerequisites.h"
33 
35 
36 namespace Ogre
37 {
41  class _OgreGLExport GLStateCacheManagerImp : public StateCacheAlloc
42  {
43  private:
44  typedef HashMap<GLenum, GLuint> BindBufferMap;
45  typedef HashMap<GLenum, GLint> TexParameteriMap;
46  typedef HashMap<GLenum, bool> GLbooleanStateMap;
47 
49  {
51  {
52  mTexParameteriMap.clear();
53  }
54 
56  };
57 
58  typedef HashMap<GLuint, TextureUnitParams> TexUnitsMap;
59 
60  /* These variables are used for caching OpenGL state.
61  They are cached because state changes can be quite expensive,
62  which is especially important on mobile or embedded systems.
63  */
64 
66  HashMap <GLenum, GLuint> mBoundTextures;
67 
68  struct TexGenParams
69  {
70  std::set<GLenum> mEnabled;
71  };
73  HashMap <GLenum, TexGenParams> mTextureCoordGen;
74 
82  vector<GLclampf>::type mClearColour;
84  vector<GLboolean>::type mColourMask;
86  GLboolean mDepthMask;
88  GLenum mPolygonMode;
90  GLenum mBlendEquation;
92  GLenum mBlendFuncSource;
94  GLenum mBlendFuncDest;
96  GLenum mCullFace;
98  GLenum mDepthFunc;
100  GLuint mStencilMask;
104  size_t mActiveTextureUnit;
106  unsigned int mDiscardBuffers;
108  GLclampf mClearDepth;
110  int mViewport[4];
111 
112  GLenum mBlendEquationRGB;
113  GLenum mBlendEquationAlpha;
114  GLenum mShadeModel;
115 
116  GLfloat mAmbient[4];
117  GLfloat mDiffuse[4];
118  GLfloat mSpecular[4];
119  GLfloat mEmissive[4];
120  GLfloat mLightAmbient[4];
121  GLfloat mShininess;
122 
123  GLfloat mPointAttenuation[3];
124  GLfloat mPointSize;
125  GLfloat mPointSizeMin;
126  GLfloat mPointSizeMax;
127 
128  public:
129  GLStateCacheManagerImp(void);
130  ~GLStateCacheManagerImp(void);
131 
133  void initializeCache();
134 
136  void clearCache();
137 
139  void bindGLBuffer(GLenum target, GLuint buffer, GLenum attach = 0, bool force = false);
140 
142  void deleteGLBuffer(GLenum target, GLuint buffer, GLenum attach = 0, bool force = false);
143 
145  void bindGLTexture(GLenum target, GLuint texture);
146 
148  void setTexParameteri(GLenum target, GLenum pname, GLint param);
149 
151  void invalidateStateForTexture(GLuint texture);
152 
154  bool activateGLTextureUnit(size_t unit);
155 
157  GLenum getBlendEquation(void) const { return mBlendEquation; }
158 
160  void setBlendEquation(GLenum eq);
161 
163  void setBlendEquation(GLenum eqRGB, GLenum eqA);
164 
166  void setBlendFunc(GLenum source, GLenum dest);
167 
169  void setShadeModel(GLenum model);
170 
172  void setLightAmbient(GLfloat r, GLfloat g, GLfloat b);
173 
175  GLboolean getDepthMask(void) const { return mDepthMask; }
176 
178  void setDepthMask(GLboolean mask);
179 
181  GLenum getDepthFunc(void) const { return mDepthFunc; }
182 
184  void setDepthFunc(GLenum func);
185 
187  GLclampf getClearDepth(void) const { return mClearDepth; }
188 
190  void setClearDepth(GLclampf depth);
191 
193  void setClearColour(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
194 
196  vector<GLboolean>::type & getColourMask(void) { return mColourMask; }
197 
199  void setColourMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
200 
202  GLuint getStencilMask(void) const { return mStencilMask; }
203 
205  void setStencilMask(GLuint mask);
206 
208  void setEnabled(GLenum flag, bool enabled);
209 
211  unsigned int getDiscardBuffers(void) const { return mDiscardBuffers; }
212 
214  void setDiscardBuffers(unsigned int flags) { mDiscardBuffers = flags; }
215 
217  GLenum getPolygonMode(void) const { return mPolygonMode; }
218 
220  void setPolygonMode(GLenum mode);
221 
223  GLenum getCullFace(void) const { return mCullFace; }
224 
226  void setCullFace(GLenum face);
227 
229  void enableTextureCoordGen(GLenum type);
231  void disableTextureCoordGen(GLenum type);
232 
233  // Set material lighting parameters
234  void setMaterialAmbient(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
235  void setMaterialDiffuse(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
236  void setMaterialEmissive(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
237  void setMaterialSpecular(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
238  void setMaterialShininess(GLfloat shininess);
239  void setPointSize(GLfloat size);
240  void setPointParameters(GLfloat* attenuation, float minSize, float maxSize);
241 
243  void setViewport(GLint x, GLint y, GLsizei width, GLsizei height);
244 
246  void getViewport(int* array);
247  };
248 }
249 
250 #endif
GLenum getCullFace(void) const
See GLStateCacheManager.getCullFace.
BindBufferMap mActiveBufferMap
A map of different buffer types and the currently bound buffer for each type.
GLenum getBlendEquation(void) const
See GLStateCacheManager.getBlendEquation.
HashMap< GLenum, GLuint > BindBufferMap
HashMap< GLenum, bool > GLbooleanStateMap
unsigned int getDiscardBuffers(void) const
See GLStateCacheManager.getDiscardBuffers.
GLuint getStencilMask(void) const
See GLStateCacheManager.getStencilMask.
GLboolean getDepthMask(void) const
See GLStateCacheManager.getDepthMask.
#define _OgreGLExport
TexUnitsMap mTexUnitsMap
A map of texture parameters for each texture unit.
Ogre::GeneralAllocatedObject StateCacheAlloc
GLclampf getClearDepth(void) const
See GLStateCacheManager.getClearDepth.
HashMap< GLenum, GLuint > mBoundTextures
Stores textures currently bound to each texture stage.
HashMap< GLenum, TexGenParams > mTextureCoordGen
Stores the currently enabled texcoord generation types per texture unit.
GLbooleanStateMap mBoolStateMap
Array of each OpenGL feature that is enabled i.e. blending, depth test, etc.
HashMap< GLenum, GLint > TexParameteriMap
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
GLenum getDepthFunc(void) const
See GLStateCacheManager.getDepthFunc.
vector< GLboolean >::type & getColourMask(void)
See GLStateCacheManager.getColourMask.
GLuint mLastBoundTexID
Stores the last bound texture id.
HashMap< GLuint, TextureUnitParams > TexUnitsMap
void setDiscardBuffers(unsigned int flags)
See GLStateCacheManager.setDiscardBuffers.
GLenum getPolygonMode(void) const
See GLStateCacheManager.getPolygonMode.