group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
SdfAtlas.hpp
Go to the documentation of this file.
1
3
4#pragma once
5
6#include "SdfFont.hpp"
7
8#include <SDL3/SDL.h>
9
10#include <glm/glm.hpp>
11
18{
19public:
20 static constexpr int k_atlasW = 1024;
21 static constexpr int k_atlasH = 1024;
22 static constexpr int k_renderPx = 48;
23 static constexpr int k_spread = 8;
24
29 bool init(SDL_GPUDevice* dev, const char* ttfPath);
30
32 void quit();
33
37 [[nodiscard]] const GlyphInfo* glyph(uint32_t codepoint) const;
38
42 void bindFragment(SDL_GPURenderPass* pass, uint32_t slot) const;
43
46 [[nodiscard]] float scale() const { return scale_; }
47
50 [[nodiscard]] bool ready() const { return texture_ != nullptr; }
51
54 [[nodiscard]] SDL_GPUTexture* gpuTexture() const { return texture_; }
55
58 [[nodiscard]] SDL_GPUSampler* gpuSampler() const { return sampler_; }
59
60private:
61 SDL_GPUDevice* device_ = nullptr;
62 SDL_GPUTexture* texture_ = nullptr;
63 SDL_GPUSampler* sampler_ = nullptr;
64 GlyphMap glyphs_;
65 float scale_ = 1.f;
66};
Glyph metric types for the SDF text rendering system.
std::unordered_map< uint32_t, GlyphInfo > GlyphMap
Immutable glyph metrics table keyed by Unicode codepoint.
Definition SdfFont.hpp:22
Loads a TTF font, bakes an SDF glyph atlas, and uploads it to the GPU.
Definition SdfAtlas.hpp:18
bool init(SDL_GPUDevice *dev, const char *ttfPath)
Load TTF from path, bake SDF, upload to GPU.
Definition SdfAtlas.cpp:100
float scale() const
Raw scale factor: bake pixels per em unit.
Definition SdfAtlas.hpp:46
static constexpr int k_spread
SDF spread in pixels.
Definition SdfAtlas.hpp:23
static constexpr int k_atlasH
Definition SdfAtlas.hpp:21
const GlyphInfo * glyph(uint32_t codepoint) const
Look up glyph metrics.
Definition SdfAtlas.cpp:252
static constexpr int k_atlasW
Definition SdfAtlas.hpp:20
SDL_GPUTexture * gpuTexture() const
GPU texture containing the baked SDF atlas (R8_UNORM, 1024x1024).
Definition SdfAtlas.hpp:54
void quit()
Release GPU resources owned by this atlas.
Definition SdfAtlas.cpp:235
SDL_GPUSampler * gpuSampler() const
Linear-clamp sampler for the SDF atlas.
Definition SdfAtlas.hpp:58
void bindFragment(SDL_GPURenderPass *pass, uint32_t slot) const
Bind the SDF atlas texture and sampler to a fragment sampler slot.
Definition SdfAtlas.cpp:261
static constexpr int k_renderPx
Rasterisation size in pixels.
Definition SdfAtlas.hpp:22
bool ready() const
Check whether the atlas has been successfully initialised.
Definition SdfAtlas.hpp:50
Per-glyph metrics stored after SDF atlas bake.
Definition SdfFont.hpp:12