00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright (c) 2000-2013 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 00029 #ifndef __GLStateCacheManagerImp_H__ 00030 #define __GLStateCacheManagerImp_H__ 00031 00032 #include "OgreGLPrerequisites.h" 00033 00034 typedef Ogre::GeneralAllocatedObject StateCacheAlloc; 00035 00036 namespace Ogre 00037 { 00041 class _OgreGLExport GLStateCacheManagerImp : public StateCacheAlloc 00042 { 00043 private: 00044 typedef HashMap<GLenum, GLuint> BindBufferMap; 00045 typedef HashMap<GLenum, GLint> TexParameteriMap; 00046 00047 struct TextureUnitParams 00048 { 00049 ~TextureUnitParams() 00050 { 00051 mTexParameteriMap.clear(); 00052 } 00053 00054 TexParameteriMap mTexParameteriMap; 00055 }; 00056 00057 typedef HashMap<GLuint, TextureUnitParams> TexUnitsMap; 00058 00059 /* These variables are used for caching OpenGL state. 00060 They are cached because state changes can be quite expensive, 00061 which is especially important on mobile or embedded systems. 00062 */ 00063 00065 HashMap <GLenum, GLuint> mBoundTextures; 00066 00067 struct TexGenParams 00068 { 00069 std::set<GLenum> mEnabled; 00070 }; 00072 HashMap <GLenum, TexGenParams> mTextureCoordGen; 00073 00075 BindBufferMap mActiveBufferMap; 00077 TexUnitsMap mTexUnitsMap; 00079 vector<GLenum>::type mEnableVector; 00081 vector<GLclampf>::type mClearColour; 00083 vector<GLboolean>::type mColourMask; 00085 GLboolean mDepthMask; 00087 GLenum mPolygonMode; 00089 GLenum mBlendEquation; 00091 GLenum mBlendFuncSource; 00093 GLenum mBlendFuncDest; 00095 GLenum mCullFace; 00097 GLenum mDepthFunc; 00099 GLuint mStencilMask; 00101 GLuint mLastBoundTexID; 00103 size_t mActiveTextureUnit; 00105 unsigned int mDiscardBuffers; 00107 GLclampf mClearDepth; 00109 int mViewport[4]; 00110 00111 GLenum mBlendEquationRGB; 00112 GLenum mBlendEquationAlpha; 00113 GLenum mShadeModel; 00114 00115 GLfloat mAmbient[4]; 00116 GLfloat mDiffuse[4]; 00117 GLfloat mSpecular[4]; 00118 GLfloat mEmissive[4]; 00119 GLfloat mLightAmbient[4]; 00120 GLfloat mShininess; 00121 00122 GLfloat mPointAttenuation[3]; 00123 GLfloat mPointSize; 00124 GLfloat mPointSizeMin; 00125 GLfloat mPointSizeMax; 00126 00127 public: 00128 GLStateCacheManagerImp(void); 00129 ~GLStateCacheManagerImp(void); 00130 00132 void initializeCache(); 00133 00135 void clearCache(); 00136 00138 void bindGLBuffer(GLenum target, GLuint buffer, GLenum attach = 0, bool force = false); 00139 00141 void deleteGLBuffer(GLenum target, GLuint buffer, GLenum attach = 0, bool force = false); 00142 00144 void bindGLTexture(GLenum target, GLuint texture); 00145 00147 void setTexParameteri(GLenum target, GLenum pname, GLint param); 00148 00150 void invalidateStateForTexture(GLuint texture); 00151 00153 bool activateGLTextureUnit(size_t unit); 00154 00156 GLenum getBlendEquation(void) const { return mBlendEquation; } 00157 00159 void setBlendEquation(GLenum eq); 00160 00162 void setBlendEquation(GLenum eqRGB, GLenum eqA); 00163 00165 void setBlendFunc(GLenum source, GLenum dest); 00166 00168 void setShadeModel(GLenum model); 00169 00171 void setLightAmbient(GLfloat r, GLfloat g, GLfloat b); 00172 00174 GLboolean getDepthMask(void) const { return mDepthMask; } 00175 00177 void setDepthMask(GLboolean mask); 00178 00180 GLenum getDepthFunc(void) const { return mDepthFunc; } 00181 00183 void setDepthFunc(GLenum func); 00184 00186 GLclampf getClearDepth(void) const { return mClearDepth; } 00187 00189 void setClearDepth(GLclampf depth); 00190 00192 void setClearColour(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); 00193 00195 vector<GLboolean>::type & getColourMask(void) { return mColourMask; } 00196 00198 void setColourMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); 00199 00201 GLuint getStencilMask(void) const { return mStencilMask; } 00202 00204 void setStencilMask(GLuint mask); 00205 00207 void setEnabled(GLenum flag); 00208 00210 void setDisabled(GLenum flag); 00211 00213 unsigned int getDiscardBuffers(void) const { return mDiscardBuffers; } 00214 00216 void setDiscardBuffers(unsigned int flags) { mDiscardBuffers = flags; } 00217 00219 GLenum getPolygonMode(void) const { return mPolygonMode; } 00220 00222 void setPolygonMode(GLenum mode); 00223 00225 GLenum getCullFace(void) const { return mCullFace; } 00226 00228 void setCullFace(GLenum face); 00229 00231 void enableTextureCoordGen(GLenum type); 00233 void disableTextureCoordGen(GLenum type); 00234 00235 // Set material lighting parameters 00236 void setMaterialAmbient(GLfloat r, GLfloat g, GLfloat b, GLfloat a); 00237 void setMaterialDiffuse(GLfloat r, GLfloat g, GLfloat b, GLfloat a); 00238 void setMaterialEmissive(GLfloat r, GLfloat g, GLfloat b, GLfloat a); 00239 void setMaterialSpecular(GLfloat r, GLfloat g, GLfloat b, GLfloat a); 00240 void setMaterialShininess(GLfloat shininess); 00241 void setPointSize(GLfloat size); 00242 void setPointParameters(GLfloat* attenuation, float minSize, float maxSize); 00243 00245 void setViewport(GLint x, GLint y, GLsizei width, GLsizei height); 00246 00248 void getViewport(int* array); 00249 }; 00250 } 00251 00252 #endif
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:43