| 89 | } |
| 90 | |
| 91 | int32 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 | |
| 136 | void ParticleSystemInstance::ClearState() |
| 137 | { |
nothing calls this directly
no test coverage detected