diff --git a/backends/conrod_gfx/src/lib.rs b/backends/conrod_gfx/src/lib.rs index 8d5ea917a..ba5e8944e 100644 --- a/backends/conrod_gfx/src/lib.rs +++ b/backends/conrod_gfx/src/lib.rs @@ -11,7 +11,7 @@ use gfx::{ use conrod_core::{ color, image, render, - text::{rt, GlyphCache}, + text::{self, rt, GlyphCache}, Rect, Scalar, }; @@ -151,6 +151,7 @@ pub struct Renderer<'a, R: Resources> { data: pipe::Data, commands: Vec, vertices: Vec, + positioned_glyphs: Vec, } impl<'a, R: Resources> Renderer<'a, R> { @@ -218,6 +219,7 @@ impl<'a, R: Resources> Renderer<'a, R> { (cache, texture, texture_view) }; + Ok(Renderer { pipeline, glyph_cache, @@ -226,6 +228,7 @@ impl<'a, R: Resources> Renderer<'a, R> { data, commands: vec![], vertices: vec![], + positioned_glyphs: vec![], }) } @@ -257,6 +260,7 @@ impl<'a, R: Resources> Renderer<'a, R> { let Renderer { ref mut commands, ref mut vertices, + ref mut positioned_glyphs, ref mut glyph_cache, ref mut cache_tex, .. @@ -432,10 +436,11 @@ impl<'a, R: Resources> Renderer<'a, R> { } => { switch_to_plain_state!(); - let positioned_glyphs = text.positioned_glyphs(dpi_factor as f32); + positioned_glyphs.clear(); + positioned_glyphs.extend(text.positioned_glyphs(dpi_factor as f32)); // Queue the glyphs to be cached - for glyph in positioned_glyphs { + for glyph in positioned_glyphs.iter() { glyph_cache.queue_glyph(font_id.index(), glyph.clone()); } @@ -469,8 +474,8 @@ impl<'a, R: Resources> Renderer<'a, R> { )) * 2.0, }; - for g in positioned_glyphs { - if let Ok(Some((uv_rect, screen_rect))) = glyph_cache.rect_for(cache_id, g) + for g in positioned_glyphs.drain(..) { + if let Ok(Some((uv_rect, screen_rect))) = glyph_cache.rect_for(cache_id, &g) { let gl_rect = to_gl_rect(screen_rect); let v = |p, t| Vertex { diff --git a/backends/conrod_glium/src/lib.rs b/backends/conrod_glium/src/lib.rs index 4560e0709..fee4ee462 100644 --- a/backends/conrod_glium/src/lib.rs +++ b/backends/conrod_glium/src/lib.rs @@ -46,6 +46,7 @@ pub struct Renderer { glyph_cache: GlyphCache, commands: Vec, vertices: Vec, + positioned_glyphs: Vec, } /// An iterator yielding `Command`s, produced by the `Renderer::commands` method. @@ -481,6 +482,7 @@ impl Renderer { glyph_cache: gc, commands: Vec::new(), vertices: Vec::new(), + positioned_glyphs: Vec::new(), }) } @@ -508,6 +510,7 @@ impl Renderer { ref mut commands, ref mut vertices, ref mut glyph_cache, + ref mut positioned_glyphs, .. } = *self; @@ -694,7 +697,8 @@ impl Renderer { } => { switch_to_plain_state!(); - let positioned_glyphs = text.positioned_glyphs(dpi_factor as f32); + positioned_glyphs.clear(); + positioned_glyphs.extend(text.positioned_glyphs(dpi_factor as f32)); let GlyphCache { ref mut cache, @@ -765,8 +769,8 @@ impl Renderer { )) * 2.0, }; - for g in positioned_glyphs { - if let Ok(Some((uv_rect, screen_rect))) = cache.rect_for(cache_id, g) { + for g in positioned_glyphs.drain(..) { + if let Ok(Some((uv_rect, screen_rect))) = cache.rect_for(cache_id, &g) { let gl_rect = to_gl_rect(screen_rect); let v = |p, t| Vertex { position: p, diff --git a/backends/conrod_piston/src/draw.rs b/backends/conrod_piston/src/draw.rs index 4a061cb74..c54d73725 100644 --- a/backends/conrod_piston/src/draw.rs +++ b/backends/conrod_piston/src/draw.rs @@ -142,7 +142,7 @@ pub fn primitive<'a, Img, G, T, C, F>( .viewport .map(|v| v.draw_size[0] as f32 / v.window_size[0] as f32) .unwrap_or(1.0); - let positioned_glyphs = text.positioned_glyphs(dpi_factor); + let positioned_glyphs: Vec<_> = text.positioned_glyphs(dpi_factor).collect(); // Re-orient the context to top-left origin with *y* facing downwards, as the // `positioned_glyphs` yield pixel positioning. let context = context @@ -167,7 +167,7 @@ pub fn primitive<'a, Img, G, T, C, F>( let rectangles = positioned_glyphs .into_iter() - .filter_map(|g| glyph_cache.rect_for(cache_id, g).ok().unwrap_or(None)) + .filter_map(|g| glyph_cache.rect_for(cache_id, &g).ok().unwrap_or(None)) .map(|(uv_rect, screen_rect)| { let rectangle = { let div_dpi_factor = |s| (s as f32 / dpi_factor as f32) as f64; diff --git a/backends/conrod_wgpu/examples/all_winit_wgpu.rs b/backends/conrod_wgpu/examples/all_winit_wgpu.rs index b4e807cbb..4381a7d7d 100644 --- a/backends/conrod_wgpu/examples/all_winit_wgpu.rs +++ b/backends/conrod_wgpu/examples/all_winit_wgpu.rs @@ -84,7 +84,7 @@ fn main() { let logo_path = assets.join("images/rust.png"); let rgba_logo_image = image::open(logo_path) .expect("Couldn't load logo") - .to_rgba(); + .to_rgba8(); // Create the GPU texture and upload the image data. let (logo_w, logo_h) = rgba_logo_image.dimensions();