2020-07-17 01:26:21 +00:00
|
|
|
pub mod camera;
|
|
|
|
pub mod color;
|
2020-10-08 17:30:23 +00:00
|
|
|
pub mod colorspace;
|
2020-06-08 21:35:13 +00:00
|
|
|
pub mod draw;
|
2020-09-11 23:23:21 +00:00
|
|
|
pub mod entity;
|
2020-03-14 19:56:37 +00:00
|
|
|
pub mod mesh;
|
2020-07-17 01:26:21 +00:00
|
|
|
pub mod pass;
|
|
|
|
pub mod pipeline;
|
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-03-20 19:47:33 +00:00
|
|
|
pub mod texture;
|
2020-04-05 21:12:14 +00:00
|
|
|
|
2021-02-09 20:14:10 +00:00
|
|
|
use bevy_ecs::{IntoExclusiveSystem, IntoSystem, SystemStage};
|
2020-11-28 00:39:59 +00:00
|
|
|
use bevy_reflect::RegisterTypeBuilder;
|
2020-12-09 21:38:48 +00:00
|
|
|
use draw::Visible;
|
2020-04-06 03:19:02 +00:00
|
|
|
pub use once_cell;
|
|
|
|
|
2020-07-17 01:26:21 +00:00
|
|
|
pub mod prelude {
|
|
|
|
pub use crate::{
|
2020-07-30 01:15:15 +00:00
|
|
|
base::Msaa,
|
2020-07-17 02:34:18 +00:00
|
|
|
color::Color,
|
2020-12-09 21:38:48 +00:00
|
|
|
draw::{Draw, Visible},
|
2020-07-17 02:34:18 +00:00
|
|
|
entity::*,
|
|
|
|
mesh::{shape, Mesh},
|
2020-08-30 18:20:11 +00:00
|
|
|
pass::ClearColor,
|
2020-07-17 02:34:18 +00:00
|
|
|
pipeline::RenderPipelines,
|
|
|
|
shader::Shader,
|
2020-07-17 01:26:21 +00:00
|
|
|
texture::Texture,
|
|
|
|
};
|
|
|
|
}
|
2020-04-05 21:12:14 +00:00
|
|
|
|
2020-07-17 01:26:21 +00:00
|
|
|
use crate::prelude::*;
|
2020-11-28 00:39:59 +00:00
|
|
|
use base::Msaa;
|
2020-07-17 01:47:51 +00:00
|
|
|
use bevy_app::prelude::*;
|
2021-02-18 21:20:37 +00:00
|
|
|
use bevy_asset::{AddAsset, AssetStage};
|
|
|
|
use bevy_ecs::StageLabel;
|
2020-08-09 23:13:04 +00:00
|
|
|
use camera::{
|
|
|
|
ActiveCameras, Camera, OrthographicProjection, PerspectiveProjection, VisibleEntities,
|
|
|
|
};
|
|
|
|
use pipeline::{
|
2020-11-10 21:20:05 +00:00
|
|
|
IndexFormat, PipelineCompiler, PipelineDescriptor, PipelineSpecialization, PrimitiveTopology,
|
|
|
|
ShaderSpecialization,
|
2020-08-09 23:13:04 +00:00
|
|
|
};
|
2020-07-17 01:26:21 +00:00
|
|
|
use render_graph::{
|
2020-11-28 00:39:59 +00:00
|
|
|
base::{self, BaseRenderGraphBuilder, BaseRenderGraphConfig, MainPass},
|
2020-07-17 01:26:21 +00:00
|
|
|
RenderGraph,
|
|
|
|
};
|
|
|
|
use renderer::{AssetRenderResourceBindings, RenderResourceBindings};
|
2020-12-07 20:32:13 +00:00
|
|
|
use shader::ShaderLoader;
|
2020-08-11 06:49:17 +00:00
|
|
|
#[cfg(feature = "hdr")]
|
|
|
|
use texture::HdrTextureLoader;
|
|
|
|
#[cfg(feature = "png")]
|
|
|
|
use texture::ImageTextureLoader;
|
2020-04-05 21:12:14 +00:00
|
|
|
|
2020-08-09 23:13:04 +00:00
|
|
|
/// The names of "render" App stages
|
2021-02-18 21:20:37 +00:00
|
|
|
#[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)]
|
|
|
|
pub enum RenderStage {
|
2020-06-14 01:38:25 +00:00
|
|
|
/// Stage where render resources are set up
|
2021-02-18 21:20:37 +00:00
|
|
|
RenderResource,
|
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.
|
2021-02-18 21:20:37 +00:00
|
|
|
RenderGraphSystems,
|
2020-06-14 01:38:25 +00:00
|
|
|
// Stage where draw systems are executed. This is generally where Draw components are setup
|
2021-02-18 21:20:37 +00:00
|
|
|
Draw,
|
|
|
|
Render,
|
|
|
|
PostRender,
|
2020-06-01 21:33:00 +00:00
|
|
|
}
|
2020-04-06 08:57:00 +00:00
|
|
|
|
2020-08-09 23:13:04 +00:00
|
|
|
/// Adds core render types and systems to an App
|
2020-05-03 17:54:30 +00:00
|
|
|
pub struct RenderPlugin {
|
2020-11-10 21:20:05 +00:00
|
|
|
/// configures the "base render graph". If this is not `None`, the "base render graph" will be added
|
2020-05-03 17:54:30 +00:00
|
|
|
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
|
|
|
|
2020-08-08 03:22:17 +00:00
|
|
|
impl Plugin for RenderPlugin {
|
2020-04-06 03:19:02 +00:00
|
|
|
fn build(&self, app: &mut AppBuilder) {
|
2020-08-11 06:49:17 +00:00
|
|
|
#[cfg(feature = "png")]
|
|
|
|
{
|
2020-10-18 20:48:15 +00:00
|
|
|
app.init_asset_loader::<ImageTextureLoader>();
|
2020-08-11 06:49:17 +00:00
|
|
|
}
|
|
|
|
#[cfg(feature = "hdr")]
|
|
|
|
{
|
2020-10-18 20:48:15 +00:00
|
|
|
app.init_asset_loader::<HdrTextureLoader>();
|
2020-08-11 06:49:17 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 20:32:13 +00:00
|
|
|
app.init_asset_loader::<ShaderLoader>();
|
|
|
|
|
2020-10-12 23:54:22 +00:00
|
|
|
if app.resources().get::<ClearColor>().is_none() {
|
|
|
|
app.resources_mut().insert(ClearColor::default());
|
|
|
|
}
|
|
|
|
|
2020-12-13 02:04:42 +00:00
|
|
|
app.add_stage_after(
|
2021-02-18 21:20:37 +00:00
|
|
|
AssetStage::AssetEvents,
|
|
|
|
RenderStage::RenderResource,
|
2020-12-13 02:04:42 +00:00
|
|
|
SystemStage::parallel(),
|
|
|
|
)
|
|
|
|
.add_stage_after(
|
2021-02-18 21:20:37 +00:00
|
|
|
RenderStage::RenderResource,
|
|
|
|
RenderStage::RenderGraphSystems,
|
2020-12-13 02:04:42 +00:00
|
|
|
SystemStage::parallel(),
|
|
|
|
)
|
|
|
|
.add_stage_after(
|
2021-02-18 21:20:37 +00:00
|
|
|
RenderStage::RenderGraphSystems,
|
|
|
|
RenderStage::Draw,
|
|
|
|
SystemStage::parallel(),
|
|
|
|
)
|
|
|
|
.add_stage_after(
|
|
|
|
RenderStage::Draw,
|
|
|
|
RenderStage::Render,
|
|
|
|
SystemStage::parallel(),
|
|
|
|
)
|
|
|
|
.add_stage_after(
|
|
|
|
RenderStage::Render,
|
|
|
|
RenderStage::PostRender,
|
2020-12-13 02:04:42 +00:00
|
|
|
SystemStage::parallel(),
|
|
|
|
)
|
|
|
|
.add_asset::<Mesh>()
|
|
|
|
.add_asset::<Texture>()
|
|
|
|
.add_asset::<Shader>()
|
|
|
|
.add_asset::<PipelineDescriptor>()
|
|
|
|
.register_type::<Camera>()
|
|
|
|
.register_type::<Draw>()
|
|
|
|
.register_type::<Visible>()
|
|
|
|
.register_type::<RenderPipelines>()
|
|
|
|
.register_type::<OrthographicProjection>()
|
|
|
|
.register_type::<PerspectiveProjection>()
|
|
|
|
.register_type::<MainPass>()
|
|
|
|
.register_type::<VisibleEntities>()
|
|
|
|
.register_type::<Color>()
|
|
|
|
.register_type::<ShaderSpecialization>()
|
|
|
|
.register_type::<PrimitiveTopology>()
|
|
|
|
.register_type::<IndexFormat>()
|
|
|
|
.register_type::<PipelineSpecialization>()
|
|
|
|
.init_resource::<RenderGraph>()
|
|
|
|
.init_resource::<PipelineCompiler>()
|
2021-02-18 21:20:37 +00:00
|
|
|
.init_resource::<Msaa>()
|
2020-12-13 02:04:42 +00:00
|
|
|
.init_resource::<RenderResourceBindings>()
|
|
|
|
.init_resource::<AssetRenderResourceBindings>()
|
|
|
|
.init_resource::<ActiveCameras>()
|
2021-02-18 21:20:37 +00:00
|
|
|
.add_system_to_stage(CoreStage::PreUpdate, draw::clear_draw_system.system())
|
2020-12-16 05:57:16 +00:00
|
|
|
.add_system_to_stage(
|
2021-02-18 21:20:37 +00:00
|
|
|
CoreStage::PostUpdate,
|
2020-12-16 05:57:16 +00:00
|
|
|
camera::active_cameras_system.system(),
|
|
|
|
)
|
2020-12-13 02:04:42 +00:00
|
|
|
.add_system_to_stage(
|
2021-02-18 21:20:37 +00:00
|
|
|
CoreStage::PostUpdate,
|
2020-12-16 05:57:16 +00:00
|
|
|
camera::camera_system::<OrthographicProjection>.system(),
|
2020-12-13 02:04:42 +00:00
|
|
|
)
|
|
|
|
.add_system_to_stage(
|
2021-02-18 21:20:37 +00:00
|
|
|
CoreStage::PostUpdate,
|
2020-12-16 05:57:16 +00:00
|
|
|
camera::camera_system::<PerspectiveProjection>.system(),
|
2020-12-13 02:04:42 +00:00
|
|
|
)
|
|
|
|
// registration order matters here. this must come after all camera_system::<T> systems
|
|
|
|
.add_system_to_stage(
|
2021-02-18 21:20:37 +00:00
|
|
|
CoreStage::PostUpdate,
|
2020-12-16 05:57:16 +00:00
|
|
|
camera::visible_entities_system.system(),
|
|
|
|
)
|
|
|
|
.add_system_to_stage(
|
2021-02-18 21:20:37 +00:00
|
|
|
RenderStage::RenderResource,
|
2020-12-16 05:57:16 +00:00
|
|
|
shader::shader_update_system.system(),
|
|
|
|
)
|
|
|
|
.add_system_to_stage(
|
2021-02-18 21:20:37 +00:00
|
|
|
RenderStage::RenderResource,
|
2020-12-16 05:57:16 +00:00
|
|
|
mesh::mesh_resource_provider_system.system(),
|
|
|
|
)
|
|
|
|
.add_system_to_stage(
|
2021-02-18 21:20:37 +00:00
|
|
|
RenderStage::RenderResource,
|
2020-12-16 05:57:16 +00:00
|
|
|
Texture::texture_resource_system.system(),
|
2020-12-13 02:04:42 +00:00
|
|
|
)
|
|
|
|
.add_system_to_stage(
|
2021-02-18 21:20:37 +00:00
|
|
|
RenderStage::RenderGraphSystems,
|
2021-02-09 20:14:10 +00:00
|
|
|
render_graph::render_graph_schedule_executor_system.exclusive_system(),
|
2020-12-13 02:04:42 +00:00
|
|
|
)
|
2020-12-16 05:57:16 +00:00
|
|
|
.add_system_to_stage(
|
2021-02-18 21:20:37 +00:00
|
|
|
RenderStage::Draw,
|
|
|
|
pipeline::draw_render_pipelines_system.system(),
|
|
|
|
)
|
|
|
|
.add_system_to_stage(
|
|
|
|
RenderStage::PostRender,
|
2020-12-16 05:57:16 +00:00
|
|
|
shader::clear_shader_defs_system.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-07-30 01:15:15 +00:00
|
|
|
let msaa = resources.get::<Msaa>().unwrap();
|
|
|
|
render_graph.add_base_graph(config, &msaa);
|
2020-06-23 22:58:06 +00:00
|
|
|
let mut active_cameras = resources.get_mut::<ActiveCameras>().unwrap();
|
|
|
|
if config.add_3d_camera {
|
2020-12-03 21:46:15 +00:00
|
|
|
active_cameras.add(base::camera::CAMERA_3D);
|
2020-06-23 22:58:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if config.add_2d_camera {
|
2020-12-03 21:46:15 +00:00
|
|
|
active_cameras.add(base::camera::CAMERA_2D);
|
2020-06-23 22:58:06 +00:00
|
|
|
}
|
2020-05-18 18:31:11 +00:00
|
|
|
}
|
2020-04-05 21:12:14 +00:00
|
|
|
}
|
|
|
|
}
|