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

Owns all particle GPU pipelines and per-category GPU buffers. More...

#include <ParticleRenderer.hpp>

Collaboration diagram for ParticleRenderer:
[legend]

Public Member Functions

bool init (SDL_GPUDevice *dev, SDL_GPUTextureFormat colorFmt, SDL_GPUShaderFormat shaderFmt)
 Initialise GPU pipelines, buffers, and procedural textures.
void quit ()
 Release all GPU pipelines, buffers, and textures.
void uploadBillboards (SDL_GPUCommandBuffer *cmd, const BillboardParticle *data, uint32_t count)
 Upload billboard particle data to the GPU.
void uploadTracers (SDL_GPUCommandBuffer *cmd, const TracerParticle *data, uint32_t count)
 Upload tracer particle data to the GPU.
void uploadRibbon (SDL_GPUCommandBuffer *cmd, const RibbonVertex *data, uint32_t count)
 Upload ribbon vertex data to the GPU.
void uploadHitscan (SDL_GPUCommandBuffer *cmd, const HitscanBeam *data, uint32_t count)
 Upload hitscan beam data to the GPU.
void uploadArcs (SDL_GPUCommandBuffer *cmd, const ArcVertex *data, uint32_t count)
 Upload lightning arc vertex data to the GPU.
void uploadSmoke (SDL_GPUCommandBuffer *cmd, const SmokeParticle *data, uint32_t count)
 Upload smoke particle data to the GPU.
void uploadDecals (SDL_GPUCommandBuffer *cmd, const DecalInstance *data, uint32_t count)
 Upload decal instance data to the GPU.
void uploadSdfWorld (SDL_GPUCommandBuffer *cmd, const SdfGlyphGPU *data, uint32_t count)
 Upload world-space SDF glyph data to the GPU.
void uploadSdfHud (SDL_GPUCommandBuffer *cmd, const SdfGlyphGPU *data, uint32_t count)
 Upload HUD SDF glyph data to the GPU.
void drawAll (SDL_GPURenderPass *pass, SDL_GPUCommandBuffer *cmd, float screenW, float screenH)
 Issue all particle draw calls in the correct blend/depth order.
SDL_GPUTexture * smokeNoiseTex () const
SDL_GPUSampler * smokeSampler () const
void setSdfAtlas (SDL_GPUTexture *tex, SDL_GPUSampler *samp)
 Register the SDF glyph atlas so drawAll() can bind it before drawing text.

Private Member Functions

bool buildPipelines ()
 Create all graphics pipelines for each particle category.
SDL_GPUGraphicsPipeline * makeStoragePipeline (const char *vertName, const char *fragName, uint32_t storageBufs, uint32_t samplers, SDL_GPUColorTargetBlendState blend, bool depthTest, bool depthWrite, bool depthBias, SDL_GPUPrimitiveType prim=SDL_GPU_PRIMITIVETYPE_TRIANGLELIST)
 Create a pipeline that reads particle data from a storage buffer.
SDL_GPUGraphicsPipeline * makeVertexPipeline (const char *vertName, const char *fragName, SDL_GPUVertexInputState vertexInput, SDL_GPUColorTargetBlendState blend, bool depthTest, bool depthWrite, SDL_GPUPrimitiveType prim=SDL_GPU_PRIMITIVETYPE_TRIANGLELIST)
 Create a pipeline that reads particle data from a vertex buffer.
void buildQuadIndexBuffer ()
 Build the shared quad index buffer ({0,1,2,2,3,0} x N).
void buildSmokeNoise ()
 Generate and upload the procedural smoke noise texture.
void buildDecalTexture ()
 Generate and upload the procedural bullet-hole decal texture.

Static Private Member Functions

static SDL_GPUColorTargetBlendState additiveBlend ()
 Return an additive blend state (src*alpha + dst*1).
static SDL_GPUColorTargetBlendState premulAlphaBlend ()
 Return a pre-multiplied alpha blend state (src*1 + dst*(1-srcAlpha)).
static SDL_GPUColorTargetBlendState alphaBlend ()
 Return a standard alpha blend state (src*alpha + dst*(1-srcAlpha)).

Private Attributes

