|
@@ -42,19 +42,33 @@ impl Mesh {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /// Draw a single instance of this mesh.
|
|
|
|
|
- /// Drawing indexed or indirectly is prefered.
|
|
|
|
|
- pub fn draw<'a>(&'a self, pass: &mut RenderPass<'a>) {
|
|
|
|
|
- pass.set_vertex_buffer(0, self.vertices.slice(..));
|
|
|
|
|
- pass.set_index_buffer(self.indices.slice(..), INDEX_FORMAT);
|
|
|
|
|
- pass.draw_indexed(0..self.index_count, 0, 0..1);
|
|
|
|
|
|
|
+ /// Draw a single instance of this mesh, using slot 0 for the vertex buffer.
|
|
|
|
|
+ /// Ideally use `draw_instanced`.
|
|
|
|
|
+ pub fn draw<'m: 'p, 'p>(&'m self, pass: &mut RenderPass<'p>) {
|
|
|
|
|
+ self.draw_instanced(pass, 0..1);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// Draw multiple instances of this mesh, the instance buffer must be bound already.
|
|
/// Draw multiple instances of this mesh, the instance buffer must be bound already.
|
|
|
- /// Drawing indirectly is prefered.
|
|
|
|
|
- pub fn draw_instanced<'a>(&'a self, pass: &mut RenderPass<'a>, instances: Range<u32>) {
|
|
|
|
|
- pass.set_vertex_buffer(0, self.vertices.slice(..));
|
|
|
|
|
- pass.set_index_buffer(self.indices.slice(..), INDEX_FORMAT);
|
|
|
|
|
|
|
+ /// Slot 0 is used for the vertex buffer
|
|
|
|
|
+ /// Drawing indirectly can have greater performance, use `bind` and call whichever indirect drawing function you need.
|
|
|
|
|
+ pub fn draw_instanced<'m: 'p, 'p>(&'m self, pass: &mut RenderPass<'p>, instances: Range<u32>) {
|
|
|
|
|
+ self.bind(pass, 0);
|
|
|
pass.draw_indexed(0..self.index_count, 0, instances);
|
|
pass.draw_indexed(0..self.index_count, 0, instances);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /// Bind this mesh's buffers for drawing
|
|
|
|
|
+ pub fn bind<'m: 'p, 'p>(&'m self, pass: &mut RenderPass<'p>, slot: u32) {
|
|
|
|
|
+ pass.set_vertex_buffer(slot, self.vertices.slice(..));
|
|
|
|
|
+ pass.set_index_buffer(self.indices.slice(..), INDEX_FORMAT);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// Returns a reference to the vertex buffer
|
|
|
|
|
+ pub fn vertices(&self) -> &Buffer {
|
|
|
|
|
+ &self.vertices
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// Returns a reference to the index buffer
|
|
|
|
|
+ pub fn indices(&self) -> &Buffer {
|
|
|
|
|
+ &self.indices
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|