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

Queues SDF glyph quads for world-space and screen-space text. More...

#include <SdfRenderer.hpp>

Collaboration diagram for SdfRenderer:
[legend]

Public Member Functions

bool init (SDL_GPUDevice *dev, const char *ttfPath)
 Initialise the renderer by loading a font and baking the SDF atlas.
void quit ()
 Release all resources owned by this renderer.
void drawWorldText (glm::vec3 worldPos, std::string_view text, glm::vec4 color, float worldHeight, glm::vec3 camRight, glm::vec3 camUp)
 Queue world-space billboard text (faces camera, depth-tested).
void drawScreenText (glm::vec2 pixelPos, std::string_view text, glm::vec4 color, float pixelHeight)
 Queue HUD text in pixel coordinates (no depth test).
void clear ()
 Clear queues (called at start of each frame).
const SdfGlyphGPU * worldData () const
 Get a pointer to the world-space glyph data buffer.
uint32_t worldCount () const
 Get the number of queued world-space glyphs.
const SdfGlyphGPU * hudData () const
 Get a pointer to the HUD glyph data buffer.
uint32_t hudCount () const
 Get the number of queued HUD glyphs.
bool ready () const
 Check whether the underlying atlas is ready for rendering.
const SdfAtlas & atlas () const
 Access the underlying SDF atlas (provides GPU texture binding).

Private Attributes

SdfAtlas atlas_
std::vector< SdfGlyphGPU > worldGlyphs_
std::vector< SdfGlyphGPU > hudGlyphs_

Detailed Description

Queues SDF glyph quads for world-space and screen-space text.

Call drawWorldText() / drawScreenText() each frame to queue text. The ParticleSystem flushes the queues during uploadToGpu() / render().

Member Function Documentation

◆ atlas()

const SdfAtlas & SdfRenderer::atlas ( ) const
inlinenodiscard

Access the underlying SDF atlas (provides GPU texture binding).

Returns
Const reference to the SdfAtlas.

◆ clear()

void SdfRenderer::clear ( )

Clear queues (called at start of each frame).

Clear all queued glyph data for the current frame.

◆ drawScreenText()

void SdfRenderer::drawScreenText ( glm::vec2 pixelPos,
std::string_view text,
glm::vec4 color,
float pixelHeight )

Queue HUD text in pixel coordinates (no depth test).

Parameters
pixelPosScreen-space position in pixels.
textUTF-8 text string to render.
colorRGBA colour for all glyphs.
pixelHeightDesired text height in pixels.

◆ drawWorldText()

void SdfRenderer::drawWorldText ( glm::vec3 worldPos,
std::string_view text,
glm::vec4 color,
float worldHeight,
glm::vec3 camRight,
glm::vec3 camUp )

Queue world-space billboard text (faces camera, depth-tested).

Parameters
worldPosWorld-space origin of the text baseline.
textUTF-8 text string to render.
colorRGBA colour for all glyphs.
worldHeightDesired text height in world units.
camRightCamera right vector for billboarding.
camUpCamera up vector for billboarding.

◆ hudCount()

uint32_t SdfRenderer::hudCount ( ) const
inlinenodiscard

Get the number of queued HUD glyphs.

Returns
HUD glyph count.

◆ hudData()

const SdfGlyphGPU * SdfRenderer::hudData ( ) const
inlinenodiscard

Get a pointer to the HUD glyph data buffer.

Returns
Pointer to the first HUD glyph, or nullptr if empty.

◆ init()

bool SdfRenderer::init ( SDL_GPUDevice * dev,
const char * ttfPath )

Initialise the renderer by loading a font and baking the SDF atlas.

Parameters
devGPU device used for atlas texture creation.
ttfPathFilesystem path to the TTF font file.
Returns
true on success.

◆ quit()

void SdfRenderer::quit ( )

Release all resources owned by this renderer.

◆ ready()

bool SdfRenderer::ready ( ) const
inlinenodiscard

Check whether the underlying atlas is ready for rendering.

Returns
true if the atlas texture is valid.

◆ worldCount()

uint32_t SdfRenderer::worldCount ( ) const
inlinenodiscard

Get the number of queued world-space glyphs.

Returns
World glyph count.

◆ worldData()

const SdfGlyphGPU * SdfRenderer::worldData ( ) const
inlinenodiscard

Get a pointer to the world-space glyph data buffer.

Returns
Pointer to the first world glyph, or nullptr if empty.

Member Data Documentation

◆ atlas_

SdfAtlas SdfRenderer::atlas_
private

◆ hudGlyphs_

std::vector<SdfGlyphGPU> SdfRenderer::hudGlyphs_
private

◆ worldGlyphs_

std::vector<SdfGlyphGPU> SdfRenderer::worldGlyphs_
private

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