VR-Forces 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) 2026 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvOsg/vrvOsg.h>
15 
17 
19 
20 #include <matrix/vlVector.h>
21 
23 
24 #include <osg/observer_ptr>
25 #include <osg/Node>
26 #include <osg/Light>
27 
28 #include <boost/thread.hpp>
29 #include <unordered_map>
30 #include <mutex>
31 
32 namespace osg
33 {
34  class Light;
35  class LightSource;
36  class State;
37  class StateSet;
38  class Matrixd;
39 }
40 
41 namespace makVrv
42 {
43  // Implements GLSL lighting
44  class DtOsgLightsObserver;
45  class DtLightManager;
46  class DtOsgSkyObject;
47  class DtThreadCameraStreamDataManager;
48 
49 
55  {
56  public:
57 
58  //constant bit masks for the light source sensor masks. Used in the compute shader to determine
59  // if a channel should apply a light source or not.
60  static const int theMwirLightSourceSensorMask = 0b0100;
61  static const int theLwirLightSourceSensorMask = 0b1000;
62  static const int theIrLightSourceSensorMask = theMwirLightSourceSensorMask | theLwirLightSourceSensorMask;
63  static const int theNvgLightSourceSensorMask = 0b0010;
64  static const int theVisualLightSourceSensorMask = 0b0001;
65  static const int theDefaultLightSourceSensorMask = theNvgLightSourceSensorMask | theVisualLightSourceSensorMask;
66 
67  public:
69  virtual ~DtOsgLightManager();
70 
71  protected:
74 
75  private:
77  DtOsgLightManager() = delete;
78 
80  DtOsgLightManager(const DtOsgLightManager& rhs) = delete;
81 
83  DtOsgLightManager& operator=(const DtOsgLightManager& rhs) = delete;
84 
85  public:
86 
88  virtual void initialize();
89 
92  virtual void attachToStateSet(osg::StateSet* stateSet);
93 
95  virtual bool isAttachedToStateSet(osg::StateSet* stateSet) const;
96 
98  virtual void setPerPixelLightingEnabled(bool enabled);
99 
101  virtual bool perPixelLightingEnabled() const;
102 
104  virtual DtLightManager& lightManager();
105 
107  virtual void setReservedID(int id);
108 
110  virtual int reservedID() const;
111 
113  virtual bool registerLight(const osg::LightSource* light, const osg::NodePath& nodePath, const osg::Matrixd& modelingMatrix, bool globalLights
114  , const osg::Camera* osgCamera);
115 
116  // De-register light?
117  virtual void deregisterLight(const osg::LightSource* light);
118 
120  virtual void update(const osg::State& state, const osg::Camera* camera);
121 
123  virtual void releaseGLObjects(void);
124 
126  virtual unsigned int getOrCreateLightSourceTypeId(const osg::LightSource& lightSource);
127 
130  virtual unsigned int getOrCreateDynamicLightSourceTypeId(const DtLight* pDtLight);
131 
133  virtual void deleteDynamicLightSourceTypeId(const DtLight* pDtLight);
134 
137  virtual LightReusableVector lightSourceTypeLightVector() const;
138 
140  virtual void updateLightSourceType(unsigned int id, const DtLight* light);
141 
143  virtual const DtOsgLightingComponent* lightingComponent() const;
144 
146  virtual DtOsgLightingComponent* lightingComponent();
147 
148  public:
150  static DtOsgLightManager& instance(DtDe& de);
151 
153  static const std::string& theClassName();
154 
155  protected:
157  virtual bool computeLightStatusForTime(const DtLight* pDtLight, float ambientLightValue) const;
158 
163  virtual void updateShaderBasedLights(const osg::State& state, const osg::Camera* camera, DtOsgLightManagerTcsUserData* tcsUserData);
164 
165  virtual void computeFrustumLights(const osg::State &state, const osg::Camera* camera, DtOsgLightManagerTcsUserData* tcsUserData) const;
166 
168  virtual void computeActiveLights(DtOsgLightManagerTcsUserData* tcsUserData, const osg::Camera* camera) const;
169 
170  virtual void proccessLightPath(DtLight* inLight, const osg::NodePath& nodePath);
171 
172  virtual void configurePerPixelLighting(osg::StateSet*);
173 
174  virtual void slot_reloadShader();
175 
176  virtual bool existsInLightManager(const DtLight* light) const;
177 
179  virtual void convertOsgLightToDtLight(DtLight* pDtLight, const osg::LightSource& lightSource, const osg::Matrixd& modelingMatrix);
180 
182  virtual void getWorldPositionAndDirection(const osg::LightSource& lightSource, const osg::Matrixd& modelingMatrix, osg::Vec3d& vWorldPos, osg::Vec3d& vWorldDir) const;
183 
185  virtual unsigned int getOrCreateLightSourceTypeId(const DtLight* pDtLight);
186 
188  virtual unsigned int sensorMaskFromLightSource(const osg::LightSource& lightSource) const;
189 
191  virtual size_t getNodePathHashValue(const osg::NodePath& nodePath) const;
192 
194  virtual void printNodePath(const osg::NodePath& nodePath) const;
195 
197  virtual size_t computeHash(const DtLight* pDtLight) const;
198 
200  virtual LightType lightType(const osg::Light* light) const;
201 
202  virtual unsigned int getOrCreateLightSourceTypeId(const DtLight* pDtLight, size_t hash);
203 
205  virtual void slot_preTick(void);
206  protected:
207 
212 
214 
216 
217  osg::observer_ptr<osg::StateSet> myStateSet;
218 
220 
221  typedef std::pair<const osg::LightSource*, const makVrv::DtLight*> LightSourceAndLight;
222 
223  typedef std::unordered_map<size_t, LightSourceAndLight> MapLightSourceHashToLights;
225  std::unordered_set<const DtLight*> myLightsCreatedViaRegister;
226  mutable std::mutex myRegisterUnRegisterPathMutex;
227 
229 
230  typedef std::map<size_t, unsigned int> MapLightSourceTypeToLightID;
233 
234  //Mutable so it can protect const functions
235  mutable boost::mutex myMutableLightSourceTypeMutex;
236 
239 
241  };
242 }
DtLightManager * myLightManager
Definition: DtOsgLightManager.h:219
Manager for DtThreadCameraStreamData Holds them as cameras come in. Deletes them as cameras go out (v...
Definition: DtThreadCameraStreamDataManager.h:86
LightManager class which allows creation/deletion of lights.
Definition: DtLightManager.h:32
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:208
MapLightSourceHashToLights myMapLightSourceHashToLights
Definition: DtOsgLightManager.h:224
DtOsgLightsObserver * myOsgLightsObserver
Definition: DtOsgLightManager.h:228
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
DtSignalConnectionManager myConnections
Definition: DtOsgLightManager.h:240
Definition: featureContext.h:36
bool myPerPixelLightingEnabled
Definition: DtOsgLightManager.h:213
std::mutex myRegisterUnRegisterPathMutex
Definition: DtOsgLightManager.h:226
bool myInitialized
Definition: DtOsgLightManager.h:209
osg::observer_ptr< osg::StateSet > myStateSet
Definition: DtOsgLightManager.h:217
MapLightSourceTypeToLightID myLightSourceTypeMap
Definition: DtOsgLightManager.h:231
This class represents the per context, per camera data and operations on it via the DtOsgLightManager...
Definition: DtOsgLightManagerTcsUserData.h:26
Variadic templated creator class for defining a DtVirtualBaseClass creator that is automatically regi...
Definition: DtVirtualBaseClassCreator.h:23
DtOsgLightManagerTcsUserDataCreator & myUserDataCreator
Definition: DtOsgLightManager.h:238
Light class.
LightType
Definition: DtLight.h:31
DtThreadCameraStreamDataManager & myTcsDataManager
Definition: DtOsgLightManager.h:237
DtOsgLightManager receives LightSource nodes from the DtOsgCullVisitor, and collects them all here wh...
Definition: DtOsgLightManager.h:54
Class to manage disconnection of boost connections on deletion.
Definition: DtSignalConnectionManager.h:20
int myReservedID
Definition: DtOsgLightManager.h:211
bool myDebugCallbackInitialized
Definition: DtOsgLightManager.h:210
boost::mutex myMutableLightSourceTypeMutex
Definition: DtOsgLightManager.h:235
LightReusableVector myLightSourceTypeLightVector
Definition: DtOsgLightManager.h:232
Base class to provide boost signal/slot management.
std::unordered_set< const DtLight * > myLightsCreatedViaRegister
Definition: DtOsgLightManager.h:225
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:49
std::unordered_map< size_t, LightSourceAndLight > MapLightSourceHashToLights
Definition: DtOsgLightManager.h:223
Contains DLL export macros.
Definition: DtOsgLightsObserver.h:24
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:76
std::map< size_t, unsigned int > MapLightSourceTypeToLightID
Definition: DtOsgLightManager.h:230
osg::ref_ptr< DtOsgLightingComponent > myLightingComponent
Definition: DtOsgLightManager.h:215
Contains the DtOsgLightManagerTcsUserData class.
std::pair< const osg::LightSource *, const makVrv::DtLight * > LightSourceAndLight
Definition: DtOsgLightManager.h:221
State component that injects lighting shaders and uniforms into a state set. It also has a DtLightCom...
Definition: DtOsgLightingComponent.h:57

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)