we (web engine): Experimental web browser project to understand the limits of Claude

Glyph texture atlas for GPU text rendering #117

open opened by pierrelf.com

Phase 12: Metal GPU Compositor (4/7)#

Goal: Pack rasterized glyph bitmaps into a GPU texture atlas for efficient text rendering.

Depends on: Metal texture management and image upload

Requirements#

  • Implement a texture atlas allocator:

    • Shelf-packing algorithm: maintain rows ("shelves") of glyphs sorted by height
    • Start with a reasonable atlas size (e.g., 1024×1024 R8 texture)
    • Grow or create additional atlas pages when full
    • Track allocated regions: (glyph_id, font_size) → AtlasRegion { x, y, width, height, atlas_page }
  • Integrate with existing glyph cache in text crate:

    • When a glyph is first rasterized (CPU scanline rasterizer), upload its grayscale bitmap to the atlas
    • Return UV coordinates for the glyph's region in the atlas
    • Existing CPU glyph cache can remain for software fallback
  • Provide an API for the Metal renderer:

    • Given a TextLine (list of positioned glyphs), produce a list of textured quads with atlas UV coordinates
    • Each quad: position from glyph metrics, UVs from atlas region, color from text color
  • Handle atlas invalidation:

    • Clear atlas when font size distribution changes significantly (rare)
    • Track atlas utilization metrics

Acceptance Criteria#

  • Glyph bitmaps are packed into a GPU texture atlas
  • Atlas lookup returns correct UV coordinates for each glyph
  • Text renders correctly using atlas quads (visual parity with software renderer)
  • Atlas grows or pages as needed when many unique glyphs are used
  • No external crate dependencies
  • cargo clippy --workspace -- -D warnings passes
  • cargo test --workspace passes
sign up or login to add to the discussion
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:meotu43t6usg4qdwzenk4s2t/sh.tangled.repo.issue/3mi4366fkxs2g