MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / GetParticlesCount

Method GetParticlesCount

Source/Engine/Particles/ParticlesSimulation.cpp:91–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89}
90
91int32 ParticleSystemInstance::GetParticlesCount() const
92{
93 int32 result = 0;
94
95 // CPU particles
96 for (const auto& emitter : Emitters)
97 {
98 if (emitter.Buffer && emitter.Buffer->Mode == ParticlesSimulationMode::CPU)
99 {
100 result += emitter.Buffer->CPU.Count;
101 }
102 }
103
104 // GPU particles
105 if (GPUParticlesCountReadback && GPUParticlesCountReadback->IsAllocated())
106 {
107 auto data = static_cast<uint32*>(GPUParticlesCountReadback->Map(GPUResourceMapMode::Read));
108 if (data)
109 {
110 for (const auto& emitter : Emitters)
111 {
112 if (emitter.Buffer && emitter.Buffer->Mode == ParticlesSimulationMode::GPU && emitter.Buffer->GPU.HasValidCount)
113 {
114 result += *data;
115 }
116 ++data;
117 }
118 GPUParticlesCountReadback->Unmap();
119 }
120 }
121 else if (Emitters.HasItems())
122 {
123 // Initialize readback buffer (next GPU particles simulation update will copy the particle counters)
124 if (!GPUParticlesCountReadback)
125 GPUParticlesCountReadback = GPUDevice::Instance->CreateBuffer(TEXT("GPUParticlesCountReadback"));
126 const auto desc = GPUBufferDescription::Buffer(Emitters.Count() * sizeof(uint32), GPUBufferFlags::None, PixelFormat::Unknown, nullptr, sizeof(uint32), GPUResourceUsage::StagingReadback);
127 if (GPUParticlesCountReadback->Init(desc))
128 {
129 LOG(Error, "Failed to create GPU particles count readback buffer.");
130 }
131 }
132
133 return result;
134}
135
136void ParticleSystemInstance::ClearState()
137{

Callers

nothing calls this directly

Calls 8

IsAllocatedMethod · 0.80
BufferClass · 0.50
MapMethod · 0.45
UnmapMethod · 0.45
HasItemsMethod · 0.45
CreateBufferMethod · 0.45
CountMethod · 0.45
InitMethod · 0.45

Tested by

no test coverage detected