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
 

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.
Here is the caller graph for this function:

◆ 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.
Here is the caller graph for this function:

◆ capacityBytes()

uint32_t GpuParticleBuffer::capacityBytes ( ) const
inline

◆ init()

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

Allocate GPU + transfer buffers of maxBytes each.

Here is the caller graph for this function:

◆ liveCount()

uint32_t GpuParticleBuffer::liveCount ( ) const
inline
Here is the caller graph for this function:

◆ quit()

void GpuParticleBuffer::quit ( )

Release all GPU resources.

Here is the caller graph for this function:

◆ 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.

Here is the caller graph for this function:

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