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