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