diff --git a/crates/bevy_pbr/src/material.rs b/crates/bevy_pbr/src/material.rs index 96e43017b877b..3674debfd4498 100644 --- a/crates/bevy_pbr/src/material.rs +++ b/crates/bevy_pbr/src/material.rs @@ -18,11 +18,11 @@ use bevy_ecs::{ }; use bevy_reflect::Reflect; use bevy_render::{ + extract_instances::{ExtractInstancesPlugin, ExtractedInstances}, extract_resource::ExtractResource, mesh::{Mesh, MeshVertexBufferLayout}, prelude::Image, render_asset::{prepare_assets, RenderAssets}, - render_instances::{RenderInstancePlugin, RenderInstances}, render_phase::{ AddRenderCommand, DrawFunctions, PhaseItem, RenderCommand, RenderCommandResult, RenderPhase, SetItemPipeline, TrackedRenderPass, @@ -201,7 +201,7 @@ where { fn build(&self, app: &mut App) { app.init_asset::() - .add_plugins(RenderInstancePlugin::>::extract_visible()); + .add_plugins(ExtractInstancesPlugin::>::extract_visible()); if let Ok(render_app) = app.get_sub_app_mut(RenderApp) { render_app @@ -393,7 +393,7 @@ impl RenderCommand

for SetMaterial } } -pub type RenderMaterialInstances = RenderInstances>; +pub type RenderMaterialInstances = ExtractedInstances>; const fn alpha_mode_pipeline_key(alpha_mode: AlphaMode) -> MeshPipelineKey { match alpha_mode { diff --git a/crates/bevy_render/src/render_instances.rs b/crates/bevy_render/src/extract_instances.rs similarity index 60% rename from crates/bevy_render/src/render_instances.rs rename to crates/bevy_render/src/extract_instances.rs index 5eb7f05368a50..82c04dba1003f 100644 --- a/crates/bevy_render/src/render_instances.rs +++ b/crates/bevy_render/src/extract_instances.rs @@ -1,4 +1,4 @@ -//! Convenience logic for turning components from the main world into render +//! Convenience logic for turning components from the main world into extracted //! instances in the render world. //! //! This is essentially the same as the `extract_component` module, but @@ -27,50 +27,50 @@ use crate::{prelude::ViewVisibility, Extract, ExtractSchedule, RenderApp}; /// This is essentially the same as /// [`ExtractComponent`](crate::extract_component::ExtractComponent), but /// higher-performance because it avoids the ECS overhead. -pub trait RenderInstance: Send + Sync + Sized + 'static { +pub trait ExtractInstance: Send + Sync + Sized + 'static { /// ECS [`WorldQuery`] to fetch the components to extract. type Query: WorldQuery + ReadOnlyWorldQuery; /// Filters the entities with additional constraints. type Filter: WorldQuery + ReadOnlyWorldQuery; /// Defines how the component is transferred into the "render world". - fn extract_to_render_instance(item: QueryItem<'_, Self::Query>) -> Option; + fn extract(item: QueryItem<'_, Self::Query>) -> Option; } /// This plugin extracts one or more components into the "render world" as -/// render instances. +/// extracted instances. /// /// Therefore it sets up the [`ExtractSchedule`] step for the specified -/// [`RenderInstances`]. +/// [`ExtractedInstances`]. #[derive(Default)] -pub struct RenderInstancePlugin +pub struct ExtractInstancesPlugin where - RI: RenderInstance, + EI: ExtractInstance, { only_extract_visible: bool, - marker: PhantomData RI>, + marker: PhantomData EI>, } -/// Stores all render instances of a type in the render world. +/// Stores all extract instances of a type in the render world. #[derive(Resource, Deref, DerefMut)] -pub struct RenderInstances(EntityHashMap) +pub struct ExtractedInstances(EntityHashMap) where - RI: RenderInstance; + EI: ExtractInstance; -impl Default for RenderInstances +impl Default for ExtractedInstances where - RI: RenderInstance, + EI: ExtractInstance, { fn default() -> Self { Self(Default::default()) } } -impl RenderInstancePlugin +impl ExtractInstancesPlugin where - RI: RenderInstance, + EI: ExtractInstance, { - /// Creates a new [`RenderInstancePlugin`] that unconditionally extracts to + /// Creates a new [`ExtractInstancesPlugin`] that unconditionally extracts to /// the render world, whether the entity is visible or not. pub fn new() -> Self { Self { @@ -78,13 +78,8 @@ where marker: PhantomData, } } -} -impl RenderInstancePlugin -where - RI: RenderInstance, -{ - /// Creates a new [`RenderInstancePlugin`] that extracts to the render world + /// Creates a new [`ExtractInstancesPlugin`] that extracts to the render world /// if and only if the entity it's attached to is visible. pub fn extract_visible() -> Self { Self { @@ -94,60 +89,60 @@ where } } -impl Plugin for RenderInstancePlugin +impl Plugin for ExtractInstancesPlugin where - RI: RenderInstance, + EI: ExtractInstance, { fn build(&self, app: &mut App) { if let Ok(render_app) = app.get_sub_app_mut(RenderApp) { - render_app.init_resource::>(); + render_app.init_resource::>(); if self.only_extract_visible { - render_app.add_systems(ExtractSchedule, extract_visible_to_render_instances::); + render_app.add_systems(ExtractSchedule, extract_visible::); } else { - render_app.add_systems(ExtractSchedule, extract_to_render_instances::); + render_app.add_systems(ExtractSchedule, extract_all::); } } } } -fn extract_to_render_instances( - mut instances: ResMut>, - query: Extract>, +fn extract_all( + mut extracted_instances: ResMut>, + query: Extract>, ) where - RI: RenderInstance, + EI: ExtractInstance, { - instances.clear(); + extracted_instances.clear(); for (entity, other) in &query { - if let Some(render_instance) = RI::extract_to_render_instance(other) { - instances.insert(entity, render_instance); + if let Some(extract_instance) = EI::extract(other) { + extracted_instances.insert(entity, extract_instance); } } } -fn extract_visible_to_render_instances( - mut instances: ResMut>, - query: Extract>, +fn extract_visible( + mut extracted_instances: ResMut>, + query: Extract>, ) where - RI: RenderInstance, + EI: ExtractInstance, { - instances.clear(); + extracted_instances.clear(); for (entity, view_visibility, other) in &query { if view_visibility.get() { - if let Some(render_instance) = RI::extract_to_render_instance(other) { - instances.insert(entity, render_instance); + if let Some(extract_instance) = EI::extract(other) { + extracted_instances.insert(entity, extract_instance); } } } } -impl RenderInstance for AssetId +impl ExtractInstance for AssetId where A: Asset, { type Query = Read>; type Filter = (); - fn extract_to_render_instance(item: QueryItem<'_, Self::Query>) -> Option { + fn extract(item: QueryItem<'_, Self::Query>) -> Option { Some(item.id()) } } diff --git a/crates/bevy_render/src/lib.rs b/crates/bevy_render/src/lib.rs index b5a3ab52d1b64..0011101740e45 100644 --- a/crates/bevy_render/src/lib.rs +++ b/crates/bevy_render/src/lib.rs @@ -9,6 +9,7 @@ pub mod batching; pub mod camera; pub mod color; pub mod extract_component; +pub mod extract_instances; mod extract_param; pub mod extract_resource; pub mod globals; @@ -18,7 +19,6 @@ pub mod pipelined_rendering; pub mod primitives; pub mod render_asset; pub mod render_graph; -pub mod render_instances; pub mod render_phase; pub mod render_resource; pub mod renderer;