| 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
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*/
40#ifndef INCLUDED_DISTI_GLOBAL_LIGHT_MGR_H
41#define INCLUDED_DISTI_GLOBAL_LIGHT_MGR_H
42
43#include "dynamic_array.h"
44#include "gls_cpp_lang_support.h"
45#include "gls_include.h"
46#include "util.h"
47
48 namespace disti
49{
50 class GlsLightSource;
51 class GlsEyePoint;
52 class 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.
56 class GlobalLightMgr DISTI_FINAL
57{
58 public:
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) */
62 typedef DynamicArray<GlsLightSource*> LightingState;
63
64 protected:
65 /** helper class for maintaining one global light mgr per calling thread */
66 friend class GlobalLightMgrThreadMap;
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
78 GLS_EXPORT GlobalLightMgr();
79
80 public:
81 GLS_EXPORT ~GlobalLightMgr();
82
83 /** \return The singleton to the one instance of GlobalLightMgr*/
84 static GLS_EXPORT GlobalLightMgr& Instance();
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 */
90 GLS_EXPORT void PushLightingState();
91
92 /** Push the current lighting state off the stack */
93 GLS_EXPORT void PopLightingState();
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 */
111 static GLS_EXPORT bool EnableNormalize();
112
113 /** Set the current lighting state to a new state
114 * \param newState The new lighting state
115 */
116 GLS_EXPORT void SetLightingState( const LightingState& newState );
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 */
122 void SetLightingState( LightingState&& newState )
123 {
124 _currentState = std::move( newState );
125 }
126#endif
127
128 /** Get the current lighting state
129 * \return The current lighting state
130 */
131 GLS_EXPORT const LightingState& GetLightingState() const;
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 */
142 GLS_EXPORT void InitializeStateFromOpenGL();
143
144 /** Restore the OpenGL state to what it was at the last call to InitializeStateFromOpenGL() */
145 GLS_EXPORT void RestoreOpenGLState();
146
147 /** Get a boolean mask of the active lights
148 * \return A boolean array with a bitmask of the currently active lights
149 */
150 GLS_EXPORT bool* GetActiveLightsMask();
151
152 /** Get a bitmask of the active lights
153 * \return An unsigned integer with each bit representing a light turned on/off
154 */
155 GLS_EXPORT unsigned int GetActiveLightsBitMask();
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 */
162 GLS_EXPORT unsigned int GetNumActiveLights();
163};
164
165} // namespace disti
166
167#endif
disti::DynamicArray< GlsLightSource * >
disti::GlobalLightMgr
Definition: global_light_mgr.h:57
disti::GlobalLightMgr::EnableNormalize
static bool EnableNormalize()
disti::GlobalLightMgr::_reapplyLights
bool _reapplyLights
If true, the lighting state will be recalculated.
Definition: global_light_mgr.h:74
disti::GlobalLightMgr::MAX_OPENGL_LIGHTS
static unsigned int MAX_OPENGL_LIGHTS
The value of glGetIntegerv(GL_MAX_LIGHTS);.
Definition: global_light_mgr.h:68
disti::GlobalLightMgr::SetLightingState
void SetLightingState(LightingState &&newState)
Definition: global_light_mgr.h:122
disti::GlobalLightMgr::LightingState
DynamicArray< GlsLightSource * > LightingState
Definition: global_light_mgr.h:62
disti::GlobalLightMgr::InitializeStateFromOpenGL
void InitializeStateFromOpenGL()
disti::GlobalLightMgr::_currentState
LightingState _currentState
This will become the _currentOpenglState when a lit object draws.
Definition: global_light_mgr.h:70
disti::GlobalLightMgr::GetLightingState
const LightingState & GetLightingState() const
disti::GlobalLightMgr::Instance
static GlobalLightMgr & Instance()
disti::GlobalLightMgr::_enableNormalize
bool _enableNormalize
If true, GL_NORMALIZE will be enabled during lighting.
Definition: global_light_mgr.h:75
disti::GlobalLightMgr::PushLightingState
void PushLightingState()
disti::GlobalLightMgr::_lightingStateStack
DynamicArray< LightingState > _lightingStateStack
As each component draws it will push it's lighting state on the stack.
Definition: global_light_mgr.h:72
disti::GlobalLightMgr::PopLightingState
void PopLightingState()
disti::GlobalLightMgr::GlMaxLights
static unsigned int GlMaxLights()
Definition: global_light_mgr.h:87
disti::GlobalLightMgr::GlobalLightMgrThreadMap
friend class GlobalLightMgrThreadMap
Definition: global_light_mgr.h:66
disti::GlobalLightMgr::GetActiveLightsMask
bool * GetActiveLightsMask()
disti::GlobalLightMgr::ReapplyLights
void ReapplyLights()
Definition: global_light_mgr.h:101
disti::GlobalLightMgr::GetNumActiveLights
unsigned int GetNumActiveLights()
disti::GlobalLightMgr::_activeLights
bool * _activeLights
An array storing the current on/off state for each light.
Definition: global_light_mgr.h:76
disti::GlobalLightMgr::_tempOpenGLLights
DynamicArray< GlsLightSource * > _tempOpenGLLights
Store temporary light source pointers (only used in InitializeStateFromOpenGL).
Definition: global_light_mgr.h:71
disti::GlobalLightMgr::SetupLighting
void SetupLighting(GlsEyePoint *relativeToEyepoint=NULL)
disti::GlobalLightMgr::_currentOpenGLState
LightingState _currentOpenGLState
The current OpenGL lighting state.
Definition: global_light_mgr.h:69
disti::GlobalLightMgr::RestoreOpenGLState
void RestoreOpenGLState()
disti::GlobalLightMgr::EnableNormalize
static void EnableNormalize(bool enableNormalize)
disti::GlobalLightMgr::GetActiveLightsBitMask
unsigned int GetActiveLightsBitMask()
disti::GlobalLightMgr::SetLightingState
void SetLightingState(const LightingState &newState)
disti::GlsEyePoint
Definition: gls_eyepoint.h:117
dynamic_array.h
The disti::DynamicArray class. A templated array of objects capable of dynamically growing.
gls_cpp_lang_support.h
Macros and helper code to determine what subset of C++11/14/17 is available.
DISTI_FINAL
#define DISTI_FINAL
Macro to wrap the final keyword, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:224
gls_include.h
A file for all GL Studio files to include.
GLS_EXPORT
#define GLS_EXPORT
Macro denoting which functions should be visible from the runtime library.
Definition: gls_include.h:52
disti
Definition: bmpimage.h:47
util.h
Generally useful defines, macros, enumerations and function prototypes.