Skip to content

Commit

Permalink
Merge pull request #211 from lachlansneff/bevy-render-draw-command
Browse files Browse the repository at this point in the history
Add Draw command to RenderCommand
  • Loading branch information
cart committed Aug 18, 2020
2 parents 99e39b5 + ccfa815 commit 6e4c959
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions crates/bevy_render/src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 12 additions & 2 deletions crates/bevy_render/src/render_graph/nodes/pass_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -306,10 +313,13 @@ impl DrawState {
self.index_buffer = Some(buffer);
}

pub fn can_draw_indexed(&self) -> bool {
pub fn can_draw(&self) -> bool {
self.bind_groups.iter().all(|b| b.is_some())
&& self.vertex_buffers.iter().all(|v| v.is_some())
&& self.index_buffer.is_some()
}

pub fn can_draw_indexed(&self) -> bool {
self.can_draw() && self.index_buffer.is_some()
}

pub fn set_pipeline(
Expand Down

0 comments on commit 6e4c959

Please sign in to comment.