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) 2024 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;
216 
218  virtual void accept(osg::PrimitiveFunctor& functor) const;
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(void);
243 
245  virtual void launchOneTimeInitOp();
246 
248  virtual void updateGpuBuffers(bool amortizeTextures);
249 
251  virtual void setFadeParameters(const DtIndirectFadeParameters& fadeParameters);
252 
254  virtual const DtIndirectFadeParameters& fadeParameters(void) const;
255 
257  virtual void perCameraUpdateAndCull(const osg::Camera* camera, const osg::Matrix& modelViewMatrix, const osg::FrameStamp* frameStamp);
258 
260  virtual void fillViewParameters(DtIndirectViewParameters& destViewParameters, const osg::Matrix& modelViewMatrix, const osg::Camera* osgCamera) const;
261 
265  virtual void fillAltitude3d(DtIndirectViewParameters& destViewParameters, const Vector3_64& eye) const;
266 
268  virtual bool readyToRender(const int instanceIdInIndirect) const;
269 
272  virtual bool hasQueuedInstances( void ) const;
273 
275  virtual bool allInstancesAreToBeDeleted() const;
276 
280  virtual bool instanceEverAdded(void) const;
281 
284  virtual int numValidInstances(void) const;
285 
289  virtual void setCellId(const Vector3_int& cellId);
290 
294  virtual const Vector3_int& cellId(void) const;
295 
297  virtual const unsigned int id( void ) const;
298 
299  public:
301  static void setTrackObjects(bool val);
303  static bool trackObjects(void);
305 
307  static int numIndirectGeometries(void);
308 
320  static void initializeDtDeKeyedInstances(DtDe& de);
321 
323  static int numUpdateGpuBuffersRanThisFrame();
324 
327  static void clearNumUpdateGpuBuffersRanThisFrame();
328  protected:
329 
332  virtual bool addInstanceActual(const DtIndirectGeometryInstance& instance);
333 
337  virtual void setupShadersIfNecessary();
338 
341  virtual void setupDebugUniforms();
342 
345  virtual void installDefaultMaterial(osg::StateSet* ss);
346 
348  virtual void slot_reloadShaders();
349 
353  virtual void updateIndicesCount(const DtIndirectModelInfo& modelInfo, int instanceContainerIndex);
354 
356  virtual void updateModelIdsToInstances(int modelId, int instanceId, bool add);
357 
359  virtual void drawFromCommandBuffer(osg::RenderInfo& renderInfo, const DtIndirectViewParameters& viewParameters, const osg::Camera* camera
360  , bool isLightBin, bool isDepthBin, bool isShadowPass, bool viaExternalRenderer) const;
361 
363  virtual void syncViewParametersToGpu(
364  const DtIndirectViewParameters& viewParameters, osg::State* state) const;
365 
369 
371  virtual void updateInstancePositionOrientationAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
372 
374  virtual void updateInstanceSwitchesAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
375 
377  virtual void updateInstanceSequencesAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
378 
380  virtual void updateInstanceUvOffsetsAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
381 
383  virtual void updateInstanceColorAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
384 
386  virtual void updateInstanceOtherData0AddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
387 
389  virtual void updateInstanceLightPointGroupIdActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
390 
392  virtual void updateInstanceVisibilityLightPointMaxDistanceActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
393 
395  virtual bool updateInstanceDeletionBeforeAddedActual(const DtIndirectGeometryInstance& instance);
396 
398  virtual void updateInstancesDofsAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
399 
401  virtual void updateInstanceModelIdAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex);
402 
405  virtual void reloadShadersIfNecessary(void) const;
406 
410  virtual void update(const osg::FrameStamp* frameStamp);
411 
413  virtual void adjustDofConstraintsIfNecessary(osgSim::DOFTransform* clone);
414 
416  virtual DtIndirectDrawComponent* drawComponent(int stateId) const;
417 
420  virtual bool hasLightPoints(void) const;
421 
423  virtual bool hasDepthOnly(void) const;
424 
426  virtual bool isDepthOnly(int stateId) const;
427 
429  virtual void nullOutDrawComponents(void);
430 
432  virtual void initDrawComponents(void);
433 
437  virtual void setPureSignalBasedUpdates(bool val);
438 
440  virtual void initializeUbosIfNecessary(osg::RenderInfo& renderInfo) const;
441 
443  virtual void slot_coordinateSystemChanged();
444 
446  virtual void trackInstanceLifeTime(int instanceIdInIndirectGeometry
447  , bool trackLifeTime
448  , const std::string& trackName);
449 
451  virtual std::pair<bool, std::string> trackInfo(int instanceIdInIndirectGeometry) const;
452 
454  virtual void drawImplementation(osg::RenderInfo& renderInfo, const osg::Matrixd& modelViewMatrix
455  , bool isLightBin, bool isDepthBin, bool isShadowPass) const;
456 
458  virtual bool isTerrainPatch(const DtIndirectGeometrySubType& geometrySubType) const;
459 
463  virtual bool disableExternalRenderForSensorFx(const osg::Camera* camera) const;
464 
468  virtual bool useExternalRenderer(const osg::Camera* camera) const;
469 
471  virtual std::string modelName(int instanceId) const;
472 
473  protected:
476 
478  tbb::concurrent_queue<DtIndirectGeometryInstance> myQueueInstancesToAdd;
479 
481 
483 
485 
487  const bool myIsTerrainPatch;
488 
490 
496  unsigned int myNumTextCoordArrays;
497 
499 
501 
506 
509 
511  unsigned int myId;
512 
515 
521 
522  mutable bool myMutableShadersSetup;
523 
526 
527  typedef boost::unique_lock<boost::shared_mutex> InstanceMutexWriteLock;
528  typedef boost::shared_lock<boost::shared_mutex> InstanceMutexReadLock;
529  mutable boost::shared_mutex myInstanceMutex;
530 
533  typedef std::unordered_map<int, int> MapIndirectIdToInstanceContainerId;
535 
536  unsigned int myLastFrameUpdated;
537  const osg::Camera* myLastCamera;
538 
540 
541  // PPP: Is this large enough?
542  std::atomic<int> myRunningInstanceId;
543 
547 
549  virtual DtIndirectDrawComponent* component(int component);
550 
551  // state set (bin) for the default components
553 
554  // state set (bin) for the light point components
556 
557  // state set (bin) for depth only components
559 
561 
566 
567  DtGlBuffer* myGpuShaderUbo = nullptr;
568  mutable int myGpuShaderUboBinding = -1;
569  DtIndirectShaderConstants* myShaderConstants = nullptr;
570 
572 
574 
577  DtCoordinateSystem* myCoordinateSystem = nullptr;
578 
579  Vector3_int myCellId = { 0,0,0 };
580 
581  std::unordered_map<int, std::string> myInstancesBeingTracked;
582 
584 
585  const bool mySensorFxLoaded;
586 
587  protected:
588  static bool theTrackObjects;
589 
592  {
593  public:
595  TotalCounter();
597  virtual ~TotalCounter();
598  public:
599  std::atomic<int> myTotalCount;
600  std::atomic<unsigned int> myIdNumbers;
601  };
603 
606  DtIndirectGeometryRenderer* myIndirectGeometryRenderer = nullptr;
607 
609  std::unordered_map<int, Vector4_32> myMapInstanceToOtherData0;
610 
612 
614  };
615 }
unsigned int myNumTextCoordArrays
Definition: DtIndirectGeometry.h:496
Contains the DtCullShaderConfig class declaration.
MapIntToInt myInstancesToModelIds
Definition: DtIndirectGeometry.h:484
This manages the draw components (shader vp wrappers) for combinations of DtIndirectEffectTexturesTem...
Definition: DtIndirectShaderManager.h:50
DtIndirectFadeParameters myFadeParameters
Definition: DtIndirectGeometry.h:539
non virtual container class for holding the information needed to create an indirect geometry instanc...
Definition: DtIndirectGeometryInstance.h:26
osg::ref_ptr< osg::StateSet > myDepthOnlyDrawStateSet
Definition: DtIndirectGeometry.h:558
structure to count total number of DtIndirectGeometrys in the system
Definition: DtIndirectGeometry.h:591
static TotalCounter theTotalCounter
Definition: DtIndirectGeometry.h:602
std::unordered_map< int, int > MapIndirectIdToInstanceContainerId
Map of instances&#39; id in indirect geometry to their id in the instance container.
Definition: DtIndirectGeometry.h:533
Contains makVrv::DtIndirectGeometrySubType declaration.
DtIndirectPerInstanceDataManager * myPerInstanceDataManager
Definition: DtIndirectGeometry.h:520
#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:518
This class is a component of the DtIndirectGeometry It inputs are: -&gt; the instances registered with Dt...
Definition: DtGpuCulling.h:87
std::atomic< unsigned int > myIdNumbers
Definition: DtIndirectGeometry.h:600
Indirect geometry can have multiple models and their corresponding ids registered in it...
Definition: DtIndirectGeometryRegistrar.h:109
DtIndirectLightPointDrawComponent * myLightPointDrawComponent
Definition: DtIndirectGeometry.h:545
boost::shared_mutex myInstanceMutex
Definition: DtIndirectGeometry.h:529
std::atomic< int > myRunningInstanceId
Definition: DtIndirectGeometry.h:542
osg::Matrixd myLocalOriginTransformMatrix
Definition: DtIndirectGeometry.h:500
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:571
Contains makVrv::DtIndirectModelScalingAlgorithm enumeration.
unsigned int myId
a unique id for the geometry
Definition: DtIndirectGeometry.h:511
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:527
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:475
3 dimensional vector
unsigned int myLastFrameUpdateTraversed
Definition: DtIndirectGeometry.h:560
DtSignalConnectionManager myConnections
Definition: DtIndirectGeometry.h:498
osg::ref_ptr< osg::StateSet > myLightPointDrawStateSet
Definition: DtIndirectGeometry.h:555
DtIndirectShaderManager & myIndirectShaderManager
Definition: DtIndirectGeometry.h:583
DtDe & myDe
Definition: DtIndirectGeometry.h:573
bool myMutableOutputInstancesBuffersChanged
Internal variable that tracks whether the output instance buffers via the culling got changed (resize...
Definition: DtIndirectGeometry.h:565
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:22
DtIndirectGeometryInstance, which holds information for creating an indirect geometry instance...
DtGpuCulling * myGpuCulling
Definition: DtIndirectGeometry.h:480
static bool theTrackObjects
Definition: DtIndirectGeometry.h:588
friend DtIndirectGeometryCreator
Definition: DtIndirectGeometry.h:123
DtIndirectDebugCullComponent * myIndirectDebugCullComponent
Definition: DtIndirectGeometry.h:546
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:482
const osg::Camera * myLastCamera
Definition: DtIndirectGeometry.h:537
unsigned int myLastFrameUpdated
Definition: DtIndirectGeometry.h:536
MapIndirectIdToInstanceContainerId myMapIndirectIdToInstanceContainerId
Definition: DtIndirectGeometry.h:534
static int theNumUpdateGpuBuffersRanThisFrame
Definition: DtIndirectGeometry.h:613
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:508
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:611
This class manages the vaos for indirect.
Definition: DtIndirectVaoManager.h:34
const bool myManagesIndividualInstances
Definition: DtIndirectGeometry.h:489
std::unordered_map< int, std::string > myInstancesBeingTracked
Definition: DtIndirectGeometry.h:581
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:505
int myNumIndicesAcrossAllModels
number of indices across all unique models across instances
Definition: DtIndirectGeometry.h:504
The DtCoordinateSystem is used to manage the current coordinate system of the scene.
Definition: DtCoordinateSystem.h:40
DtIndirectSwitchManager * mySwitchManager
Definition: DtIndirectGeometry.h:516
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:478
Contains makVrv::DtIndirectAnnotationAndUvOffset class.
DtIndirectUvOffsetManager * myUvOffsetManager
Definition: DtIndirectGeometry.h:519
bool myMutableShadersSetup
Definition: DtIndirectGeometry.h:522
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:486
boost::shared_lock< boost::shared_mutex > InstanceMutexReadLock
Definition: DtIndirectGeometry.h:528
DtIndirectGeometrySubType
Definition: DtIndirectGeometrySubType.h:16
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:514
std::atomic< int > myTotalCount
Definition: DtIndirectGeometry.h:599
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:552
Contains DLL export macros.
bool myMutableShouldReloadShaders
FIXME should be a static but currently the cull shader is per indirect.
Definition: DtIndirectGeometry.h:525
DtIndirectEffectTexturesTemplate myEffectTexturesState
the accumulated effect textures&#39; state which represents the superset of all effect textures cumulativ...
Definition: DtIndirectGeometry.h:495
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:72
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:609
Definition: DtIndirectShaderConstants.h:42
const bool myIsTerrainPatch
Definition: DtIndirectGeometry.h:487
Contains the DtIndirectGeometryRegistrar class declaration.
Contains makVrv::DtIndirectViewParameters class.
Contains makVrv::DtInstanceContainer.
const bool mySensorFxLoaded
Definition: DtIndirectGeometry.h:585
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:544
Contains the per Model info which the indirect module needs It is owned by the Indirect geometry regi...
Definition: DtIndirectModelInfo.h:55
DtIndirectDofManager * myDofManager
Definition: DtIndirectGeometry.h:517
Contains makVrv::DtIndirectFadeParameters class.
class to draw a subset of light points of an indirect geometry
Definition: DtIndirectLightPointDrawComponent.h:52

Document ID: Generated on Tue Sep 24 19:28:17 EDT 2024 from SVN revision 269799
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)