Class SdfGlyphCache
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
FieldsModifier and TypeFieldDescriptionstatic final doubleWidth of the distance gradient around the glyph edge, in primary-texture texels. -
Method Summary
Modifier and TypeMethodDescriptionstatic int[]glyphMask(char c) Returns the cachedGLYPH_WxGLYPH_Hdistance field for the given character, generating it on first access.
-
Field Details
-
SPREAD_TEXELS
public static final double SPREAD_TEXELSWidth 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 cachedGLYPH_WxGLYPH_Hdistance 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)
-