SDL_GPUDevice * device_ = nullptr
SDL_GPUShaderFormat shaderFmt_ = SDL_GPU_SHADERFORMAT_INVALID
SDL_GPUTextureFormat colorFmt_ = SDL_GPU_TEXTUREFORMAT_INVALID
SDL_GPUGraphicsPipeline * billboardPipeline_ = nullptr
SDL_GPUGraphicsPipeline * tracerPipeline_ = nullptr
SDL_GPUGraphicsPipeline * ribbonPipeline_ = nullptr
SDL_GPUGraphicsPipeline * hitscanPipeline_ = nullptr
SDL_GPUGraphicsPipeline * arcPipeline_ = nullptr
SDL_GPUGraphicsPipeline * smokePipeline_ = nullptr
SDL_GPUGraphicsPipeline * decalPipeline_ = nullptr
SDL_GPUGraphicsPipeline * sdfWorldPipeline_ = nullptr
SDL_GPUGraphicsPipeline * sdfHudPipeline_ = nullptr
SDL_GPUBuffer * quadIndexBuf_ = nullptr
GpuParticleBuffer billboardBuf_
GpuParticleBuffer tracerBuf_
GpuParticleBuffer ribbonBuf_
GpuParticleBuffer hitscanBuf_
GpuParticleBuffer arcBuf_
GpuParticleBuffer smokeBuf_
GpuParticleBuffer decalBuf_
GpuParticleBuffer sdfWorldBuf_
GpuParticleBuffer sdfHudBuf_
SDL_GPUTexture * smokeNoise_ = nullptr
SDL_GPUSampler * smokeSampler_ = nullptr
SDL_GPUTexture * decalTex_ = nullptr
SDL_GPUSampler * decalSamp_ = nullptr
SDL_GPUTexture * sdfAtlasTex_ = nullptr
SDL_GPUSampler * sdfAtlasSamp_ = nullptr

Static Private Attributes

static constexpr uint32_t k_maxQuadInstances = 4096

Detailed Description

Owns all particle GPU pipelines and per-category GPU buffers.

ParticleSystem calls uploadAll() (before render pass) and drawAll() (inside render pass).

Member Function Documentation

◆ additiveBlend()

SDL_GPUColorTargetBlendState ParticleRenderer::additiveBlend ( )
staticprivate

Return an additive blend state (src*alpha + dst*1).

Here is the caller graph for this function:

◆ alphaBlend()

SDL_GPUColorTargetBlendState ParticleRenderer::alphaBlend ( )
staticprivate

Return a standard alpha blend state (src*alpha + dst*(1-srcAlpha)).

Here is the caller graph for this function:

◆ buildDecalTexture()

void ParticleRenderer::buildDecalTexture ( )
private

Generate and upload the procedural bullet-hole decal texture.

Here is the caller graph for this function:

◆ buildPipelines()

bool ParticleRenderer::buildPipelines ( )
nodiscardprivate

Create all graphics pipelines for each particle category.

Returns
True if all pipelines were created successfully.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ buildQuadIndexBuffer()

void ParticleRenderer::buildQuadIndexBuffer ( )
private

Build the shared quad index buffer ({0,1,2,2,3,0} x N).

Here is the caller graph for this function:

◆ buildSmokeNoise()

void ParticleRenderer::buildSmokeNoise ( )
private

Generate and upload the procedural smoke noise texture.

Here is the caller graph for this function:

◆ drawAll()

void ParticleRenderer::drawAll ( SDL_GPURenderPass * pass,
SDL_GPUCommandBuffer * cmd,
float screenW,
float screenH )

Issue all particle draw calls in the correct blend/depth order.

Parameters
passThe active render pass.
cmdThe command buffer (for push uniforms).
screenWWindow width in pixels for HUD uniform.
screenHWindow height in pixels for HUD uniform.

◆ init()

bool ParticleRenderer::init ( SDL_GPUDevice * dev,
SDL_GPUTextureFormat colorFmt,
SDL_GPUShaderFormat shaderFmt )

Initialise GPU pipelines, buffers, and procedural textures.

Parameters
devThe SDL GPU device.
colorFmtSwapchain colour format.
shaderFmtShader binary format (SPIRV or MSL).
Returns
True on success.
Here is the call graph for this function:

◆ makeStoragePipeline()

SDL_GPUGraphicsPipeline * ParticleRenderer::makeStoragePipeline ( const char * vertName,
const char * fragName,
uint32_t storageBufs,
uint32_t samplers,
SDL_GPUColorTargetBlendState blend,
bool depthTest,
bool depthWrite,
bool depthBias,
SDL_GPUPrimitiveType prim = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST )
nodiscardprivate

