summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-10-27 02:29:23 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-10-27 02:29:23 +0100
commit0a0aa3edd9c5185551040c75a934f12d3bce7618 (patch)
treef158003fb4e4316a318453ddd53f2cd3357474e4 /wgpu
parent63c10b67ab213c5971313743fde566bd5c0f0c15 (diff)
downloadiced-0a0aa3edd9c5185551040c75a934f12d3bce7618.tar.gz
iced-0a0aa3edd9c5185551040c75a934f12d3bce7618.tar.bz2
iced-0a0aa3edd9c5185551040c75a934f12d3bce7618.zip
Implement clipping for images
Diffstat (limited to 'wgpu')
-rw-r--r--wgpu/src/image.rs8
-rw-r--r--wgpu/src/renderer.rs31
2 files changed, 33 insertions, 6 deletions
diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs
index c883eaa8..c42e1cd4 100644
--- a/wgpu/src/image.rs
+++ b/wgpu/src/image.rs
@@ -1,4 +1,5 @@
use crate::Transformation;
+use iced_native::Rectangle;
use std::cell::RefCell;
use std::collections::HashMap;
@@ -218,6 +219,7 @@ impl Pipeline {
encoder: &mut wgpu::CommandEncoder,
instances: &[Image],
transformation: Transformation,
+ bounds: Rectangle<u32>,
target: &wgpu::TextureView,
) {
let matrix: [f32; 16] = transformation.into();
@@ -291,6 +293,12 @@ impl Pipeline {
0,
&[(&self.vertices, 0), (&self.instances, 0)],
);
+ render_pass.set_scissor_rect(
+ bounds.x,
+ bounds.y,
+ bounds.width,
+ bounds.height,
+ );
render_pass.draw_indexed(
0..QUAD_INDICES.len() as u32,
diff --git a/wgpu/src/renderer.rs b/wgpu/src/renderer.rs
index bb0e7b27..d838c6ee 100644
--- a/wgpu/src/renderer.rs
+++ b/wgpu/src/renderer.rs
@@ -1,7 +1,7 @@
use crate::{quad, Image, Primitive, Quad, Transformation};
use iced_native::{
renderer::Debugger, renderer::Windowed, Background, Color, Layout,
- MouseCursor, Point, Widget,
+ MouseCursor, Point, Rectangle, Widget,
};
use raw_window_handle::HasRawWindowHandle;
@@ -43,19 +43,21 @@ pub struct Target {
}
pub struct Layer {
+ bounds: Rectangle<u32>,
+ y_offset: u32,
quads: Vec<Quad>,
images: Vec<Image>,
layers: Vec<Layer>,
- y_offset: u32,
}
impl Layer {
- pub fn new(y_offset: u32) -> Self {
+ pub fn new(bounds: Rectangle<u32>, y_offset: u32) -> Self {
Self {
+ bounds,
+ y_offset,
quads: Vec::new(),
images: Vec::new(),
layers: Vec::new(),
- y_offset,
}
}
}
@@ -147,7 +149,15 @@ impl Renderer {
depth_stencil_attachment: None,
});
- let mut layer = Layer::new(0);
+ let mut layer = Layer::new(
+ Rectangle {
+ x: 0,
+ y: 0,
+ width: u32::from(target.width),
+ height: u32::from(target.height),
+ },
+ 0,
+ );
self.draw_primitive(primitive, &mut layer);
self.flush(target.transformation, &layer, &mut encoder, &frame.view);
@@ -263,7 +273,15 @@ impl Renderer {
offset,
content,
} => {
- let mut new_layer = Layer::new(layer.y_offset + offset);
+ let mut new_layer = Layer::new(
+ Rectangle {
+ x: bounds.x as u32,
+ y: bounds.y as u32 - layer.y_offset,
+ width: bounds.width as u32,
+ height: bounds.height as u32,
+ },
+ layer.y_offset + offset,
+ );
// TODO: Primitive culling
self.draw_primitive(content, &mut new_layer);
@@ -296,6 +314,7 @@ impl Renderer {
encoder,
&layer.images,
translated,
+ layer.bounds,
target,
);