From 21eb2f692c687a675c54ae5e951556e28e7435eb Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 27 Oct 2019 03:10:49 +0100 Subject: Implement clipping for quads --- wgpu/src/quad.rs | 8 ++++++++ wgpu/src/renderer.rs | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs index adb294f0..6365e117 100644 --- a/wgpu/src/quad.rs +++ b/wgpu/src/quad.rs @@ -1,4 +1,5 @@ use crate::Transformation; +use iced_native::Rectangle; use std::mem; @@ -165,6 +166,7 @@ impl Pipeline { encoder: &mut wgpu::CommandEncoder, instances: &[Quad], transformation: Transformation, + bounds: Rectangle, target: &wgpu::TextureView, ) { let matrix: [f32; 16] = transformation.into(); @@ -227,6 +229,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 5bd7be8d..ba140a66 100644 --- a/wgpu/src/renderer.rs +++ b/wgpu/src/renderer.rs @@ -251,7 +251,7 @@ impl Renderer { border_radius, } => { layer.quads.push(Quad { - position: [bounds.x, bounds.y], + position: [bounds.x, bounds.y - layer.y_offset as f32], scale: [bounds.width, bounds.height], color: match background { Background::Color(color) => color.into_linear(), @@ -304,6 +304,7 @@ impl Renderer { encoder, &layer.quads, transformation, + layer.bounds, target, ); -- cgit