incomplete plug in
This commit is contained in:
parent
b0df491559
commit
e4d42c29a9
64
examples/simple_new_graph.rs
Normal file
64
examples/simple_new_graph.rs
Normal file
@ -0,0 +1,64 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
fn main() {
|
||||
AppBuilder::new().add_defaults().setup_world(setup).run();
|
||||
}
|
||||
|
||||
fn setup(world: &mut World) {
|
||||
let cube = Mesh::load(MeshType::Cube);
|
||||
let plane = Mesh::load(MeshType::Plane { size: 10.0 });
|
||||
|
||||
let (cube_handle, plane_handle) = {
|
||||
let mut mesh_storage = world.resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||
(mesh_storage.add(cube), mesh_storage.add(plane))
|
||||
};
|
||||
|
||||
world.build()
|
||||
// plane
|
||||
.build_archetype(MeshEntity {
|
||||
mesh: plane_handle.clone(),
|
||||
material: Material::new(Albedo::Color(math::vec4(0.1, 0.2, 0.1, 1.0))),
|
||||
local_to_world: LocalToWorld::identity(),
|
||||
translation: Translation::new(0.0, 0.0, 0.0),
|
||||
})
|
||||
// cube
|
||||
.build_archetype(MeshEntity {
|
||||
mesh: cube_handle,
|
||||
material: Material::new(Albedo::Color(math::vec4(0.5, 0.3, 0.3, 1.0))),
|
||||
local_to_world: LocalToWorld::identity(),
|
||||
translation: Translation::new(0.0, 0.0, 1.0),
|
||||
})
|
||||
// light
|
||||
.build_archetype(LightEntity {
|
||||
light: Light {
|
||||
color: wgpu::Color {
|
||||
r: 0.8,
|
||||
g: 0.8,
|
||||
b: 0.5,
|
||||
a: 1.0,
|
||||
},
|
||||
fov: f32::to_radians(60.0),
|
||||
depth: 0.1..50.0,
|
||||
target_view: None,
|
||||
},
|
||||
local_to_world: LocalToWorld::identity(),
|
||||
translation: Translation::new(4.0, -4.0, 5.0),
|
||||
rotation: Rotation::from_euler_angles(0.0, 0.0, 0.0),
|
||||
})
|
||||
// camera
|
||||
.build_archetype(CameraEntity {
|
||||
camera: Camera::new(CameraType::Projection {
|
||||
fov: std::f32::consts::PI / 4.0,
|
||||
near: 1.0,
|
||||
far: 1000.0,
|
||||
aspect_ratio: 1.0,
|
||||
}),
|
||||
active_camera: ActiveCamera,
|
||||
local_to_world: LocalToWorld(Mat4::look_at_rh(
|
||||
Vec3::new(3.0, 8.0, 5.0),
|
||||
Vec3::new(0.0, 0.0, 0.0),
|
||||
Vec3::new(0.0, 0.0, 1.0),
|
||||
)),
|
||||
})
|
||||
.build();
|
||||
}
|
@ -6,12 +6,13 @@ use winit::{
|
||||
|
||||
use legion::prelude::*;
|
||||
|
||||
use crate::{core::Time, render::*, app::AppBuilder};
|
||||
use crate::{core::Time, render, app::AppBuilder, render::render_graph_2::{Renderer, RenderGraph}};
|
||||
|
||||
pub struct App {
|
||||
pub universe: Universe,
|
||||
pub world: World,
|
||||
pub legacy_render_graph: Option<RenderGraph>,
|
||||
pub legacy_render_graph: Option<render::RenderGraph>,
|
||||
pub renderer: Option<Box<dyn Renderer>>,
|
||||
pub schedule: Schedule,
|
||||
}
|
||||
|
||||
@ -20,13 +21,15 @@ impl App {
|
||||
universe: Universe,
|
||||
world: World,
|
||||
schedule: Schedule,
|
||||
legacy_render_graph: Option<RenderGraph>,
|
||||
legacy_render_graph: Option<render::RenderGraph>,
|
||||
renderer: Option<Box<dyn Renderer>>,
|
||||
) -> App {
|
||||
App {
|
||||
universe,
|
||||
world,
|
||||
schedule: schedule,
|
||||
legacy_render_graph: legacy_render_graph,
|
||||
renderer: renderer,
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,6 +48,12 @@ impl App {
|
||||
render_graph.render(&mut self.world);
|
||||
}
|
||||
|
||||
if let Some(ref mut renderer) = self.renderer {
|
||||
if let Some(render_graph) = self.world.resources.get::<RenderGraph>() {
|
||||
renderer.process_render_graph(&render_graph, &mut self.world);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(mut time) = self.world.resources.get_mut::<Time>() {
|
||||
time.stop();
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ use crate::{
|
||||
core::Time,
|
||||
legion::prelude::{Runnable, Schedulable, Schedule, Universe, World},
|
||||
render::{passes::*, *},
|
||||
render::render_graph_2,
|
||||
ui,
|
||||
};
|
||||
|
||||
@ -16,6 +17,7 @@ pub struct AppBuilder {
|
||||
pub world: World,
|
||||
pub universe: Universe,
|
||||
pub legacy_render_graph: Option<RenderGraph>,
|
||||
pub renderer: Option<Box<dyn render_graph_2::Renderer>>,
|
||||
pub system_stages: HashMap<String, Vec<Box<dyn Schedulable>>>,
|
||||
pub runnable_stages: HashMap<String, Vec<Box<dyn Runnable>>>,
|
||||
pub stage_order: Vec<String>,
|
||||
@ -29,6 +31,7 @@ impl AppBuilder {
|
||||
universe,
|
||||
world,
|
||||
legacy_render_graph: None,
|
||||
renderer: None,
|
||||
system_stages: HashMap::new(),
|
||||
runnable_stages: HashMap::new(),
|
||||
stage_order: Vec::new(),
|
||||
@ -60,6 +63,7 @@ impl AppBuilder {
|
||||
self.world,
|
||||
schedule_builder.build(),
|
||||
self.legacy_render_graph,
|
||||
self.renderer,
|
||||
)
|
||||
}
|
||||
|
||||
@ -152,6 +156,7 @@ impl AppBuilder {
|
||||
resources.insert(Time::new());
|
||||
resources.insert(AssetStorage::<Mesh>::new());
|
||||
resources.insert(AssetStorage::<Texture>::new());
|
||||
resources.insert(render_graph_2::RenderGraph::default());
|
||||
self
|
||||
}
|
||||
|
||||
@ -164,6 +169,11 @@ impl AppBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
// pub fn add_wgpu_renderer(mut self) -> Self {
|
||||
// self.renderer = Some(render_graph_2::WgpuRenderer);
|
||||
// self
|
||||
// }
|
||||
|
||||
pub fn add_defaults_legacy(self) -> Self {
|
||||
self
|
||||
.with_legacy_render_graph()
|
||||
@ -171,4 +181,10 @@ impl AppBuilder {
|
||||
.add_default_passes()
|
||||
.add_default_systems()
|
||||
}
|
||||
|
||||
pub fn add_defaults(self) -> Self {
|
||||
self
|
||||
.add_default_resources()
|
||||
.add_default_systems()
|
||||
}
|
||||
}
|
||||
|
@ -4,13 +4,14 @@ mod renderer;
|
||||
mod shader;
|
||||
mod render_graph;
|
||||
mod example;
|
||||
|
||||
mod render_system;
|
||||
|
||||
pub use pipeline::*;
|
||||
pub use pass::*;
|
||||
pub use renderer::*;
|
||||
pub use shader::*;
|
||||
pub use render_graph::*;
|
||||
pub use render_system::*;
|
||||
|
||||
// a named graphics resource provided by a resource provider
|
||||
pub struct Resource {
|
||||
|
19
src/render/render_graph_2/render_system.rs
Normal file
19
src/render/render_graph_2/render_system.rs
Normal file
@ -0,0 +1,19 @@
|
||||
use crate::prelude::*;
|
||||
use crate::render::render_graph_2::{RenderGraph, WgpuRenderer, Renderer};
|
||||
use winit::window::Window;
|
||||
|
||||
pub fn build_wgpu_render_system(world: &mut World) -> Box<dyn Schedulable> {
|
||||
let window = world.resources.get::<Window>();
|
||||
let renderer = WgpuRenderer {
|
||||
|
||||
};
|
||||
|
||||
SystemBuilder::new("wgpu_render_system")
|
||||
.read_resource::<RenderGraph>()
|
||||
.with_query(<(Write<Node>,)>::query().filter(!component::<Parent>()))
|
||||
.write_component::<Node>()
|
||||
.read_component::<Children>()
|
||||
.build(move |_, world, render_graph, node_query| {
|
||||
renderer.process_render_graph(*render_graph);
|
||||
})
|
||||
}
|
@ -65,6 +65,11 @@ pub struct WgpuRenderer {
|
||||
}
|
||||
|
||||
impl WgpuRenderer {
|
||||
pub fn new() -> Self {
|
||||
WgpuRenderer {
|
||||
|
||||
}
|
||||
}
|
||||
pub fn create_render_pipeline(
|
||||
pipeline_descriptor: &PipelineDescriptor,
|
||||
device: &wgpu::Device,
|
||||
|
Loading…
Reference in New Issue
Block a user