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 = 48
 Rasterisation size in pixels.
 
static constexpr int k_spread = 8
 SDF spread in pixels.
 

Detailed Description

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

Uses stb_truetype for glyph rasterization. The SDF is computed on the CPU (brute-force nearest-edge scan, spread = 8 px) and packed into a 1024x1024 R8_UNORM 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

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

◆ gpuSampler()

SDL_GPUSampler * SdfAtlas::gpuSampler ( ) const
inline

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
inline

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

◆ quit()

void SdfAtlas::quit ( )

Release GPU resources owned by this atlas.

Release all GPU resources and reset internal state.

Here is the caller graph for this function:

◆ ready()

bool SdfAtlas::ready ( ) const
inline

Check whether the atlas has been successfully initialised.

Returns
true if the GPU texture is valid.
Here is the caller graph for this function:

◆ scale()

float SdfAtlas::scale ( ) const
inline

Raw scale factor: bake pixels per em unit.

Returns
Scale factor used during atlas bake.

Member Data Documentation

◆ k_atlasH

constexpr int SdfAtlas::k_atlasH = 1024
staticconstexpr

◆ k_atlasW

constexpr int SdfAtlas::k_atlasW = 1024
staticconstexpr

◆ k_renderPx

constexpr int SdfAtlas::k_renderPx = 48
staticconstexpr

Rasterisation size in pixels.

◆ k_spread

constexpr int SdfAtlas::k_spread = 8
staticconstexpr

SDF spread in pixels.


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