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

Loads a TTF font, bakes an SDF glyph atlas, and uploads it to the GPU. More...

#include <SdfAtlas.hpp>

Public Member Functions

bool init (SDL_GPUDevice *dev, const char *ttfPath)
 Load TTF from path, bake SDF, upload to GPU.
void quit ()
 Release GPU resources owned by this atlas.
const GlyphInfoglyph (uint32_t codepoint) const
 Look up glyph metrics.
void bindFragment (SDL_GPURenderPass *pass, uint32_t slot) const
 Bind the SDF atlas texture and sampler to a fragment sampler slot.
float scale () const
 Raw scale factor: bake pixels per em unit.
bool ready () const
 Check whether the atlas has been successfully initialised.
SDL_GPUTexture * gpuTexture () const
 GPU texture containing the baked SDF atlas (R8_UNORM, 1024x1024).
SDL_GPUSampler * gpuSampler () const
 Linear-clamp sampler for the SDF atlas.

Static Public Attributes

static constexpr int k_atlasW = 1024
static constexpr int k_atlasH = 1024
static constexpr int k_renderPx = 72
 Rasterisation size in pixels.
static constexpr int k_spread = 12
 SDF spread in pixels.

Private Attributes

SDL_GPUDevice * device_ = nullptr
SDL_GPUTexture * texture_ = nullptr
SDL_GPUSampler * sampler_ = nullptr
GlyphMap glyphs_
float scale_ = 1.f

Detailed Description

Loads a TTF font, bakes an SDF glyph atlas, and uploads it to the GPU.

Uses stb_truetype's analytic SDF generator (stbtt_GetCodepointSDF) to compute distance fields directly from font vector outlines, then packs them into a 1024x1024 R8_UNORM atlas texture.

Member Function Documentation

◆ bindFragment()

void SdfAtlas::bindFragment ( SDL_GPURenderPass * pass,
uint32_t slot ) const

Bind the SDF atlas texture and sampler to a fragment sampler slot.

Parameters
passActive render pass.
slotFragment sampler slot index.

◆ glyph()

const GlyphInfo * SdfAtlas::glyph ( uint32_t codepoint) const
nodiscard

Look up glyph metrics.

Look up glyph metrics by Unicode codepoint.

Parameters
codepointUnicode codepoint to look up.
Returns
Pointer to glyph info, or nullptr if the codepoint was not baked.

◆ gpuSampler()

SDL_GPUSampler * SdfAtlas::gpuSampler ( ) const
inlinenodiscard

Linear-clamp sampler for the SDF atlas.

Returns
SDL GPU sampler handle.
Here is the caller graph for this function:

◆ gpuTexture()

SDL_GPUTexture * SdfAtlas::gpuTexture ( ) const
inlinenodiscard

GPU texture containing the baked SDF atlas (R8_UNORM, 1024x1024).

Returns
SDL GPU texture handle.
Here is the caller graph for this function:

◆ init()

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

Load TTF from path, bake SDF, upload to GPU.

Parameters
devGPU device to upload the atlas texture to.
ttfPathFilesystem path to the TTF font file.
Returns
true on success.
Here is the call graph for this function:

◆ quit()

void SdfAtlas::quit ( )

Release GPU resources owned by this atlas.

Release all GPU resources and reset internal state.

◆ ready()

bool SdfAtlas::ready ( ) const
inlinenodiscard

Check whether the atlas has been successfully initialised.

Returns
true if the GPU texture is valid.

◆ scale()

float SdfAtlas::scale ( ) const
inlinenodiscard

Raw scale factor: bake pixels per em unit.

Returns
Scale factor used during atlas bake.

Member Data Documentation

◆ device_

SDL_GPUDevice* SdfAtlas::device_ = nullptr
private

◆ glyphs_

GlyphMap SdfAtlas::glyphs_
private

◆ k_atlasH

int SdfAtlas::k_atlasH = 1024
staticconstexpr

◆ k_atlasW

int SdfAtlas::k_atlasW = 1024
staticconstexpr

◆ k_renderPx

int SdfAtlas::k_renderPx = 72
staticconstexpr

Rasterisation size in pixels.

◆ k_spread

int SdfAtlas::k_spread = 12
staticconstexpr

SDF spread in pixels.

◆ sampler_

SDL_GPUSampler* SdfAtlas::sampler_ = nullptr
private

◆ scale_

float SdfAtlas::scale_ = 1.f
private

◆ texture_

SDL_GPUTexture* SdfAtlas::texture_ = nullptr
private

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