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 /*
55  * This singleton class is responsible for keeping track of the GlsLightSource objects
56  * currently affecting the OpenGL lighting state and changing the state
57  * when needed.
58  */
59 class GlobalLightMgr DISTI_FINAL
60 {
61 public:
62  /** List of the currently active lights
63  * The number of the light is equal to it's array index.
64  * (i.e. The light at index 0 is GL_LIGHT0) */
66 
67 protected:
68  /** helper class for maintaining one global light mgr per calling thread */
70 
71  static GLS_EXPORT unsigned int MAX_OPENGL_LIGHTS; /** The value of glGetIntegerv(GL_MAX_LIGHTS); */
72  LightingState _currentOpenGLState; /** The current OpenGL lighting state */
73  LightingState _currentState; /** This will become the _currentOpenglState when a lit object draws */
74  DynamicArray<GlsLightSource*> _tempOpenGLLights; /** Store temporary light source pointers (only used in InitializeStateFromOpenGL) */
75  DynamicArray<LightingState> _lightingStateStack; /** As each component draws it will push it's lighting state on the stack */
76 
78  bool _enableNormalize;
79  bool* _activeLights;
80 
81  GLS_EXPORT GlobalLightMgr();
82 
83 public:
84  GLS_EXPORT ~GlobalLightMgr();
85 
86  /** \return The singleton to the one instance of GlobalLightMgr*/
87  static GLS_EXPORT GlobalLightMgr& Instance();
88 
89  /** \return The value of GL_MAX_LIGHTS */
90  static unsigned int GlMaxLights() { return MAX_OPENGL_LIGHTS; }
91 
92  /** Push the current lighting state onto the stack */
93  GLS_EXPORT void PushLightingState();
94 
95  /** Push the current lighting state off the stack */
96  GLS_EXPORT void PopLightingState();
97 
98  /** Flags the need to reapply the lights. This may
99  * be necessary for special cases where the OpenGL matrices
100  * have changed during a traversel. This can
101  * happen when drawing multiple views of the same
102  * geometry.
103  */
104  void ReapplyLights() { _reapplyLights = true; }
105 
106  /** Set whether or not GL_NORMALIZE is enabled
107  * \param enableNormalize Set GL_NORMALIZE to true or false
108  */
109  static GLS_EXPORT void EnableNormalize( bool enableNormalize );
110 
111  /** Get the state of whether GL_NORMALIZE is enabled
112  * \return Whether or not GL_NORMALIZE is enabled
113  */
114  static GLS_EXPORT bool EnableNormalize();
115 
116  /** Set the current lighting state to a new state
117  * \param newState The new lighting state
118  */
119  GLS_EXPORT void SetLightingState( const LightingState& newState );
120 
121 #if defined( DISTI_HAS_RVAL_REFS )
122  /** Set the current lighting state to a new state
123  * \param newState The new lighting state
124  */
125  void SetLightingState( LightingState&& newState )
126  {
127  _currentState = std::move( newState );
128  }
129 #endif
130 
131  /** Get the current lighting state
132  * \return The current lighting state
133  */
134  GLS_EXPORT const LightingState& GetLightingState() const;
135 
136  /** Set OpenGL lighting state to match the current state.
137  * If relativeToEyepoint is set, the light will be applied
138  * using the modelview matrix calculated from the eyepoint to the light.
139  */
140  GLS_EXPORT void SetupLighting( GlsEyePoint* relativeToEyepoint = NULL /*(Top Level)*/ );
141 
142  /** Clear the lighting stack, create GlsLightSource objects based on the current
143  * OpenGL lighting state and store them as the current state.
144  */
145  GLS_EXPORT void InitializeStateFromOpenGL();
146 
147  /** Restore the OpenGL state to what it was at the last call to InitializeStateFromOpenGL() */
148  GLS_EXPORT void RestoreOpenGLState();
149 
150  /** Get a boolean mask of the active lights
151  * \return A boolean array with a bitmask of the currently active lights
152  */
153  GLS_EXPORT bool* GetActiveLightsMask();
154 
155  /** Get a bitmask of the active lights
156  * \return An unsigned integer with each bit representing a light turned on/off
157  */
158  GLS_EXPORT unsigned int GetActiveLightsBitMask();
159 
160  /** Get the number of active lights. Really is the max index(+1) of lights that
161  * you need to cycle through to have taken all of them into account (in case of
162  * holes in the list created by an outside party).
163  * \return An integer representing the (max) number of currently active lights
164  */
165  GLS_EXPORT unsigned int GetNumActiveLights();
166 };
167 
168 } // namespace disti
169 
170 #endif
friend class GlobalLightMgrThreadMap
Definition: global_light_mgr.h:69
void SetLightingState(LightingState &&newState)
Definition: global_light_mgr.h:125
unsigned int GetNumActiveLights()
void SetLightingState(const LightingState &newState)
The disti::DynamicArray class. A templated array of objects capable of dynamically growing...
const LightingState & GetLightingState() const
bool * GetActiveLightsMask()
void ReapplyLights()
Definition: global_light_mgr.h:104
A file for all GL Studio files to include.
bool _reapplyLights
Definition: global_light_mgr.h:77
DynamicArray< LightingState > _lightingStateStack
Definition: global_light_mgr.h:75
DynamicArray< GlsLightSource * > _tempOpenGLLights
Definition: global_light_mgr.h:74
void SetupLighting(GlsEyePoint *relativeToEyepoint=NULL)
LightingState _currentOpenGLState
Definition: global_light_mgr.h:72
Generally useful defines, macros, enumerations and function prototypes.
void InitializeStateFromOpenGL()
static GlobalLightMgr & Instance()
static unsigned int GlMaxLights()
Definition: global_light_mgr.h:90
Definition: gls_eyepoint.h:115
unsigned int GetActiveLightsBitMask()
Definition: global_light_mgr.h:59
DynamicArray< GlsLightSource * > LightingState
Definition: global_light_mgr.h:65
Macros and helper code to determine what subset of C++11/14/17 is available.
static bool EnableNormalize()
Definition: bmpimage.h:46
LightingState _currentState
Definition: global_light_mgr.h:73