2020-04-06 22:54:17 +00:00
|
|
|
#![feature(min_specialization)]
|
2020-03-14 19:56:37 +00:00
|
|
|
mod camera;
|
2020-04-06 23:15:59 +00:00
|
|
|
pub mod entity;
|
2020-03-14 19:56:37 +00:00
|
|
|
pub mod mesh;
|
2020-02-18 02:36:31 +00:00
|
|
|
pub mod render_graph;
|
2020-04-09 22:03:54 +00:00
|
|
|
pub mod render_graph_2;
|
|
|
|
pub mod renderer_2;
|
2020-04-04 19:43:16 +00:00
|
|
|
pub mod shader;
|
2020-04-19 17:08:47 +00:00
|
|
|
pub mod vertex;
|
2020-01-08 06:35:07 +00:00
|
|
|
|
2020-02-18 17:16:34 +00:00
|
|
|
mod color;
|
2019-12-02 04:03:04 +00:00
|
|
|
mod light;
|
2019-12-01 09:16:15 +00:00
|
|
|
|
2020-01-11 10:11:27 +00:00
|
|
|
pub use camera::*;
|
2020-02-22 23:02:01 +00:00
|
|
|
pub use color::*;
|
2019-12-02 04:03:04 +00:00
|
|
|
pub use light::*;
|
2020-04-04 19:43:16 +00:00
|
|
|
pub use renderable::*;
|
2019-12-02 09:31:07 +00:00
|
|
|
|
2020-01-11 19:29:57 +00:00
|
|
|
pub use vertex::Vertex;
|
2020-01-01 20:23:39 +00:00
|
|
|
|
2020-03-10 06:08:09 +00:00
|
|
|
pub mod draw_target;
|
|
|
|
pub mod pass;
|
|
|
|
pub mod pipeline;
|
|
|
|
pub mod render_resource;
|
|
|
|
mod renderable;
|
2020-03-20 19:47:33 +00:00
|
|
|
pub mod texture;
|
2020-04-05 21:12:14 +00:00
|
|
|
|
2020-04-06 03:19:02 +00:00
|
|
|
pub use once_cell;
|
|
|
|
|
2020-04-05 21:12:14 +00:00
|
|
|
use self::{
|
|
|
|
draw_target::draw_targets::{
|
|
|
|
AssignedBatchesDrawTarget, AssignedMeshesDrawTarget, MeshesDrawTarget, UiDrawTarget,
|
|
|
|
},
|
2020-04-06 23:15:59 +00:00
|
|
|
mesh::Mesh,
|
2020-04-05 21:12:14 +00:00
|
|
|
pass::passes::ForwardPassBuilder,
|
|
|
|
pipeline::{
|
2020-04-12 21:47:41 +00:00
|
|
|
pipelines::ForwardPipelineBuilder, PipelineAssignments, PipelineCompiler,
|
|
|
|
PipelineDescriptor, VertexBufferDescriptors,
|
2020-04-05 21:12:14 +00:00
|
|
|
},
|
|
|
|
render_graph::RenderGraph,
|
|
|
|
render_resource::{
|
2020-04-20 02:06:41 +00:00
|
|
|
entity_render_resource_assignments_system,
|
2020-04-05 21:12:14 +00:00
|
|
|
resource_providers::{
|
|
|
|
Camera2dResourceProvider, CameraResourceProvider, LightResourceProvider,
|
2020-04-16 00:46:22 +00:00
|
|
|
UniformResourceProvider,
|
2020-04-05 21:12:14 +00:00
|
|
|
},
|
|
|
|
AssetBatchers, EntityRenderResourceAssignments, RenderResourceAssignments,
|
|
|
|
},
|
2020-04-06 23:15:59 +00:00
|
|
|
shader::{uniforms::StandardMaterial, Shader},
|
|
|
|
texture::Texture,
|
2020-04-05 21:12:14 +00:00
|
|
|
};
|
|
|
|
|
2020-04-06 23:15:59 +00:00
|
|
|
use bevy_app::{stage, AppBuilder, AppPlugin, GetEventReader};
|
2020-04-06 03:19:02 +00:00
|
|
|
use bevy_asset::AssetStorage;
|
2020-04-06 23:15:59 +00:00
|
|
|
use bevy_transform::prelude::LocalToWorld;
|
2020-04-06 03:19:02 +00:00
|
|
|
use bevy_window::WindowResized;
|
2020-04-20 21:29:21 +00:00
|
|
|
use render_resource::resource_providers::{CameraNode, mesh_resource_provider_system};
|
|
|
|
use render_graph_2::RenderGraph2;
|
2020-04-05 21:12:14 +00:00
|
|
|
|
2020-04-16 00:46:22 +00:00
|
|
|
pub static RENDER_RESOURCE_STAGE: &str = "render_resource";
|
2020-04-06 08:57:00 +00:00
|
|
|
pub static RENDER_STAGE: &str = "render";
|
|
|
|
|
2020-04-05 21:12:14 +00:00
|
|
|
#[derive(Default)]
|
|
|
|
pub struct RenderPlugin;
|
|
|
|
|
|
|
|
impl RenderPlugin {
|
|
|
|
pub fn setup_render_graph_defaults(app: &mut AppBuilder) {
|
2020-04-06 03:19:02 +00:00
|
|
|
let resources = app.resources();
|
2020-04-05 21:12:14 +00:00
|
|
|
let mut pipelines = app
|
2020-04-06 03:19:02 +00:00
|
|
|
.resources()
|
2020-04-05 21:12:14 +00:00
|
|
|
.get_mut::<AssetStorage<PipelineDescriptor>>()
|
|
|
|
.unwrap();
|
2020-04-06 03:19:02 +00:00
|
|
|
let mut shaders = resources.get_mut::<AssetStorage<Shader>>().unwrap();
|
|
|
|
let mut render_graph = resources.get_mut::<RenderGraph>().unwrap();
|
2020-04-05 21:12:14 +00:00
|
|
|
render_graph
|
|
|
|
.build(&mut pipelines, &mut shaders)
|
|
|
|
.add_draw_target(MeshesDrawTarget::default())
|
|
|
|
.add_draw_target(AssignedBatchesDrawTarget::default())
|
|
|
|
.add_draw_target(AssignedMeshesDrawTarget::default())
|
|
|
|
.add_draw_target(UiDrawTarget::default())
|
|
|
|
.add_resource_provider(Camera2dResourceProvider::new(
|
2020-04-06 03:19:02 +00:00
|
|
|
resources.get_event_reader::<WindowResized>(),
|
2020-04-05 21:12:14 +00:00
|
|
|
))
|
|
|
|
.add_resource_provider(LightResourceProvider::new(10))
|
|
|
|
.add_resource_provider(UniformResourceProvider::<StandardMaterial>::new(true))
|
|
|
|
.add_resource_provider(UniformResourceProvider::<LocalToWorld>::new(true))
|
|
|
|
.add_forward_pass()
|
|
|
|
.add_forward_pipeline();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AppPlugin for RenderPlugin {
|
2020-04-06 03:19:02 +00:00
|
|
|
fn build(&self, app: &mut AppBuilder) {
|
2020-04-20 21:29:21 +00:00
|
|
|
let mut render_graph = RenderGraph2::default();
|
|
|
|
render_graph.add_system_node(CameraNode::default(), app.resources_mut());
|
2020-04-05 21:12:14 +00:00
|
|
|
let mut asset_batchers = AssetBatchers::default();
|
|
|
|
asset_batchers.batch_types2::<Mesh, StandardMaterial>();
|
2020-04-16 00:46:22 +00:00
|
|
|
app.add_stage_after(stage::POST_UPDATE, RENDER_RESOURCE_STAGE)
|
|
|
|
.add_stage_after(RENDER_RESOURCE_STAGE, RENDER_STAGE)
|
|
|
|
// resources
|
2020-04-05 21:12:14 +00:00
|
|
|
.add_resource(RenderGraph::default())
|
2020-04-20 21:29:21 +00:00
|
|
|
.add_resource(render_graph)
|
2020-04-05 21:12:14 +00:00
|
|
|
.add_resource(AssetStorage::<Mesh>::new())
|
|
|
|
.add_resource(AssetStorage::<Texture>::new())
|
|
|
|
.add_resource(AssetStorage::<Shader>::new())
|
|
|
|
.add_resource(AssetStorage::<StandardMaterial>::new())
|
|
|
|
.add_resource(AssetStorage::<PipelineDescriptor>::new())
|
2020-04-12 18:45:44 +00:00
|
|
|
.add_resource(PipelineAssignments::new())
|
2020-04-05 21:12:14 +00:00
|
|
|
.add_resource(PipelineCompiler::new())
|
|
|
|
.add_resource(RenderResourceAssignments::default())
|
2020-04-20 21:29:21 +00:00
|
|
|
.add_resource(VertexBufferDescriptors::default())
|
2020-04-05 21:12:14 +00:00
|
|
|
.add_resource(EntityRenderResourceAssignments::default())
|
2020-04-16 00:46:22 +00:00
|
|
|
.add_resource(asset_batchers)
|
|
|
|
// core systems
|
2020-04-20 02:06:41 +00:00
|
|
|
.add_system(entity_render_resource_assignments_system())
|
2020-04-16 02:40:24 +00:00
|
|
|
.add_system_to_stage_init(stage::POST_UPDATE, camera::camera_update_system)
|
2020-04-20 02:06:41 +00:00
|
|
|
.add_system_to_stage(
|
|
|
|
stage::POST_UPDATE,
|
|
|
|
mesh::mesh_specializer_system(),
|
|
|
|
)
|
2020-04-16 00:46:22 +00:00
|
|
|
.add_system_to_stage(stage::POST_UPDATE, mesh::mesh_batcher_system())
|
|
|
|
.add_system_to_stage(
|
|
|
|
stage::POST_UPDATE,
|
|
|
|
shader::asset_handle_shader_def_system::<StandardMaterial>(),
|
|
|
|
)
|
|
|
|
.add_system_to_stage(
|
|
|
|
stage::POST_UPDATE,
|
|
|
|
shader::asset_handle_batcher_system::<StandardMaterial>(),
|
|
|
|
)
|
|
|
|
// render resource provider systems
|
2020-04-16 02:40:24 +00:00
|
|
|
.add_system_to_stage_init(RENDER_RESOURCE_STAGE, mesh_resource_provider_system);
|
2020-04-06 03:19:02 +00:00
|
|
|
RenderPlugin::setup_render_graph_defaults(app);
|
2020-04-05 21:12:14 +00:00
|
|
|
}
|
|
|
|
}
|