Create a pipeline that reads particle data from a storage buffer.

Parameters
vertNameVertex shader filename (without path/extension).
fragNameFragment shader filename (without path/extension).
storageBufsNumber of storage buffers bound to the vertex stage.
samplersNumber of texture samplers bound to the fragment stage.
blendColour target blend state.
depthTestEnable depth testing.
depthWriteEnable depth writes.
depthBiasEnable depth bias (for decals).
primPrimitive topology.
Returns
The created pipeline, or nullptr on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ makeVertexPipeline()

SDL_GPUGraphicsPipeline * ParticleRenderer::makeVertexPipeline ( const char * vertName,
const char * fragName,
SDL_GPUVertexInputState vertexInput,
SDL_GPUColorTargetBlendState blend,
bool depthTest,
bool depthWrite,
SDL_GPUPrimitiveType prim = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST )
nodiscardprivate

Create a pipeline that reads particle data from a vertex buffer.

Parameters
vertNameVertex shader filename (without path/extension).
fragNameFragment shader filename (without path/extension).
vertexInputVertex input layout description.
blendColour target blend state.
depthTestEnable depth testing.
depthWriteEnable depth writes.
primPrimitive topology.
Returns
The created pipeline, or nullptr on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ premulAlphaBlend()

SDL_GPUColorTargetBlendState ParticleRenderer::premulAlphaBlend ( )
staticprivate

Return a pre-multiplied alpha blend state (src*1 + dst*(1-srcAlpha)).

Here is the caller graph for this function:

◆ quit()

void ParticleRenderer::quit ( )

Release all GPU pipelines, buffers, and textures.

◆ setSdfAtlas()

void ParticleRenderer::setSdfAtlas ( SDL_GPUTexture * tex,
SDL_GPUSampler * samp )
inline

Register the SDF glyph atlas so drawAll() can bind it before drawing text.

Call this once after SdfAtlas::init() succeeds.

◆ smokeNoiseTex()

SDL_GPUTexture * ParticleRenderer::smokeNoiseTex ( ) const
inlinenodiscard

◆ smokeSampler()

SDL_GPUSampler * ParticleRenderer::smokeSampler ( ) const
inlinenodiscard

◆ uploadArcs()

void ParticleRenderer::uploadArcs ( SDL_GPUCommandBuffer * cmd,
const ArcVertex * data,
uint32_t count )

Upload lightning arc vertex data to the GPU.

Parameters
cmdActive command buffer.
dataPointer to arc vertex array.
countNumber of vertices to upload.

◆ uploadBillboards()

void ParticleRenderer::uploadBillboards ( SDL_GPUCommandBuffer * cmd,
const BillboardParticle * data,
uint32_t count )

Upload billboard particle data to the GPU.

Parameters
cmdActive command buffer.
dataPointer to billboard particle array.
countNumber of particles to upload.

◆ uploadDecals()

void ParticleRenderer::uploadDecals ( SDL_GPUCommandBuffer * cmd,
const DecalInstance * data,
uint32_t count )

Upload decal instance data to the GPU.

Parameters
cmdActive command buffer.
dataPointer to decal instance array.
countNumber of instances to upload.

◆ uploadHitscan()

void ParticleRenderer::uploadHitscan ( SDL_GPUCommandBuffer * cmd,
const HitscanBeam * data,
uint32_t count )

Upload hitscan beam data to the GPU.

Parameters
cmdActive command buffer.
dataPointer to hitscan beam array.
countNumber of beams to upload.

◆ uploadRibbon()

void ParticleRenderer::uploadRibbon ( SDL_GPUCommandBuffer * cmd,
const RibbonVertex * data,
uint32_t count )

Upload ribbon vertex data to the GPU.

Parameters
cmdActive command buffer.
dataPointer to ribbon vertex array.
countNumber of vertices to upload.

◆ uploadSdfHud()

void ParticleRenderer::uploadSdfHud ( SDL_GPUCommandBuffer * cmd,
const SdfGlyphGPU * data,
uint32_t count )

Upload HUD SDF glyph data to the GPU.

Parameters
cmdActive command buffer.
dataPointer to SDF glyph array.
countNumber of glyphs to upload.

◆ uploadSdfWorld()

void ParticleRenderer::uploadSdfWorld ( SDL_GPUCommandBuffer * cmd,
const SdfGlyphGPU * data,
uint32_t count )

Upload world-space SDF glyph data to the GPU.

