Add Draw command to RenderCommand

This commit is contained in:
Lachlan Sneff 2020-08-16 16:28:52 -04:00
parent 77ebb461f9
commit e24aaf3dd3
2 changed files with 16 additions and 0 deletions

View File

@ -43,6 +43,10 @@ pub enum RenderCommand {
base_vertex: i32,
instances: Range<u32>,
},
Draw {
vertices: Range<u32>,
instances: Range<u32>,
},
}
/// A component that indicates how to draw an entity.

View File

@ -245,6 +245,13 @@ impl<Q: HecsQuery + Send + Sync + 'static> Node for PassNode<Q> {
log::info!("Could not draw indexed because the pipeline layout wasn't fully set for pipeline: {:?}", draw_state.pipeline);
}
}
RenderCommand::Draw { vertices, instances } => {
if draw_state.can_draw() {
render_pass.draw(vertices.clone(), instances.clone());
} else {
log::info!("Could not draw because the pipeline layout wasn't fully set for pipeline: {:?}", draw_state.pipeline);
}
}
RenderCommand::SetVertexBuffer {
buffer,
offset,
@ -306,6 +313,11 @@ impl DrawState {
self.index_buffer = Some(buffer);
}
pub fn can_draw(&self) -> bool {
self.bind_groups.iter().all(|b| b.is_some())
&& self.vertex_buffers.iter().all(|v| v.is_some())
}
pub fn can_draw_indexed(&self) -> bool {
self.bind_groups.iter().all(|b| b.is_some())
&& self.vertex_buffers.iter().all(|v| v.is_some())