Implement basic image rendering in iced_wgpu

This commit is contained in:
Héctor Ramón Jiménez 2019-10-23 01:21:23 +02:00
parent f8a232c8af
commit 38b6c84e77
11 changed files with 543 additions and 10 deletions

View file

@ -1,4 +1,4 @@
use crate::{quad, Primitive, Quad, Transformation};
use crate::{quad, Image, Primitive, Quad, Transformation};
use iced_native::{
renderer::Debugger, renderer::Windowed, Background, Color, Layout,
MouseCursor, Point, Widget,
@ -29,8 +29,10 @@ pub struct Renderer {
device: Device,
queue: Queue,
quad_pipeline: quad::Pipeline,
image_pipeline: crate::image::Pipeline,
quads: Vec<Quad>,
images: Vec<Image>,
glyph_brush: Rc<RefCell<GlyphBrush<'static, ()>>>,
}
@ -67,6 +69,7 @@ impl Renderer {
.build(&mut device, TextureFormat::Bgra8UnormSrgb);
let quad_pipeline = quad::Pipeline::new(&mut device);
let image_pipeline = crate::image::Pipeline::new(&mut device);
Self {
surface,
@ -74,8 +77,10 @@ impl Renderer {
device,
queue,
quad_pipeline,
image_pipeline,
quads: Vec::new(),
images: Vec::new(),
glyph_brush: Rc::new(RefCell::new(glyph_brush)),
}
}
@ -139,6 +144,16 @@ impl Renderer {
self.quads.clear();
self.image_pipeline.draw(
&mut self.device,
&mut encoder,
&self.images,
target.transformation,
&frame.view,
);
self.images.clear();
self.glyph_brush
.borrow_mut()
.draw_queued(
@ -238,6 +253,13 @@ impl Renderer {
border_radius: u32::from(*border_radius),
});
}
Primitive::Image { path, bounds } => {
self.images.push(Image {
path: path.clone(),
position: [bounds.x, bounds.y],
scale: [bounds.width, bounds.height],
});
}
}
}
}