VR-Forces 5.0.3 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtOsgLightManager.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2022 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
14 
16 
17 
18 #include <osg/observer_ptr>
19 #include <osg/Node>
20 #include <osg/Light>
21 
22 #include <matrix/vlVector.h>
23 
26 
27 #include <boost/thread.hpp>
28 #include <unordered_map>
29 
30 namespace osg
31 {
32  class Light;
33  class LightSource;
34  class State;
35  class StateSet;
36  class Matrixd;
37 }
38 
39 namespace makVrv
40 {
41  // Implements GLSL lighting
42  class DtOsgLightsObserver;
43  class DtLightManager;
44  class DtOsgSkyObject;
45 
46 
52  {
53  public:
54 
55  //constant bit masks for the light source sensor masks. Used in the compute shader to determine
56  // if a channel should apply a light source or not.
57  static const int theMwirLightSourceSensorMask = 0b0100;
58  static const int theLwirLightSourceSensorMask = 0b1000;
59  static const int theIrLightSourceSensorMask = theMwirLightSourceSensorMask | theLwirLightSourceSensorMask;
60  static const int theNvgLightSourceSensorMask = 0b0010;
61  static const int theVisualLightSourceSensorMask = 0b0001;
62  static const int theDefaultLightSourceSensorMask = theNvgLightSourceSensorMask | theVisualLightSourceSensorMask;
63 
64  public:
66  virtual ~DtOsgLightManager();
67 
68  protected:
71 
72  private:
74  DtOsgLightManager() = delete;
75 
77  DtOsgLightManager(const DtOsgLightManager& rhs) = delete;
78 
80  DtOsgLightManager& operator=(const DtOsgLightManager& rhs) = delete;
81 
82  public:
83 
85  virtual void initialize();
86 
89  virtual void attachToStateSet(osg::StateSet* stateSet);
90 
92  virtual void setPerPixelLightingEnabled(bool enabled);
93 
95  virtual bool perPixelLightingEnabled() const;
96 
98  virtual DtLightManager& lightManager();
99 
101  virtual void setReservedID(int id);
102 
104  virtual int reservedID() const;
105 
108  virtual void cullReset();
109 
111  virtual bool registerLight(const osg::LightSource* light, const osg::NodePath& nodePath, const osg::Matrixd& modelingMatrix, bool globalLights);
112 
115  virtual DtLight* createDtLight(const osg::Light* osgLight);
116 
118  virtual void convertOsgLightToDtLight(const osg::LightSource& lightSource, DtLight* pDtLight, const osg::Matrixd& modelingMatrix);
119 
121  virtual unsigned int sensorMaskFromLightSource(const osg::LightSource& lightSource) const;
122 
123  // PPP: TO DO. How to deregister ligths?
124  virtual void deregisterLight(const osg::LightSource* light);
125 
127  virtual void getWorldPositionAndDirection(const osg::LightSource& lightSource, const osg::Matrixd& modelingMatrix, osg::Vec3d& vWorldPos, osg::Vec3d& vWorldDir) const;
128 
130  virtual void update(osg::State& state, DtDe& de, const osg::Camera* camera);
131 
133  virtual int getTextureStartOffset(void) const;
134 
136  virtual const Vector2_uint32& tileSize(void) const;
137 
139  virtual const Vector2_uint32& gridMaxDims(void) const;
140 
142  virtual void releaseGLObjects(void);
143 
145  virtual unsigned int getOrCreateLightSourceTypeId(DtLight* pDtLight);
146 
148  virtual unsigned int getOrCreateLightSourceTypeId(const osg::LightSource& lightSource);
149 
152  virtual unsigned int getOrCreateDynamicLightSourceTypeId(const DtLight* pDtLight);
153 
155  virtual void deleteDynamicLightSourceTypeId(const DtLight* pDtLight);
156 
159  virtual LightReusableVector lightSourceTypeLightVector() const;
160 
162  virtual void updateLightSourceType(unsigned int id, const DtLight* light);
163 
165  virtual const DtOsgLightingComponent* lightingComponent() const;
166 
168  virtual DtOsgLightingComponent* lightingComponent();
169 
170  public:
172  static DtOsgLightManager& instance(DtDe& de);
173 
175  static const std::string& theClassName();
176 
178  static LightType lightType(const osg::Light* light);
179 
180  protected:
182  virtual void updateLightOnOffStatus(const VectorLights& lights);
183 
185  virtual bool computeLightStatusForTime(const DtLight* pDtLight, DtOsgSkyObject* skyObject);
186 
187  virtual void updateFixedFunctionLights(const osg::State& state);
188 
193  virtual void updateShaderBasedLights(const osg::State& state, const VectorLights& lights, const osg::Camera* camera);
194 
195  virtual const VectorLights& computeFrustumLights(const osg::State &state, const osg::Camera* camera);
196 
197  virtual void proccessLightPath(DtLight* inLight, const osg::NodePath& nodePath);
198 
199  virtual void configurePerPixelLighting(osg::StateSet*);
200 
201  virtual void slot_reloadShader();
202 
203  virtual bool existsInLightManager(const DtLight* light) const;
204 
205  protected:
206 
211 
213 
215 
216 
217  osg::observer_ptr<osg::StateSet> myStateSet;
218  VectorLights myActiveLights;
219 
221 
222  typedef std::pair<const osg::LightSource*, const makVrv::DtLight*> LightSourceAndLight;
223 
224  typedef std::unordered_map<size_t, LightSourceAndLight> MapLightSourceHashToLights;
226 
227  DtOsgLightsObserver* myOsgLightsObserver;
228 
229  typedef std::map<size_t, unsigned int> MapLightSourceTypeToLightID;
232 
233  //Mutable so it can protect const functions
234  mutable boost::mutex myMutableLightSourceTypeMutex;
235  };
236 }
DtLightManager * myLightManager
Definition: DtOsgLightManager.h:220
LightManager class which allows creation/deletion of lights.
Definition: DtLightManager.h:30
Virtual base class. Allows for RTTI and proper virtual destruction. Used by Creators, Factories, Providers, Assemblers and User Interfaces.
Definition: DtVirtualBaseClass.h:19
DtDe & myDe
Definition: DtOsgLightManager.h:207
MapLightSourceHashToLights myMapLightSourceHashToLights
Definition: DtOsgLightManager.h:225
DtOsgLightsObserver * myOsgLightsObserver
Definition: DtOsgLightManager.h:227
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
Definition: featureContext.h:37
bool myPerPixelLightingEnabled
Definition: DtOsgLightManager.h:212
An OSG implementation of the sky.
Definition: DtOsgSkyObject.h:28
bool myInitialized
Definition: DtOsgLightManager.h:208
osg::observer_ptr< osg::StateSet > myStateSet
Definition: DtOsgLightManager.h:217
MapLightSourceTypeToLightID myLightSourceTypeMap
Definition: DtOsgLightManager.h:230
Light class.
LightType
Definition: DtLight.h:30
VectorLights myActiveLights
Definition: DtOsgLightManager.h:218
DtOsgLightManager receives LightSource nodes from the DtOsgCullVisitor, and collects them all here wh...
Definition: DtOsgLightManager.h:51
int myReservedID
Definition: DtOsgLightManager.h:210
bool myDebugCallbackInitialized
Definition: DtOsgLightManager.h:209
boost::mutex myMutableLightSourceTypeMutex
Definition: DtOsgLightManager.h:234
LightReusableVector myLightSourceTypeLightVector
Definition: DtOsgLightManager.h:231
Contains the DtOsgLightingComponent class.
Contains makVrv::DtReusableMemoryVector class.
Class for generic lights This holds per-light data such as range, attenuation factors, colors, etc.
Definition: DtLight.h:48
std::unordered_map< size_t, LightSourceAndLight > MapLightSourceHashToLights
Definition: DtOsgLightManager.h:224
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer, DtDeCommunicator, as well as a DtDisplay and other things.
Definition: DtDe.h:70
std::map< size_t, unsigned int > MapLightSourceTypeToLightID
Definition: DtOsgLightManager.h:229
Contains makVrv::DtOsgShaderManager class.
osg::ref_ptr< DtOsgLightingComponent > myLightingComponent
Definition: DtOsgLightManager.h:214
std::pair< const osg::LightSource *, const makVrv::DtLight * > LightSourceAndLight
Definition: DtOsgLightManager.h:222
State component that injects lighting shaders and uniforms into a state set. It also has a DtLightCom...
Definition: DtOsgLightingComponent.h:68

Document ID: Generated on Thu Jun 1 17:58:13 EDT 2023 from SVN revision 255404
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)