bevy/crates/bevy_render/src/lib.rs

207 lines
6.4 KiB
Rust
Raw Normal View History

pub mod camera;
pub mod color;
pub mod colorspace;
pub mod draw;
pub mod entity;
2020-03-14 19:56:37 +00:00
pub mod mesh;
pub mod pass;
pub mod pipeline;
2020-02-18 02:36:31 +00:00
pub mod render_graph;
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
use bevy_ecs::{IntoExclusiveSystem, IntoSystem, SystemStage};
2020-11-28 00:39:59 +00:00
use bevy_reflect::RegisterTypeBuilder;
use draw::Visible;
2020-04-06 03:19:02 +00:00
pub use once_cell;
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,
draw::{Draw, Visible},
2020-07-17 02:34:18 +00:00
entity::*,
mesh::{shape, Mesh},
pass::ClearColor,
2020-07-17 02:34:18 +00:00
pipeline::RenderPipelines,
shader::Shader,
texture::Texture,
};
}
2020-04-05 21:12:14 +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::*;
use bevy_asset::{AddAsset, AssetStage};
use bevy_ecs::StageLabel;
use camera::{
ActiveCameras, Camera, OrthographicProjection, PerspectiveProjection, VisibleEntities,
};
use pipeline::{
IndexFormat, PipelineCompiler, PipelineDescriptor, PipelineSpecialization, PrimitiveTopology,
ShaderSpecialization,
};
use render_graph::{
2020-11-28 00:39:59 +00:00
base::{self, BaseRenderGraphBuilder, BaseRenderGraphConfig, MainPass},
RenderGraph,
};
use renderer::{AssetRenderResourceBindings, RenderResourceBindings};
use shader::ShaderLoader;
#[cfg(feature = "hdr")]
use texture::HdrTextureLoader;
#[cfg(feature = "png")]
use texture::ImageTextureLoader;
2020-04-05 21:12:14 +00:00
/// The names of "render" App stages
#[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)]
pub enum RenderStage {
/// Stage where render resources are set up
RenderResource,
/// Stage where Render Graph systems are run. In general you shouldn't add systems to this stage manually.
RenderGraphSystems,
// Stage where draw systems are executed. This is generally where Draw components are setup
Draw,
Render,
PostRender,
}
2020-04-06 08:57:00 +00:00
/// Adds core render types and systems to an App
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
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) {
#[cfg(feature = "png")]
{
app.init_asset_loader::<ImageTextureLoader>();
}
#[cfg(feature = "hdr")]
{
app.init_asset_loader::<HdrTextureLoader>();
}
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(
AssetStage::AssetEvents,
RenderStage::RenderResource,
2020-12-13 02:04:42 +00:00
SystemStage::parallel(),
)
.add_stage_after(
RenderStage::RenderResource,
RenderStage::RenderGraphSystems,
2020-12-13 02:04:42 +00:00
SystemStage::parallel(),
)
.add_stage_after(
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>()
.init_resource::<Msaa>()
2020-12-13 02:04:42 +00:00
.init_resource::<RenderResourceBindings>()
.init_resource::<AssetRenderResourceBindings>()
.init_resource::<ActiveCameras>()
.add_system_to_stage(CoreStage::PreUpdate, draw::clear_draw_system.system())
.add_system_to_stage(
CoreStage::PostUpdate,
camera::active_cameras_system.system(),
)
2020-12-13 02:04:42 +00:00
.add_system_to_stage(
CoreStage::PostUpdate,
camera::camera_system::<OrthographicProjection>.system(),
2020-12-13 02:04:42 +00:00
)
.add_system_to_stage(
CoreStage::PostUpdate,
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(
CoreStage::PostUpdate,
camera::visible_entities_system.system(),
)
.add_system_to_stage(
RenderStage::RenderResource,
shader::shader_update_system.system(),
)
.add_system_to_stage(
RenderStage::RenderResource,
mesh::mesh_resource_provider_system.system(),
)
.add_system_to_stage(
RenderStage::RenderResource,
Texture::texture_resource_system.system(),
2020-12-13 02:04:42 +00:00
)
.add_system_to_stage(
RenderStage::RenderGraphSystems,
render_graph::render_graph_schedule_executor_system.exclusive_system(),
2020-12-13 02:04:42 +00:00
)
.add_system_to_stage(
RenderStage::Draw,
pipeline::draw_render_pipelines_system.system(),
)
.add_system_to_stage(
RenderStage::PostRender,
shader::clear_shader_defs_system.system(),
);
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);
let mut active_cameras = resources.get_mut::<ActiveCameras>().unwrap();
if config.add_3d_camera {
active_cameras.add(base::camera::CAMERA_3D);
}
if config.add_2d_camera {
active_cameras.add(base::camera::CAMERA_2D);
}
}
2020-04-05 21:12:14 +00:00
}
}