Skip to content

Commit

Permalink
bevy_reflect: Register missing reflected types for bevy_render (bev…
Browse files Browse the repository at this point in the history
…yengine#6725)

# Objective 

Many types in `bevy_render` implemented `Reflect` but were not registered.

## Solution

Register all types in `bevy_render` that impl `Reflect`.

This also registers additional dependent types (i.e. field types).

> Note: Adding these dependent types would not be needed using something like bevyengine#5781 😉 

---

## Changelog

- Register missing `bevy_render` types in the `TypeRegistry`:
  - `camera::RenderTarget`
  - `globals::GlobalsUniform`
  - `texture::Image`
  - `view::ComputedVisibility`
  - `view::Visibility`
  - `view::VisibleEntities`
- Register additional dependent types:
  - `view::ComputedVisibilityFlags`
  - `Vec<Entity>`
  • Loading branch information
MrGVSV authored and ItsDoot committed Feb 1, 2023
1 parent 1375896 commit 13e1ab2
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 24 deletions.
13 changes: 2 additions & 11 deletions crates/bevy_render/src/camera/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ pub use camera::*;
pub use camera_driver_node::*;
pub use projection::*;

use crate::{
primitives::Aabb,
render_graph::RenderGraph,
view::{ComputedVisibility, RenderLayers, Visibility, VisibleEntities},
RenderApp, RenderStage,
};
use crate::{render_graph::RenderGraph, RenderApp, RenderStage};
use bevy_app::{App, Plugin};

#[derive(Default)]
Expand All @@ -23,14 +18,10 @@ impl Plugin for CameraPlugin {
app.register_type::<Camera>()
.register_type::<Viewport>()
.register_type::<Option<Viewport>>()
.register_type::<Visibility>()
.register_type::<ComputedVisibility>()
.register_type::<VisibleEntities>()
.register_type::<WindowOrigin>()
.register_type::<ScalingMode>()
.register_type::<Aabb>()
.register_type::<CameraRenderGraph>()
.register_type::<RenderLayers>()
.register_type::<RenderTarget>()
.add_plugin(CameraProjectionPlugin::<Projection>::default())
.add_plugin(CameraProjectionPlugin::<OrthographicProjection>::default())
.add_plugin(CameraProjectionPlugin::<PerspectiveProjection>::default());
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_render/src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct GlobalsPlugin;

impl Plugin for GlobalsPlugin {
fn build(&self, app: &mut App) {
app.register_type::<GlobalsUniform>();
if let Ok(render_app) = app.get_sub_app_mut(RenderApp) {
render_app
.init_resource::<GlobalsBuffer>()
Expand Down
20 changes: 9 additions & 11 deletions crates/bevy_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,10 @@ pub mod prelude {

use globals::GlobalsPlugin;
pub use once_cell;
use prelude::ComputedVisibility;

use crate::{
camera::CameraPlugin,
color::Color,
mesh::MeshPlugin,
primitives::{CubemapFrusta, Frustum},
render_graph::RenderGraph,
render_resource::{PipelineCache, Shader, ShaderLoader},
renderer::{render_system, RenderInstance},
view::{ViewPlugin, WindowRenderPlugin},
Expand Down Expand Up @@ -137,8 +133,7 @@ impl Plugin for RenderPlugin {
app.add_asset::<Shader>()
.add_debug_asset::<Shader>()
.init_asset_loader::<ShaderLoader>()
.init_debug_asset_loader::<ShaderLoader>()
.register_type::<Color>();
.init_debug_asset_loader::<ShaderLoader>();

if let Some(backends) = options.backends {
let windows = app.world.resource_mut::<bevy_window::Windows>();
Expand Down Expand Up @@ -166,9 +161,7 @@ impl Plugin for RenderPlugin {
.insert_resource(queue.clone())
.insert_resource(adapter_info.clone())
.insert_resource(render_adapter.clone())
.init_resource::<ScratchMainWorld>()
.register_type::<Frustum>()
.register_type::<CubemapFrusta>();
.init_resource::<ScratchMainWorld>();

let pipeline_cache = PipelineCache::new(device.clone());
let asset_server = app.world.resource::<AssetServer>().clone();
Expand Down Expand Up @@ -203,7 +196,7 @@ impl Plugin for RenderPlugin {
.with_system(render_system.at_end()),
)
.add_stage(RenderStage::Cleanup, SystemStage::parallel())
.init_resource::<RenderGraph>()
.init_resource::<render_graph::RenderGraph>()
.insert_resource(RenderInstance(instance))
.insert_resource(device)
.insert_resource(queue)
Expand Down Expand Up @@ -327,12 +320,17 @@ impl Plugin for RenderPlugin {
});
}

app.add_plugin(ValidParentCheckPlugin::<ComputedVisibility>::default())
app.add_plugin(ValidParentCheckPlugin::<view::ComputedVisibility>::default())
.add_plugin(WindowRenderPlugin)
.add_plugin(CameraPlugin)
.add_plugin(ViewPlugin)
.add_plugin(MeshPlugin)
.add_plugin(GlobalsPlugin);

app.register_type::<color::Color>()
.register_type::<primitives::Aabb>()
.register_type::<primitives::CubemapFrusta>()
.register_type::<primitives::Frustum>();
}
}

Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_render/src/mesh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub use mesh::*;
use crate::render_asset::RenderAssetPlugin;
use bevy_app::{App, Plugin};
use bevy_asset::AddAsset;
use bevy_ecs::entity::Entity;

/// Adds the [`Mesh`] as an asset and makes sure that they are extracted and prepared for the GPU.
pub struct MeshPlugin;
Expand All @@ -17,6 +18,7 @@ impl Plugin for MeshPlugin {
app.add_asset::<Mesh>()
.add_asset::<skinning::SkinnedMeshInverseBindposes>()
.register_type::<skinning::SkinnedMesh>()
.register_type::<Vec<Entity>>()
.add_plugin(RenderAssetPlugin::<Mesh>::default());
}
}
1 change: 1 addition & 0 deletions crates/bevy_render/src/texture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ impl Plugin for ImagePlugin {
app.add_plugin(RenderAssetPlugin::<Image>::with_prepare_asset_label(
PrepareAssetLabel::PreAssetPrepare,
))
.register_type::<Image>()
.add_asset::<Image>()
.register_asset_reflect::<Image>();
app.world
Expand Down
7 changes: 6 additions & 1 deletion crates/bevy_render/src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ pub struct ViewPlugin;

impl Plugin for ViewPlugin {
fn build(&self, app: &mut App) {
app.register_type::<Msaa>()
app.register_type::<ComputedVisibility>()
.register_type::<ComputedVisibilityFlags>()
.register_type::<Msaa>()
.register_type::<RenderLayers>()
.register_type::<Visibility>()
.register_type::<VisibleEntities>()
.init_resource::<Msaa>()
// NOTE: windows.is_changed() handles cases where a window was resized
.add_plugin(ExtractResourcePlugin::<Msaa>::default())
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/view/visibility/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Visibility {

bitflags::bitflags! {
#[derive(Reflect)]
struct ComputedVisibilityFlags: u8 {
pub(super) struct ComputedVisibilityFlags: u8 {
const VISIBLE_IN_VIEW = 1 << 0;
const VISIBLE_IN_HIERARCHY = 1 << 1;
}
Expand Down

0 comments on commit 13e1ab2

Please sign in to comment.