From c11b62726d69538763586ba9558f320d1b02b54a Mon Sep 17 00:00:00 2001 From: Gino Valente Date: Wed, 23 Nov 2022 00:41:21 +0000 Subject: [PATCH] bevy_reflect: Register missing reflected types for `bevy_render` (#6725) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Many types in `bevy_render` implemented `Reflect` but were not registered. 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 #5781 😉 --- - 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` --- crates/bevy_render/src/camera/mod.rs | 13 ++----------- crates/bevy_render/src/globals.rs | 1 + crates/bevy_render/src/lib.rs | 19 +++++++++---------- crates/bevy_render/src/mesh/mod.rs | 2 ++ crates/bevy_render/src/texture/mod.rs | 1 + crates/bevy_render/src/view/mod.rs | 6 +++++- 6 files changed, 20 insertions(+), 22 deletions(-) diff --git a/crates/bevy_render/src/camera/mod.rs b/crates/bevy_render/src/camera/mod.rs index daf1f6cb56561..df81b87b261c8 100644 --- a/crates/bevy_render/src/camera/mod.rs +++ b/crates/bevy_render/src/camera/mod.rs @@ -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)] @@ -23,14 +18,10 @@ impl Plugin for CameraPlugin { app.register_type::() .register_type::() .register_type::>() - .register_type::() - .register_type::() - .register_type::() .register_type::() .register_type::() - .register_type::() .register_type::() - .register_type::() + .register_type::() .add_plugin(CameraProjectionPlugin::::default()) .add_plugin(CameraProjectionPlugin::::default()) .add_plugin(CameraProjectionPlugin::::default()); diff --git a/crates/bevy_render/src/globals.rs b/crates/bevy_render/src/globals.rs index eea40342e1046..f5fa30482f850 100644 --- a/crates/bevy_render/src/globals.rs +++ b/crates/bevy_render/src/globals.rs @@ -14,6 +14,7 @@ pub struct GlobalsPlugin; impl Plugin for GlobalsPlugin { fn build(&self, app: &mut App) { + app.register_type::(); if let Ok(render_app) = app.get_sub_app_mut(RenderApp) { render_app .init_resource::() diff --git a/crates/bevy_render/src/lib.rs b/crates/bevy_render/src/lib.rs index 59b5cc5b462b8..754d9fa208927 100644 --- a/crates/bevy_render/src/lib.rs +++ b/crates/bevy_render/src/lib.rs @@ -38,14 +38,11 @@ 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, + prelude::ComputedVisibility, render_resource::{PipelineCache, Shader, ShaderLoader}, renderer::{render_system, RenderInstance}, view::{ViewPlugin, WindowRenderPlugin}, @@ -138,8 +135,7 @@ impl Plugin for RenderPlugin { app.add_asset::() .add_debug_asset::() .init_asset_loader::() - .init_debug_asset_loader::() - .register_type::(); + .init_debug_asset_loader::(); if let Some(backends) = options.backends { let windows = app.world.resource_mut::(); @@ -167,9 +163,7 @@ impl Plugin for RenderPlugin { .insert_resource(queue.clone()) .insert_resource(adapter_info.clone()) .insert_resource(render_adapter.clone()) - .init_resource::() - .register_type::() - .register_type::(); + .init_resource::(); let pipeline_cache = PipelineCache::new(device.clone()); let asset_server = app.world.resource::().clone(); @@ -204,7 +198,7 @@ impl Plugin for RenderPlugin { .with_system(render_system.at_end()), ) .add_stage(RenderStage::Cleanup, SystemStage::parallel()) - .init_resource::() + .init_resource::() .insert_resource(RenderInstance(instance)) .insert_resource(device) .insert_resource(queue) @@ -335,6 +329,11 @@ impl Plugin for RenderPlugin { .add_plugin(MeshPlugin) .add_plugin(GlobalsPlugin) .add_plugin(FrameCountPlugin); + + app.register_type::() + .register_type::() + .register_type::() + .register_type::(); } } diff --git a/crates/bevy_render/src/mesh/mod.rs b/crates/bevy_render/src/mesh/mod.rs index 156e44de8da64..790d4531b2456 100644 --- a/crates/bevy_render/src/mesh/mod.rs +++ b/crates/bevy_render/src/mesh/mod.rs @@ -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; @@ -17,6 +18,7 @@ impl Plugin for MeshPlugin { app.add_asset::() .add_asset::() .register_type::() + .register_type::>() .add_plugin(RenderAssetPlugin::::default()); } } diff --git a/crates/bevy_render/src/texture/mod.rs b/crates/bevy_render/src/texture/mod.rs index 596b586f44cba..89637d730b2fc 100644 --- a/crates/bevy_render/src/texture/mod.rs +++ b/crates/bevy_render/src/texture/mod.rs @@ -86,6 +86,7 @@ impl Plugin for ImagePlugin { app.add_plugin(RenderAssetPlugin::::with_prepare_asset_label( PrepareAssetLabel::PreAssetPrepare, )) + .register_type::() .add_asset::() .register_asset_reflect::(); app.world diff --git a/crates/bevy_render/src/view/mod.rs b/crates/bevy_render/src/view/mod.rs index 843b0c638cb36..072b2b5113aac 100644 --- a/crates/bevy_render/src/view/mod.rs +++ b/crates/bevy_render/src/view/mod.rs @@ -31,7 +31,11 @@ pub struct ViewPlugin; impl Plugin for ViewPlugin { fn build(&self, app: &mut App) { - app.register_type::() + app.register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::() .init_resource::() // NOTE: windows.is_changed() handles cases where a window was resized .add_plugin(ExtractResourcePlugin::::default())