java.lang.Object
eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.textcanvas.SdfGlyphCache

public final class SdfGlyphCache extends Object
Per-glyph signed distance field (SDF) cache for sharp text rendering.

Instead of storing ink coverage (a photocopy of the glyph that blurs under any resampling), a distance field stores, per texel, the distance to the nearest glyph edge — negative inside the ink, positive outside. The rasterizer re-derives the edge per screen pixel from this smooth field, so text stays sharp at any magnification and degrades to clean gray under minification instead of aliasing.

Each glyph is rendered at SUPERSAMPLEx the cell resolution with anti-aliasing (giving the contour sub-texel precision), converted to a signed distance field by an exact Euclidean distance transform (Felzenszwalb & Huttenlocher separable EDT), clamped to SPREAD_TEXELS texels of gradient around the edge, and downsampled by averaging to the cell size. Results are cached per character; stamping a glyph into a canvas mask is a small block copy.

Mask values: 0 = deep inside ink, 127/128 = the edge, 255 = far outside any glyph. The matching coverage formula lives in TexturedTriangle's SDF scanline path.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    Width of the distance gradient around the glyph edge, in primary-texture texels.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int[]
    glyphMask(char c)
    Returns the cached GLYPH_W x GLYPH_H distance field for the given character, generating it on first access.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SPREAD_TEXELS

      public static final double SPREAD_TEXELS
      Width of the distance gradient around the glyph edge, in primary-texture texels. The normalized mask value 0.5 +/- 0.5 spans -SPREAD..+SPREAD texels of signed distance.
      See Also:
  • Method Details

    • glyphMask

      public static int[] glyphMask(char c)
      Returns the cached GLYPH_W x GLYPH_H distance field for the given character, generating it on first access. Values 0 (inside ink) .. 255 (far outside), edge at ~127.5.
      Parameters:
      c - the character
      Returns:
      the glyph mask (row-major, one int per texel, do not modify)