VR-Forces 5.0.2 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtIndirectGeometry.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2022 VT-MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvOsg/vrvOsg.h>
13 
20 
26 
28 
31 
32 #include <matrix/vlTaitBryan.h>
33 
34 #include <osg/Drawable>
35 #include <osg/Uniform>
36 #include <osg/StateSet>
37 #include <osg/OperationThread>
38 #include <osgSim/MultiSwitch>
39 
40 #include <tbb/concurrent_queue.h>
41 
42 #include <atomic>
43 #include <string>
44 #include <unordered_map>
45 #include <unordered_set>
46 #include <tuple>
47 
48 namespace osg
49 {
50  class NodeVisitor;
51  class State;
52 }
53 
54 namespace osgEarth {
55  class VirtualProgram;
56 };
57 
58 namespace makVrv
59 {
60  class DtIndirectGeometryRegistrar;
61  class DtCullShaderConfig;
62  class DtGpuCulling;
63  class DtGlBuffer;
64  class DtOsgCullVisitorParameters;
65 
66  class DtIndirectGeometryInitMainThreadJob;
67  class DtIndirectGeometryUpdateBuffersMainThreadJob;
68  class DtVirtualProgramCache;
69 
70  class DtIndirectDrawComponent;
71  class DtIndirectDefaultDrawComponent;
72  class DtIndirectLightPointDrawComponent;
73  class DtIndirectDebugCullComponent;
74 
75  class DtIndirectSwitchManager;
76  class DtIndirectDofManager;
77  class DtIndirectLodManager;
78  class DtIndirectUvOffsetManager;
79  class DtIndirectPerInstanceDataManager;
80  class DtIndirectShaderConstants;
81  class DtOsgLightPointManager;
82 
83  class DtIndirectVaoManager;
84 
85  class DtCoordinateSystem;
86 
89 
92 
94  template <>
95  inline const char* creatorTypeName<DtIndirectGeometry>(void) { return "DtIndirectGeometryCreator"; }
96 
115  class DT_DLL_VRVOSG DtIndirectGeometry : public osg::Drawable
116  {
117  public:
119 
120  protected:
124  DtIndirectGeometry(DtDe& de, const DtCullShaderConfig& cullShaderConfig, bool terrainPatch, bool managesIndividualInstances);
125 
127  virtual ~DtIndirectGeometry();
128 
129  private:
131  DtIndirectGeometry() = delete;
132 
134  DtIndirectGeometry(const DtIndirectGeometry& other) = delete;
136  DtIndirectGeometry& operator=(const DtIndirectGeometry& other) = delete;
137 
138  public:
139 
141  virtual void setName(const std::string& name) override;
142 
150  virtual void setRegistrar(DtIndirectGeometryRegistrar* registrar);
151 
153  virtual DtIndirectGeometryRegistrar* registrar();
154 
156  virtual const char* className() const;
157 
161  virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
162 
164  virtual unsigned int rebuildRegistrar(osg::RenderInfo& renderInfo) const;
165 
171  virtual int addInstance(const DtIndirectGeometryInstance& instance);
172 
178  virtual int addInstance(int modelId, const osg::Matrixd& xForm, float modelScale, float modelRadius, int lightPointGroupId);
179 
183  virtual void accept(osg::NodeVisitor& nv);
184 
186  virtual void setParent(const osg::Group* parent);
187 
193  virtual void setRegistrarInvalid(void);
194 
196  virtual void releaseGLObjects(osg::State* state) const;
197 
199  virtual void accept(osg::PrimitiveFunctor& functor) const;
200 
204  virtual void setupIndirect();
205 
208  virtual void setupIndirectShadersOnly();
209 
212  virtual const osg::Geode* parentGeode(void) const;
213  virtual osg::Geode* parentGeode(void);
215 
219  virtual void setLocalOriginTransform(const osg::Matrixd& localOriginTransform);
220 
224  virtual const osg::Matrixd& localOriginTransform() const;
225 
227  virtual bool actuallyAddQueuedUpInstances(void);
228 
230  virtual void launchMainThreadJobAndWait(DtDe& de, DtOsgRenderer& renderer);
231 
233  virtual boost::condition_variable& waitCondition();
234 
236  virtual void updateGpuBuffers(osg::RenderInfo& renderInfo);
237 
238 
240  virtual void setFadeParameters(const DtIndirectFadeParameters& fadeParameters);
241 
243  virtual const DtIndirectFadeParameters& fadeParameters(void) const;
244 
246  virtual void perCameraUpdateAndCull(osg::RenderInfo& renderInfo, const osg::Camera* camera, const osg::Matrix& modelViewMatrix, const osg::FrameStamp* frameStamp);
247 
249  virtual void fillViewParameters(DtIndirectViewParameters& destViewParameters, const osg::Matrix& modelViewMatrix, const osg::Camera* camera, osg::RenderInfo& renderInfo) const;
250 
254  virtual void fillAltitude3d(DtIndirectViewParameters& destViewParameters, const Vector3_64& eye) const;
255 
257  virtual void setUpdateBuffersJobsRequiredCurrentFrame(bool requiredCurrentFrame);
264  virtual bool updateBuffersJobsRequiredCurrentFrame(void) const;
266 
268  virtual bool readyToRender(const int instanceIdInIndirect) const;
269 
270 
274  virtual bool instanceEverAdded(void) const;
275 
278  virtual int numValidInstances(void) const;
279 
280  public:
282  static void setTrackObjects(bool val);
284  static bool trackObjects(void);
286 
288  static int numIndirectGeometries(void);
289  protected:
290 
293  virtual bool addInstanceActual(const DtIndirectGeometryInstance& instance);
294 
298  virtual void setupShadersIfNecessary();
299 
302  virtual void setupDebugUniforms();
303 
306  virtual void installDefaultMaterial(osg::StateSet* ss);
307 
309  virtual void slot_reloadShaders();
310 
314  virtual void updateIndicesCount(const DtIndirectModelInfo& modelInfo, int instanceContainerIndex);
315 
317  virtual void updateModelIdsToInstances(int modelId, int instanceId, bool add);
318 
320  virtual void drawFromCommandBuffer(osg::RenderInfo& renderInfo, const DtIndirectViewParameters& viewParameters, const osg::Camera* camera) const;
321 
325 
327  virtual void updateInstancePositionOrientationAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
328 
330  virtual void updateInstanceSwitchesAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
331 
333  virtual void updateInstanceSequencesAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
334 
336  virtual void updateInstanceUvOffsetsAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
337 
339  virtual void updateInstanceColorAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
340 
342  virtual void updateInstanceOtherData0AddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
343 
345  virtual void updateInstanceVisibilityLightPointMaxDistanceActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
346 
348  virtual bool updateInstanceDeletionBeforeAddedActual(const DtIndirectGeometryInstance& instance);
349 
351  virtual void updateInstancesDofsAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
352 
355  virtual void reloadShadersIfNecessary(void) const;
356 
360  virtual void update(const osg::FrameStamp* frameStamp);
361 
363  virtual void adjustDofConstraintsIfNecessary(osgSim::DOFTransform* clone);
364 
366  virtual DtIndirectDrawComponent* drawComponent(int stateId) const;
367 
370  virtual bool hasLightPoints(void) const;
371 
373  virtual bool hasDepthOnly(void) const;
374 
376  virtual bool isDepthOnly(int stateId) const;
377 
378  // do debug drawing of bounding boxes of all geometries within each instance
379  virtual void debugDrawIfNecessary(osg::RenderInfo& renderInfo, const int maxCommands, const osg::Camera* camera);
380 
382  virtual void deleteDrawComponents(void);
383 
385  virtual void initDrawComponents(void);
386 
388  virtual const DtOsgCullVisitorParameters* findCullVisitorParameters(osg::RenderInfo& renderInfo) const;
389 
393  virtual void setPureSignalBasedUpdates(bool val);
394 
396  virtual void initializeUbosIfNecessary(osg::RenderInfo& renderInfo) const;
397 
399  virtual void slot_coordinateSystemChanged();
400 
401 
402  protected:
405 
407  tbb::concurrent_queue<DtIndirectGeometryInstance> myQueueInstancesToAdd;
408 
410 
412 
414 
415  const bool myIsTerrainPatch;
416 
418 
424  unsigned int myNumTextCoordArrays;
425 
427 
429 
434 
438 
441 
443  int myId;
444 
447 
453 
455  mutable unsigned int myMutableLastFrameTexturesUpdated;
456 
457  mutable bool myMutableShadersSetup;
458 
461 
464  typedef std::unordered_map<int, int> MapIndirectIdToInstanceContainerId;
466 
467  unsigned int myLastFrameUpdated;
468  const osg::Camera* myLastCamera;
469 
470  boost::condition_variable myWaitCondition;
471  boost::mutex myWaitMutex;
472 
475 
476  boost::mutex myInternalsMutex;
477 
481 
483 
484  // PPP: Is this large enough?
485  std::atomic<int> myRunningInstanceId;
486 
490 
491  // state set (bin) for the default components
493 
494  // state set (bin) for the light point components
496 
497  // state set (bin) for depth only components
499 
502 
504 
509 
510  DtGlBuffer* myGpuShaderUbo = nullptr;
511  mutable int myGpuShaderUboBinding = -1;
512  DtIndirectShaderConstants* myShaderConstants = nullptr;
513 
515 
517 
520  DtCoordinateSystem* myCoordinateSystem = nullptr;
521 
522 
523  protected:
524  static bool theTrackObjects;
525 
528  {
529  public:
531  TotalCounter();
533  virtual ~TotalCounter();
534  public:
535  std::atomic<int> myCount;
536  };
538  };
539 }
unsigned int myNumTextCoordArrays
Definition: DtIndirectGeometry.h:424
boost::condition_variable myWaitCondition
Definition: DtIndirectGeometry.h:470
Contains the DtCullShaderConfig class declaration.
MapIntToInt myInstancesToModelIds
Definition: DtIndirectGeometry.h:413
DtIndirectFadeParameters myFadeParameters
Definition: DtIndirectGeometry.h:482
The DtOsgRenderer is the component responsible for rendering 3D images onto the screen via OpenSceneG...
Definition: DtOsgRenderer.h:87
non virtual container class for holding the information needed to create an indirect geometry instanc...
Definition: DtIndirectGeometryInstance.h:26
int myId
a unique id for the geometry
Definition: DtIndirectGeometry.h:443
osg::ref_ptr< osg::StateSet > myDepthOnlyDrawStateSet
Definition: DtIndirectGeometry.h:498
structure to count total number of DtIndirectGeometrys in the system
Definition: DtIndirectGeometry.h:527
static TotalCounter theTotalCounter
Definition: DtIndirectGeometry.h:537
std::unordered_map< int, int > MapIndirectIdToInstanceContainerId
Map of instances&#39; id in indirect geometry to their id in the instance container.
Definition: DtIndirectGeometry.h:464
DtIndirectPerInstanceDataManager * myPerInstanceDataManager
Definition: DtIndirectGeometry.h:452
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
handles the switches for all the indirect geometry. Sets up the default state of osg::Switch, osgSim::MultiSwitch, and DtDynamicTerrainSwitchNode. Connects to a signal for the DtDynamicTerrainSwitchNode so it can update the indirect buffer when a switch changes. saves off the node path hash for every switch path that is added. Owned by a DtIndirectGeometry 1:1 This manager&#39;s switches get updated per frame via looking at the actual switches/multi-switches
Definition: DtIndirectSwitchManager.h:70
Definition: DtIndirectDebugCullComponent.h:45
DtIndirectLodManager * myLodManager
Definition: DtIndirectGeometry.h:450
This class is a component of the DtIndirectGeometry It inputs are: -&gt; the instances registered with Dt...
Definition: DtGpuCulling.h:82
bool myLastMissingTextureColorOn
Definition: DtIndirectGeometry.h:437
unsigned int myMutableLastRegistrarRebuildNumber
Definition: DtIndirectGeometry.h:454
Indirect geometry can have multiple models and their corresponding ids registered in it...
Definition: DtIndirectGeometryRegistrar.h:106
DtIndirectLightPointDrawComponent * myLightPointDrawComponent
Definition: DtIndirectGeometry.h:488
std::atomic< int > myRunningInstanceId
Definition: DtIndirectGeometry.h:485
osg::Matrixd myLocalOriginTransformMatrix
Definition: DtIndirectGeometry.h:428
DtOsgLightPointManager & myLightPointManager
Definition: DtIndirectGeometry.h:514
Contains makVrv::DtIndirectModelScalingAlgorithm enumeration.
Contains the DtIndirectGeometryUpdateBuffersMainThreadJob class declaration.
bool myUpdateBuffersJobsRequiredCurrentFrame
whether gpu buffers for instances are updated immediately
Definition: DtIndirectGeometry.h:501
std::atomic< int > myCount
Definition: DtIndirectGeometry.h:535
shader configuration storage class. Has 3 available options which are described in the constructor&#39;s ...
Definition: DtCullShaderConfig.h:21
DtOsgLightPointManager registers LightPoint nodes so their TBO can be created and updated in a single...
Definition: DtOsgLightPointManager.h:106
Contains the DtIndirectGeometryUpdateMainThreadJob class declaration.
std::map< int, int > MapIntToInt
Definition: DtCommonTypes.h:25
osg::ref_ptr< DtIndirectGeometryUpdateBuffersMainThreadJob > myMainThreadUpdateBuffersJob
Definition: DtIndirectGeometry.h:479
handles the lods for all the indirect geometry. sets up and runs a compute shader prepass for process...
Definition: DtIndirectLodManager.h:53
osg::ref_ptr< DtIndirectGeometryRegistrar > myRegistrar
pointer to the (external) registrar
Definition: DtIndirectGeometry.h:404
3 dimensional vector
unsigned int myLastFrameUpdateTraversed
Definition: DtIndirectGeometry.h:503
DtSignalConnectionManager myConnections
Definition: DtIndirectGeometry.h:426
osg::ref_ptr< osg::StateSet > myLightPointDrawStateSet
Definition: DtIndirectGeometry.h:495
DtDe & myDe
Definition: DtIndirectGeometry.h:516
osg::ref_ptr< DtIndirectGeometryInitMainThreadJob > myMainThreadInitJob
Definition: DtIndirectGeometry.h:478
bool myMutableOutputInstancesBuffersChanged
Internal variable that tracks whether the output instance buffers via the culling got changed (resize...
Definition: DtIndirectGeometry.h:508
const char * creatorTypeName< DtIndirectGeometry >(void)
template specialization for the creator (pass the class being created to the creatorTypeName template...
Definition: DtIndirectGeometry.h:95
Variadic templated creator class for defining a DtVirtualBaseClass creator that is automatically regi...
Definition: DtVirtualBaseClassCreator.h:22
DtIndirectGeometryInstance, which holds information for creating an indirect geometry instance...
DtGpuCulling * myGpuCulling
Definition: DtIndirectGeometry.h:409
static bool theTrackObjects
Definition: DtIndirectGeometry.h:524
friend DtIndirectGeometryCreator
Definition: DtIndirectGeometry.h:118
DtIndirectDebugCullComponent * myIndirectDebugCullComponent
Definition: DtIndirectGeometry.h:489
\ ::, which allows us to hook into our indirect engine to render using indirect rendering...
Definition: DtIndirectGeometry.h:115
MapIntToInt myModelIDsToInstances
Definition: DtIndirectGeometry.h:411
const osg::Camera * myLastCamera
Definition: DtIndirectGeometry.h:468
Contains the DtIndirectGeometryInitMainThreadJob class declaration.
unsigned int myLastFrameUpdated
Definition: DtIndirectGeometry.h:467
MapIndirectIdToInstanceContainerId myMapIndirectIdToInstanceContainerId
Definition: DtIndirectGeometry.h:465
handles the dof nodes for all the indirect geometry. Sets up the default state of osg::Dof...
Definition: DtIndirectDofManager.h:64
DtIndirectVaoManager & myVaoManager
This is de-referenced here for speed.
Definition: DtIndirectGeometry.h:440
Class to manage disconnection of boost connections on deletion.
Definition: DtSignalConnectionManager.h:20
The osg cull vistor parameters class provides additional culling and intersector parameters for choos...
Definition: DtOsgCullVisitorParameters.h:42
bool myLastDebugIndirectColorOn
Definition: DtIndirectGeometry.h:435
&#39;super&#39; class for managing the per gc vao for all indirect geometries There is only one vao per gl co...
Definition: DtIndirectVaoManager.h:35
boost::mutex myInternalsMutex
Definition: DtIndirectGeometry.h:476
const bool myManagesIndividualInstances
Definition: DtIndirectGeometry.h:417
struct for holding the fade parameters used by the indirect rendering cull compute shader ...
Definition: DtIndirectFadeParameters.h:17
std::map< int, int > myInstanceContainerIdToNumIndices
Definition: DtIndirectGeometry.h:433
int myNumIndicesAcrossAllModels
number of indices across all unique models across instances
Definition: DtIndirectGeometry.h:432
The DtCoordinateSystem is used to manage the current coordinate system of the scene.
Definition: DtCoordinateSystem.h:40
responsible for initializing the indirect buffers in the main thread
Definition: DtIndirectGeometryInitMainThreadJob.h:42
bool myLastColorizePerDrawableEnabled
Definition: DtIndirectGeometry.h:436
DtIndirectSwitchManager * mySwitchManager
Definition: DtIndirectGeometry.h:448
A generic OpenGL buffer. This can be: -&gt; a vertex buffer -&gt; an index buffer -&gt; a shader storage buffe...
Definition: DtGlBuffer.h:29
tbb::concurrent_queue< DtIndirectGeometryInstance > myQueueInstancesToAdd
addInstance may be called from multiple threads. Hence, concurrent queue
Definition: DtIndirectGeometry.h:407
Contains makVrv::DtIndirectAnnotationAndUvOffset class.
DtIndirectUvOffsetManager * myUvOffsetManager
Definition: DtIndirectGeometry.h:451
bool myMutableShadersSetup
Definition: DtIndirectGeometry.h:457
The class that is used to communicate the camera viewing parameters to the DtICullingAndLOD interface...
Definition: DtIndirectViewParameters.h:26
osg::ref_ptr< DtIndirectGeometryUpdateMainThreadJob > myMainThreadUpdateJob
Definition: DtIndirectGeometry.h:480
Base class to provide boost signal/slot management.
DtVirtualBaseClassCreator< DtIndirectGeometry, const DtCullShaderConfig &, const bool &, const bool & > DtIndirectGeometryCreator
creator
Definition: DtIndirectGeometry.h:88
handles the uv offsets for all the indirect geometry. Sets up the default state of the uv offset...
Definition: DtIndirectUvOffsetManager.h:49
unsigned int myMutableLastFrameTexturesUpdated
Definition: DtIndirectGeometry.h:455
DtInstanceContainer myInstanceContainer
container for all the instances registered here
Definition: DtIndirectGeometry.h:446
handles data that is specified per instance. Currently only the blend color from the DtOsgArticulated...
Definition: DtIndirectPerInstanceDataManager.h:59
osg::ref_ptr< osg::StateSet > myDefaultDrawStateSet
Definition: DtIndirectGeometry.h:492
Contains DLL export macros.
bool myMutableShouldReloadShaders
FIXME should be a static but currently the cull shader is per indirect.
Definition: DtIndirectGeometry.h:460
DtIndirectEffectTexturesTemplate myEffectTexturesState
the accumulated effect textures&#39; state which represents the superset of all effect textures cumulativ...
Definition: DtIndirectGeometry.h:423
Interface class to manage/configure drawing of a subset of rendering components within an indirect ge...
Definition: DtIndirectDrawComponent.h:32
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
class to draw a subset of items of an indirect geometry (everything except light points), the default way
Definition: DtIndirectDefaultDrawComponent.h:36
Helper class to manage instances This class allows you to add a DtInstance_64 Internally, however it stores this as a DtInstance (which the GPU can directly read)
Definition: DtInstanceContainer.h:31
boost::mutex myWaitMutex
Definition: DtIndirectGeometry.h:471
Definition: DtIndirectShaderConstants.h:42
const bool myIsTerrainPatch
Definition: DtIndirectGeometry.h:415
Contains the DtIndirectGeometryRegistrar class declaration.
Contains makVrv::DtIndirectViewParameters class.
Contains makVrv::DtInstanceContainer.
Class that allows you to abstractly register effect texture types the effect texture types are client...
Definition: DtIndirectEffectTexturesTemplate.h:40
DtIndirectDefaultDrawComponent * myDefaultDrawComponent
Definition: DtIndirectGeometry.h:487
Contains the per Model info which the indirect module needs It is owned by the Indirect geometry regi...
Definition: DtIndirectModelInfo.h:44
DtIndirectDofManager * myDofManager
Definition: DtIndirectGeometry.h:449
Contains makVrv::DtIndirectFadeParameters class.
class to draw a subset of light points of an indirect geometry
Definition: DtIndirectLightPointDrawComponent.h:49

Document ID: Generated on Sun Dec 4 20:22:03 EST 2022 from SVN revision 249613
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)