GL Studio C++ Runtime API
gls_state_manager_interface.h
Go to the documentation of this file.
1 /*! \file
2  \brief IGlsStateManager, interface to a state manager that manages the GL Studio
3 runtime library's use of the OpenGL context, minimizing unnecessary state changes.
4 
5  \par Copyright Information
6 
7  Copyright (c) 2017 by The DiSTI Corporation.<br>
8  11301 Corporate Blvd; Suite 100<br>
9  Orlando, Florida 32817<br>
10  USA<br>
11  <br>
12  All rights reserved.<br>
13 
14  This Software contains proprietary trade secrets of DiSTI and may not be
15 reproduced, in whole or part, in any form, or by any means of electronic,
16 mechanical, or otherwise, without the written permission of DiSTI. Said
17 permission may be derived through the purchase of applicable DiSTI product
18 licenses which detail the distribution rights of this content and any
19 Derivative Works based on this or other copyrighted DiSTI Software.
20 
21  NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
22 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
23 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
24 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
25 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
26 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
27 
28  LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
29 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
30 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
31 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
32 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
33 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
34 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
35 EXCEED FIVE DOLLARS (US$5.00).
36 
37  The aforementioned terms and restrictions are governed by the laws of the
38 State of Florida and the United States of America. Use, distribution,
39 duplication, or disclosure by the U. S. Government is subject to
40 "Restricted Rights" as set forth in DFARS 252.227-7014(c)(1)(ii).
41 
42 */
43 
44 #ifndef DISTI_GLS_STATE_MANAGER_INTERFACE_H_INCLUDED
45 #define DISTI_GLS_STATE_MANAGER_INTERFACE_H_INCLUDED
46 
47 #include "IFontImage.h"
48 #include "gls_color.h"
49 #include "gls_gl.h"
50 #include "gls_include.h"
51 #include "gls_matrix_affine.h"
52 #include "non_copyable.h"
53 
54 #ifndef LESS_MAX_LIGHTS
55 # define MAX_LIGHTS 8
56 #else
57 # define MAX_LIGHTS 6
58 #endif
59 
60 namespace disti
61 {
62 /** \interface IGlsStateManager
63  * The interface to a state manager that manages the GL Studio
64  * runtime library's use of the OpenGL context, minimizing unnecessary state changes
65  */
67 {
68 public:
69  /** supported texture mapping modes */
70  enum
71  {
72  GLS_TEXTURE_MAP_MODE_MODULATE = 0x2100, // = GL_MODULATE
73  GLS_TEXTURE_MAP_MODE_DECAL = 0x2101, // = GL_DECAL
74  GLS_TEXTURE_MAP_MODE_BLEND = 0x0BE2, // = GL_BLEND
75  GLS_TEXTURE_MAP_MODE_REPLACE = 0x1E01 // = GL_REPLACE
76  };
77 
78  /** Initializes the state manager to its default states and then sends that state
79  * to the OpenGL context
80  * \param forceResetUnmanagedState force the reset of all GL state, even state unmanaged by GL Studio
81  */
82  GLS_EXPORT virtual void SetDefaultState( bool forceResetUnmanagedState = false ) = 0;
83 
84  ////////////////////////////////////////////////////////////////
85  //
86  // Matrix Stack
87  //
88  ////////////////////////////////////////////////////////////////
89  enum
90  {
91  MATRIX_STACK_DEPTH = 64u, /**< depth of model view matrix stack */
92  PROJECTION_STACK_DEPTH = 64u, /**< depth of projection matrix stack */
93  TEXTURE_STACK_DEPTH = 64u, /**< depth of texture matrix stack */
94  CUSTOM_SHADER_PROGRAM_STACK_DEPTH = 64u /**< depth of custom shader stack */
95  };
96 
97  /** load the given matrix into the projection matrix
98  * \pre GLMatrixAffineFIsValid( m )
99  * \post the given matrix is the projection matrix
100  */
101  GLS_EXPORT virtual void LoadProjectionMatrixf( const GlsMatrixType& m ) = 0;
102 
103  GLS_EXPORT virtual void LoadProjectionIdentityMatrix( void ) = 0;
104 
105  GLS_EXPORT virtual void PushProjectionMatrix( void ) = 0;
106 
107  GLS_EXPORT virtual void PopProjectionMatrix( void ) = 0;
108 
109  /** load the given matrix on to the top of the matrix stack
110  * \pre GLMatrixAffineFIsValid( m )
111  * \post the given matrix is on the top of the matrix stack
112  */
113  GLS_EXPORT virtual void LoadModelViewMatrixf( const GlsMatrixType& m ) = 0;
114 
115  GLS_EXPORT virtual void LoadModelViewIdentityMatrix( void ) = 0;
116 
117  /** Multiply (and optionally push) the top of the stack by the given matrix such that if
118  * t is the top of the matrix then t=t*m . If pushMatrix is true then the matrix stack
119  * is pushed before the multiplication.
120  * \param m matrix to multiply by
121  * \param pushMatrix true to push the matrix stack before multiplying
122  * \pre GLMatrixAffineFIsValid( m ), current matrix stack index is < ( MATRIX_STACK_DEPTH - 1u ) if pushMatrix is true
123  * \post the top of the stack is multiplied by the given matrix
124  */
125  GLS_EXPORT virtual void MultModelViewMatrixf( const GlsMatrixType& m, const GLboolean pushMatrix ) = 0;
126 
127  /** apply a translation to the top of the model view matrix stack
128  * \param x the x-coordinate of the translation vector
129  * \param y the y-coordinate of the translation vector
130  * \param z the z-coordinate of the translation vector
131  */
132  GLS_EXPORT virtual void TranslateModelViewMatrixf( GLfloat x, GLfloat y, GLfloat z ) = 0;
133 
134  /** push the matrix stack
135  * \pre current matrix stack index is < ( MATRIX_STACK_DEPTH - 1u )
136  * \post matrix stack is popped
137  */
138  GLS_EXPORT virtual void PushModelViewMatrix( void ) = 0;
139 
140  /** pop the matrix stack
141  * \pre current matrix stack index is > 0u
142  * \post matrix stack is popped
143  */
144  GLS_EXPORT virtual void PopModelViewMatrix( void ) = 0;
145 
146  /** load the given matrix on to the top of the texture matrix stack
147  * \pre GLMatrixAffineFIsValid( m )
148  * \post the given matrix is on the top of the texture matrix stack
149  */
150  GLS_EXPORT virtual void LoadTextureMatrixf( const GlsMatrixType& m ) = 0;
151 
152  GLS_EXPORT virtual void LoadTextureIdentityMatrix( void ) = 0;
153 
154  /** apply a scale factor to the top of the texture matrix stack
155  * \param x the x-coordinate of the scale vector
156  * \param y the y-coordinate of the scale vector
157  * \param z the z-coordinate of the scale vector
158  */
159  GLS_EXPORT virtual void ScaleTextureMatrixf( GLfloat x, GLfloat y, GLfloat z ) = 0;
160 
161  /** apply a translation to the top of the texture matrix stack
162  * \param x the x-coordinate of the translation vector
163  * \param y the y-coordinate of the translation vector
164  * \param z the z-coordinate of the translation vector
165  */
166  GLS_EXPORT virtual void TranslateTextureMatrixf( GLfloat x, GLfloat y, GLfloat z ) = 0;
167 
168  /** push the texture matrix stack
169  * \pre current matrix stack index is < ( MATRIX_STACK_DEPTH - 1u )
170  * \post matrix stack is popped
171  */
172  GLS_EXPORT virtual void PushTextureMatrix( void ) = 0;
173 
174  /** pop the texture matrix stack
175  * \pre current matrix stack index is > 0u
176  * \post matrix stack is popped
177  */
178  GLS_EXPORT virtual void PopTextureMatrix( void ) = 0;
179 
180  ////////////////////////////////////////////////////////////////
181  //
182  // The following methods manage the various OpenGL state calls
183  //
184  ////////////////////////////////////////////////////////////////
185  GLS_EXPORT virtual void AlphaBlendFunc( GLenum src, GLenum dst ) = 0;
186  GLS_EXPORT virtual void AlphaBlendEnabled( bool val ) = 0;
187  GLS_EXPORT virtual void AlphaTestEnabled( bool val ) = 0;
188  GLS_EXPORT virtual void AlphaTestFunc( GLenum func, GLfloat val ) = 0;
189 
190  GLS_EXPORT virtual void DepthTestEnabled( bool val ) = 0;
191  GLS_EXPORT virtual void DepthMaskEnabled( bool val ) = 0;
192  GLS_EXPORT virtual bool IsDepthMaskEnabled( void ) = 0;
193  GLS_EXPORT virtual void DepthFunc( GLenum func ) = 0;
194  GLS_EXPORT virtual void DepthRange( GLfloat min, GLfloat max ) = 0;
195 
196  GLS_EXPORT virtual void BackfaceCullingEnabled( bool val ) = 0;
197 
198  GLS_EXPORT virtual void Texture2DEnabled( bool val ) = 0;
199  GLS_EXPORT virtual void ActiveTexture( GLenum textureUnit ) = 0;
200  GLS_EXPORT virtual void BindTexture( IFontImage* texture ) = 0;
201  GLS_EXPORT virtual void DeleteTexture( IFontImage* texture ) = 0;
202  GLS_EXPORT virtual void SetTextureWrapS( GLenum mode ) = 0;
203  GLS_EXPORT virtual void SetTextureWrapT( GLenum mode ) = 0;
204  GLS_EXPORT virtual void SetTextureEnvMode( GLenum mode ) = 0;
205  GLS_EXPORT virtual void SetTextureBlendColor( GLfloat* color ) = 0;
206  GLS_EXPORT virtual void SetTextureMinFilter( GLenum mode ) = 0;
207  GLS_EXPORT virtual void SetTextureMagFilter( GLenum mode ) = 0;
208 
209  GLS_EXPORT virtual void BindIndexBuffer( unsigned int handle ) = 0;
210  GLS_EXPORT virtual void BindVertexBuffer( unsigned int handle ) = 0;
211 
212  GLS_EXPORT virtual void VertexArrayEnabled( bool val ) = 0;
213  GLS_EXPORT virtual void NormalArrayEnabled( bool val ) = 0;
214  GLS_EXPORT virtual void TextureArrayEnabled( bool val ) = 0;
215  GLS_EXPORT virtual void ColorArrayEnabled( bool val ) = 0;
216 
217  GLS_EXPORT virtual void VertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid* pointer ) = 0;
218  GLS_EXPORT virtual void TexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid* pointer ) = 0;
219  GLS_EXPORT virtual void NormalPointer( GLenum type, GLsizei stride, const GLvoid* pointer ) = 0;
220  GLS_EXPORT virtual void ColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid* pointer ) = 0;
221 
222  GLS_EXPORT virtual void LineSmoothEnabled( bool val ) = 0;
223  GLS_EXPORT virtual void LineWidth( float width ) = 0;
224  GLS_EXPORT virtual void PointSize( float size ) = 0;
225  GLS_EXPORT virtual void LineStipple( unsigned short pattern, unsigned int multiplier ) = 0;
226  GLS_EXPORT virtual void SetColor( const glsColor& color ) = 0;
227  GLS_EXPORT virtual void Normal3f( float x, float y, float z ) = 0;
228 
229  GLS_EXPORT virtual void AmbientMaterial( const glsColor& color ) = 0;
230  GLS_EXPORT virtual void DiffuseMaterial( const glsColor& color ) = 0;
231  GLS_EXPORT virtual void SpecularMaterial( const glsColor& color ) = 0;
232  GLS_EXPORT virtual void EmissionMaterial( const glsColor& color ) = 0;
233  GLS_EXPORT virtual void ShininessMaterial( float shininess ) = 0;
234 
235  GLS_EXPORT virtual void LightingEnabled( bool val ) = 0;
236  GLS_EXPORT virtual void GouraudShadingEnabled( bool val ) = 0;
237  GLS_EXPORT virtual bool IsLightingEnabled( void ) = 0;
238  GLS_EXPORT virtual bool IsLightSourceEnabled( unsigned int index ) = 0;
239  GLS_EXPORT virtual unsigned int GetMaxNumLights( void ) = 0;
240  GLS_EXPORT virtual void SetLightEnabled( unsigned int index, bool enabled ) = 0;
241 
242  // These functions work similar to glLightfv / glGetLightfv. For spacial data, the data is always set in local space and
243  // retrieved in eye space (so the retrieved value is different than the set value unless the modelview matrix is identity) */
244  GLS_EXPORT virtual void SetLightAmbientColor( unsigned int index, GLfloat* color ) = 0;
245  GLS_EXPORT virtual void GetLightAmbientColor( unsigned int index, GLfloat* color ) = 0;
246  GLS_EXPORT virtual void SetLightDiffuseColor( unsigned int index, GLfloat* color ) = 0;
247  GLS_EXPORT virtual void GetLightDiffuseColor( unsigned int index, GLfloat* color ) = 0;
248  GLS_EXPORT virtual void SetLightSpecularColor( unsigned int index, GLfloat* color ) = 0;
249  GLS_EXPORT virtual void GetLightSpecularColor( unsigned int index, GLfloat* color ) = 0;
250  GLS_EXPORT virtual void SetLightPosition( unsigned int index, GLfloat* position ) = 0;
251  GLS_EXPORT virtual void GetLightPosition( unsigned int index, GLfloat* position ) = 0;
252  GLS_EXPORT virtual void SetSpotlightDirection( unsigned int index, GLfloat* direction ) = 0;
253  GLS_EXPORT virtual void GetSpotlightDirection( unsigned int index, GLfloat* direction ) = 0;
254  GLS_EXPORT virtual void SetSpotlightCutoff( unsigned int index, GLfloat cutoff ) = 0;
255  GLS_EXPORT virtual GLfloat GetSpotlightCutoff( unsigned int index ) = 0;
256  GLS_EXPORT virtual void SetSpotlightExponent( unsigned int index, GLfloat exponent ) = 0;
257  GLS_EXPORT virtual GLfloat GetSpotlightExponent( unsigned int index ) = 0;
258  GLS_EXPORT virtual void SetLightAttenuation( unsigned int index, GLfloat constant, GLfloat linear, GLfloat quadratic ) = 0;
259  GLS_EXPORT virtual void GetLightAttenuation( unsigned int index, GLfloat& constant, GLfloat& linear, GLfloat& quadratic ) = 0;
260 
261  GLS_EXPORT virtual unsigned int GetMaxClipPlanes( void ) = 0;
262 
263  // These functions work similar to glClipPlane / glGetClipPlane. The equation is always set in local space and retrieved in eye space
264  // (so the retrieved value is different than the set value unless the modelview matrix is identity) */
265  GLS_EXPORT virtual void ClipPlanef( unsigned int index, float* equation ) = 0;
266  GLS_EXPORT virtual void GetClipPlanef( unsigned int index, float* equation ) = 0;
267 
268  GLS_EXPORT virtual void EnableClipPlane( unsigned int index ) = 0;
269  GLS_EXPORT virtual void DisableClipPlane( unsigned int index ) = 0;
270  GLS_EXPORT virtual bool IsClipPlaneEnabled( unsigned int index ) = 0;
271 
272  /** equivalent to glDrawArrays call
273  * \param mode primitive mode to draw ( GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, or GL_TRIANGLES )
274  * \param first starting index in the enabled arrays
275  * \param count the number of indices to be rendered
276  * \pre mode must be GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, or GL_TRIANGLES
277  * \pre first >= 0
278  * \post (GLES20) updated shader program is selected if needed
279  * \post primitives are drawn to GL
280  */
281  GLS_EXPORT virtual void DrawArrays( const GLenum mode, const GLint first, const GLsizei count ) = 0;
282 
283  /** equivalent to glDrawElements call
284  * \param mode primitive mode to draw ( GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, or GL_TRIANGLES )
285  * \param count the number of elements to be rendered
286  * \param type Specifies the type of the values in indices ( GL_UNSIGNED_BYTE or GL_UNSIGNED_SHORT )
287  * \param indices pointer to the location where the indices are stored else an offset in bytes into the
288  * the currently bound element array buffer
289  * \pre mode must be GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, or GL_TRIANGLES
290  * \pre type must be GL_UNSIGNED_BYTE or GL_UNSIGNED_SHORT
291  * \post (GLES20) updated shader program is selected if needed
292  * \post primitives are drawn to GL
293  */
294  GLS_EXPORT virtual void DrawElements( const GLenum mode, const GLsizei count, const GLenum type, const GLvoid* indices ) = 0;
295 
296 protected:
297  /** empty ctor */
298  IGlsStateManager( void ) {}
299 
300  /** empty dtor */
302 };
303 
304 } // namespace disti
305 
306 #endif // DISTI_GLS_STATE_MANAGER_INTERFACE_H_INCLUDED
virtual void DrawElements(const GLenum mode, const GLsizei count, const GLenum type, const GLvoid *indices)=0
Definition: IFontImage.h:53
virtual void MultModelViewMatrixf(const GlsMatrixType &m, const GLboolean pushMatrix)=0
~IGlsStateManager()
Definition: gls_state_manager_interface.h:301
A base class for objects that are not copyable via the standard C++ copy constructor.
Definition: gls_state_manager_interface.h:91
The GlsMatrixAffine class.
virtual void PushTextureMatrix(void)=0
virtual void TranslateTextureMatrixf(GLfloat x, GLfloat y, GLfloat z)=0
virtual void ScaleTextureMatrixf(GLfloat x, GLfloat y, GLfloat z)=0
Definition: gls_state_manager_interface.h:66
virtual void TranslateModelViewMatrixf(GLfloat x, GLfloat y, GLfloat z)=0
The Color class: Implements a 4 component RGBA color.
virtual void SetDefaultState(bool forceResetUnmanagedState=false)=0
Definition: gls_state_manager_interface.h:94
A file for all GL Studio files to include.
IGlsStateManager(void)
Definition: gls_state_manager_interface.h:298
Definition: gls_state_manager_interface.h:93
virtual void LoadProjectionMatrixf(const GlsMatrixType &m)=0
virtual void PopModelViewMatrix(void)=0
virtual void LoadTextureMatrixf(const GlsMatrixType &m)=0
Definition: gls_color.h:53
Definition: gls_state_manager_interface.h:92
virtual void PushModelViewMatrix(void)=0
virtual void PopTextureMatrix(void)=0
virtual void DrawArrays(const GLenum mode, const GLint first, const GLsizei count)=0
Definition: non_copyable.h:45
Definition: bmpimage.h:46
virtual void LoadModelViewMatrixf(const GlsMatrixType &m)=0
IFontImage.
The gls_gl.