Expand description
Glyph vertex cache for the GL rendering path.
§Problem
fill_text called shape_and_flatten_text_via_agg every frame, running
rustybuzz shaping + AGG ConvCurve Bézier flattening + tess2 tessellation
for every visible text string. On a frame with ~20 text strings this
dominated render time (~60 ms/frame).
§Solution
GlyphCache tessellates each (font, glyph_id, size) triple once and
stores the resulting triangle mesh in glyph-local pixel coordinates
(origin 0, 0; scaled by size / units_per_em). On subsequent frames the
caller offsets those vertices by the glyph’s screen position and uploads
directly to the GPU — no Bézier evaluation or tessellation.
§Key design choices
- One entry per (font_ptr, glyph_id, size_bits) — different sizes produce different tessellations; identical sizes share a single entry.
- Glyph-local coordinates — the CTM is applied at draw time
(
transform_pt(pen_x + vx, y + vy)), which is correct for any affine transform including rotation. Noneentries are cached too — so glyphs without outlines (space, tab) never re-enter the shaper.- The cache is never cleared between frames (
reset()must NOT callglyph_cache.clear()); it grows until the widget tree changes fonts or sizes, then entries for the old parameters simply become dead weight (acceptable for typical UI workloads).
Structs§
- Cached
Glyph - Pre-tessellated triangle mesh for one glyph at a specific pixel size.
- Glyph
Cache - Per-frame glyph vertex cache shared by one [
GlGfxCtx] instance.