GL Studio C++ Runtime API
global_light_mgr.h
Go to the documentation of this file.
1/// \file global_light_mgr.h
2/// \brief The disti::GlobalLightMgr.
3///
4/// \par Copyright Information
5///
6/// Copyright (c) 2017 by The DiSTI Corporation.<br>
7/// 12249 Science Drive; Suite 300<br>
8/// Orlando, Florida 32826<br>
9/// USA<br>
10/// <br>
11/// All rights reserved.<br>
12///
13/// This Software contains proprietary trade secrets of DiSTI and may not be
14/// reproduced, in whole or part, in any form, or by any means of electronic,
15/// mechanical, or otherwise, without the written permission of DiSTI. Said
16/// permission may be derived through the purchase of applicable DiSTI product
17/// licenses which detail the distribution rights of this content and any
18/// Derivative Works based on this or other copyrighted DiSTI Software.
19///
20/// NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21/// AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22/// PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23/// AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24/// IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25/// PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26///
27/// LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28/// IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29/// INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30/// DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31/// INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32/// INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33/// OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34/// EXCEED FIVE DOLLARS (US$5.00).
35///
36/// The aforementioned terms and restrictions are governed by the laws of the
37/// State of Florida and the United States of America.
38
39#ifndef INCLUDED_DISTI_GLOBAL_LIGHT_MGR_H
40#define INCLUDED_DISTI_GLOBAL_LIGHT_MGR_H
41
42#include "dynamic_array.h"
44#include "gls_include.h"
45#include "util.h"
46
47namespace disti
48{
49class GlsLightSource;
50class GlsEyePoint;
51class GlobalLightMgrThreadMap;
52
53/// \details This singleton class is responsible for keeping track of the GlsLightSource objects
54/// currently affecting the OpenGL lighting state and changing the state when needed.
56{
57public:
58 /** List of the currently active lights
59 * The number of the light is equal to it's array index.
60 * (i.e. The light at index 0 is GL_LIGHT0) */
62
63protected:
64 /** helper class for maintaining one global light mgr per calling thread */
66
67 static GLS_EXPORT unsigned int MAX_OPENGL_LIGHTS; ///< The value of glGetIntegerv(GL_MAX_LIGHTS);
68 LightingState _currentOpenGLState; ///< The current OpenGL lighting state.
69 LightingState _currentState; ///< This will become the _currentOpenglState when a lit object draws.
70 DynamicArray<GlsLightSource*> _tempOpenGLLights; ///< Store temporary light source pointers (only used in InitializeStateFromOpenGL).
71 DynamicArray<LightingState> _lightingStateStack; ///< As each component draws it will push it's lighting state on the stack.
72
73 bool _reapplyLights; ///< If true, the lighting state will be recalculated.
74 bool _enableNormalize; ///< If true, GL_NORMALIZE will be enabled during lighting.
75 bool* _activeLights; ///< An array storing the current on/off state for each light.
76
78
79public:
81
82 /** \return The singleton to the one instance of GlobalLightMgr*/
84
85 /** \return The value of GL_MAX_LIGHTS */
86 static unsigned int GlMaxLights() { return MAX_OPENGL_LIGHTS; }
87
88 /** Push the current lighting state onto the stack */
90
91 /** Push the current lighting state off the stack */
93
94 /** Flags the need to reapply the lights. This may
95 * be necessary for special cases where the OpenGL matrices
96 * have changed during a traversel. This can
97 * happen when drawing multiple views of the same
98 * geometry.
99 */
100 void ReapplyLights() { _reapplyLights = true; }
101
102 /** Set whether or not GL_NORMALIZE is enabled
103 * \param enableNormalize Set GL_NORMALIZE to true or false
104 */
105 static GLS_EXPORT void EnableNormalize( bool enableNormalize );
106
107 /** Get the state of whether GL_NORMALIZE is enabled
108 * \return Whether or not GL_NORMALIZE is enabled
109 */
111
112 /** Set the current lighting state to a new state
113 * \param newState The new lighting state
114 */
116
117#if defined( DISTI_HAS_RVAL_REFS )
118 /** Set the current lighting state to a new state
119 * \param newState The new lighting state
120 */
122 {
123 _currentState = std::move( newState );
124 }
125#endif
126
127 /** Get the current lighting state
128 * \return The current lighting state
129 */
131
132 /// Set OpenGL lighting state to match the current state.
133 /// If relativeToEyepoint is set, the light will be applied
134 /// using the modelview matrix calculated from the eyepoint to the light.
135 /// \param relativeToEyepoint Optional eyepoint used to calculate modelview matrix to apply with the light.
136 GLS_EXPORT void SetupLighting( GlsEyePoint* relativeToEyepoint = NULL /*(Top Level)*/ );
137
138 /** Clear the lighting stack, create GlsLightSource objects based on the current
139 * OpenGL lighting state and store them as the current state.
140 */
142
143 /** Restore the OpenGL state to what it was at the last call to InitializeStateFromOpenGL() */
145
146 /** Get a boolean mask of the active lights
147 * \return A boolean array with a bitmask of the currently active lights
148 */
150
151 /** Get a bitmask of the active lights
152 * \return An unsigned integer with each bit representing a light turned on/off
153 */
155
156 /** Get the number of active lights. Really is the max index(+1) of lights that
157 * you need to cycle through to have taken all of them into account (in case of
158 * holes in the list created by an outside party).
159 * \return An integer representing the (max) number of currently active lights
160 */
162};
163
164} // namespace disti
165
166#endif
Definition: global_light_mgr.h:56
static bool EnableNormalize()
bool _reapplyLights
If true, the lighting state will be recalculated.
Definition: global_light_mgr.h:73
static unsigned int MAX_OPENGL_LIGHTS
The value of glGetIntegerv(GL_MAX_LIGHTS);.
Definition: global_light_mgr.h:67
void SetLightingState(LightingState &&newState)
Definition: global_light_mgr.h:121
DynamicArray< GlsLightSource * > LightingState
Definition: global_light_mgr.h:61
void InitializeStateFromOpenGL()
LightingState _currentState
This will become the _currentOpenglState when a lit object draws.
Definition: global_light_mgr.h:69
const LightingState & GetLightingState() const
static GlobalLightMgr & Instance()
bool _enableNormalize
If true, GL_NORMALIZE will be enabled during lighting.
Definition: global_light_mgr.h:74
DynamicArray< LightingState > _lightingStateStack
As each component draws it will push it's lighting state on the stack.
Definition: global_light_mgr.h:71
static unsigned int GlMaxLights()
Definition: global_light_mgr.h:86
friend class GlobalLightMgrThreadMap
Definition: global_light_mgr.h:65
bool * GetActiveLightsMask()
void ReapplyLights()
Definition: global_light_mgr.h:100
unsigned int GetNumActiveLights()
bool * _activeLights
An array storing the current on/off state for each light.
Definition: global_light_mgr.h:75
DynamicArray< GlsLightSource * > _tempOpenGLLights
Store temporary light source pointers (only used in InitializeStateFromOpenGL).
Definition: global_light_mgr.h:70
void SetupLighting(GlsEyePoint *relativeToEyepoint=NULL)
LightingState _currentOpenGLState
The current OpenGL lighting state.
Definition: global_light_mgr.h:68
static void EnableNormalize(bool enableNormalize)
unsigned int GetActiveLightsBitMask()
void SetLightingState(const LightingState &newState)
Definition: gls_eyepoint.h:116
The disti::DynamicArray class. A templated array of objects capable of dynamically growing.
Macros and helper code to determine what subset of C++11/14/17 is available.
#define DISTI_FINAL
Macro to wrap the final keyword, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:223
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:50
Definition: bmpimage.h:46
Generally useful defines, macros, enumerations and function prototypes.