From e24aaf3dd396e6240c9d1c856703dbea9465bc22 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Sun, 16 Aug 2020 16:28:52 -0400 Subject: [PATCH] Add Draw command to RenderCommand --- crates/bevy_render/src/draw.rs | 4 ++++ .../bevy_render/src/render_graph/nodes/pass_node.rs | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/crates/bevy_render/src/draw.rs b/crates/bevy_render/src/draw.rs index e2e7227764..281bde6b7e 100644 --- a/crates/bevy_render/src/draw.rs +++ b/crates/bevy_render/src/draw.rs @@ -43,6 +43,10 @@ pub enum RenderCommand { base_vertex: i32, instances: Range, }, + Draw { + vertices: Range, + instances: Range, + }, } /// A component that indicates how to draw an entity. diff --git a/crates/bevy_render/src/render_graph/nodes/pass_node.rs b/crates/bevy_render/src/render_graph/nodes/pass_node.rs index 56089d8e9c..70ec34003d 100644 --- a/crates/bevy_render/src/render_graph/nodes/pass_node.rs +++ b/crates/bevy_render/src/render_graph/nodes/pass_node.rs @@ -245,6 +245,13 @@ impl Node for PassNode { 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())