make legacy rendergraph optional (and off by default)

This commit is contained in:
Carter Anderson 2020-01-19 12:43:18 -08:00
parent 3783deed07
commit b0df491559
13 changed files with 73 additions and 82 deletions

View file

@ -1,7 +1,7 @@
use bevy::prelude::*;
fn main() {
AppBuilder::new().add_defaults().setup_world(setup).run();
AppBuilder::new().add_defaults_legacy().setup_world(setup).run();
}
#[allow(dead_code)]

View file

@ -21,7 +21,7 @@ struct Wander {
fn main() {
AppBuilder::new()
.add_defaults()
.add_defaults_legacy()
.setup_world(setup)
.add_system(build_wander_system())
.add_system(build_navigate_system())

View file

@ -2,5 +2,5 @@ use bevy::{asset, prelude::*};
fn main() {
asset::load_gltf("examples/assets/Box.gltf").unwrap();
AppBuilder::new().add_defaults().run();
AppBuilder::new().add_defaults_legacy().run();
}

View file

@ -4,7 +4,7 @@ struct Rotator;
fn main() {
AppBuilder::new()
.add_defaults()
.add_defaults_legacy()
.setup_world(setup)
.add_system(build_rotator_system())
.run();

View file

@ -2,7 +2,7 @@ use bevy::{prelude::*, serialization::*};
use serde::{Deserialize, Serialize};
use type_uuid::TypeUuid;
fn main() {
let app = AppBuilder::new().add_defaults().setup_world(setup).build();
let app = AppBuilder::new().add_defaults_legacy().setup_world(setup).build();
let comp_registrations = [ComponentRegistration::of::<Test>()];

View file

@ -1,7 +1,7 @@
use bevy::{prelude::*, asset, render::{Albedo, render_graph_2::{StandardMaterial, ShaderMaterials, ShaderMaterial, ShaderValue}}};
fn main() {
AppBuilder::new().add_defaults().setup_world(setup).run();
AppBuilder::new().add_defaults_legacy().setup_world(setup).run();
}
fn setup(world: &mut World) {

View file

@ -1,7 +1,7 @@
use bevy::prelude::*;
fn main() {
AppBuilder::new().add_defaults().setup_world(setup).run();
AppBuilder::new().add_defaults_legacy().setup_world(setup).run();
}
fn setup(world: &mut World) {

View file

@ -1,7 +1,7 @@
use bevy::{asset, prelude::*};
fn main() {
AppBuilder::new().add_defaults().setup_world(setup).run();
AppBuilder::new().add_defaults_legacy().setup_world(setup).run();
}
fn setup(world: &mut World) {

View file

@ -1,7 +1,7 @@
use bevy::prelude::*;
fn main() {
AppBuilder::new().add_defaults().setup_world(setup).run();
AppBuilder::new().add_defaults_legacy().setup_world(setup).run();
}
fn setup(world: &mut World) {

View file

@ -11,7 +11,7 @@ use crate::{core::Time, render::*, app::AppBuilder};
pub struct App {
pub universe: Universe,
pub world: World,
pub render_graph: RenderGraph,
pub legacy_render_graph: Option<RenderGraph>,
pub schedule: Schedule,
}
@ -20,13 +20,13 @@ impl App {
universe: Universe,
world: World,
schedule: Schedule,
render_graph: RenderGraph,
legacy_render_graph: Option<RenderGraph>,
) -> App {
App {
universe,
world,
schedule: schedule,
render_graph,
legacy_render_graph: legacy_render_graph,
}
}
@ -39,7 +39,12 @@ impl App {
time.start();
}
self.schedule.execute(&mut self.world);
self.render_graph.render(&mut self.world);
// TODO: remove me
if let Some(ref mut render_graph) = self.legacy_render_graph {
render_graph.render(&mut self.world);
}
if let Some(mut time) = self.world.resources.get_mut::<Time>() {
time.stop();
}
@ -59,7 +64,9 @@ impl App {
self.world.resources.insert(window);
log::info!("Initializing the example...");
self.render_graph.initialize(&mut self.world);
if let Some(ref mut render_graph) = self.legacy_render_graph {
render_graph.initialize(&mut self.world);
}
log::info!("Entering render loop...");
event_loop.run(move |event, _, control_flow| {
@ -73,8 +80,10 @@ impl App {
event: WindowEvent::Resized(size),
..
} => {
self.render_graph
.resize(size.width, size.height, &mut self.world);
if let Some(ref mut render_graph) = self.legacy_render_graph {
render_graph
.resize(size.width, size.height, &mut self.world);
}
}
event::Event::WindowEvent { event, .. } => match event {
WindowEvent::KeyboardInput {

View file

@ -15,7 +15,7 @@ pub const UPDATE: &str = "update";
pub struct AppBuilder {
pub world: World,
pub universe: Universe,
pub render_graph: RenderGraph,
pub legacy_render_graph: Option<RenderGraph>,
pub system_stages: HashMap<String, Vec<Box<dyn Schedulable>>>,
pub runnable_stages: HashMap<String, Vec<Box<dyn Runnable>>>,
pub stage_order: Vec<String>,
@ -28,7 +28,7 @@ impl AppBuilder {
AppBuilder {
universe,
world,
render_graph: RenderGraph::new(),
legacy_render_graph: None,
system_stages: HashMap::new(),
runnable_stages: HashMap::new(),
stage_order: Vec::new(),
@ -59,7 +59,7 @@ impl AppBuilder {
self.universe,
self.world,
schedule_builder.build(),
self.render_graph,
self.legacy_render_graph,
)
}
@ -107,33 +107,42 @@ impl AppBuilder {
self
}
pub fn with_legacy_render_graph(mut self) -> Self {
self.legacy_render_graph = Some(RenderGraph::new());
self
}
pub fn add_default_passes(mut self) -> Self {
let msaa_samples = 4;
let render_graph = &mut self.render_graph;
render_graph
.add_render_resource_manager(Box::new(render_resources::MaterialResourceManager));
render_graph
.add_render_resource_manager(Box::new(render_resources::LightResourceManager::new(10)));
render_graph.add_render_resource_manager(Box::new(render_resources::GlobalResourceManager));
render_graph
.add_render_resource_manager(Box::new(render_resources::Global2dResourceManager));
{
let render_graph = &mut self.legacy_render_graph.as_mut().unwrap();
render_graph
.add_render_resource_manager(Box::new(render_resources::MaterialResourceManager));
render_graph.add_render_resource_manager(Box::new(
render_resources::LightResourceManager::new(10),
));
render_graph
.add_render_resource_manager(Box::new(render_resources::GlobalResourceManager));
render_graph
.add_render_resource_manager(Box::new(render_resources::Global2dResourceManager));
let depth_format = wgpu::TextureFormat::Depth32Float;
render_graph.set_pass(
"forward",
Box::new(ForwardPass::new(depth_format, msaa_samples)),
);
render_graph.set_pipeline(
"forward",
"forward",
Box::new(ForwardPipeline::new(msaa_samples)),
);
render_graph.set_pipeline(
"forward",
"forward_instanced",
Box::new(ForwardInstancedPipeline::new(depth_format, msaa_samples)),
);
render_graph.set_pipeline("forward", "ui", Box::new(UiPipeline::new(msaa_samples)));
let depth_format = wgpu::TextureFormat::Depth32Float;
render_graph.set_pass(
"forward",
Box::new(ForwardPass::new(depth_format, msaa_samples)),
);
render_graph.set_pipeline(
"forward",
"forward",
Box::new(ForwardPipeline::new(msaa_samples)),
);
render_graph.set_pipeline(
"forward",
"forward_instanced",
Box::new(ForwardInstancedPipeline::new(depth_format, msaa_samples)),
);
render_graph.set_pipeline("forward", "ui", Box::new(UiPipeline::new(msaa_samples)));
}
self
}
@ -155,8 +164,10 @@ impl AppBuilder {
self
}
pub fn add_defaults(self) -> Self {
self.add_default_resources()
pub fn add_defaults_legacy(self) -> Self {
self
.with_legacy_render_graph()
.add_default_resources()
.add_default_passes()
.add_default_systems()
}

View file

@ -1,8 +1,6 @@
use crate::render::render_graph_2::{PassDescriptor, PipelineDescriptor};
use std::collections::HashMap;
// holds on to passes, pipeline descriptions, instances
// passes: shadow, forward
pub struct RenderGraph {
pub pipeline_descriptors: HashMap<String, PipelineDescriptor>,
pub pass_descriptors: HashMap<String, PassDescriptor>,
@ -62,37 +60,4 @@ impl RenderGraphBuilder {
pub fn build(self) -> RenderGraph {
self.render_graph
}
}
/*
RenderGraph::build()
.AddPass("forward", Pass {
})
.AddPipeline(Pipeline::build()
.with_vertex_shader("pbr.vert")
.with_fragment_shader("pbr.frag")
.add_vertex_layout(Vertex::get_layout()) // maybe someday reflect this using spirv-reflect
.add_uniform_binding("camera_resource", "shader_camera") // if a uniform is not bound directly, and no uniforms are set on entity, produce an error
.add_texture_binding("some_texture", "shader_texture") // if a uniform is not bound directly, and no uniforms are set on entity, produce an error
.add_draw_target(MeshDrawTarget)
.add_draw_target(InstancedMeshDrawTarget)
)
.AddPipeline(Pipeline::build()
.with_vertex_shader("ui.vert")
.with_fragment_shader("ui.frag")
.with_vertex_layout(Vertex::get_layout())
.with_draw_target(UiDrawTarget)
)
.AddPass("shadow", Pass {
render_target: Null
depth_target: DepthTexture (TextureView)
})
.AddPipeline(Pipeline::build()
.with_vertex_shader("pbr.vert")
.with_fragment_shader("pbr.frag")
.with_vertex_layout(Vertex::get_layout())
.with_draw_target(ShadowedMeshDrawTarget)
.with_draw_target(ShadowedInstancedMeshDrawTarget)
)
*/
}

View file

@ -209,4 +209,10 @@ impl<'a, 'b, 'c> RenderPass for WgpuRenderPass<'a, 'b, 'c> {
fn set_index_buffer(&mut self, buffer: &wgpu::Buffer, offset: wgpu::BufferAddress) {
self.render_pass.set_index_buffer(buffer, offset);
}
}
}
// pub trait RenderResources {
// fn get_buffer(name: &str) -> Option<Buffer>;
// fn get_texture(name: &str) -> Option<Texture>;
// fn get_sampler(name: &str) -> Option<Sampler>;
// }