From 78f5de493560b6981d7a73c35bf40b3c957bda9c Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Mon, 6 Jun 2016 14:31:12 -0700 Subject: Support dynamic character loading The glyph cache was previously initialized with a list of glyphs from INIT_LIST, and never updated again. This meant that code points not included in that list were not displayed. Now, the glyph cache has gained the ability to load new glyphs at render time. This seems to have lightly decreased performance for some reason. --- src/main.rs | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index e9817331..498cdee6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,7 +33,7 @@ use std::fs::File; use std::os::unix::io::{FromRawFd, AsRawFd}; -use renderer::{Glyph, QuadRenderer}; +use renderer::{QuadRenderer, GlyphCache, LoadGlyph}; use text::FontDesc; use grid::Grid; use term::Term; @@ -50,13 +50,6 @@ mod gl { include!(concat!(env!("OUT_DIR"), "/gl_bindings.rs")); } -static INIT_LIST: &'static str = "abcdefghijklmnopqrstuvwxyz\ - ABCDEFGHIJKLMNOPQRSTUVWXYZ\ - 01234567890\ - ~`!@#$%^&*()[]{}-_=+\\|\"'/?.,<>;:█└│├─➜"; - -type GlyphCache = HashMap; - #[derive(Debug)] struct TermProps { width: f32, @@ -108,13 +101,21 @@ fn main() { let mut grid = Grid::new(num_rows as usize, num_cols as usize); + let props = TermProps { + cell_width: cell_width as f32, + sep_x: sep_x as f32, + cell_height: cell_height as f32, + sep_y: sep_y as f32, + height: height as f32, + width: width as f32, + }; + let mut renderer = QuadRenderer::new(width, height); - let mut glyph_cache = HashMap::new(); - for c in INIT_LIST.chars() { - let glyph = renderer.load_glyph(&rasterizer.get_glyph(&desc, font_size, c)); - glyph_cache.insert(c, glyph); - } + let mut glyph_cache = GlyphCache::new(rasterizer, desc, font_size); + renderer.with_api(&props, |mut api| { + glyph_cache.init(&mut api); + }); unsafe { gl::Enable(gl::BLEND); @@ -182,24 +183,15 @@ fn main() { gl::Clear(gl::COLOR_BUFFER_BIT); } - let props = TermProps { - cell_width: cell_width as f32, - sep_x: sep_x as f32, - cell_height: cell_height as f32, - sep_y: sep_y as f32, - height: height as f32, - width: width as f32, - }; - { let _sampler = meter.sampler(); renderer.with_api(&props, |mut api| { // Draw the grid - api.render_grid(terminal.grid(), &glyph_cache); + api.render_grid(terminal.grid(), &mut glyph_cache); // Also draw the cursor - api.render_cursor(terminal.cursor(), &glyph_cache); + api.render_cursor(terminal.cursor(), &mut glyph_cache); }) } @@ -207,7 +199,7 @@ fn main() { let timing = format!("{:.3} usec", meter.average()); let color = Rgb { r: 0xd5, g: 0x4e, b: 0x53 }; renderer.with_api(&props, |mut api| { - api.render_string(&timing[..], &glyph_cache, &color); + api.render_string(&timing[..], &mut glyph_cache, &color); }); window.swap_buffers().unwrap(); -- cgit