summaryrefslogtreecommitdiffstats
path: root/wgpu/src/renderer.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-04-28 04:41:09 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-04-28 04:41:09 +0200
commite65585ae17bf2fae1bbad1cde839d6f767a29b82 (patch)
tree49d36c227011d6aed771fa73bd66b26ac31a4142 /wgpu/src/renderer.rs
parent69c60d372c18c20856f733efd337ac302b7de926 (diff)
downloadiced-e65585ae17bf2fae1bbad1cde839d6f767a29b82.tar.gz
iced-e65585ae17bf2fae1bbad1cde839d6f767a29b82.tar.bz2
iced-e65585ae17bf2fae1bbad1cde839d6f767a29b82.zip
Clip and cull `Mesh2D` primitives in `iced_wgpu`
Diffstat (limited to '')
-rw-r--r--wgpu/src/renderer.rs36
1 files changed, 23 insertions, 13 deletions
diff --git a/wgpu/src/renderer.rs b/wgpu/src/renderer.rs
index e93532bc..5c38ce61 100644
--- a/wgpu/src/renderer.rs
+++ b/wgpu/src/renderer.rs
@@ -29,7 +29,7 @@ pub struct Renderer {
struct Layer<'a> {
bounds: Rectangle<u32>,
quads: Vec<Quad>,
- meshes: Vec<(Vector, &'a triangle::Mesh2D)>,
+ meshes: Vec<(Vector, Rectangle<u32>, &'a triangle::Mesh2D)>,
text: Vec<wgpu_glyph::Section<'a>>,
#[cfg(any(feature = "image", feature = "svg"))]
@@ -48,6 +48,12 @@ impl<'a> Layer<'a> {
images: Vec::new(),
}
}
+
+ pub fn intersection(&self, rectangle: Rectangle) -> Option<Rectangle<u32>> {
+ let layer_bounds: Rectangle<f32> = self.bounds.into();
+
+ layer_bounds.intersection(&rectangle).map(Into::into)
+ }
}
impl Renderer {
@@ -214,10 +220,20 @@ impl Renderer {
border_color: border_color.into_linear(),
});
}
- Primitive::Mesh2D { buffers } => {
+ Primitive::Mesh2D { size, buffers } => {
let layer = layers.last_mut().unwrap();
- layer.meshes.push((translation, buffers));
+ // Only draw visible content
+ if let Some(clip_bounds) = layer.intersection(Rectangle::new(
+ Point::new(translation.x, translation.y),
+ *size,
+ )) {
+ layer.meshes.push((
+ translation,
+ clip_bounds.into(),
+ buffers,
+ ));
+ }
}
Primitive::Clip {
bounds,
@@ -226,16 +242,10 @@ impl Renderer {
} => {
let layer = layers.last_mut().unwrap();
- let layer_bounds: Rectangle<f32> = layer.bounds.into();
-
- let clip = Rectangle {
- x: bounds.x + translation.x,
- y: bounds.y + translation.y,
- ..*bounds
- };
-
// Only draw visible content
- if let Some(clip_bounds) = layer_bounds.intersection(&clip) {
+ if let Some(clip_bounds) =
+ layer.intersection(*bounds + translation)
+ {
let clip_layer = Layer::new(clip_bounds.into());
let new_layer = Layer::new(layer.bounds);
@@ -356,8 +366,8 @@ impl Renderer {
target_width,
target_height,
scaled,
+ scale_factor,
&layer.meshes,
- bounds,
);
}