bevy/crates/bevy_render/src/lib.rs

181 lines
6.4 KiB
Rust
Raw Normal View History

2020-04-28 00:41:02 +00:00
pub mod batch;
pub mod camera;
pub mod color;
pub mod draw;
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
mod entity;
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,
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::*;
use base::{MainPass, Msaa};
2020-07-17 01:47:51 +00:00
use bevy_app::prelude::*;
2020-05-13 23:17:44 +00:00
use bevy_asset::AddAsset;
use bevy_ecs::{IntoQuerySystem, IntoThreadLocalSystem};
use bevy_type_registry::RegisterType;
use camera::{
ActiveCameras, Camera, OrthographicProjection, PerspectiveProjection, VisibleEntities,
};
use pipeline::{
DynamicBinding, PipelineCompiler, PipelineDescriptor, PipelineSpecialization,
PrimitiveTopology, ShaderSpecialization, VertexBufferDescriptors,
};
use render_graph::{
base::{self, BaseRenderGraphBuilder, BaseRenderGraphConfig},
RenderGraph,
};
use renderer::{AssetRenderResourceBindings, RenderResourceBindings};
use std::ops::Range;
#[cfg(feature = "hdr")]
use texture::HdrTextureLoader;
#[cfg(feature = "png")]
use texture::ImageTextureLoader;
use texture::TextureResourceSystemState;
2020-04-05 21:12:14 +00:00
/// The names of "render" App stages
pub mod stage {
/// Stage where render resources are set up
pub static RENDER_RESOURCE: &str = "render_resource";
/// 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";
pub static RENDER: &str = "render";
pub static POST_RENDER: &str = "post_render";
}
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.add_asset_loader::<Texture, ImageTextureLoader>();
}
#[cfg(feature = "hdr")]
{
app.add_asset_loader::<Texture, HdrTextureLoader>();
}
app.add_stage_after(bevy_asset::stage::ASSET_EVENTS, stage::RENDER_RESOURCE)
.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>()
.register_component::<Camera>()
.register_component::<Draw>()
.register_component::<RenderPipelines>()
.register_component::<OrthographicProjection>()
.register_component::<PerspectiveProjection>()
.register_component::<MainPass>()
.register_component::<VisibleEntities>()
.register_property::<Color>()
.register_property::<Range<f32>>()
.register_property::<ShaderSpecialization>()
.register_property::<DynamicBinding>()
.register_property::<PrimitiveTopology>()
.register_properties::<PipelineSpecialization>()
.init_resource::<RenderGraph>()
2020-05-13 23:35:38 +00:00
.init_resource::<PipelineCompiler>()
.init_resource::<RenderResourceBindings>()
2020-05-13 23:35:38 +00:00
.init_resource::<VertexBufferDescriptors>()
.init_resource::<TextureResourceSystemState>()
.init_resource::<AssetRenderResourceBindings>()
.init_resource::<ActiveCameras>()
.add_system_to_stage(
bevy_app::stage::PRE_UPDATE,
draw::clear_draw_system.system(),
)
.add_system_to_stage(
bevy_app::stage::POST_UPDATE,
camera::active_cameras_system.system(),
)
.add_system_to_stage(
2020-06-04 03:08:20 +00:00
bevy_app::stage::POST_UPDATE,
2020-07-10 04:18:35 +00:00
camera::camera_system::<OrthographicProjection>.system(),
2020-06-04 03:08:20 +00:00
)
.add_system_to_stage(
bevy_app::stage::POST_UPDATE,
2020-07-10 04:18:35 +00:00
camera::camera_system::<PerspectiveProjection>.system(),
)
// registration order matters here. this must come after all camera_system::<T> systems
.add_system_to_stage(
2020-06-04 03:08:20 +00:00
bevy_app::stage::POST_UPDATE,
camera::visible_entities_system.system(),
2020-06-04 03:08:20 +00:00
)
// TODO: turn these "resource systems" into graph nodes and remove the RENDER_RESOURCE stage
2020-07-10 08:37:06 +00:00
.add_system_to_stage(
stage::RENDER_RESOURCE,
mesh::mesh_resource_provider_system.system(),
2020-07-10 08:37:06 +00:00
)
.add_system_to_stage(
stage::RENDER_RESOURCE,
Texture::texture_resource_system.system(),
)
.add_system_to_stage(
stage::RENDER_GRAPH_SYSTEMS,
render_graph::render_graph_schedule_executor_system.thread_local_system(),
)
.add_system_to_stage(stage::DRAW, pipeline::draw_render_pipelines_system.system())
.add_system_to_stage(
stage::POST_RENDER,
shader::clear_shader_defs_system.system(),
);
2020-07-30 01:15:15 +00:00
if app.resources().get::<Msaa>().is_none() {
app.init_resource::<Msaa>();
}
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::CAMERA3D);
}
if config.add_2d_camera {
active_cameras.add(base::camera::CAMERA2D);
}
}
2020-04-05 21:12:14 +00:00
}
}