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

Renders batched HUD geometry to an offscreen RGBA8 texture. More...

#include <HudRenderer.hpp>

Classes

struct  ScreenUniforms

Public Member Functions

bool init (SDL_GPUDevice *device, SDL_GPUShaderFormat shaderFormat, const SdfAtlas &sdfAtlas, uint32_t screenW, uint32_t screenH)
 Initialise GPU resources.
void quit ()
 Release all GPU resources.
void resize (uint32_t newW, uint32_t newH)
 Recreate the offscreen target on window resize.
void render (std::span< const HudVertex > vertices, std::span< const std::array< float, 6 > > clipRects)
 Upload vertex data, execute the HUD render pass, and submit.
SDL_GPUTexture * getOutputTexture () const
 The offscreen texture to be blitted by the renderer.
uint32_t width () const
 Current target width.
uint32_t height () const
 Current target height.

Private Member Functions

bool createOffscreenTarget (uint32_t w, uint32_t h)
bool createPipeline ()
bool ensureVertexBuffer (uint32_t requiredVertices)
SDL_GPUShader * loadShader (const char *name, SDL_GPUShaderStage stage, uint32_t samplerCount, uint32_t uniformBufferCount)
 Load a compiled shader from the shaders/ directory.

Private Attributes

SDL_GPUDevice * device_ = nullptr
SDL_GPUShaderFormat shaderFormat_ = SDL_GPU_SHADERFORMAT_INVALID
SDL_GPUTexture * offscreenTarget_ = nullptr
uint32_t width_ = 0
uint32_t height_ = 0
SDL_GPUGraphicsPipeline * pipeline_ = nullptr
SDL_GPUTexture * sdfAtlasTex_ = nullptr
 Non-owning: from SdfAtlas.
SDL_GPUSampler * sdfAtlasSamp_ = nullptr
 Non-owning: from SdfAtlas.
SDL_GPUTexture * iconAtlasTex_ = nullptr
 Owning: 1x1 white fallback until real atlas.
SDL_GPUSampler * iconAtlasSamp_ = nullptr
 Owning.
SDL_GPUBuffer * vertexBuffer_ = nullptr
SDL_GPUTransferBuffer * transferBuffer_ = nullptr
uint32_t vertexCapacity_ = 0
 Current buffer capacity in vertices.

Detailed Description

Renders batched HUD geometry to an offscreen RGBA8 texture.

Owns the GPU pipeline, offscreen render target, dynamic vertex buffer, and sampler bindings. The renderer (legacy/new) reads getOutputTexture() and blits it after tone mapping.

Member Function Documentation

◆ createOffscreenTarget()

bool HudRenderer::createOffscreenTarget ( uint32_t w,
uint32_t h )
private
Here is the caller graph for this function:

◆ createPipeline()

bool HudRenderer::createPipeline ( )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ensureVertexBuffer()

bool HudRenderer::ensureVertexBuffer ( uint32_t requiredVertices)
private
Here is the caller graph for this function:

◆ getOutputTexture()

SDL_GPUTexture * HudRenderer::getOutputTexture ( ) const
inlinenodiscard

The offscreen texture to be blitted by the renderer.

◆ height()

uint32_t HudRenderer::height ( ) const
inlinenodiscard

Current target height.

◆ init()

bool HudRenderer::init ( SDL_GPUDevice * device,
SDL_GPUShaderFormat shaderFormat,
const SdfAtlas & sdfAtlas,
uint32_t screenW,
uint32_t screenH )

Initialise GPU resources.

Parameters
deviceShared SDL GPU device.
shaderFormatSPIR-V, MSL, or DXIL.
sdfAtlasFont atlas for SDF text rendering.
screenWInitial viewport width.
screenHInitial viewport height.
Returns
true on success.
Here is the call graph for this function:

◆ loadShader()

SDL_GPUShader * HudRenderer::loadShader ( const char * name,
SDL_GPUShaderStage stage,
uint32_t samplerCount,
uint32_t uniformBufferCount )
private

Load a compiled shader from the shaders/ directory.

Here is the caller graph for this function:

◆ quit()

void HudRenderer::quit ( )

Release all GPU resources.

◆ render()

void HudRenderer::render ( std::span< const HudVertex > vertices,
std::span< const std::array< float, 6 > > clipRects )

Upload vertex data, execute the HUD render pass, and submit.

Acquires its own command buffer, clears the offscreen target to transparent black, draws all batched quads, and submits.

Parameters
verticesFlat vertex array produced by HudContext.
clipRectsParallel array of clip rects for scissor state changes. Each entry is {startVertex, vertexCount, x, y, w, h}.
Here is the call graph for this function:

◆ resize()

void HudRenderer::resize ( uint32_t newW,
uint32_t newH )

Recreate the offscreen target on window resize.

Here is the call graph for this function:

◆ width()

uint32_t HudRenderer::width ( ) const
inlinenodiscard

Current target width.

Member Data Documentation

◆ device_

SDL_GPUDevice* HudRenderer::device_ = nullptr
private

◆ height_

uint32_t HudRenderer::height_ = 0
private

◆ iconAtlasSamp_

SDL_GPUSampler* HudRenderer::iconAtlasSamp_ = nullptr
private

Owning.

◆ iconAtlasTex_

SDL_GPUTexture* HudRenderer::iconAtlasTex_ = nullptr
private

Owning: 1x1 white fallback until real atlas.

◆ offscreenTarget_

SDL_GPUTexture* HudRenderer::offscreenTarget_ = nullptr
private

◆ pipeline_

SDL_GPUGraphicsPipeline* HudRenderer::pipeline_ = nullptr
private

◆ sdfAtlasSamp_

SDL_GPUSampler* HudRenderer::sdfAtlasSamp_ = nullptr
private

Non-owning: from SdfAtlas.

◆ sdfAtlasTex_

SDL_GPUTexture* HudRenderer::sdfAtlasTex_ = nullptr
private

Non-owning: from SdfAtlas.

◆ shaderFormat_

SDL_GPUShaderFormat HudRenderer::shaderFormat_ = SDL_GPU_SHADERFORMAT_INVALID
private

◆ transferBuffer_

SDL_GPUTransferBuffer* HudRenderer::transferBuffer_ = nullptr
private

◆ vertexBuffer_

SDL_GPUBuffer* HudRenderer::vertexBuffer_ = nullptr
private

◆ vertexCapacity_

uint32_t HudRenderer::vertexCapacity_ = 0
private

Current buffer capacity in vertices.

◆ width_

uint32_t HudRenderer::width_ = 0
private

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