2020-01-23 09:06:37 +00:00
|
|
|
use crate::render::render_graph_2::{PassDescriptor, PipelineDescriptor, ResourceProvider};
|
2020-01-18 22:09:53 +00:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
pub struct RenderGraph {
|
|
|
|
pub pipeline_descriptors: HashMap<String, PipelineDescriptor>,
|
2020-01-24 07:39:56 +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-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-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);
|
|
|
|
|
|
|
|
if let Some(current_pass) = self.current_pass.as_ref() {
|
|
|
|
if let None = self.render_graph.pass_pipelines.get(current_pass) {
|
|
|
|
self.render_graph.pass_pipelines.insert(current_pass.to_string(), Vec::new());
|
|
|
|
}
|
|
|
|
|
|
|
|
let pass_pipelines = self.render_graph.pass_pipelines.get_mut(current_pass).unwrap();
|
|
|
|
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-01-18 22:09:53 +00:00
|
|
|
pub fn build(self) -> RenderGraph {
|
|
|
|
self.render_graph
|
|
|
|
}
|
2020-01-19 20:43:18 +00:00
|
|
|
}
|