27 releases

0.7.8 Sep 29, 2023
0.7.7 Feb 24, 2023
0.7.5 Aug 19, 2022
0.7.4 May 7, 2022
0.2.2 Nov 9, 2018

#5 in Rendering

Download history 5629/week @ 2024-01-11 5749/week @ 2024-01-18 4106/week @ 2024-01-25 3790/week @ 2024-02-01 5947/week @ 2024-02-08 6475/week @ 2024-02-15 6015/week @ 2024-02-22 5605/week @ 2024-02-29 6639/week @ 2024-03-07 5158/week @ 2024-03-14 6202/week @ 2024-03-21 6066/week @ 2024-03-28 5507/week @ 2024-04-04 5906/week @ 2024-04-11 5678/week @ 2024-04-18 4603/week @ 2024-04-25

22,537 downloads per month
Used in 163 crates (28 directly)

Apache-2.0

230KB
4.5K SLoC

glyph_brush crates.io Documentation

Fast caching text render library using ab_glyph. Provides render API agnostic rasterization & draw caching logic.

Makes extensive use of caching to optimise frame performance.

  • GPU texture cache logic to dynamically maintain a GPU texture of rendered glyphs.
  • Caching of glyph layout output to avoid repeated cost of identical text rendering on sequential frames.
  • Layouts are re-used to optimise similar layout calculation after a change.
  • Vertex generation is cached per section and re-assembled into the total vertex array on change.
  • Avoids any layout or vertex calculations when identical text is rendered on sequential frames.

The crate is designed to be easily wrapped to create a convenient render API specific version, for example gfx-glyph.

use glyph_brush::{ab_glyph::FontArc, BrushAction, BrushError, GlyphBrushBuilder, Section, Text};

let dejavu = FontArc::try_from_slice(include_bytes!("../../fonts/DejaVuSans.ttf"))?;
let mut glyph_brush = GlyphBrushBuilder::using_font(dejavu).build();

glyph_brush.queue(Section::default().add_text(Text::new("Hello glyph_brush")));
glyph_brush.queue(some_other_section);

match glyph_brush.process_queued(
    |rect, tex_data| update_texture(rect, tex_data),
    |vertex_data| into_vertex(vertex_data),
) {
    Ok(BrushAction::Draw(vertices)) => {
        // Draw new vertices.
    }
    Ok(BrushAction::ReDraw) => {
        // Re-draw last frame's vertices unmodified.
    }
    Err(BrushError::TextureTooSmall { suggested }) => {
        // Enlarge texture + glyph_brush texture cache and retry.
    }
}

Examples

Have a look at

  • cargo run --example opengl --release

Dependencies

~2MB
~34K SLoC