Loads a TTF font, bakes an SDF glyph atlas, and uploads it to the GPU.
More...
#include <SdfAtlas.hpp>
|
| 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 GlyphInfo * | glyph (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 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.
|
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.
◆ bindFragment()
| void SdfAtlas::bindFragment |
( |
SDL_GPURenderPass * | pass, |
|
|
uint32_t | slot ) const |
Bind the SDF atlas texture and sampler to a fragment sampler slot.
- Parameters
-
| pass | Active render pass. |
| slot | Fragment 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
-
| codepoint | Unicode 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.
◆ gpuTexture()
| SDL_GPUTexture * SdfAtlas::gpuTexture |
( |
| ) |
const |
|
inlinenodiscard |
GPU texture containing the baked SDF atlas (R8_UNORM, 1024x1024).
- Returns
- SDL GPU texture handle.
◆ init()
| bool SdfAtlas::init |
( |
SDL_GPUDevice * | dev, |
|
|
const char * | ttfPath ) |
Load TTF from path, bake SDF, upload to GPU.
- Parameters
-
| dev | GPU device to upload the atlas texture to. |
| ttfPath | Filesystem path to the TTF font file. |
- Returns
- true on success.
◆ 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.
◆ device_
| SDL_GPUDevice* SdfAtlas::device_ = nullptr |
|
private |
◆ glyphs_
◆ 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 |
◆ 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: