mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
make legacy rendergraph optional (and off by default)
This commit is contained in:
parent
3783deed07
commit
b0df491559
13 changed files with 73 additions and 82 deletions
|
@ -1,7 +1,7 @@
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
AppBuilder::new().add_defaults().setup_world(setup).run();
|
AppBuilder::new().add_defaults_legacy().setup_world(setup).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
|
|
@ -21,7 +21,7 @@ struct Wander {
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
AppBuilder::new()
|
AppBuilder::new()
|
||||||
.add_defaults()
|
.add_defaults_legacy()
|
||||||
.setup_world(setup)
|
.setup_world(setup)
|
||||||
.add_system(build_wander_system())
|
.add_system(build_wander_system())
|
||||||
.add_system(build_navigate_system())
|
.add_system(build_navigate_system())
|
||||||
|
|
|
@ -2,5 +2,5 @@ use bevy::{asset, prelude::*};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
asset::load_gltf("examples/assets/Box.gltf").unwrap();
|
asset::load_gltf("examples/assets/Box.gltf").unwrap();
|
||||||
AppBuilder::new().add_defaults().run();
|
AppBuilder::new().add_defaults_legacy().run();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ struct Rotator;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
AppBuilder::new()
|
AppBuilder::new()
|
||||||
.add_defaults()
|
.add_defaults_legacy()
|
||||||
.setup_world(setup)
|
.setup_world(setup)
|
||||||
.add_system(build_rotator_system())
|
.add_system(build_rotator_system())
|
||||||
.run();
|
.run();
|
||||||
|
|
|
@ -2,7 +2,7 @@ use bevy::{prelude::*, serialization::*};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use type_uuid::TypeUuid;
|
use type_uuid::TypeUuid;
|
||||||
fn main() {
|
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>()];
|
let comp_registrations = [ComponentRegistration::of::<Test>()];
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use bevy::{prelude::*, asset, render::{Albedo, render_graph_2::{StandardMaterial, ShaderMaterials, ShaderMaterial, ShaderValue}}};
|
use bevy::{prelude::*, asset, render::{Albedo, render_graph_2::{StandardMaterial, ShaderMaterials, ShaderMaterial, ShaderValue}}};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
AppBuilder::new().add_defaults().setup_world(setup).run();
|
AppBuilder::new().add_defaults_legacy().setup_world(setup).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(world: &mut World) {
|
fn setup(world: &mut World) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
AppBuilder::new().add_defaults().setup_world(setup).run();
|
AppBuilder::new().add_defaults_legacy().setup_world(setup).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(world: &mut World) {
|
fn setup(world: &mut World) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use bevy::{asset, prelude::*};
|
use bevy::{asset, prelude::*};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
AppBuilder::new().add_defaults().setup_world(setup).run();
|
AppBuilder::new().add_defaults_legacy().setup_world(setup).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(world: &mut World) {
|
fn setup(world: &mut World) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
AppBuilder::new().add_defaults().setup_world(setup).run();
|
AppBuilder::new().add_defaults_legacy().setup_world(setup).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(world: &mut World) {
|
fn setup(world: &mut World) {
|
||||||
|
|
|
@ -11,7 +11,7 @@ use crate::{core::Time, render::*, app::AppBuilder};
|
||||||
pub struct App {
|
pub struct App {
|
||||||
pub universe: Universe,
|
pub universe: Universe,
|
||||||
pub world: World,
|
pub world: World,
|
||||||
pub render_graph: RenderGraph,
|
pub legacy_render_graph: Option<RenderGraph>,
|
||||||
pub schedule: Schedule,
|
pub schedule: Schedule,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,13 +20,13 @@ impl App {
|
||||||
universe: Universe,
|
universe: Universe,
|
||||||
world: World,
|
world: World,
|
||||||
schedule: Schedule,
|
schedule: Schedule,
|
||||||
render_graph: RenderGraph,
|
legacy_render_graph: Option<RenderGraph>,
|
||||||
) -> App {
|
) -> App {
|
||||||
App {
|
App {
|
||||||
universe,
|
universe,
|
||||||
world,
|
world,
|
||||||
schedule: schedule,
|
schedule: schedule,
|
||||||
render_graph,
|
legacy_render_graph: legacy_render_graph,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,12 @@ impl App {
|
||||||
time.start();
|
time.start();
|
||||||
}
|
}
|
||||||
self.schedule.execute(&mut self.world);
|
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>() {
|
if let Some(mut time) = self.world.resources.get_mut::<Time>() {
|
||||||
time.stop();
|
time.stop();
|
||||||
}
|
}
|
||||||
|
@ -59,7 +64,9 @@ impl App {
|
||||||
self.world.resources.insert(window);
|
self.world.resources.insert(window);
|
||||||
|
|
||||||
log::info!("Initializing the example...");
|
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...");
|
log::info!("Entering render loop...");
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
|
@ -73,8 +80,10 @@ impl App {
|
||||||
event: WindowEvent::Resized(size),
|
event: WindowEvent::Resized(size),
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
self.render_graph
|
if let Some(ref mut render_graph) = self.legacy_render_graph {
|
||||||
.resize(size.width, size.height, &mut self.world);
|
render_graph
|
||||||
|
.resize(size.width, size.height, &mut self.world);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
event::Event::WindowEvent { event, .. } => match event {
|
event::Event::WindowEvent { event, .. } => match event {
|
||||||
WindowEvent::KeyboardInput {
|
WindowEvent::KeyboardInput {
|
||||||
|
|
|
@ -15,7 +15,7 @@ pub const UPDATE: &str = "update";
|
||||||
pub struct AppBuilder {
|
pub struct AppBuilder {
|
||||||
pub world: World,
|
pub world: World,
|
||||||
pub universe: Universe,
|
pub universe: Universe,
|
||||||
pub render_graph: RenderGraph,
|
pub legacy_render_graph: Option<RenderGraph>,
|
||||||
pub system_stages: HashMap<String, Vec<Box<dyn Schedulable>>>,
|
pub system_stages: HashMap<String, Vec<Box<dyn Schedulable>>>,
|
||||||
pub runnable_stages: HashMap<String, Vec<Box<dyn Runnable>>>,
|
pub runnable_stages: HashMap<String, Vec<Box<dyn Runnable>>>,
|
||||||
pub stage_order: Vec<String>,
|
pub stage_order: Vec<String>,
|
||||||
|
@ -28,7 +28,7 @@ impl AppBuilder {
|
||||||
AppBuilder {
|
AppBuilder {
|
||||||
universe,
|
universe,
|
||||||
world,
|
world,
|
||||||
render_graph: RenderGraph::new(),
|
legacy_render_graph: None,
|
||||||
system_stages: HashMap::new(),
|
system_stages: HashMap::new(),
|
||||||
runnable_stages: HashMap::new(),
|
runnable_stages: HashMap::new(),
|
||||||
stage_order: Vec::new(),
|
stage_order: Vec::new(),
|
||||||
|
@ -59,7 +59,7 @@ impl AppBuilder {
|
||||||
self.universe,
|
self.universe,
|
||||||
self.world,
|
self.world,
|
||||||
schedule_builder.build(),
|
schedule_builder.build(),
|
||||||
self.render_graph,
|
self.legacy_render_graph,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,33 +107,42 @@ impl AppBuilder {
|
||||||
self
|
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 {
|
pub fn add_default_passes(mut self) -> Self {
|
||||||
let msaa_samples = 4;
|
let msaa_samples = 4;
|
||||||
let render_graph = &mut self.render_graph;
|
{
|
||||||
render_graph
|
let render_graph = &mut self.legacy_render_graph.as_mut().unwrap();
|
||||||
.add_render_resource_manager(Box::new(render_resources::MaterialResourceManager));
|
render_graph
|
||||||
render_graph
|
.add_render_resource_manager(Box::new(render_resources::MaterialResourceManager));
|
||||||
.add_render_resource_manager(Box::new(render_resources::LightResourceManager::new(10)));
|
render_graph.add_render_resource_manager(Box::new(
|
||||||
render_graph.add_render_resource_manager(Box::new(render_resources::GlobalResourceManager));
|
render_resources::LightResourceManager::new(10),
|
||||||
render_graph
|
));
|
||||||
.add_render_resource_manager(Box::new(render_resources::Global2dResourceManager));
|
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;
|
let depth_format = wgpu::TextureFormat::Depth32Float;
|
||||||
render_graph.set_pass(
|
render_graph.set_pass(
|
||||||
"forward",
|
"forward",
|
||||||
Box::new(ForwardPass::new(depth_format, msaa_samples)),
|
Box::new(ForwardPass::new(depth_format, msaa_samples)),
|
||||||
);
|
);
|
||||||
render_graph.set_pipeline(
|
render_graph.set_pipeline(
|
||||||
"forward",
|
"forward",
|
||||||
"forward",
|
"forward",
|
||||||
Box::new(ForwardPipeline::new(msaa_samples)),
|
Box::new(ForwardPipeline::new(msaa_samples)),
|
||||||
);
|
);
|
||||||
render_graph.set_pipeline(
|
render_graph.set_pipeline(
|
||||||
"forward",
|
"forward",
|
||||||
"forward_instanced",
|
"forward_instanced",
|
||||||
Box::new(ForwardInstancedPipeline::new(depth_format, msaa_samples)),
|
Box::new(ForwardInstancedPipeline::new(depth_format, msaa_samples)),
|
||||||
);
|
);
|
||||||
render_graph.set_pipeline("forward", "ui", Box::new(UiPipeline::new(msaa_samples)));
|
render_graph.set_pipeline("forward", "ui", Box::new(UiPipeline::new(msaa_samples)));
|
||||||
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -155,8 +164,10 @@ impl AppBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_defaults(self) -> Self {
|
pub fn add_defaults_legacy(self) -> Self {
|
||||||
self.add_default_resources()
|
self
|
||||||
|
.with_legacy_render_graph()
|
||||||
|
.add_default_resources()
|
||||||
.add_default_passes()
|
.add_default_passes()
|
||||||
.add_default_systems()
|
.add_default_systems()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
use crate::render::render_graph_2::{PassDescriptor, PipelineDescriptor};
|
use crate::render::render_graph_2::{PassDescriptor, PipelineDescriptor};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
// holds on to passes, pipeline descriptions, instances
|
|
||||||
// passes: shadow, forward
|
|
||||||
pub struct RenderGraph {
|
pub struct RenderGraph {
|
||||||
pub pipeline_descriptors: HashMap<String, PipelineDescriptor>,
|
pub pipeline_descriptors: HashMap<String, PipelineDescriptor>,
|
||||||
pub pass_descriptors: HashMap<String, PassDescriptor>,
|
pub pass_descriptors: HashMap<String, PassDescriptor>,
|
||||||
|
@ -62,37 +60,4 @@ impl RenderGraphBuilder {
|
||||||
pub fn build(self) -> RenderGraph {
|
pub fn build(self) -> RenderGraph {
|
||||||
self.render_graph
|
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)
|
|
||||||
)
|
|
||||||
*/
|
|
|
@ -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) {
|
fn set_index_buffer(&mut self, buffer: &wgpu::Buffer, offset: wgpu::BufferAddress) {
|
||||||
self.render_pass.set_index_buffer(buffer, offset);
|
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>;
|
||||||
|
// }
|
Loading…
Reference in a new issue