Skip to content

Commit

Permalink
Reflect parts of RenderGraph
Browse files Browse the repository at this point in the history
  • Loading branch information
makspll committed Jul 7, 2022
1 parent 3459c6c commit 52fa11a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
5 changes: 4 additions & 1 deletion crates/bevy_render/src/render_graph/edge.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use bevy_reflect::{FromReflect, Reflect};

use super::NodeId;

/// An edge, which connects two [`Nodes`](super::Node) in
Expand All @@ -13,7 +15,8 @@ use super::NodeId;
/// while the later connects an output slot of the `output_node`
/// with an input slot of the `input_node` to pass additional data along.
/// For more information see [`SlotType`](super::SlotType).
#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Clone, Debug, Eq, PartialEq, Reflect, FromReflect)]
#[reflect(Debug,PartialEq)]
pub enum Edge {
/// An edge describing to ordering of both nodes (`output_node` before `input_node`)
/// and connecting the output slot at the `output_index` of the output_node
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_render/src/render_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
renderer::RenderContext,
};
use bevy_ecs::prelude::World;
use bevy_reflect::{Reflect,prelude::ReflectDefault, FromReflect};
use bevy_utils::HashMap;
use std::{borrow::Cow, fmt::Debug};

Expand Down
11 changes: 9 additions & 2 deletions crates/bevy_render/src/render_graph/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ use crate::{
renderer::RenderContext,
};
use bevy_ecs::world::World;
use bevy_reflect::{Reflect, FromReflect, prelude::{ReflectSerialize,ReflectDeserialize}};
use bevy_utils::Uuid;
use downcast_rs::{impl_downcast, Downcast};
use serde::{Serialize, Deserialize};
use std::{borrow::Cow, fmt::Debug};
use thiserror::Error;

/// A [`Node`] identifier.
/// It automatically generates its own random uuid.
///
/// This id is used to reference the node internally (edges, etc).
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize, Reflect, FromReflect)]
#[reflect(Debug, PartialEq, Serialize, Deserialize, Hash)]
pub struct NodeId(Uuid);

impl NodeId {
Expand Down Expand Up @@ -81,7 +84,8 @@ pub enum NodeRunError {
}

/// A collection of input and output [`Edges`](Edge) for a [`Node`].
#[derive(Debug)]
#[derive(Debug, Reflect, FromReflect)]
#[reflect(Debug)]
pub struct Edges {
id: NodeId,
input_edges: Vec<Edge>,
Expand Down Expand Up @@ -206,11 +210,14 @@ impl Edges {
/// by the [`RenderGraph`](super::RenderGraph).
///
/// The `input_slots` and `output_slots` are provided by the `node`.
#[derive(Reflect, FromReflect)]
pub struct NodeState {
pub id: NodeId,
pub name: Option<Cow<'static, str>>,
/// The name of the type that implements [`Node`].
#[reflect(ignore)]
pub type_name: &'static str,
#[reflect(ignore)]
pub node: Box<dyn Node>,
pub input_slots: SlotInfos,
pub output_slots: SlotInfos,
Expand Down
9 changes: 6 additions & 3 deletions crates/bevy_render/src/render_graph/node_slot.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use bevy_ecs::entity::Entity;
use bevy_reflect::{Reflect, prelude::ReflectDefault, FromReflect};
use std::{borrow::Cow, fmt};

use crate::render_resource::{Buffer, Sampler, TextureView};
Expand Down Expand Up @@ -62,7 +63,8 @@ impl From<Entity> for SlotValue {
/// the render [`Nodes`](super::Node).
///
/// This should not be confused with [`SlotValue`], which actually contains the passed data.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Reflect, FromReflect)]
#[reflect_value(Debug,PartialEq)]
pub enum SlotType {
/// A GPU-accessible [`Buffer`].
Buffer,
Expand Down Expand Up @@ -126,7 +128,7 @@ impl From<usize> for SlotLabel {
}

/// The internal representation of a slot, which specifies its [`SlotType`] and name.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Reflect, FromReflect)]
pub struct SlotInfo {
pub name: Cow<'static, str>,
pub slot_type: SlotType,
Expand All @@ -143,7 +145,8 @@ impl SlotInfo {

/// A collection of input or output [`SlotInfos`](SlotInfo) for
/// a [`NodeState`](super::NodeState).
#[derive(Default, Debug)]
#[derive(Default, Debug, Reflect, FromReflect)]
#[reflect(Default, Debug)]
pub struct SlotInfos {
slots: Vec<SlotInfo>,
}
Expand Down

0 comments on commit 52fa11a

Please sign in to comment.