38 #define CPU_SIDE_COMPILATION 1
39 #include <../data/shaders/indirect/DrawElementsIndirectCommand.h>
40 #include <../data/shaders/ballistics/bullet_spawn.h>
41 #include <../data/shaders/ballistics/observer.h>
42 #include <../data/shaders/ballistics/query.h>
43 #include <../data/shaders/ballistics/tracer_definition_buffer.h>
44 #undef CPU_SIDE_COMPILATION
49 class DtBallisticGeometry;
50 class DtIndirectShaderManager;
51 class DtBallisticDrawComponent;
52 class DtBallisticRunTimeSettings;
53 class DtTracerDefinition;
54 class DtOsgBallisticManager;
92 static constexpr uint32_t MAX_BULLETS = 16384;
98 virtual std::string buildShaderPreamble()
const;
127 virtual void slot_reloadShaders();
132 virtual void slot_windSpeedChanged(
float metersPerSecond);
137 virtual void slot_windDirectionChanged(
float radians);
140 virtual void execute();
143 virtual void update(osg::RenderInfo& renderInfo);
146 virtual void apply(osg::RenderInfo& renderInfo);
149 virtual void releaseGLObjects(osg::State* state);
152 virtual bool shouldDraw(
bool isShadowPass);
166 virtual void setSimulationActive(
bool active);
171 virtual void beginFrame();
176 virtual void insertFrameFence();
182 virtual void pollReadback();
187 virtual void pollQueryReadback();
193 virtual void writeSpawnData(
int slotIndex,
const BulletSpawn& spawn);
206 virtual uint32_t registerTracerDefinition(
const DtTracerDefinition& def,
const float otherData0[4]);
215 virtual void unregisterTracerDefinition(uint32_t index);
221 virtual void setSlotActive(
int slotIndex, uint32_t active);
229 virtual void deactivateSlot(
int slotIndex);
238 virtual void updateEnvironment(
float gravity,
float windSpeed,
float windDirection,
239 float deltaTime,
double currentTime);
244 virtual void dispatchTrajectoryUpdate();
247 virtual void dispatchOctreeBuild();
258 virtual void bindGlobalCullBuffers();
263 virtual void bindGlobalDrawBuffers();
272 virtual void drainSoundTriggers(
273 std::function<
void(
const std::vector<std::vector<DtBallisticSoundTrigger>>&)> callback);
276 virtual void unbindCullBuffers();
282 virtual void unbindDrawBuffers();
289 virtual void initIndirectDrawCommands(
GLuint indexCount);
295 virtual CullMode frustumCullMode()
const;
301 virtual QueryMode proximityQueryMode()
const;
304 virtual void setGravity(
float gravity);
307 virtual float gravity()
const;
316 virtual void setMaxQueryResults(
int n);
322 virtual void dispatchFrustumCull();
328 virtual void dispatchOctreeCull();
331 virtual void dispatchGatherActiveFlags();
336 virtual void bindProjectileBuffer(
unsigned int bindingPoint);
344 virtual void debugDumpBuffers();
353 virtual void debugDrawCullResults(
DtGlBuffer* visibleSSBO);
364 virtual void debugDrawPositions();
371 virtual void debugDumpCullBuffers(
DtGlBuffer* visibleSSBO);
376 virtual void initializeBuffers();
379 virtual void doReloadShaders();
384 virtual void recomputeOctreeConstants();
480 GLsync myFenceSync[3];
498 uint64_t myReadbackFrameNumber[3];
511 GLsync myQueryFence[3];
bool myMutableShadersFailedToCompile
True if the most recent shader compilation failed.
Definition: DtBallisticComputeComponent.h:415
This manages the draw components (shader vp wrappers) for combinations of DtIndirectEffectTexturesTem...
Definition: DtIndirectShaderManager.h:50
int myFrameIndex
Current triple-buffer frame slot (cycles 0, 1, 2).
Definition: DtBallisticComputeComponent.h:482
float myWindDirection
Current wind direction (radians, clockwise from north).
Definition: DtBallisticComputeComponent.h:396
std::vector< TracerDefinition > myTracerDefTable
CPU-side table of registered tracer types; mirrored to myTracerDefinitionSSBO each frame...
Definition: DtBallisticComputeComponent.h:468
DtGlBuffer * myBoundsSSBO
BoundsBuffer SSBO (world AABB for octree root).
Definition: DtBallisticComputeComponent.h:456
DtBallisticDrawComponent * mySharedDrawComponent
Shared draw component; all ballistic geometries reference this single instance.
Definition: DtBallisticComputeComponent.h:548
GLuint myMeshIndexCount
Mesh index count set by initIndirectDrawCommands(); cached for reference.
Definition: DtBallisticComputeComponent.h:551
Abstract base for any operation that runs on the GPU via DtGpuArena.
Definition: DtGpuOperation.h:30
DtGlProgram * myOctreeMarkProgram
Compute program for octree internal-node frustum mark pass.
Definition: DtBallisticComputeComponent.h:431
float myGravity
Current gravity magnitude (m/s^2).
Definition: DtBallisticComputeComponent.h:392
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
DtGlProgram * myOctreeLeafProgram
Compute program for octree leaf frustum cull pass.
Definition: DtBallisticComputeComponent.h:433
std::function< void(int slotIndex)> SlotReleasedCallback
Callback type invoked on the CPU thread for each pool slot the GPU has killed.
Definition: DtBallisticComputeComponent.h:101
Visual and physical appearance parameters for a single tracer round type.
Definition: DtTracerDefinition.h:32
Plain data struct for cross-thread transfer of a ballistic flyby sound trigger.Written by the render ...
std::vector< uint32_t > myFreeTracerSlots
Indices of free slots in myTracerDefTable (reference count == 0), available for reuse.
Definition: DtBallisticComputeComponent.h:474
unsigned int GLuint
Definition: DtGlTextureBufferObject.h:18
DtGlProgram * myOctreeBoundsProgram
Compute program for octree bounds calculation.
Definition: DtBallisticComputeComponent.h:421
DtGlProgram * myTrajectoryProgram
Compute program for trajectory integration.
Definition: DtBallisticComputeComponent.h:419
uint32_t myLeafCount
8^myOctreeDepth leaf nodes.
Definition: DtBallisticComputeComponent.h:403
double myLastFrameTime
Simulation time of the previous execute() call, used to compute deltaTime.
Definition: DtBallisticComputeComponent.h:539
DtGlProgram * myOctreeStructureProgram
Compute program for octree structure build.
Definition: DtBallisticComputeComponent.h:423
DtGlProgram * myProximityQueryOctreeProgram
Compute program for octree-accelerated proximity queries.
Definition: DtBallisticComputeComponent.h:437
CullMode
Selects whether octree or brute-force frustum culling is used.
Definition: DtBallisticComputeComponent.h:75
std::mutex myPendingSoundTriggersMutex
Guards myPendingSoundTriggers for render/sim cross-thread access.
Definition: DtBallisticComputeComponent.h:522
std::atomic< bool > mySimulationActive
True when the manager has active bullets or pending burst rounds. Written by the sim thread via setSi...
Definition: DtBallisticComputeComponent.h:529
A convenience class to represent an OpenGL Shader Program.
Definition: DtGlProgram.h:66
float myWindSpeed
Current wind speed (m/s).
Definition: DtBallisticComputeComponent.h:394
DtGlProgram * myProximityQueryProgram
Compute program for brute-force proximity queries.
Definition: DtBallisticComputeComponent.h:435
DtGlProgram * myActiveFlagProgram
Compute program for gathering active-flags.
Definition: DtBallisticComputeComponent.h:427
Contains the DtGpuOperation class declaration.
Variadic templated creator class for defining a DtVirtualBaseClass creator that is automatically regi...
Definition: DtVirtualBaseClassCreator.h:23
DtSignalConnectionManager myConnections
Manages signal connections for wind change notifications.
Definition: DtBallisticComputeComponent.h:390
DtGlBuffer * myEnvironmentUBO
BallisticEnvironment UBO (gravity, wind, deltaTime, currentTime).
Definition: DtBallisticComputeComponent.h:446
QueryMode
Selects whether octree or brute-force proximity queries are used.
Definition: DtBallisticComputeComponent.h:82
DtGlProgram * myFrustumCullProgram
Compute program for brute-force frustum cull.
Definition: DtBallisticComputeComponent.h:429
DtGlProgram * myOctreeInsertProgram
Compute program for octree bullet insertion.
Definition: DtBallisticComputeComponent.h:425
const char * creatorTypeName< DtBallisticComputeComponent >(void)
template specialization for the creator (pass the class being created to the creatorTypeName template...
Definition: DtBallisticComputeComponent.h:64
DtDe & myDe
Reference to the simulation environment.
Definition: DtBallisticComputeComponent.h:388
DtGlProgram * myQuerySortProgram
Sort shader (sort_query_results.cs.glsl).
Definition: DtBallisticComputeComponent.h:513
const DtBallisticRunTimeSettings & myBallisticRunTimeSettings
Reference to the shared ballistic runtime settings.
Definition: DtBallisticComputeComponent.h:412
bool myBuffersInitialized
True after initializeBuffers() has completed; reset by releaseGLObjects().
Definition: DtBallisticComputeComponent.h:545
uint32_t myOctreeDepth
Current octree depth; all derived octree constants are recomputed when this changes.
Definition: DtBallisticComputeComponent.h:399
DtGlBuffer * myOctreeNodeFlagsSSBO
OctreeNodeFlags SSBO (per-node frustum visibility from the mark pass).
Definition: DtBallisticComputeComponent.h:462
std::mutex myPendingReleasedSlotsMutex
Guards myPendingReleasedSlots for cross-thread access.
Definition: DtBallisticComputeComponent.h:502
Class to manage disconnection of boost connections on deletion.
Definition: DtSignalConnectionManager.h:20
uint32_t myOctreeTotalNodes
Total nodes in the uniform octree (breadth-first).
Definition: DtBallisticComputeComponent.h:405
std::vector< int > myPendingReleasedSlots
Slot indices confirmed dead by GPU readback, pending CPU-thread processing.
Definition: DtBallisticComputeComponent.h:501
Interface for the ballistic rendering draw pass.
Definition: DtBallisticDrawComponent.h:52
Interface for GPU compute operations driving the ballistic simulation pipeline.
Definition: DtBallisticComputeComponent.h:71
DtGlBuffer * myNodeCounterSSBO
NodeCounter SSBO (total node and bullet-list counts).
Definition: DtBallisticComputeComponent.h:458
uint32_t myInternalNodeCount
Internal (non-leaf) node count; used to size the node-flags SSBO.
Definition: DtBallisticComputeComponent.h:407
std::vector< uint64_t > myLifeTracker
Per-slot CPU liveness tracker; 0 = free, non-zero = frame number when spawned.
Definition: DtBallisticComputeComponent.h:489
A generic OpenGL buffer. This can be: -> a vertex buffer -> an index buffer -> a shader storage buffe...
Definition: DtGlBuffer.h:29
std::vector< std::vector< DtBallisticSoundTrigger > > myPendingSoundTriggers
Pending raw sound trigger frame batches enqueued by pollQueryReadback(); drained each tick...
Definition: DtBallisticComputeComponent.h:520
DtGlBuffer * myOctreeBulletListSSBO
OctreeBulletLists SSBO (per-leaf bullet index arrays).
Definition: DtBallisticComputeComponent.h:454
Base class to provide boost signal/slot management.
uint64_t myGlobalFrameCount
Monotonically increasing frame counter, incremented once per execute().
Definition: DtBallisticComputeComponent.h:492
Singleton holding runtime-tweakable settings for the ballistic system.
Definition: DtBallisticRunTimeSettings.h:43
const char int mode
Definition: ioapi.h:38
QueryMode myQueryMode
Active proximity query algorithm.
Definition: DtBallisticComputeComponent.h:442
Contains DLL export macros.
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
CullMode myCullMode
Active frustum cull algorithm.
Definition: DtBallisticComputeComponent.h:440
int myMaxQueryResults
Maximum result entries to read back per frame; immutable after init.
Definition: DtBallisticComputeComponent.h:515
Ballistic manager that owns the projectile pool, compute component, and spatial grid.
Definition: DtOsgBallisticManager.h:58
DtGlBuffer * myActiveFlagSSBO
Dense active-flag output buffer used for CPU readback.
Definition: DtBallisticComputeComponent.h:460
friend DtBallisticComputeComponentCreator
Definition: DtBallisticComputeComponent.h:104
DtGlBuffer * mySpawnSSBO
SpawnBuffer SSBO (immutable per-bullet spawn data).
Definition: DtBallisticComputeComponent.h:448
DtIndirectShaderManager & myIndirectShaderManager
Shared indirect shader manager for loading/caching compute shaders.
Definition: DtBallisticComputeComponent.h:542
std::atomic< bool > myPendingShaderReload
Set from any thread by slot_reloadShaders(); consumed on the GL thread at the top of execute()...
Definition: DtBallisticComputeComponent.h:525
int myActiveSlotCount
Number of slots currently non-zero in myLifeTracker.
Definition: DtBallisticComputeComponent.h:536
std::vector< int32_t > myTracerDefRefCounts
Reference count per entry in myTracerDefTable; zero means the slot is free and available for reuse...
Definition: DtBallisticComputeComponent.h:471
uint32_t myBulletsPerLeaf
Bullet slots per leaf = MAX_BULLETS / myLeafCount.
Definition: DtBallisticComputeComponent.h:409
DtGlBuffer * myStateSSBO
StateBuffer SSBO (GPU-updated per-bullet state).
Definition: DtBallisticComputeComponent.h:450
DtGlBuffer * myOctreeSSBO
OctreeBuffer SSBO (octree node array).
Definition: DtBallisticComputeComponent.h:452
DtVirtualBaseClassCreator< DtBallisticComputeComponent > DtBallisticComputeComponentCreator
creator
Definition: DtBallisticComputeComponent.h:57
bool myWarnedSoundProgramNull
One-shot warning flag for dispatchSoundQuery() early-return conditions.
Definition: DtBallisticComputeComponent.h:517