group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
GpuParticleBuffer Class Reference

Manages a GPU storage buffer + CPU-side transfer buffer pair for particle data. More...

#include <GpuParticleBuffer.hpp>

Public Types

enum class  Mode { Storage , Vertex }

Public Member Functions

void init (SDL_GPUDevice *dev, uint32_t maxBytes, Mode mode=Mode::Storage)
 Allocate GPU + transfer buffers of maxBytes each.
void quit ()
 Release all GPU resources.
void upload (SDL_GPUCommandBuffer *cmd, const void *data, uint32_t count, uint32_t stride)
 Upload count * stride bytes from data to the GPU buffer.
void bindAsVertexStorage (SDL_GPURenderPass *pass, uint32_t slot) const
 Bind as a vertex storage buffer at the given slot.
void bindAsVertex (SDL_GPURenderPass *pass) const
 Bind as a vertex buffer at binding index 0.
uint32_t liveCount () const
uint32_t capacityBytes () const

Private Attributes

SDL_GPUDevice * device_ = nullptr
SDL_GPUBuffer * gpuBuf_ = nullptr
SDL_GPUTransferBuffer * transfer_ = nullptr
uint32_t capacity_ = 0
 Bytes allocated.
uint32_t liveCount_ = 0
 Updated by upload().

Detailed Description

Manages a GPU storage buffer + CPU-side transfer buffer pair for particle data.

Two usage modes are supported:

Storage mode (default): GPU buffer created with SDL_GPU_BUFFERUSAGE_GRAPHICS_STORAGE_READ. Vertex shaders read particle data as a readonly storage buffer via gl_InstanceIndex. Bound with bindAsVertexStorage().

Vertex mode: GPU buffer created with SDL_GPU_BUFFERUSAGE_VERTEX. Used for pre-expanded flat vertex streams (ribbon trails, lightning arcs). Bound with bindAsVertex().

In both cases upload() must be called inside a copy pass, BEFORE the render pass begins.

Member Enumeration Documentation

◆ Mode

enum class GpuParticleBuffer::Mode
strong
Enumerator
Storage 
Vertex 

Member Function Documentation

◆ bindAsVertex()

void GpuParticleBuffer::bindAsVertex ( SDL_GPURenderPass * pass) const

Bind as a vertex buffer at binding index 0.

Precondition
Mode::Vertex, called inside a render pass.

◆ bindAsVertexStorage()

void GpuParticleBuffer::bindAsVertexStorage ( SDL_GPURenderPass * pass,
uint32_t slot ) const

Bind as a vertex storage buffer at the given slot.

Precondition
Mode::Storage, called inside a render pass.

◆ capacityBytes()

uint32_t GpuParticleBuffer::capacityBytes ( ) const
inlinenodiscard

◆ init()

void GpuParticleBuffer::init ( SDL_GPUDevice * dev,
uint32_t maxBytes,
Mode mode = Mode::Storage )

Allocate GPU + transfer buffers of maxBytes each.

◆ liveCount()

uint32_t GpuParticleBuffer::liveCount ( ) const
inlinenodiscard

◆ quit()

void GpuParticleBuffer::quit ( )

Release all GPU resources.

◆ upload()

void GpuParticleBuffer::upload ( SDL_GPUCommandBuffer * cmd,
const void * data,
uint32_t count,
uint32_t stride )

Upload count * stride bytes from data to the GPU buffer.

Opens and closes its own SDL_GPUCopyPass internally. Must be called BEFORE SDL_BeginGPURenderPass.

Member Data Documentation

◆ capacity_

uint32_t GpuParticleBuffer::capacity_ = 0
private

Bytes allocated.

◆ device_

SDL_GPUDevice* GpuParticleBuffer::device_ = nullptr
private

◆ gpuBuf_

SDL_GPUBuffer* GpuParticleBuffer::gpuBuf_ = nullptr
private

◆ liveCount_

uint32_t GpuParticleBuffer::liveCount_ = 0
private

Updated by upload().

◆ transfer_

SDL_GPUTransferBuffer* GpuParticleBuffer::transfer_ = nullptr
private

The documentation for this class was generated from the following files: