summaryrefslogtreecommitdiffstats
path: root/wgpu/src/renderer.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2020-01-03 14:31:37 +0100
committerLibravatar GitHub <noreply@github.com>2020-01-03 14:31:37 +0100
commite4de2132e993ec6656da52063faf09bcfb978207 (patch)
treeea1f08e8c135aa1632d4b96076fe28c7d8b3a8f9 /wgpu/src/renderer.rs
parent26de688e68347e1f6e388d01014eac89cea71afa (diff)
parentdc094df214a4eab53d3fa8bdf8087fef5a37e9b3 (diff)
downloadiced-e4de2132e993ec6656da52063faf09bcfb978207.tar.gz
iced-e4de2132e993ec6656da52063faf09bcfb978207.tar.bz2
iced-e4de2132e993ec6656da52063faf09bcfb978207.zip
Merge pull request #140 from artursapek/artur/canvas
Mesh2D primitive for rendering arbitrary geometry in `iced_wgpu`
Diffstat (limited to 'wgpu/src/renderer.rs')
-rw-r--r--wgpu/src/renderer.rs32
1 files changed, 30 insertions, 2 deletions
diff --git a/wgpu/src/renderer.rs b/wgpu/src/renderer.rs
index 365ef1ef..050daca9 100644
--- a/wgpu/src/renderer.rs
+++ b/wgpu/src/renderer.rs
@@ -1,9 +1,11 @@
-use crate::{image, quad, text, Image, Primitive, Quad, Transformation};
+use crate::{
+ image, quad, text, triangle, Image, Primitive, Quad, Transformation,
+};
use iced_native::{
renderer::{Debugger, Windowed},
Background, Color, Layout, MouseCursor, Point, Rectangle, Vector, Widget,
};
-
+use std::sync::Arc;
use wgpu::{
Adapter, BackendBit, CommandEncoderDescriptor, Device, DeviceDescriptor,
Extensions, Limits, PowerPreference, Queue, RequestAdapterOptions,
@@ -24,6 +26,7 @@ pub struct Renderer {
quad_pipeline: quad::Pipeline,
image_pipeline: crate::image::Pipeline,
text_pipeline: text::Pipeline,
+ triangle_pipeline: crate::triangle::Pipeline,
}
struct Layer<'a> {
@@ -31,6 +34,7 @@ struct Layer<'a> {
offset: Vector<u32>,
quads: Vec<Quad>,
images: Vec<Image>,
+ meshes: Vec<Arc<triangle::Mesh2D>>,
text: Vec<wgpu_glyph::Section<'a>>,
}
@@ -42,6 +46,7 @@ impl<'a> Layer<'a> {
quads: Vec::new(),
images: Vec::new(),
text: Vec::new(),
+ meshes: Vec::new(),
}
}
}
@@ -64,6 +69,7 @@ impl Renderer {
let text_pipeline = text::Pipeline::new(&mut device);
let quad_pipeline = quad::Pipeline::new(&mut device);
let image_pipeline = crate::image::Pipeline::new(&mut device);
+ let triangle_pipeline = triangle::Pipeline::new(&mut device);
Self {
device,
@@ -71,6 +77,7 @@ impl Renderer {
quad_pipeline,
image_pipeline,
text_pipeline,
+ triangle_pipeline,
}
}
@@ -244,6 +251,9 @@ impl Renderer {
scale: [bounds.width, bounds.height],
});
}
+ Primitive::Mesh2D(mesh) => {
+ layer.meshes.push(mesh.clone());
+ }
Primitive::Clip {
bounds,
offset,
@@ -322,6 +332,24 @@ impl Renderer {
) {
let bounds = layer.bounds * dpi;
+ if layer.meshes.len() > 0 {
+ let translated = transformation
+ * Transformation::translate(
+ -(layer.offset.x as f32) * dpi,
+ -(layer.offset.y as f32) * dpi,
+ );
+
+ self.triangle_pipeline.draw(
+ &mut self.device,
+ encoder,
+ target,
+ translated,
+ dpi,
+ &layer.meshes,
+ bounds,
+ );
+ }
+
if layer.quads.len() > 0 {
self.quad_pipeline.draw(
&mut self.device,