Implement clipping for quads

This commit is contained in:
Héctor Ramón Jiménez 2019-10-27 03:10:49 +01:00
parent e21890168f
commit 21eb2f692c
2 changed files with 10 additions and 1 deletions

View file

@ -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<u32>,
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,

View file

@ -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,
);