Skip to content

Commit

Permalink
add_node_edges
Browse files Browse the repository at this point in the history
  • Loading branch information
IceSentry committed Mar 16, 2023
1 parent 9a977b1 commit 94bcf89
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 31 deletions.
11 changes: 5 additions & 6 deletions crates/bevy_core_pipeline/src/core_2d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,14 @@ impl Plugin for Core2dPlugin {
graph::node::UPSCALING,
UpscalingNode::IN_VIEW,
);
draw_2d_graph.add_node_edge(graph::node::MAIN_PASS, graph::node::TONEMAPPING);
draw_2d_graph.add_node_edge(

draw_2d_graph.add_node_edges(&[
graph::node::MAIN_PASS,
graph::node::TONEMAPPING,
graph::node::END_MAIN_PASS_POST_PROCESSING,
);
draw_2d_graph.add_node_edge(
graph::node::END_MAIN_PASS_POST_PROCESSING,
graph::node::UPSCALING,
);
]);

graph.add_sub_graph(graph::NAME, draw_2d_graph);
}
}
Expand Down
13 changes: 6 additions & 7 deletions crates/bevy_core_pipeline/src/core_3d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,15 @@ impl Plugin for Core3dPlugin {
graph::node::UPSCALING,
UpscalingNode::IN_VIEW,
);
draw_3d_graph.add_node_edge(graph::node::PREPASS, graph::node::MAIN_PASS);
draw_3d_graph.add_node_edge(graph::node::MAIN_PASS, graph::node::TONEMAPPING);
draw_3d_graph.add_node_edge(

draw_3d_graph.add_node_edges(&[
graph::node::PREPASS,
graph::node::MAIN_PASS,
graph::node::TONEMAPPING,
graph::node::END_MAIN_PASS_POST_PROCESSING,
);
draw_3d_graph.add_node_edge(
graph::node::END_MAIN_PASS_POST_PROCESSING,
graph::node::UPSCALING,
);
]);

graph.add_sub_graph(graph::NAME, draw_3d_graph);
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_core_pipeline/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ pub fn add_node<T: Node + FromWorld>(
let mut render_graph = render_app.world.resource_mut::<RenderGraph>();

let graph = render_graph.get_sub_graph_mut(sub_graph_name).unwrap();
graph.add_node_with_edges(node_name, node, edges);
graph.add_node(node_name, node);
graph.add_node_edges(edges);

graph.add_slot_edge(graph.input_node().id, output_slot, node_name, input_slot);
}
22 changes: 5 additions & 17 deletions crates/bevy_render/src/render_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,12 @@ impl RenderGraph {
id
}

/// Adds the `node` with the `name` to the graph.
/// If the name is already present replaces it instead.
/// Also adds `node_edge` based on the order of the given `edges`.
pub fn add_node_with_edges<T>(
&mut self,
name: impl Into<Cow<'static, str>>,
node: T,
edges: &[&'static str],
) -> NodeId
where
T: Node,
{
let id = self.add_node(name, node);
/// Add `node_edge` based on the order of the given `edges` array.
pub fn add_node_edges(&mut self, edges: &[&'static str]) {
for window in edges.windows(2) {
let [a, b] = window else { break; };
self.add_node_edge(*a, *b);
}
id
}

/// Removes the `node` with the `name` from the graph.
Expand Down Expand Up @@ -855,7 +843,7 @@ mod tests {
}

#[test]
fn test_add_node_with_edges() {
fn test_add_node_edges() {
struct SimpleNode;
impl Node for SimpleNode {
fn run(
Expand All @@ -875,10 +863,10 @@ mod tests {

let mut graph = RenderGraph::default();
let a_id = graph.add_node("A", SimpleNode);
let b_id = graph.add_node("B", SimpleNode);
let c_id = graph.add_node("C", SimpleNode);

// A and C need to exist first
let b_id = graph.add_node_with_edges("B", SimpleNode, &["A", "B", "C"]);
graph.add_node_edges(&["A", "B", "C"]);

assert!(
output_nodes("A", &graph) == HashSet::from_iter(vec![b_id]),
Expand Down

0 comments on commit 94bcf89

Please sign in to comment.