summaryrefslogtreecommitdiffstats
path: root/wgpu/src/triangle.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/triangle.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/triangle.rs23
1 files changed, 13 insertions, 10 deletions
diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs
index b58cc03c..246dc7ce 100644
--- a/wgpu/src/triangle.rs
+++ b/wgpu/src/triangle.rs
@@ -201,15 +201,15 @@ impl Pipeline {
target_width: u32,
target_height: u32,
transformation: Transformation,
- meshes: &[(Vector, &Mesh2D)],
- bounds: Rectangle<u32>,
+ scale_factor: f32,
+ meshes: &[(Vector, Rectangle<u32>, &Mesh2D)],
) {
// This looks a bit crazy, but we are just counting how many vertices
// and indices we will need to handle.
// TODO: Improve readability
let (total_vertices, total_indices) = meshes
.iter()
- .map(|(_, mesh)| (mesh.vertices.len(), mesh.indices.len()))
+ .map(|(_, _, mesh)| (mesh.vertices.len(), mesh.indices.len()))
.fold((0, 0), |(total_v, total_i), (v, i)| {
(total_v + v, total_i + i)
});
@@ -230,7 +230,7 @@ impl Pipeline {
let mut last_index = 0;
// We upload everything upfront
- for (origin, mesh) in meshes {
+ for (origin, _, mesh) in meshes {
let transform = (transformation
* Transformation::translate(origin.x, origin.y))
.into();
@@ -316,16 +316,19 @@ impl Pipeline {
});
render_pass.set_pipeline(&self.pipeline);
- render_pass.set_scissor_rect(
- bounds.x,
- bounds.y,
- bounds.width,
- bounds.height,
- );
for (i, (vertex_offset, index_offset, indices)) in
offsets.into_iter().enumerate()
{
+ let bounds = meshes[i].1 * scale_factor;
+
+ render_pass.set_scissor_rect(
+ bounds.x,
+ bounds.y,
+ bounds.width,
+ bounds.height,
+ );
+
render_pass.set_bind_group(
0,
&self.constants,