Fix offsets of buffer uploads in triangle pipeline

This commit is contained in:
Héctor Ramón Jiménez 2020-02-28 19:38:17 +01:00
parent bab7dbcaef
commit 96f75eae4d

View File

@ -248,7 +248,7 @@ impl Pipeline {
&vertex_buffer, &vertex_buffer,
0, 0,
&self.vertex_buffer.raw, &self.vertex_buffer.raw,
last_vertex as u64, (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.vertices.len()) as u64,
); );
@ -256,7 +256,7 @@ impl Pipeline {
&index_buffer, &index_buffer,
0, 0,
&self.index_buffer.raw, &self.index_buffer.raw,
last_index as u64, (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.indices.len()) as u64,
); );
@ -313,21 +313,7 @@ impl Pipeline {
depth_stencil_attachment: None, depth_stencil_attachment: None,
}); });
for (i, (vertex_offset, index_offset, indices)) in
offsets.drain(..).enumerate()
{
render_pass.set_pipeline(&self.pipeline); render_pass.set_pipeline(&self.pipeline);
render_pass.set_bind_group(
0,
&self.constants,
&[(std::mem::size_of::<Uniforms>() * i) as u64],
);
render_pass
.set_index_buffer(&self.index_buffer.raw, index_offset);
render_pass.set_vertex_buffers(
0,
&[(&self.vertex_buffer.raw, vertex_offset)],
);
render_pass.set_scissor_rect( render_pass.set_scissor_rect(
bounds.x, bounds.x,
bounds.y, bounds.y,
@ -335,6 +321,23 @@ impl Pipeline {
bounds.height, bounds.height,
); );
for (i, (vertex_offset, index_offset, indices)) in
offsets.into_iter().enumerate()
{
render_pass.set_bind_group(
0,
&self.constants,
&[(std::mem::size_of::<Uniforms>() * i) as u64],
);
render_pass
.set_index_buffer(&self.index_buffer.raw, index_offset);
render_pass.set_vertex_buffers(
0,
&[(&self.vertex_buffer.raw, vertex_offset)],
);
render_pass.draw_indexed(0..indices as u32, 0, 0..1); render_pass.draw_indexed(0..indices as u32, 0, 0..1);
} }
} }