Parameters
cmdActive command buffer.
dataPointer to SDF glyph array.
countNumber of glyphs to upload.

◆ uploadSmoke()

void ParticleRenderer::uploadSmoke ( SDL_GPUCommandBuffer * cmd,
const SmokeParticle * data,
uint32_t count )

Upload smoke particle data to the GPU.

Parameters
cmdActive command buffer.
dataPointer to smoke particle array.
countNumber of particles to upload.

◆ uploadTracers()

void ParticleRenderer::uploadTracers ( SDL_GPUCommandBuffer * cmd,
const TracerParticle * data,
uint32_t count )

Upload tracer particle data to the GPU.

Parameters
cmdActive command buffer.
dataPointer to tracer particle array.
countNumber of particles to upload.

Member Data Documentation

◆ arcBuf_

GpuParticleBuffer ParticleRenderer::arcBuf_
private

◆ arcPipeline_

SDL_GPUGraphicsPipeline* ParticleRenderer::arcPipeline_ = nullptr
private

◆ billboardBuf_

GpuParticleBuffer ParticleRenderer::billboardBuf_
private

◆ billboardPipeline_

SDL_GPUGraphicsPipeline* ParticleRenderer::billboardPipeline_ = nullptr
private

◆ colorFmt_

SDL_GPUTextureFormat ParticleRenderer::colorFmt_ = SDL_GPU_TEXTUREFORMAT_INVALID
private

◆ decalBuf_

GpuParticleBuffer ParticleRenderer::decalBuf_
private

◆ decalPipeline_

SDL_GPUGraphicsPipeline* ParticleRenderer::decalPipeline_ = nullptr
private

◆ decalSamp_

SDL_GPUSampler* ParticleRenderer::decalSamp_ = nullptr
private

◆ decalTex_

SDL_GPUTexture* ParticleRenderer::decalTex_ = nullptr
private

◆ device_

SDL_GPUDevice* ParticleRenderer::device_ = nullptr
private

◆ hitscanBuf_

GpuParticleBuffer ParticleRenderer::hitscanBuf_
private

◆ hitscanPipeline_

SDL_GPUGraphicsPipeline* ParticleRenderer::hitscanPipeline_ = nullptr
private

◆ k_maxQuadInstances

uint32_t ParticleRenderer::k_maxQuadInstances = 4096
staticconstexprprivate

◆ quadIndexBuf_

SDL_GPUBuffer* ParticleRenderer::quadIndexBuf_ = nullptr
private

◆ ribbonBuf_

GpuParticleBuffer ParticleRenderer::ribbonBuf_
private

◆ ribbonPipeline_

SDL_GPUGraphicsPipeline* ParticleRenderer::ribbonPipeline_ = nullptr
private

◆ sdfAtlasSamp_

SDL_GPUSampler* ParticleRenderer::sdfAtlasSamp_ = nullptr
private

◆ sdfAtlasTex_

SDL_GPUTexture* ParticleRenderer::sdfAtlasTex_ = nullptr
private

◆ sdfHudBuf_

GpuParticleBuffer ParticleRenderer::sdfHudBuf_
private

◆ sdfHudPipeline_

SDL_GPUGraphicsPipeline* ParticleRenderer::sdfHudPipeline_ = nullptr
private

◆ sdfWorldBuf_

GpuParticleBuffer ParticleRenderer::sdfWorldBuf_
private

◆ sdfWorldPipeline_

SDL_GPUGraphicsPipeline* ParticleRenderer::sdfWorldPipeline_ = nullptr
private

◆ shaderFmt_

SDL_GPUShaderFormat ParticleRenderer::shaderFmt_ = SDL_GPU_SHADERFORMAT_INVALID
private

◆ smokeBuf_

GpuParticleBuffer ParticleRenderer::smokeBuf_
private

◆ smokeNoise_

SDL_GPUTexture* ParticleRenderer::smokeNoise_ = nullptr
private

◆ smokePipeline_

SDL_GPUGraphicsPipeline* ParticleRenderer::smokePipeline_ = nullptr
private

◆ smokeSampler_

SDL_GPUSampler* ParticleRenderer::smokeSampler_ = nullptr
private

◆ tracerBuf_

GpuParticleBuffer ParticleRenderer::tracerBuf_
private

◆ tracerPipeline_

SDL_GPUGraphicsPipeline* ParticleRenderer::tracerPipeline_ = nullptr
private

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