| 105 | } |
| 106 | |
| 107 | bool ParticleBuffer::Init(ParticleEmitter* emitter) |
| 108 | { |
| 109 | PROFILE_MEM(Particles); |
| 110 | ASSERT(emitter && emitter->IsLoaded()); |
| 111 | |
| 112 | Version = emitter->Graph.Version; |
| 113 | Capacity = emitter->Capacity; |
| 114 | Emitter = emitter; |
| 115 | Layout = &emitter->Graph.Layout; |
| 116 | Stride = Layout->Size; |
| 117 | Mode = emitter->SimulationMode; |
| 118 | |
| 119 | const int32 size = Capacity * Stride; |
| 120 | switch (Mode) |
| 121 | { |
| 122 | case ParticlesSimulationMode::CPU: |
| 123 | { |
| 124 | CPU.Count = 0; |
| 125 | CPU.Buffer.Resize(size); |
| 126 | CPU.RibbonOrder.Resize(0); |
| 127 | GPU.Buffer = GPUDevice::Instance->CreateBuffer(TEXT("ParticleBuffer")); |
| 128 | if (GPU.Buffer->Init(GPUBufferDescription::Raw(size, GPUBufferFlags::ShaderResource, GPUResourceUsage::Dynamic))) |
| 129 | return true; |
| 130 | break; |
| 131 | } |
| 132 | #if COMPILE_WITH_GPU_PARTICLES |
| 133 | case ParticlesSimulationMode::GPU: |
| 134 | { |
| 135 | if (!emitter->GPU.IsInitialized()) |
| 136 | { |
| 137 | LOG(Warning, "GPU particles context is not initialized. Cannot create particles buffer."); |
| 138 | return true; |
| 139 | } |
| 140 | |
| 141 | // Particle data buffer: attributes + counter + custom data |
| 142 | GPU.Buffer = GPUDevice::Instance->CreateBuffer(TEXT("ParticleBuffer A")); |
| 143 | if (GPU.Buffer->Init(GPUBufferDescription::Raw(size + sizeof(uint32) + emitter->GPU.CustomDataSize, GPUBufferFlags::ShaderResource | GPUBufferFlags::UnorderedAccess))) |
| 144 | return true; |
| 145 | GPU.BufferSecondary = GPUDevice::Instance->CreateBuffer(TEXT("ParticleBuffer B")); |
| 146 | if (GPU.BufferSecondary->Init(GPU.Buffer->GetDescription())) |
| 147 | return true; |
| 148 | GPU.PendingClear = true; |
| 149 | GPU.HasValidCount = false; |
| 150 | GPU.ParticleCounterOffset = size; |
| 151 | GPU.ParticlesCountMax = 0; |
| 152 | break; |
| 153 | } |
| 154 | #endif |
| 155 | default: |
| 156 | CRASH; |
| 157 | } |
| 158 | |
| 159 | return false; |
| 160 | } |
| 161 | |
| 162 | bool ParticleBuffer::AllocateSortBuffer() |
| 163 | { |
no test coverage detected