summaryrefslogtreecommitdiffstats
path: root/wgpu/src/triangle.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-05-19 22:55:12 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-05-19 23:19:39 +0200
commit720e7756f2afe30706b6b1a7fbde86b9f15e1d8c (patch)
tree3a55248a4b25654b1d63b8c547fd0f653471606d /wgpu/src/triangle.rs
parente6180912488db4d59fbffcb46c5930282306cb92 (diff)
downloadiced-720e7756f2afe30706b6b1a7fbde86b9f15e1d8c.tar.gz
iced-720e7756f2afe30706b6b1a7fbde86b9f15e1d8c.tar.bz2
iced-720e7756f2afe30706b6b1a7fbde86b9f15e1d8c.zip
Move `Layer` to `iced_graphics`
Diffstat (limited to 'wgpu/src/triangle.rs')
-rw-r--r--wgpu/src/triangle.rs38
1 files changed, 21 insertions, 17 deletions
diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs
index a71bcedc..31975005 100644
--- a/wgpu/src/triangle.rs
+++ b/wgpu/src/triangle.rs
@@ -1,6 +1,6 @@
//! Draw meshes of triangles.
use crate::{settings, Transformation};
-use iced_native::{Rectangle, Vector};
+use iced_graphics::layer;
use std::mem;
use zerocopy::AsBytes;
@@ -204,14 +204,16 @@ impl Pipeline {
target_height: u32,
transformation: Transformation,
scale_factor: f32,
- meshes: &[(Vector, Rectangle<u32>, &Mesh2D)],
+ meshes: &[layer::Mesh<'_>],
) {
// 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(|layer::Mesh { buffers, .. }| {
+ (buffers.vertices.len(), buffers.indices.len())
+ })
.fold((0, 0), |(total_v, total_i), (v, i)| {
(total_v + v, total_i + i)
});
@@ -232,18 +234,18 @@ impl Pipeline {
let mut last_index = 0;
// We upload everything upfront
- for (origin, _, mesh) in meshes {
+ for mesh in meshes {
let transform = (transformation
- * Transformation::translate(origin.x, origin.y))
+ * Transformation::translate(mesh.origin.x, mesh.origin.y))
.into();
let vertex_buffer = device.create_buffer_with_data(
- bytemuck::cast_slice(&mesh.vertices),
+ bytemuck::cast_slice(&mesh.buffers.vertices),
wgpu::BufferUsage::COPY_SRC,
);
let index_buffer = device.create_buffer_with_data(
- mesh.indices.as_bytes(),
+ mesh.buffers.indices.as_bytes(),
wgpu::BufferUsage::COPY_SRC,
);
@@ -252,7 +254,8 @@ impl Pipeline {
0,
&self.vertex_buffer.raw,
(std::mem::size_of::<Vertex2D>() * last_vertex) as u64,
- (std::mem::size_of::<Vertex2D>() * mesh.vertices.len()) as u64,
+ (std::mem::size_of::<Vertex2D>() * mesh.buffers.vertices.len())
+ as u64,
);
encoder.copy_buffer_to_buffer(
@@ -260,18 +263,19 @@ impl Pipeline {
0,
&self.index_buffer.raw,
(std::mem::size_of::<u32>() * last_index) as u64,
- (std::mem::size_of::<u32>() * mesh.indices.len()) as u64,
+ (std::mem::size_of::<u32>() * mesh.buffers.indices.len())
+ as u64,
);
uniforms.push(transform);
offsets.push((
last_vertex as u64,
last_index as u64,
- mesh.indices.len(),
+ mesh.buffers.indices.len(),
));
- last_vertex += mesh.vertices.len();
- last_index += mesh.indices.len();
+ last_vertex += mesh.buffers.vertices.len();
+ last_index += mesh.buffers.indices.len();
}
let uniforms_buffer = device.create_buffer_with_data(
@@ -322,13 +326,13 @@ impl Pipeline {
for (i, (vertex_offset, index_offset, indices)) in
offsets.into_iter().enumerate()
{
- let bounds = meshes[i].1 * scale_factor;
+ let clip_bounds = meshes[i].clip_bounds * scale_factor;
render_pass.set_scissor_rect(
- bounds.x,
- bounds.y,
- bounds.width,
- bounds.height,
+ clip_bounds.x,
+ clip_bounds.y,
+ clip_bounds.width,
+ clip_bounds.height,
);
render_pass.set_bind_group(