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-2013 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 
48  {
50  {
51  mTexParameteriMap.clear();
52  }
53 
54  TexParameteriMap mTexParameteriMap;
55  };
56 
57  typedef HashMap<GLuint, TextureUnitParams> TexUnitsMap;
58 
59  /* These variables are used for caching OpenGL state.
60  They are cached because state changes can be quite expensive,
61  which is especially important on mobile or embedded systems.
62  */
63 
65  HashMap <GLenum, GLuint> mBoundTextures;
66 
67  struct TexGenParams
68  {
69  std::set<GLenum> mEnabled;
70  };
72  HashMap <GLenum, TexGenParams> mTextureCoordGen;
73 
75  BindBufferMap mActiveBufferMap;
77  TexUnitsMap mTexUnitsMap;
81  vector<GLclampf>::type mClearColour;
83  vector<GLboolean>::type mColourMask;
85  GLboolean mDepthMask;
87  GLenum mPolygonMode;
89  GLenum mBlendEquation;
91  GLenum mBlendFuncSource;
93  GLenum mBlendFuncDest;
95  GLenum mCullFace;
97  GLenum mDepthFunc;
99  GLuint mStencilMask;
103  size_t mActiveTextureUnit;
105  unsigned int mDiscardBuffers;
107  GLclampf mClearDepth;
109  int mViewport[4];
110 
111  GLenum mBlendEquationRGB;
112  GLenum mBlendEquationAlpha;
113  GLenum mShadeModel;
114 
115  GLfloat mAmbient[4];
116  GLfloat mDiffuse[4];
117  GLfloat mSpecular[4];
118  GLfloat mEmissive[4];
119  GLfloat mLightAmbient[4];
120  GLfloat mShininess;
121 
122  GLfloat mPointAttenuation[3];
123  GLfloat mPointSize;
124  GLfloat mPointSizeMin;
125  GLfloat mPointSizeMax;
126 
127  public:
128  GLStateCacheManagerImp(void);
129  ~GLStateCacheManagerImp(void);
130 
132  void initializeCache();
133 
135  void clearCache();
136 
138  void bindGLBuffer(GLenum target, GLuint buffer, GLenum attach = 0, bool force = false);
139 
141  void deleteGLBuffer(GLenum target, GLuint buffer, GLenum attach = 0, bool force = false);
142 
144  void bindGLTexture(GLenum target, GLuint texture);
145 
147  void setTexParameteri(GLenum target, GLenum pname, GLint param);
148 
150  void invalidateStateForTexture(GLuint texture);
151 
153  bool activateGLTextureUnit(size_t unit);
154 
156  GLenum getBlendEquation(void) const { return mBlendEquation; }
157 
159  void setBlendEquation(GLenum eq);
160 
162  void setBlendEquation(GLenum eqRGB, GLenum eqA);
163 
165  void setBlendFunc(GLenum source, GLenum dest);
166 
168  void setShadeModel(GLenum model);
169 
171  void setLightAmbient(GLfloat r, GLfloat g, GLfloat b);
172 
174  GLboolean getDepthMask(void) const { return mDepthMask; }
175 
177  void setDepthMask(GLboolean mask);
178 
180  GLenum getDepthFunc(void) const { return mDepthFunc; }
181 
183  void setDepthFunc(GLenum func);
184 
186  GLclampf getClearDepth(void) const { return mClearDepth; }
187 
189  void setClearDepth(GLclampf depth);
190 
192  void setClearColour(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
193 
195  vector<GLboolean>::type & getColourMask(void) { return mColourMask; }
196 
198  void setColourMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
199 
201  GLuint getStencilMask(void) const { return mStencilMask; }
202 
204  void setStencilMask(GLuint mask);
205 
207  void setEnabled(GLenum flag);
208 
210  void setDisabled(GLenum flag);
211 
213  unsigned int getDiscardBuffers(void) const { return mDiscardBuffers; }
214 
216  void setDiscardBuffers(unsigned int flags) { mDiscardBuffers = flags; }
217 
219  GLenum getPolygonMode(void) const { return mPolygonMode; }
220 
222  void setPolygonMode(GLenum mode);
223 
225  GLenum getCullFace(void) const { return mCullFace; }
226 
228  void setCullFace(GLenum face);
229 
231  void enableTextureCoordGen(GLenum type);
233  void disableTextureCoordGen(GLenum type);
234 
235  // Set material lighting parameters
236  void setMaterialAmbient(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
237  void setMaterialDiffuse(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
238  void setMaterialEmissive(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
239  void setMaterialSpecular(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
240  void setMaterialShininess(GLfloat shininess);
241  void setPointSize(GLfloat size);
242  void setPointParameters(GLfloat* attenuation, float minSize, float maxSize);
243 
245  void setViewport(GLint x, GLint y, GLsizei width, GLsizei height);
246 
248  void getViewport(int* array);
249  };
250 }
251 
252 #endif
GLclampf getClearDepth(void) const
See GLStateCacheManager.getClearDepth.
GLuint getStencilMask(void) const
See GLStateCacheManager.getStencilMask.
GLenum getBlendEquation(void) const
See GLStateCacheManager.getBlendEquation.
vector< GLboolean >::type & getColourMask(void)
See GLStateCacheManager.getColourMask.
HashMap< GLuint, TextureUnitParams > TexUnitsMap
HashMap< GLenum, GLuint > BindBufferMap
unsigned int getDiscardBuffers(void) const
See GLStateCacheManager.getDiscardBuffers.
GLenum getCullFace(void) const
See GLStateCacheManager.getCullFace.
vector< GLenum >::type mEnableVector
Array of each OpenGL feature that is enabled i.e. blending, depth test, etc.
Ogre::GeneralAllocatedObject StateCacheAlloc
#define _OgreGLExport
BindBufferMap mActiveBufferMap
A map of different buffer types and the currently bound buffer for each type.
GLenum getDepthFunc(void) const
See GLStateCacheManager.getDepthFunc.
HashMap< GLenum, GLuint > mBoundTextures
Stores textures currently bound to each texture stage.
GLboolean getDepthMask(void) const
See GLStateCacheManager.getDepthMask.
GLuint mLastBoundTexID
Stores the last bound texture id.
void setDiscardBuffers(unsigned int flags)
See GLStateCacheManager.setDiscardBuffers.
This source file is part of OGRE (Object-oriented Graphics Rendering Engine) For the latest info...
GLenum getPolygonMode(void) const
See GLStateCacheManager.getPolygonMode.
TexUnitsMap mTexUnitsMap
A map of texture parameters for each texture unit.
HashMap< GLenum, TexGenParams > mTextureCoordGen
Stores the currently enabled texcoord generation types per texture unit.
HashMap< GLenum, GLint > TexParameteriMap
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Oct 22 2017 04:04:15