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