Skip to content

Commit

Permalink
Update piston, glium, old gfx and wgpu backends for rusttype related …
Browse files Browse the repository at this point in the history
…text rendering API tweaks
  • Loading branch information
mitchmindtree committed Apr 14, 2021
1 parent 2126765 commit e717586
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
15 changes: 10 additions & 5 deletions backends/conrod_gfx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use gfx::{

use conrod_core::{
color, image, render,
text::{rt, GlyphCache},
text::{self, rt, GlyphCache},
Rect, Scalar,
};

Expand Down Expand Up @@ -151,6 +151,7 @@ pub struct Renderer<'a, R: Resources> {
data: pipe::Data<R>,
commands: Vec<PreparedCommand>,
vertices: Vec<Vertex>,
positioned_glyphs: Vec<text::PositionedGlyph>,
}

impl<'a, R: Resources> Renderer<'a, R> {
Expand Down Expand Up @@ -218,6 +219,7 @@ impl<'a, R: Resources> Renderer<'a, R> {

(cache, texture, texture_view)
};

Ok(Renderer {
pipeline,
glyph_cache,
Expand All @@ -226,6 +228,7 @@ impl<'a, R: Resources> Renderer<'a, R> {
data,
commands: vec![],
vertices: vec![],
positioned_glyphs: vec![],
})
}

Expand Down Expand Up @@ -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,
..
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 7 additions & 3 deletions backends/conrod_glium/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub struct Renderer {
glyph_cache: GlyphCache,
commands: Vec<PreparedCommand>,
vertices: Vec<Vertex>,
positioned_glyphs: Vec<text::PositionedGlyph>,
}

/// An iterator yielding `Command`s, produced by the `Renderer::commands` method.
Expand Down Expand Up @@ -481,6 +482,7 @@ impl Renderer {
glyph_cache: gc,
commands: Vec::new(),
vertices: Vec::new(),
positioned_glyphs: Vec::new(),
})
}

Expand Down Expand Up @@ -508,6 +510,7 @@ impl Renderer {
ref mut commands,
ref mut vertices,
ref mut glyph_cache,
ref mut positioned_glyphs,
..
} = *self;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions backends/conrod_piston/src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion backends/conrod_wgpu/examples/all_winit_wgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit e717586

Please sign in to comment.