7 releases

0.1.6 Jun 22, 2024
0.1.5 Nov 13, 2021
0.1.4 Jan 21, 2021
0.1.3 Oct 17, 2020
0.1.0 May 23, 2020

#245 in Graphics APIs

Download history 7138/week @ 2025-10-22 7301/week @ 2025-10-29 10011/week @ 2025-11-05 6515/week @ 2025-11-12 6082/week @ 2025-11-19 5801/week @ 2025-11-26 5182/week @ 2025-12-03 5031/week @ 2025-12-10 5305/week @ 2025-12-17 5466/week @ 2025-12-24 5406/week @ 2025-12-31 2891/week @ 2026-01-07 5394/week @ 2026-01-14 5788/week @ 2026-01-21 5372/week @ 2026-01-28 5366/week @ 2026-02-04

22,157 downloads per month
Used in 120 crates (via glyph_brush)

Apache-2.0

65KB
890 lines

glyph_brush_draw_cache crates.io Documentation

Rasterization cache for ab_glyph used in glyph_brush.

  • Manages a texture. Draws glyphs into it and provides texture rect lookup for glyphs.
  • Automatic re-use & reordering when needed.
use glyph_brush_draw_cache::DrawCache;

// build a cache with default settings
let mut draw_cache = DrawCache::builder().build();

// queue up some glyphs to store in the cache
for (font_id, glyph) in glyphs {
    draw_cache.queue_glyph(font_id, glyph);
}

// process everything in the queue, rasterizing & uploading as necessary
draw_cache.cache_queued(&fonts, |rect, tex_data| update_texture(rect, tex_data))?;

// access a given glyph's texture position & pixel position for the texture quad
match draw_cache.rect_for(font_id, &glyph) {
    Some((tex_coords, px_coords)) => {}
    None => {/* The glyph has no outline, or wasn't queued up to be cached */}
}

Example

See the draw_cache_guts example to see how it works (run it from the top level).

cargo run --example draw_cache_guts

Dependencies

~1–1.3MB
~28K SLoC