#1565·melonJS

Text: dynamic glyph atlas (rasterize glyphs once, compose strings as per-glyph quads)

Author: obiotCreated Aug 6, 2026Updated Aug 6, 2026

Summary

The structural fix for dynamic text, split out of #1554's re-scope: instead of baking every Text string into its own canvas-backed texture (re-uploaded on every content change), rasterize glyphs on demand into a shared atlas and compose strings as per-glyph quads — changing a string then allocates nothing and uploads at most the few glyphs never seen before.

Why

  • Canvas-text churn is a whole class of cost: every content change re-bakes a canvas and re-uploads a texture (and on a size-bucket change, reallocates it — see #1554). Counters, timers, damage numbers and typewriter text pay it continuously.
  • BitmapText already proves the compose-from-quads path in the engine, but requires pre-baked font assets. This ticket is the runtime-generated equivalent for system/web fonts: same rendering model, glyphs sourced from canvas rasterization on first use.

Sketch

  • A shared glyph atlas texture per (font, size, style, resolution) family, packed shelf-style; glyphs rasterized on demand via the existing canvas measurement/draw path.
  • Text.draw composes per-glyph quads through the quad batcher (multi-texture batching keeps several atlas pages in one draw on 20.0 backends).
  • Metrics/kerning from the existing TextMetrics; fallback to the current canvas bake for features the atlas can't compose (e.g. complex shaping), so the change is incremental.
  • Atlas residency and eviction should ride the #1410 texture-identity refactor rather than invent a parallel lifetime scheme — this ticket is gated on #1410.

Non-goals

  • Replacing BitmapText (pre-baked fonts remain the zero-rasterization option).
  • Distance-field text rendering — a possible later evolution of the same atlas, not part of this.