VR-Forces 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) 2025 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvOsg/vrvOsg.h>
13 
18 
24 
25 #include <vrvMath/DtVector3.h>
26 
29 
30 #include <matrix/vlTaitBryan.h>
31 
32 #include <osg/Drawable>
33 #include <osg/Uniform>
34 #include <osg/StateSet>
35 #include <osg/OperationThread>
36 #include <osgSim/MultiSwitch>
37 
38 #include <tbb/concurrent_queue.h>
39 #include <boost/thread/condition_variable.hpp>
40 #include <boost/thread/shared_mutex.hpp>
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 DtVirtualProgramCache;
67 
68  class DtIndirectDrawComponent;
69  class DtIndirectDefaultDrawComponent;
70  class DtIndirectLightPointDrawComponent;
71  class DtIndirectDebugCullComponent;
72 
73  class DtIndirectSwitchManager;
74  class DtIndirectDofManager;
75  class DtIndirectLodManager;
76  class DtIndirectUvOffsetManager;
77  class DtIndirectPerInstanceDataManager;
78  class DtIndirectShaderConstants;
79  class DtOsgLightPointManager;
80  class DtIndirectRunTimeSettings;
81 
82  class DtIndirectVaoManager;
83 
84  class DtCoordinateSystem;
85 
86  class DtDebugLog;
87 
88  class DtIndirectShaderManager;
89 
91  class DtIndirectGeometry;
92 
94 
97 
99  template <>
100  inline const char* creatorTypeName<DtIndirectGeometry>(void) { return "DtIndirectGeometryCreator"; }
101 
120  class DT_DLL_VRVOSG DtIndirectGeometry : public osg::Drawable
121  {
122  public:
124 
125  protected:
129  DtIndirectGeometry(DtDe& de, const DtCullShaderConfig& cullShaderConfig, const DtIndirectGeometrySubType& geometrySubType, bool managesIndividualInstances);
130 
132  virtual ~DtIndirectGeometry();
133 
134  private:
136  DtIndirectGeometry() = delete;
137 
139  DtIndirectGeometry(const DtIndirectGeometry& other) = delete;
141  DtIndirectGeometry& operator=(const DtIndirectGeometry& other) = delete;
142 
143  public:
144 
146  virtual void setName(const std::string& name) override;
147 
149  virtual void setRenderer(DtIndirectGeometryRenderer* drawerNode);
150 
158  virtual void setRegistrar(DtIndirectGeometryRegistrar* registrar);
159 
161  virtual DtIndirectGeometryRegistrar* registrar();
162 
164  virtual const char* className() const;
165 
169  virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
170 
173  virtual void debugDrawImplementation(osg::RenderInfo& renderInfo,
174  const osg::Matrixd& modelViewMatrix);
175 
181  virtual int addInstance(const DtIndirectGeometryInstance& instance);
182 
188  virtual int addInstance(int modelId, const osg::Matrixd& xForm, float modelScale, float modelRadius, int lightPointGroupId
189  , bool trackLifeTime
190  , const std::string& trackName
191  , bool defaultVisibility = true );
192 
194  virtual void setInstanceOtherData0(int instanceIdIndirect, const Vector4_32& data);
196  virtual Vector4_32 instanceOtherData0(int instanceIdIndirect) const;
198 
202  virtual void accept(osg::NodeVisitor& nv);
203 
205  virtual void setParent(const osg::Group* parent);
206 
212  virtual void setRegistrarInvalid(void);
213 
215  virtual void releaseGLObjects(osg::State* state) const override;
216 
218  virtual void accept(osg::PrimitiveFunctor& functor) const override;
219 
223  virtual void setupIndirectShaders();
224 
227  virtual const osg::Geode* parentGeode(void) const;
228  virtual osg::Geode* parentGeode(void);
230 
234  virtual void setLocalOriginTransform(const osg::Matrixd& localOriginTransform);
235 
239  virtual const osg::Matrixd& localOriginTransform() const;
240 
242  virtual bool actuallyAddQueuedUpInstances( bool backgroundThreadLoadWaitForLock = false );
243 
245  virtual void launchOneTimeInitOp();
246 
249  virtual void updateGpuBuffers(bool amortizeTextures, size_t& statsObjectsRemaining);
250 
252  virtual void setFadeParameters(const DtIndirectFadeParameters& fadeParameters);
253 
255  virtual const DtIndirectFadeParameters& fadeParameters(void) const;
256 
258  virtual void perCameraUpdateAndCull(const osg::Camera* camera, const osg::Matrix& modelViewMatrix, const osg::FrameStamp* frameStamp);
259 
261  virtual void fillViewParameters(DtIndirectViewParameters& destViewParameters, const osg::Matrix& modelViewMatrix, const osg::Camera* osgCamera) const;
262 
266  virtual void fillAltitude3d(DtIndirectViewParameters& destViewParameters, const Vector3_64& eye) const;
267 
269  virtual bool readyToRender(const int instanceIdInIndirect) const;
270 
273  virtual bool hasQueuedInstances( void ) const;
274 
276  virtual bool allInstancesAreToBeDeleted() const;
277 
281  virtual bool instanceEverAdded(void) const;
282 
285  virtual int numValidInstances(void) const;
286 
290  virtual void setCellId(const Vector3_int& cellId);
291 
295  virtual const Vector3_int& cellId(void) const;
296 
298  virtual const unsigned int id( void ) const;
299 
305  virtual void update(const osg::FrameStamp* frameStamp);
306 
307  public:
309  static void setTrackObjects(bool val);
311  static bool trackObjects(void);
313 
315  static int numIndirectGeometries(void);
316 
328  static void initializeDtDeKeyedInstances(DtDe& de);
329 
331  static int numUpdateGpuBuffersRanThisFrame();
332 
335  static void clearNumUpdateGpuBuffersRanThisFrame();
336 
339  virtual void submitOneTimeOpForFrame();
340 
342  virtual DtIndirectGeometrySubType subType() const;
343 
344  protected:
345 
348  virtual bool addInstanceActual(const DtIndirectGeometryInstance& instance);
349 
353  virtual void setupShadersIfNecessary();
354 
357  virtual void setupDebugUniforms();
358 
361  virtual void installDefaultMaterial(osg::StateSet* ss);
362 
364  virtual void slot_reloadShaders();
365 
369  virtual void updateIndicesCount(const DtIndirectModelInfo& modelInfo, int instanceContainerIndex);
370 
372  virtual void updateModelIdsToInstances(int modelId, int instanceId, bool add);
373 
375  virtual void drawFromCommandBuffer(osg::RenderInfo& renderInfo, const DtIndirectViewParameters& viewParameters, const osg::Camera* camera
376  , bool isLightBin, bool isDepthBin, bool isShadowPass, bool viaExternalRenderer) const;
377 
379  virtual void syncViewParametersToGpu(
380  const DtIndirectViewParameters& viewParameters, osg::State* state) const;
381 
385 
387  virtual void updateInstancePositionOrientationAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
388 
390  virtual void updateInstanceSwitchesAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
391 
393  virtual void updateInstanceSequencesAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
394 
396  virtual void updateInstanceUvOffsetsAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
397 
399  virtual void updateInstanceColorAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
400 
402  virtual void updateInstanceOtherData0AddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
403 
405  virtual void updateInstanceLightPointGroupIdActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
406 
408  virtual void updateInstanceVisibilityLightPointMaxDistanceActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
409 
411  virtual bool updateInstanceDeletionBeforeAddedActual(const DtIndirectGeometryInstance& instance);
412 
414  virtual void updateInstancesDofsAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
415 
417  virtual void updateInstanceModelIdAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
418 
421  virtual void reloadShadersIfNecessary(void) const;
422 
424  virtual void adjustDofConstraintsIfNecessary(osgSim::DOFTransform* clone);
425 
427  virtual DtIndirectDrawComponent* drawComponent(int stateId) const;
428 
431  virtual bool hasLightPoints(void) const;
432 
434  virtual bool hasDepthOnly(void) const;
435 
437  virtual bool isDepthOnly(int stateId) const;
438 
440  virtual void nullOutDrawComponents(void);
441 
443  virtual void initDrawComponents(void);
444 
448  virtual void setPureSignalBasedUpdates(bool val);
449 
451  virtual void initializeUbosIfNecessary(osg::RenderInfo& renderInfo) const;
452 
454  virtual void slot_coordinateSystemChanged();
455 
457  virtual void trackInstanceLifeTime(int instanceIdInIndirectGeometry
458  , bool trackLifeTime
459  , const std::string& trackName);
460 
462  virtual std::pair<bool, std::string> trackInfo(int instanceIdInIndirectGeometry) const;
463 
465  virtual void drawImplementation(osg::RenderInfo& renderInfo, const osg::Matrixd& modelViewMatrix
466  , bool isLightBin, bool isDepthBin, bool isShadowPass) const;
467 
469  virtual bool isTerrainPatch(const DtIndirectGeometrySubType& geometrySubType) const;
470 
474  virtual bool disableExternalRenderForSensorFx(const osg::Camera* camera) const;
475 
479  virtual bool useExternalRenderer(const osg::Camera* camera) const;
480 
482  virtual std::string modelName(int instanceId) const;
483 
486  virtual void registerUpdateComponent();
487 
488  protected:
491 
493  tbb::concurrent_queue<DtIndirectGeometryInstance> myQueueInstancesToAdd;
494 
496 
498 
500 
502  const bool myIsTerrainPatch;
503 
505 
511  unsigned int myNumTextCoordArrays;
512 
514 
516 
521 
524 
526  unsigned int myId;
527 
530 
536 
537  mutable bool myMutableShadersSetup;
538 
541 
542  typedef boost::unique_lock<boost::shared_mutex> InstanceMutexWriteLock;
543  typedef boost::shared_lock<boost::shared_mutex> InstanceMutexReadLock;
544  mutable boost::shared_mutex myInstanceMutex;
545 
548  typedef std::unordered_map<int, int> MapIndirectIdToInstanceContainerId;
550 
551  unsigned int myLastFrameUpdated;
552  const osg::Camera* myLastCamera;
553 
555 
556  // PPP: Is this large enough?
557  std::atomic<int> myRunningInstanceId;
558 
562 
564  virtual DtIndirectDrawComponent* component(int component);
565 
566  // state set (bin) for the default components
568 
569  // state set (bin) for the light point components
571 
572  // state set (bin) for depth only components
574 
576 
581 
582  DtGlBuffer* myGpuShaderUbo = nullptr;
583  mutable int myGpuShaderUboBinding = -1;
584  DtIndirectShaderConstants* myShaderConstants = nullptr;
585 
587 
589 
592  DtCoordinateSystem* myCoordinateSystem = nullptr;
593 
594  Vector3_int myCellId = { 0,0,0 };
595 
596  std::unordered_map<int, std::string> myInstancesBeingTracked;
597 
599 
600  const bool mySensorFxLoaded;
601 
607  protected:
608  static bool theTrackObjects;
609 
612  {
613  public:
615  TotalCounter();
617  virtual ~TotalCounter();
618  public:
619  std::atomic<int> myTotalCount;
620  std::atomic<unsigned int> myIdNumbers;
621  };
623 
626  DtIndirectGeometryRenderer* myIndirectGeometryRenderer = nullptr;
627 
629  std::unordered_map<int, Vector4_32> myMapInstanceToOtherData0;
630 
632 
634  };
635 }
unsigned int myNumTextCoordArrays
Definition: DtIndirectGeometry.h:511
Contains the DtCullShaderConfig class declaration.
MapIntToInt myInstancesToModelIds
Definition: DtIndirectGeometry.h:499
This manages the draw components (shader vp wrappers) for combinations of DtIndirectEffectTexturesTem...
Definition: DtIndirectShaderManager.h:50
DtIndirectFadeParameters myFadeParameters
Definition: DtIndirectGeometry.h:554
non virtual container class for holding the information needed to create an indirect geometry instanc...
Definition: DtIndirectGeometryInstance.h:26
bool myHasCullTraversedThisFrame
Definition: DtIndirectGeometry.h:602
osg::ref_ptr< osg::StateSet > myDepthOnlyDrawStateSet
Definition: DtIndirectGeometry.h:573
structure to count total number of DtIndirectGeometrys in the system
Definition: DtIndirectGeometry.h:611
static TotalCounter theTotalCounter
Definition: DtIndirectGeometry.h:622
std::unordered_map< int, int > MapIndirectIdToInstanceContainerId
Map of instances&#39; id in indirect geometry to their id in the instance container.
Definition: DtIndirectGeometry.h:548
Contains makVrv::DtIndirectGeometrySubType declaration.
DtIndirectPerInstanceDataManager * myPerInstanceDataManager
Definition: DtIndirectGeometry.h:535
#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:533
This class is a component of the DtIndirectGeometry It inputs are: -&gt; the instances registered with Dt...
Definition: DtGpuCulling.h:88
std::atomic< unsigned int > myIdNumbers
Definition: DtIndirectGeometry.h:620
Indirect geometry can have multiple models and their corresponding ids registered in it...
Definition: DtIndirectGeometryRegistrar.h:111
DtIndirectLightPointDrawComponent * myLightPointDrawComponent
Definition: DtIndirectGeometry.h:560
boost::shared_mutex myInstanceMutex
Definition: DtIndirectGeometry.h:544
std::atomic< int > myRunningInstanceId
Definition: DtIndirectGeometry.h:557
osg::Matrixd myLocalOriginTransformMatrix
Definition: DtIndirectGeometry.h:515
Represents setting that are runtime tweakable/toggleable.
Definition: DtIndirectRunTimeSettings.h:24
DtVirtualBaseClassCreator< DtIndirectGeometry, const DtCullShaderConfig &, const DtIndirectGeometrySubType &, const bool & > DtIndirectGeometryCreator
creator
Definition: DtIndirectGeometry.h:93
DtOsgLightPointManager & myLightPointManager
Definition: DtIndirectGeometry.h:586
Contains makVrv::DtIndirectModelScalingAlgorithm enumeration.
unsigned int myId
a unique id for the geometry
Definition: DtIndirectGeometry.h:526
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:128
std::map< int, int > MapIntToInt
Definition: DtCommonTypes.h:25
boost::unique_lock< boost::shared_mutex > InstanceMutexWriteLock
Definition: DtIndirectGeometry.h:542
handles the lods for all the indirect geometry. sets up and runs a compute shader prepass for process...
Definition: DtIndirectLodManager.h:54
osg::ref_ptr< DtIndirectGeometryRegistrar > myRegistrar
pointer to the (external) registrar
Definition: DtIndirectGeometry.h:490
3 dimensional vector
DtSignalConnectionManager myConnections
Definition: DtIndirectGeometry.h:513
osg::ref_ptr< osg::StateSet > myLightPointDrawStateSet
Definition: DtIndirectGeometry.h:570
DtIndirectShaderManager & myIndirectShaderManager
Definition: DtIndirectGeometry.h:598
DtDe & myDe
Definition: DtIndirectGeometry.h:588
bool myMutableOutputInstancesBuffersChanged
Internal variable that tracks whether the output instance buffers via the culling got changed (resize...
Definition: DtIndirectGeometry.h:580
bool myUpdateComponentRegistered
Definition: DtIndirectGeometry.h:575
const char * creatorTypeName< DtIndirectGeometry >(void)
template specialization for the creator (pass the class being created to the creatorTypeName template...
Definition: DtIndirectGeometry.h:100
Variadic templated creator class for defining a DtVirtualBaseClass creator that is automatically regi...
Definition: DtVirtualBaseClassCreator.h:23
DtIndirectGeometryInstance, which holds information for creating an indirect geometry instance...
DtGpuCulling * myGpuCulling
Definition: DtIndirectGeometry.h:495
static bool theTrackObjects
Definition: DtIndirectGeometry.h:608
friend DtIndirectGeometryCreator
Definition: DtIndirectGeometry.h:123
DtIndirectDebugCullComponent * myIndirectDebugCullComponent
Definition: DtIndirectGeometry.h:561
This class allows us to draw all indirect geometries one after the other with minimal state changes...
Definition: DtIndirectGeometryRenderer.h:63
\ ::, which allows us to hook into our indirect engine to render using indirect rendering...
Definition: DtIndirectGeometry.h:120
MapIntToInt myModelIDsToInstances
Definition: DtIndirectGeometry.h:497
const osg::Camera * myLastCamera
Definition: DtIndirectGeometry.h:552
unsigned int myLastFrameUpdated
Definition: DtIndirectGeometry.h:551
MapIndirectIdToInstanceContainerId myMapIndirectIdToInstanceContainerId
Definition: DtIndirectGeometry.h:549
static int theNumUpdateGpuBuffersRanThisFrame
Definition: DtIndirectGeometry.h:633
handles the dof nodes for all the indirect geometry. Sets up the default state of osg::Dof...
Definition: DtIndirectDofManager.h:65
DtIndirectVaoManager & myVaoManager
This is de-referenced here for speed.
Definition: DtIndirectGeometry.h:523
Class to manage disconnection of boost connections on deletion.
Definition: DtSignalConnectionManager.h:20
This represents per camera+thread data It is used by DtIndirectGeometryRenderer to sort and draw indi...
Definition: DtIndirectGeometryRendererUserData.h:50
const DtIndirectRunTimeSettings & myIndirectRunTimeSettings
Definition: DtIndirectGeometry.h:631
This class manages the vaos for indirect.
Definition: DtIndirectVaoManager.h:34
const bool myManagesIndividualInstances
Definition: DtIndirectGeometry.h:504
std::unordered_map< int, std::string > myInstancesBeingTracked
Definition: DtIndirectGeometry.h:596
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:520
int myNumIndicesAcrossAllModels
number of indices across all unique models across instances
Definition: DtIndirectGeometry.h:519
The DtCoordinateSystem is used to manage the current coordinate system of the scene.
Definition: DtCoordinateSystem.h:40
DtIndirectSwitchManager * mySwitchManager
Definition: DtIndirectGeometry.h:531
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:493
Contains makVrv::DtIndirectAnnotationAndUvOffset class.
DtIndirectUvOffsetManager * myUvOffsetManager
Definition: DtIndirectGeometry.h:534
bool myMutableShadersSetup
Definition: DtIndirectGeometry.h:537
The class that is used to communicate the camera viewing parameters to the DtICullingAndLOD interface...
Definition: DtIndirectViewParameters.h:26
Base class to provide boost signal/slot management.
const DtIndirectGeometrySubType myGeometrySubType
Definition: DtIndirectGeometry.h:501
boost::shared_lock< boost::shared_mutex > InstanceMutexReadLock
Definition: DtIndirectGeometry.h:543
DtIndirectGeometrySubType
Definition: DtIndirectGeometrySubType.h:16
unsigned int myOneTimeOpSubmittedForFrameNumber
The frame number when the one time op was processed Only used when multiple one time ops are required...
Definition: DtIndirectGeometry.h:606
handles the uv offsets for all the indirect geometry. Sets up the default state of the uv offset...
Definition: DtIndirectUvOffsetManager.h:49
DtInstanceContainer myInstanceContainer
container for all the instances registered here
Definition: DtIndirectGeometry.h:529
std::atomic< int > myTotalCount
Definition: DtIndirectGeometry.h:619
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:567
Contains DLL export macros.
bool myMutableShouldReloadShaders
FIXME should be a static but currently the cull shader is per indirect.
Definition: DtIndirectGeometry.h:540
DtIndirectEffectTexturesTemplate myEffectTexturesState
the accumulated effect textures&#39; state which represents the superset of all effect textures cumulativ...
Definition: DtIndirectGeometry.h:510
Interface class to manage/configure drawing of a subset of rendering components within an indirect ge...
Definition: DtIndirectDrawComponent.h:33
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
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
std::unordered_map< int, Vector4_32 > myMapInstanceToOtherData0
Maps an instance id to the other data0 for that instance.
Definition: DtIndirectGeometry.h:629
Definition: DtIndirectShaderConstants.h:42
const bool myIsTerrainPatch
Definition: DtIndirectGeometry.h:502
Contains the DtIndirectGeometryRegistrar class declaration.
Contains makVrv::DtIndirectViewParameters class.
Contains makVrv::DtInstanceContainer.
const bool mySensorFxLoaded
Definition: DtIndirectGeometry.h:600
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:559
Contains the per Model info which the indirect module needs These objects are owned by the Indirect g...
Definition: DtIndirectModelInfo.h:67
DtIndirectDofManager * myDofManager
Definition: DtIndirectGeometry.h:532
Contains makVrv::DtIndirectFadeParameters class.
class to draw a subset of light points of an indirect geometry
Definition: DtIndirectLightPointDrawComponent.h:52

Document ID: Generated on Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)