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 = 48 |
| | Rasterisation size in pixels.
|
| |
| static constexpr int | k_spread = 8 |
| | SDF spread in pixels.
|
| |
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.
◆ 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 |
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 |
|
inline |
Linear-clamp sampler for the SDF atlas.
- Returns
- SDL GPU sampler handle.
◆ gpuTexture()
| SDL_GPUTexture * SdfAtlas::gpuTexture |
( |
| ) |
const |
|
inline |
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 |
|
inline |
Check whether the atlas has been successfully initialised.
- Returns
- true if the GPU texture is valid.
◆ scale()
| float SdfAtlas::scale |
( |
| ) |
const |
|
inline |
Raw scale factor: bake pixels per em unit.
- Returns
- Scale factor used during atlas bake.
◆ 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 |
The documentation for this class was generated from the following files: