lightManager.h

Engine/source/lighting/lightManager.h

More...

Classes:

Public Defines

define
LIGHTMGR() ()

Returns the current active light manager.

Public Typedefs

LightManagerMap 

Detailed Description

Public Defines

LIGHTMGR() ()

Returns the current active light manager.

Public Typedefs

typedef Map< String, LightManager * > LightManagerMap 
  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _LIGHTMANAGER_H_
 25#define _LIGHTMANAGER_H_
 26
 27#ifndef _TORQUE_STRING_H_
 28#include "core/util/str.h"
 29#endif
 30#ifndef _TSIGNAL_H_
 31#include "core/util/tSignal.h"
 32#endif
 33#ifndef _LIGHTINFO_H_
 34#include "lighting/lightInfo.h"
 35#endif
 36#ifndef _LIGHTQUERY_H_
 37#include "lighting/lightQuery.h"
 38#endif
 39
 40class SimObject;
 41class LightManager;
 42class Material;
 43class ProcessedMaterial;
 44class SceneManager;
 45struct SceneData;
 46class Point3F;
 47class AvailableSLInterfaces;
 48class SceneObject;
 49class GFXShaderConstBuffer;
 50class GFXShaderConstHandle;
 51class ShaderConstHandles;
 52class SceneRenderState;
 53class RenderDeferredMgr;
 54class Frustum;
 55
 56///
 57typedef Map<String,LightManager*> LightManagerMap;
 58
 59
 60class LightManager
 61{
 62public:
 63
 64   enum SpecialLightTypesEnum
 65   {
 66      slSunLightType,
 67      slSpecialLightTypesCount
 68   };
 69
 70   LightManager( const char *name, const char *id );
 71
 72   virtual ~LightManager();
 73
 74   ///
 75   static void initLightFields();
 76
 77   /// 
 78   static LightInfo* createLightInfo(LightInfo* light = NULL);
 79
 80   ///
 81   static LightManager* findByName( const char *name );
 82
 83   /// Returns a tab seperated list of available light managers.
 84   static void getLightManagerNames( String *outString );
 85
 86   /// The light manager activation signal.
 87   static Signal<void(const char*,bool)> smActivateSignal;
 88
 89   /// Returns the active LM.
 90   static inline LightManager* getActiveLM() { return smActiveLM; }
 91
 92   /// Return an id string used to load different versions of light manager
 93   /// specific assets.  It shoud be short, contain no spaces, and be safe 
 94   /// for filename use.
 95   const char* getName() const { return mName.c_str(); }
 96
 97   /// Return an id string used to load different versions of light manager
 98   /// specific assets.  It shoud be short, contain no spaces, and be safe 
 99   /// for filename use.
100   const char* getId() const { return mId.c_str(); }
101
102   // Returns the scene manager passed at activation.
103   SceneManager* getSceneManager() { return mSceneManager; }
104
105   // Should return true if this light manager is compatible
106   // on the current platform and GFX device.
107   virtual bool isCompatible() const = 0;
108
109   // Called when the lighting manager should become active
110   virtual void activate( SceneManager *sceneManager );
111
112   // Called when we don't want the light manager active (should clean up)
113   virtual void deactivate();
114
115   // Returns the active scene lighting interface for this light manager.  
116   virtual AvailableSLInterfaces* getSceneLightingInterface();
117
118   // Returns a "default" light info that callers should not free.  Used for instances where we don't actually care about 
119   // the light (for example, setting default data for SceneData)
120   virtual LightInfo* getDefaultLight();
121
122   /// Returns the special light or the default light if useDefault is true.
123   /// @see getDefaultLight
124   virtual LightInfo* getSpecialLight( SpecialLightTypesEnum type, 
125                                       bool useDefault = true );
126
127   /// Set a special light type.
128   virtual void setSpecialLight( SpecialLightTypesEnum type, LightInfo *light );
129
130   // registered before scene traversal...
131   virtual void registerGlobalLight( LightInfo *light, SimObject *obj );
132   virtual void unregisterGlobalLight( LightInfo *light );
133
134   // registered per object...
135   virtual void registerLocalLight( LightInfo *light );
136   virtual void unregisterLocalLight( LightInfo *light );
137
138   virtual void registerGlobalLights( const Frustum *frustum, bool staticlighting, bool enableZoneLightCulling = false );
139   virtual void unregisterAllLights();
140
141   /// Returns all unsorted and un-scored lights (both global and local).
142   void getAllUnsortedLights( Vector<LightInfo*> *list ) const;
143
144   /// Sets shader constants / textures for light infos
145   virtual void setLightInfo( ProcessedMaterial *pmat, 
146                              const Material *mat, 
147                              const SceneData &sgData, 
148                              const SceneRenderState *state,
149                              U32 pass, 
150                              GFXShaderConstBuffer *shaderConsts ) = 0;
151
152   /// Allows us to set textures during the Material::setTextureStage call, return true if we've done work.
153   virtual bool setTextureStage( const SceneData &sgData, 
154                                 const U32 currTexFlag, 
155                                 const U32 textureSlot, 
156                                 GFXShaderConstBuffer *shaderConsts, 
157                                 ShaderConstHandles *handles ) = 0;
158
159   /// Called when the static scene lighting (aka lightmaps) should be computed.
160   virtual bool lightScene( const char* callback, const char* param );
161
162   /// Returns true if this light manager is active
163   virtual bool isActive() const { return mIsActive; }
164
165protected:
166
167   /// The current active light manager.
168   static LightManager *smActiveLM;
169
170   /// Find the pre-pass render bin on the scene's default render pass.
171   RenderDeferredMgr* _findDeferredRenderBin();
172
173   /// This helper function sets the shader constansts
174   /// for the stock 4 light forward lighting code.
175   static void _update4LightConsts( const SceneData &sgData,
176                                    GFXShaderConstHandle *lightPositionSC,
177                                    GFXShaderConstHandle *lightDiffuseSC,
178                                    GFXShaderConstHandle *lightAmbientSC,
179                                    GFXShaderConstHandle *lightInvRadiusSqSC,
180                                    GFXShaderConstHandle *lightSpotDirSC,
181                                    GFXShaderConstHandle * lightSpotParamsSC,
182                                    GFXShaderConstHandle* hasVectorLightSC,
183                                    GFXShaderConstHandle* vectorLightDirectionSC,
184                                    GFXShaderConstHandle* vectorLightColorSC,
185                                    GFXShaderConstHandle* vectorLightBrightnessSC,
186                                    GFXShaderConstBuffer *shaderConsts );
187
188   /// A dummy default light used when no lights
189   /// happen to be registered with the manager.
190   LightInfo *mDefaultLight;
191  
192   /// The list of global registered lights which is
193   /// initialized before the scene is rendered.
194   LightInfoList mRegisteredLights;
195
196   /// The registered special light list.
197   LightInfo *mSpecialLights[slSpecialLightTypesCount];
198
199   /// The root culling position used for
200   /// special sun light placement.
201   /// @see setSpecialLight
202   Point3F mCullPos;
203
204   /// The scene lighting interfaces for 
205   /// lightmap generation.
206   AvailableSLInterfaces *mAvailableSLInterfaces;
207
208   /// Attaches any LightInfoEx data for this manager 
209   /// to the light info object.
210   virtual void _addLightInfoEx( LightInfo *lightInfo ) = 0;
211
212   ///
213   virtual void _initLightFields() = 0;
214
215   /// Returns the static light manager map.
216   static LightManagerMap& _getLightManagers();
217  
218   /// The constant light manager name initialized
219   /// in the constructor.
220   const String mName;
221
222   /// The constant light manager identifier initialized
223   /// in the constructor.
224   const String mId;
225
226   /// Is true if this light manager has been activated.
227   bool mIsActive;
228
229   /// The scene graph the light manager is associated with.
230   SceneManager *mSceneManager;
231};
232
233/// Returns the current active light manager.
234#define LIGHTMGR LightManager::getActiveLM()
235
236#endif // _LIGHTMANAGER_H_
237