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 __GLES2StateCacheManager_H__
30 #define __GLES2StateCacheManager_H__
31 
32 #include "OgreGLES2Prerequisites.h"
33 
34 typedef Ogre::GeneralAllocatedObject StateCacheAlloc;
35 
36 namespace Ogre
37 {
38 	class GLES2StateCacheManagerImp;
39 
40     /** An in memory cache of the OpenGL ES state.
41      @remarks
42      State changes can be particularly expensive time wise. This is because
43      a change requires OpenGL to re-evaluate and update the state machine.
44      Because of the general purpose nature of OGRE we often set the state for
45      a specific texture, material, buffer, etc. But this may be the same as the
46      current status of the state machine and is therefore redundant and causes
47      unnecessary work to be performed by OpenGL.
48      @par
49      Instead we are caching the state so that we can check whether it actually
50      does need to be updated. This leads to improved performance all around and
51      can be somewhat dramatic in some cases.
52      */
53     class _OgreGLES2Export GLES2StateCacheManager : public StateCacheAlloc
54     {
55     private:
56 		GLES2StateCacheManagerImp* mImp;
57 
58     public:
59         GLES2StateCacheManager(void);
60         ~GLES2StateCacheManager(void);
61 
62 		/** Initialize our cache variables and sets the
63             GL states on the current context.
64         */
65         void initializeCache();
66 
67         /** Clears all cached values
68         */
69         void clearCache();
70 
71 		/** Bind an OpenGL buffer of any type.
72          @param target The buffer target.
73          @param buffer The buffer ID.
74          @param force Optional parameter to force an update.
75          */
76         void bindGLBuffer(GLenum target, GLuint buffer, bool force = false);
77 
78 		/** Delete an OpenGL buffer of any type.
79          @param target The buffer target.
80          @param buffer The buffer ID.
81          @param force Optional parameter to force an update.
82          */
83         void deleteGLBuffer(GLenum target, GLuint buffer, bool force = false);
84 
85 		/** Bind an OpenGL texture of any type.
86          @param target The texture target.
87          @param texture The texture ID.
88          */
89         void bindGLTexture(GLenum target, GLuint texture);
90 
91         /** Invalidates the state associated with a particular texture ID.
92          @param texture The texture ID.
93          */
94         void invalidateStateForTexture(GLuint texture);
95 
96         /** Sets an integer parameter value per texture target.
97          @param target The texture target.
98          @param pname The parameter name.
99          @param param The parameter value.
100          */
101         void setTexParameteri(GLenum target, GLenum pname, GLint param);
102 
103         /** Sets a float parameter value per texture target.
104          @param target The texture target.
105          @param pname The parameter name.
106          @param params The parameter value.
107          */
108         void setTexParameterf(GLenum target, GLenum pname, GLfloat param);
109 
110         /** Sets a float parameter value per texture target.
111          @param target The texture target.
112          @param pname The parameter name.
113          @param params The parameter value.
114          */
115         void getTexParameterfv(GLenum target, GLenum pname, GLfloat *param);
116 
117         /** Activate an OpenGL texture unit.
118          @param unit The texture unit to activate.
119          @return Whether or not the texture unit was successfully activated.
120          */
121         bool activateGLTextureUnit(unsigned char unit);
122 
123         /** Gets the current blend equation setting.
124          @return The blend equation.
125          */
126         GLenum getBlendEquation(void) const;
127 
128         /** Sets the current blend equation setting.
129          @param eq The blend equation to use.
130          */
131         void setBlendEquation(GLenum eq);
132 
133         /** Sets the blending function.
134          @param source The blend mode for the source.
135          @param dest The blend mode for the destination
136          */
137         void setBlendFunc(GLenum source, GLenum dest);
138 
139         /** Gets the current depth mask setting.
140          @return The current depth mask.
141          */
142         GLboolean getDepthMask(void) const;
143 
144         /** Sets the current depth mask setting.
145          @param mask The depth mask to use.
146          */
147         void setDepthMask(GLboolean mask);
148 
149         /** Gets the current depth test function.
150          @return The current depth test function.
151          */
152         GLenum getDepthFunc(void) const;
153 
154         /** Sets the current depth test function.
155          @param func The depth test function to use.
156          */
157         void setDepthFunc(GLenum func);
158 
159 		/** Gets the clear depth in the range from [0..1].
160          @return The current clearing depth.
161          */
162         GLclampf getClearDepth(void) const;
163 
164         /** Sets the clear depth in the range from [0..1].
165          @param depth The clear depth to use.
166          */
167         void setClearDepth(GLclampf depth);
168 
169         /** Sets the color to clear to.
170          @param red The red component.
171          @param green The green component.
172          @param blue The blue component.
173          @param alpha The alpha component.
174          */
175         void setClearColour(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
176 
177         /** Gets the current colour mask setting.
178          @return An array containing the mask in RGBA order.
179          */
180         vector<GLboolean>::type & getColourMask(void) const;
181 
182         /** Sets the current colour mask.
183          @param red The red component.
184          @param green The green component.
185          @param blue The blue component.
186          @param alpha The alpha component.
187          */
188         void setColourMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
189 
190         /** Gets the current stencil mask.
191          @return The stencil mask.
192          */
193         GLuint getStencilMask(void) const;
194 
195         /** Sets the stencil mask.
196          @param mask The stencil mask to use
197          */
198         void setStencilMask(GLuint mask);
199 
200         /** Enables a piece of OpenGL functionality.
201          @param flag The function to enable.
202          */
203         void setEnabled(GLenum flag);
204 
205         /** Disables a piece of OpenGL functionality.
206          @param flag The function to disable.
207          */
208         void setDisabled(GLenum flag);
209 
210         /** Enables a vertex attribute.
211          @param attrib The attribute to enable.
212          */
213         void setVertexAttribEnabled(GLuint attrib);
214 
215         /** Disables a vertex attribute.
216          @param attrib The attribute to disable.
217          */
218         void setVertexAttribDisabled(GLuint attrib);
219 
220         /** Gets the mask of buffers to be discarded if GL_EXT_discard_framebuffer is supported
221          @return The buffer mask.
222          */
223         unsigned int getDiscardBuffers(void) const;
224 
225         /** Sets the mask of buffers to be discarded if GL_EXT_discard_framebuffer is supported
226          @param flags The bit mask of buffers to be discarded. Stored as Ogre::FrameBufferType.
227          */
228         void setDiscardBuffers(unsigned int flags);
229 
230         /** Gets the current polygon rendering mode, fill, wireframe, points, etc.
231          @return The current polygon rendering mode.
232          */
233         GLenum getPolygonMode(void) const;
234 
235         /** Sets the current polygon rendering mode.
236          @param mode The polygon mode to use.
237          */
238         void setPolygonMode(GLenum mode);
239 
240         /** Sets the face culling mode.
241          @return The current face culling mode
242          */
243         GLenum getCullFace(void) const;
244 
245         /** Sets the face culling setting.
246          @param face The face culling mode to use.
247          */
248         void setCullFace(GLenum face);
249     };
250 }
251 
252 #endif