2020-04-28 00:41:02 +00:00
|
|
|
pub mod batch;
|
2020-03-14 19:56:37 +00:00
|
|
|
mod camera;
|
2020-06-08 21:35:13 +00:00
|
|
|
pub mod draw;
|
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-25 00:46:54 +00:00
|
|
|
pub mod renderer;
|
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-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 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-05-03 17:54:30 +00:00
|
|
|
pub mod base_render_graph;
|
2020-03-10 06:08:09 +00:00
|
|
|
pub mod pass;
|
|
|
|
pub mod pipeline;
|
|
|
|
pub mod render_resource;
|
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::{
|
2020-04-06 23:15:59 +00:00
|
|
|
mesh::Mesh,
|
2020-06-10 06:16:48 +00:00
|
|
|
pipeline::{PipelineCompiler, PipelineDescriptor, VertexBufferDescriptors},
|
2020-06-14 19:02:19 +00:00
|
|
|
render_resource::RenderResourceBindings,
|
2020-04-25 00:46:54 +00:00
|
|
|
shader::Shader,
|
2020-04-06 23:15:59 +00:00
|
|
|
texture::Texture,
|
2020-04-05 21:12:14 +00:00
|
|
|
};
|
|
|
|
|
2020-05-03 17:54:30 +00:00
|
|
|
use base_render_graph::{BaseRenderGraphBuilder, BaseRenderGraphConfig};
|
2020-06-01 21:33:00 +00:00
|
|
|
use bevy_app::{AppBuilder, AppPlugin};
|
2020-05-13 23:17:44 +00:00
|
|
|
use bevy_asset::AddAsset;
|
2020-05-28 02:27:55 +00:00
|
|
|
use bevy_type_registry::RegisterType;
|
2020-06-15 07:08:50 +00:00
|
|
|
use draw::{clear_draw_system, draw_system, Draw};
|
2020-05-16 07:27:30 +00:00
|
|
|
use legion::prelude::IntoSystem;
|
2020-04-25 00:46:54 +00:00
|
|
|
use mesh::mesh_resource_provider_system;
|
2020-06-15 19:45:18 +00:00
|
|
|
use pipeline::{compile_pipelines_system, RenderPipelines};
|
2020-06-14 01:38:25 +00:00
|
|
|
use render_graph::{system::render_graph_schedule_executor_system, RenderGraph};
|
2020-06-15 19:45:18 +00:00
|
|
|
use render_resource::{bind_groups_system, AssetRenderResourceBindings};
|
2020-05-27 20:46:43 +00:00
|
|
|
use std::ops::Range;
|
2020-06-04 03:08:20 +00:00
|
|
|
use texture::{PngTextureLoader, TextureResourceSystemState};
|
2020-04-05 21:12:14 +00:00
|
|
|
|
2020-06-01 21:33:00 +00:00
|
|
|
pub mod stage {
|
2020-06-14 01:38:25 +00:00
|
|
|
/// Stage where render resources are set up
|
2020-06-01 21:33:00 +00:00
|
|
|
pub static RENDER_RESOURCE: &str = "render_resource";
|
2020-06-14 01:38:25 +00:00
|
|
|
/// Stage where Render Graph systems are run. In general you shouldn't add systems to this stage manually.
|
|
|
|
pub static RENDER_GRAPH_SYSTEMS: &str = "render_graph_systems";
|
|
|
|
// Stage where draw systems are executed. This is generally where Draw components are setup
|
|
|
|
pub static DRAW: &str = "draw";
|
2020-06-01 21:33:00 +00:00
|
|
|
pub static RENDER: &str = "render";
|
2020-06-14 01:38:25 +00:00
|
|
|
pub static POST_RENDER: &str = "post_render";
|
2020-06-01 21:33:00 +00:00
|
|
|
}
|
2020-04-06 08:57:00 +00:00
|
|
|
|
2020-05-03 17:54:30 +00:00
|
|
|
pub struct RenderPlugin {
|
|
|
|
/// configures the "base render graph". If this is not `None`, the "base render graph" will be added
|
|
|
|
pub base_render_graph_config: Option<BaseRenderGraphConfig>,
|
|
|
|
}
|
2020-04-05 21:12:14 +00:00
|
|
|
|
2020-05-03 17:54:30 +00:00
|
|
|
impl Default for RenderPlugin {
|
|
|
|
fn default() -> Self {
|
|
|
|
RenderPlugin {
|
|
|
|
base_render_graph_config: Some(BaseRenderGraphConfig::default()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-05 21:12:14 +00:00
|
|
|
|
|
|
|
impl AppPlugin for RenderPlugin {
|
2020-04-06 03:19:02 +00:00
|
|
|
fn build(&self, app: &mut AppBuilder) {
|
2020-06-01 21:33:00 +00:00
|
|
|
app.add_stage_after(bevy_asset::stage::ASSET_EVENTS, stage::RENDER_RESOURCE)
|
2020-06-14 01:38:25 +00:00
|
|
|
.add_stage_after(stage::RENDER_RESOURCE, stage::RENDER_GRAPH_SYSTEMS)
|
|
|
|
.add_stage_after(stage::RENDER_GRAPH_SYSTEMS, stage::DRAW)
|
|
|
|
.add_stage_after(stage::DRAW, stage::RENDER)
|
|
|
|
.add_stage_after(stage::RENDER, stage::POST_RENDER)
|
2020-05-13 23:17:44 +00:00
|
|
|
.add_asset::<Mesh>()
|
|
|
|
.add_asset::<Texture>()
|
|
|
|
.add_asset::<Shader>()
|
|
|
|
.add_asset::<PipelineDescriptor>()
|
2020-05-22 00:21:33 +00:00
|
|
|
.add_asset_loader::<Texture, PngTextureLoader>()
|
2020-05-26 01:27:04 +00:00
|
|
|
.register_component::<Camera>()
|
2020-06-10 06:16:48 +00:00
|
|
|
.register_component::<Draw>()
|
|
|
|
.register_component::<RenderPipelines>()
|
2020-05-30 19:31:04 +00:00
|
|
|
.register_component::<OrthographicProjection>()
|
|
|
|
.register_component::<PerspectiveProjection>()
|
2020-05-27 02:47:33 +00:00
|
|
|
.register_property_type::<Color>()
|
2020-05-27 20:46:43 +00:00
|
|
|
.register_property_type::<Range<f32>>()
|
2020-05-18 18:31:11 +00:00
|
|
|
.init_resource::<RenderGraph>()
|
2020-05-13 23:35:38 +00:00
|
|
|
.init_resource::<PipelineCompiler>()
|
2020-06-14 19:02:19 +00:00
|
|
|
.init_resource::<RenderResourceBindings>()
|
2020-05-13 23:35:38 +00:00
|
|
|
.init_resource::<VertexBufferDescriptors>()
|
2020-05-18 18:31:11 +00:00
|
|
|
.init_resource::<TextureResourceSystemState>()
|
2020-06-15 19:45:18 +00:00
|
|
|
.init_resource::<AssetRenderResourceBindings>()
|
2020-06-10 06:16:48 +00:00
|
|
|
.add_system_to_stage(bevy_app::stage::PRE_UPDATE, clear_draw_system.system())
|
2020-06-04 03:08:20 +00:00
|
|
|
.init_system_to_stage(
|
|
|
|
bevy_app::stage::POST_UPDATE,
|
|
|
|
camera::camera_system::<OrthographicProjection>,
|
|
|
|
)
|
|
|
|
.init_system_to_stage(
|
|
|
|
bevy_app::stage::POST_UPDATE,
|
|
|
|
camera::camera_system::<PerspectiveProjection>,
|
|
|
|
)
|
2020-06-14 01:38:25 +00:00
|
|
|
// TODO: turn these "resource systems" into graph nodes and remove the RENDER_RESOURCE stage
|
2020-06-01 21:33:00 +00:00
|
|
|
.init_system_to_stage(stage::RENDER_RESOURCE, mesh_resource_provider_system)
|
2020-05-18 18:31:11 +00:00
|
|
|
.add_system_to_stage(
|
2020-06-01 21:33:00 +00:00
|
|
|
stage::RENDER_RESOURCE,
|
2020-05-18 18:31:11 +00:00
|
|
|
Texture::texture_resource_system.system(),
|
2020-06-14 01:38:25 +00:00
|
|
|
)
|
|
|
|
.add_system_to_stage(
|
|
|
|
stage::RENDER_GRAPH_SYSTEMS,
|
|
|
|
render_graph_schedule_executor_system,
|
|
|
|
)
|
|
|
|
.add_system_to_stage(
|
|
|
|
stage::RENDER_GRAPH_SYSTEMS,
|
|
|
|
compile_pipelines_system.system(),
|
|
|
|
)
|
2020-06-15 19:45:18 +00:00
|
|
|
.add_system_to_stage(stage::RENDER_GRAPH_SYSTEMS, bind_groups_system.system())
|
2020-06-14 01:38:25 +00:00
|
|
|
.add_system_to_stage(stage::DRAW, draw_system::<RenderPipelines>.system());
|
2020-05-18 18:31:11 +00:00
|
|
|
|
|
|
|
if let Some(ref config) = self.base_render_graph_config {
|
|
|
|
let resources = app.resources();
|
|
|
|
let mut render_graph = resources.get_mut::<RenderGraph>().unwrap();
|
2020-06-04 06:53:00 +00:00
|
|
|
render_graph.add_base_graph(config);
|
2020-05-18 18:31:11 +00:00
|
|
|
}
|
2020-04-05 21:12:14 +00:00
|
|
|
}
|
|
|
|
}
|