bevy/src/render/render_graph_2/render_graph.rs

87 lines
2.5 KiB
Rust
Raw Normal View History

2020-02-08 07:17:51 +00:00
use crate::render::render_graph_2::{
PassDescriptor, PipelineDescriptor, ResourceProvider, TextureDescriptor,
};
2020-01-18 22:09:53 +00:00
use std::collections::HashMap;
pub struct RenderGraph {
pub pipeline_descriptors: HashMap<String, PipelineDescriptor>,
2020-02-08 07:17:51 +00:00
// TODO: make this ordered
2020-01-18 22:09:53 +00:00
pub pass_descriptors: HashMap<String, PassDescriptor>,
pub pass_pipelines: HashMap<String, Vec<String>>,
2020-01-23 09:06:37 +00:00
pub resource_providers: Vec<Box<dyn ResourceProvider>>,
2020-02-06 01:50:56 +00:00
pub queued_textures: Vec<(String, TextureDescriptor)>,
2020-01-18 22:09:53 +00:00
}
impl Default for RenderGraph {
fn default() -> Self {
RenderGraph {
pipeline_descriptors: HashMap::new(),
pass_descriptors: HashMap::new(),
pass_pipelines: HashMap::new(),
2020-01-23 09:06:37 +00:00
resource_providers: Vec::new(),
2020-02-06 01:50:56 +00:00
queued_textures: Vec::new(),
2020-01-18 22:09:53 +00:00
}
}
}
pub struct RenderGraphBuilder {
render_graph: RenderGraph,
current_pass: Option<String>,
}
impl RenderGraphBuilder {
2020-01-20 08:57:54 +00:00
pub fn new() -> Self {
RenderGraphBuilder {
render_graph: RenderGraph::default(),
current_pass: None,
}
}
2020-01-18 22:09:53 +00:00
pub fn add_pass(mut self, name: &str, pass: PassDescriptor) -> Self {
self.current_pass = Some(name.to_string());
self.render_graph
.pass_descriptors
.insert(name.to_string(), pass);
self
}
pub fn add_pipeline(mut self, name: &str, pipeline: PipelineDescriptor) -> Self {
self.render_graph
.pipeline_descriptors
.insert(name.to_string(), pipeline);
2020-02-08 07:17:51 +00:00
2020-01-18 22:09:53 +00:00
if let Some(current_pass) = self.current_pass.as_ref() {
if let None = self.render_graph.pass_pipelines.get(current_pass) {
2020-02-08 07:17:51 +00:00
self.render_graph
.pass_pipelines
.insert(current_pass.to_string(), Vec::new());
2020-01-18 22:09:53 +00:00
}
2020-02-08 07:17:51 +00:00
let pass_pipelines = self
.render_graph
.pass_pipelines
.get_mut(current_pass)
.unwrap();
2020-01-18 22:09:53 +00:00
pass_pipelines.push(name.to_string());
}
self
}
2020-01-23 09:06:37 +00:00
pub fn add_resource_provider(mut self, resource_provider: Box<dyn ResourceProvider>) -> Self {
self.render_graph.resource_providers.push(resource_provider);
self
}
2020-02-06 01:50:56 +00:00
pub fn add_texture(mut self, name: &str, texture_descriptor: TextureDescriptor) -> Self {
2020-02-08 07:17:51 +00:00
self.render_graph
.queued_textures
.push((name.to_string(), texture_descriptor));
2020-02-06 01:50:56 +00:00
self
}
2020-01-18 22:09:53 +00:00
pub fn build(self) -> RenderGraph {
self.render_graph
}
2020-02-08 07:17:51 +00:00
}