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) 2023 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 
24 
25 #include <osg/observer_ptr>
26 #include <osg/Node>
27 #include <osg/Light>
28 
29 #include <boost/thread.hpp>
30 #include <unordered_map>
31 #include <mutex>
32 
33 namespace osg
34 {
35  class Light;
36  class LightSource;
37  class State;
38  class StateSet;
39  class Matrixd;
40 }
41 
42 namespace makVrv
43 {
44  // Implements GLSL lighting
45  class DtOsgLightsObserver;
46  class DtLightManager;
47  class DtOsgSkyObject;
48  class DtThreadCameraStreamDataManager;
49 
50 
56  {
57  public:
58 
59  //constant bit masks for the light source sensor masks. Used in the compute shader to determine
60  // if a channel should apply a light source or not.
61  static const int theMwirLightSourceSensorMask = 0b0100;
62  static const int theLwirLightSourceSensorMask = 0b1000;
63  static const int theIrLightSourceSensorMask = theMwirLightSourceSensorMask | theLwirLightSourceSensorMask;
64  static const int theNvgLightSourceSensorMask = 0b0010;
65  static const int theVisualLightSourceSensorMask = 0b0001;
66  static const int theDefaultLightSourceSensorMask = theNvgLightSourceSensorMask | theVisualLightSourceSensorMask;
67 
68  public:
70  virtual ~DtOsgLightManager();
71 
72  protected:
75 
76  private:
78  DtOsgLightManager() = delete;
79 
81  DtOsgLightManager(const DtOsgLightManager& rhs) = delete;
82 
84  DtOsgLightManager& operator=(const DtOsgLightManager& rhs) = delete;
85 
86  public:
87 
89  virtual void initialize();
90 
93  virtual void attachToStateSet(osg::StateSet* stateSet);
94 
96  virtual void setPerPixelLightingEnabled(bool enabled);
97 
99  virtual bool perPixelLightingEnabled() const;
100 
102  virtual DtLightManager& lightManager();
103 
105  virtual void setReservedID(int id);
106 
108  virtual int reservedID() const;
109 
111  virtual bool registerLight(const osg::LightSource* light, const osg::NodePath& nodePath, const osg::Matrixd& modelingMatrix, bool globalLights
112  , const osg::Camera* osgCamera);
113 
114  // De-register light?
115  virtual void deregisterLight(const osg::LightSource* light);
116 
118  virtual void update(const osg::State& state, const osg::Camera* camera);
119 
121  virtual void releaseGLObjects(void);
122 
124  virtual unsigned int getOrCreateLightSourceTypeId(const osg::LightSource& lightSource);
125 
128  virtual unsigned int getOrCreateDynamicLightSourceTypeId(const DtLight* pDtLight);
129 
131  virtual void deleteDynamicLightSourceTypeId(const DtLight* pDtLight);
132 
135  virtual LightReusableVector lightSourceTypeLightVector() const;
136 
138  virtual void updateLightSourceType(unsigned int id, const DtLight* light);
139 
141  virtual const DtOsgLightingComponent* lightingComponent() const;
142 
144  virtual DtOsgLightingComponent* lightingComponent();
145 
146  public:
148  static DtOsgLightManager& instance(DtDe& de);
149 
151  static const std::string& theClassName();
152 
153  protected:
155  virtual bool computeLightStatusForTime(const DtLight* pDtLight, float ambientLightValue) const;
156 
161  virtual void updateShaderBasedLights(const osg::State& state, const osg::Camera* camera, DtOsgLightManagerTcsUserData* tcsUserData);
162 
163  virtual void computeFrustumLights(const osg::State &state, const osg::Camera* camera, DtOsgLightManagerTcsUserData* tcsUserData) const;
164 
166  virtual void computeActiveLights(DtOsgLightManagerTcsUserData* tcsUserData, const osg::Camera* camera) const;
167 
168  virtual void proccessLightPath(DtLight* inLight, const osg::NodePath& nodePath);
169 
170  virtual void configurePerPixelLighting(osg::StateSet*);
171 
172  virtual void slot_reloadShader();
173 
174  virtual bool existsInLightManager(const DtLight* light) const;
175 
177  virtual void convertOsgLightToDtLight(DtLight* pDtLight, const osg::LightSource& lightSource, const osg::Matrixd& modelingMatrix);
178 
180  virtual void getWorldPositionAndDirection(const osg::LightSource& lightSource, const osg::Matrixd& modelingMatrix, osg::Vec3d& vWorldPos, osg::Vec3d& vWorldDir) const;
181 
183  virtual unsigned int getOrCreateLightSourceTypeId(const DtLight* pDtLight);
184 
186  virtual unsigned int sensorMaskFromLightSource(const osg::LightSource& lightSource) const;
187 
189  virtual size_t getNodePathHashValue(const osg::NodePath& nodePath) const;
190 
192  virtual void printNodePath(const osg::NodePath& nodePath) const;
193 
195  virtual size_t computeHash(const DtLight* pDtLight) const;
196 
198  virtual LightType lightType(const osg::Light* light) const;
199 
200  virtual unsigned int getOrCreateLightSourceTypeId(const DtLight* pDtLight, size_t hash);
201 
203  virtual void slot_preTick(void);
204  protected:
205 
210 
212 
214 
215  osg::observer_ptr<osg::StateSet> myStateSet;
216 
218 
219  typedef std::pair<const osg::LightSource*, const makVrv::DtLight*> LightSourceAndLight;
220 
221  typedef std::unordered_map<size_t, LightSourceAndLight> MapLightSourceHashToLights;
223  std::unordered_set<const DtLight*> myLightsCreatedViaRegister;
224  mutable std::mutex myRegisterUnRegisterPathMutex;
225 
227 
228  typedef std::map<size_t, unsigned int> MapLightSourceTypeToLightID;
231 
232  //Mutable so it can protect const functions
233  mutable boost::mutex myMutableLightSourceTypeMutex;
234 
237 
239  };
240 }
DtLightManager * myLightManager
Definition: DtOsgLightManager.h:217
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:206
MapLightSourceHashToLights myMapLightSourceHashToLights
Definition: DtOsgLightManager.h:222
DtOsgLightsObserver * myOsgLightsObserver
Definition: DtOsgLightManager.h:226
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
DtSignalConnectionManager myConnections
Definition: DtOsgLightManager.h:238
Definition: featureContext.h:37
bool myPerPixelLightingEnabled
Definition: DtOsgLightManager.h:211
std::mutex myRegisterUnRegisterPathMutex
Definition: DtOsgLightManager.h:224
bool myInitialized
Definition: DtOsgLightManager.h:207
osg::observer_ptr< osg::StateSet > myStateSet
Definition: DtOsgLightManager.h:215
MapLightSourceTypeToLightID myLightSourceTypeMap
Definition: DtOsgLightManager.h:229
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:22
DtOsgLightManagerTcsUserDataCreator & myUserDataCreator
Definition: DtOsgLightManager.h:236
Light class.
LightType
Definition: DtLight.h:31
DtThreadCameraStreamDataManager & myTcsDataManager
Definition: DtOsgLightManager.h:235
DtOsgLightManager receives LightSource nodes from the DtOsgCullVisitor, and collects them all here wh...
Definition: DtOsgLightManager.h:55
Class to manage disconnection of boost connections on deletion.
Definition: DtSignalConnectionManager.h:20
int myReservedID
Definition: DtOsgLightManager.h:209
bool myDebugCallbackInitialized
Definition: DtOsgLightManager.h:208
boost::mutex myMutableLightSourceTypeMutex
Definition: DtOsgLightManager.h:233
LightReusableVector myLightSourceTypeLightVector
Definition: DtOsgLightManager.h:230
Base class to provide boost signal/slot management.
std::unordered_set< const DtLight * > myLightsCreatedViaRegister
Definition: DtOsgLightManager.h:223
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:221
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:72
std::map< size_t, unsigned int > MapLightSourceTypeToLightID
Definition: DtOsgLightManager.h:228
osg::ref_ptr< DtOsgLightingComponent > myLightingComponent
Definition: DtOsgLightManager.h:213
Contains the DtOsgLightManagerTcsUserData class.
std::pair< const osg::LightSource *, const makVrv::DtLight * > LightSourceAndLight
Definition: DtOsgLightManager.h:219
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 Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)