bevy_render/render_graph/
edge.rs

1use super::InternedRenderLabel;
2
3/// An edge, which connects two [`Nodes`](super::Node) in
4/// a [`RenderGraph`](crate::render_graph::RenderGraph).
5///
6/// They are used to describe the ordering (which node has to run first)
7/// and may be of two kinds: [`NodeEdge`](Self::NodeEdge) and [`SlotEdge`](Self::SlotEdge).
8///
9/// Edges are added via the [`RenderGraph::add_node_edge`] and the
10/// [`RenderGraph::add_slot_edge`] methods.
11///
12/// The former simply states that the `output_node` has to be run before the `input_node`,
13/// while the later connects an output slot of the `output_node`
14/// with an input slot of the `input_node` to pass additional data along.
15/// For more information see [`SlotType`](super::SlotType).
16///
17/// [`RenderGraph::add_node_edge`]: crate::render_graph::RenderGraph::add_node_edge
18/// [`RenderGraph::add_slot_edge`]: crate::render_graph::RenderGraph::add_slot_edge
19#[derive(Clone, Debug, Eq, PartialEq)]
20pub enum Edge {
21    /// An edge describing to ordering of both nodes (`output_node` before `input_node`)
22    /// and connecting the output slot at the `output_index` of the `output_node`
23    /// with the slot at the `input_index` of the `input_node`.
24    SlotEdge {
25        input_node: InternedRenderLabel,
26        input_index: usize,
27        output_node: InternedRenderLabel,
28        output_index: usize,
29    },
30    /// An edge describing to ordering of both nodes (`output_node` before `input_node`).
31    NodeEdge {
32        input_node: InternedRenderLabel,
33        output_node: InternedRenderLabel,
34    },
35}
36
37impl Edge {
38    /// Returns the id of the `input_node`.
39    pub fn get_input_node(&self) -> InternedRenderLabel {
40        match self {
41            Edge::SlotEdge { input_node, .. } | Edge::NodeEdge { input_node, .. } => *input_node,
42        }
43    }
44
45    /// Returns the id of the `output_node`.
46    pub fn get_output_node(&self) -> InternedRenderLabel {
47        match self {
48            Edge::SlotEdge { output_node, .. } | Edge::NodeEdge { output_node, .. } => *output_node,
49        }
50    }
51}
52
53#[derive(PartialEq, Eq)]
54pub enum EdgeExistence {
55    Exists,
56    DoesNotExist,
57}