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 __GLES2StateCacheManager_H__ 30 #define __GLES2StateCacheManager_H__ 31 32 #include "OgreGLES2Prerequisites.h" 33 #include "OgreGLStateCacheManagerCommon.h" 34 35 namespace Ogre 36 { 37 class _OgreGLES2Export GLES2StateCacheManager : public GLStateCacheManagerCommon 38 { 39 protected: 40 struct TextureUnitParams 41 { 42 TexParameteriMap mTexParameteriMap; 43 TexParameterfMap mTexParameterfMap; 44 }; 45 46 typedef std::unordered_map<GLuint, TextureUnitParams> TexUnitsMap; 47 48 /// Stores the currently bound vertex array object 49 GLuint mActiveVertexArray; 50 /// A map of texture parameters for each texture unit 51 TexUnitsMap mTexUnitsMap; 52 /// Stores the currently enabled vertex attributes 53 std::vector<GLuint> mEnabledVertexAttribs; 54 /// Stores the last bound texture id 55 GLuint mLastBoundTexID; 56 public: 57 GLES2StateCacheManager(void); 58 59 /** Initialize our cache variables and sets the 60 GL states on the current context. 61 */ 62 void initializeCache(); 63 64 /** Clears all cached values 65 */ 66 void clearCache(); 67 68 /** Bind an OpenGL buffer of any type. 69 @param target The buffer target. 70 @param buffer The buffer ID. 71 @param force Optional parameter to force an update. 72 */ 73 void bindGLBuffer(GLenum target, GLuint buffer, bool force = false); 74 75 /** Delete an OpenGL buffer of any type. 76 @param target The buffer target. 77 @param buffer The buffer ID. 78 */ 79 void deleteGLBuffer(GLenum target, GLuint buffer); 80 81 /** Bind an OpenGL Vertex array object. 82 @param vao The vertex array object ID. 83 */ 84 void bindGLVertexArray(GLuint vao); 85 86 /** Bind an OpenGL texture of any type. 87 @param target The texture target. 88 @param texture The texture ID. 89 */ 90 void bindGLTexture(GLenum target, GLuint texture); 91 92 /** Invalidates the state associated with a particular texture ID. 93 @param texture The texture ID. 94 */ 95 void invalidateStateForTexture(GLuint texture); 96 97 /** Sets an integer parameter value per texture target. 98 @param target The texture target. 99 @param pname The parameter name. 100 @param param The parameter value. 101 */ 102 void setTexParameteri(GLenum target, GLenum pname, GLint param); 103 104 /** Sets a float parameter value per texture target. 105 @param target The texture target. 106 @param pname The parameter name. 107 @param param The parameter value. 108 */ 109 void setTexParameterf(GLenum target, GLenum pname, GLfloat param); 110 111 /** Activate an OpenGL texture unit. 112 @param unit The texture unit to activate. 113 @return Whether or not the texture unit was successfully activated. 114 */ 115 bool activateGLTextureUnit(size_t unit); 116 117 /// Set the blend equation for RGB and alpha separately. 118 void setBlendEquation(GLenum eqRGB, GLenum eqA); 119 120 /// Set the blend function for RGB and alpha separately. 121 void setBlendFunc(GLenum source, GLenum dest, GLenum sourceA, GLenum destA); 122 123 /** Sets the current depth mask setting. 124 @param mask The depth mask to use. 125 */ 126 void setDepthMask(GLboolean mask); 127 128 /** Sets the current depth test function. 129 @param func The depth test function to use. 130 */ 131 void setDepthFunc(GLenum func); 132 133 /** Sets the clear depth in the range from [0..1]. 134 @param depth The clear depth to use. 135 */ 136 void setClearDepth(GLclampf depth); 137 138 /** Sets the color to clear to. 139 @param red The red component. 140 @param green The green component. 141 @param blue The blue component. 142 @param alpha The alpha component. 143 */ 144 void setClearColour(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); 145 146 /** Sets the current colour mask. 147 @param red The red component. 148 @param green The green component. 149 @param blue The blue component. 150 @param alpha The alpha component. 151 */ 152 void setColourMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); 153 154 /** Sets the stencil mask. 155 @param mask The stencil mask to use 156 */ 157 void setStencilMask(GLuint mask); 158 159 /** Enables a piece of OpenGL functionality. 160 @param flag The function to enable. 161 */ 162 void setEnabled(GLenum flag); 163 164 /** Disables a piece of OpenGL functionality. 165 @param flag The function to disable. 166 */ 167 void setDisabled(GLenum flag); 168 169 /** Sets the face culling setting. 170 @param face The face culling mode to use. 171 */ 172 void setCullFace(GLenum face); 173 174 void setViewport(GLint x, GLint y, GLsizei width, GLsizei height); 175 }; 176 } 177 178 #endif 179