diff --git a/crates/bevy_pbr/src/material.rs b/crates/bevy_pbr/src/material.rs index 50738889f5910f..95590cee311e7e 100644 --- a/crates/bevy_pbr/src/material.rs +++ b/crates/bevy_pbr/src/material.rs @@ -20,7 +20,7 @@ use bevy_render::{ mesh::{Mesh, MeshVertexBufferLayout}, prelude::Image, render_asset::{prepare_assets, RenderAssets}, - render_instances::{RenderInstancePlugin, RenderInstances}, + extract_instances::{ExtractInstancePlugin, ExtractedInstances}, render_phase::{ AddRenderCommand, DrawFunctions, PhaseItem, RenderCommand, RenderCommandResult, RenderPhase, SetItemPipeline, TrackedRenderPass, @@ -178,7 +178,7 @@ where { fn build(&self, app: &mut App) { app.init_asset::() - .add_plugins(RenderInstancePlugin::>::extract_visible()); + .add_plugins(ExtractInstancePlugin::>::extract_visible()); if let Ok(render_app) = app.get_sub_app_mut(RenderApp) { render_app @@ -370,7 +370,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 66% rename from crates/bevy_render/src/render_instances.rs rename to crates/bevy_render/src/extract_instances.rs index 5eb7f05368a504..8ad6194c65323f 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,25 +27,25 @@ 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 ExtractInstancePlugin where - RI: RenderInstance, + RI: ExtractInstance, { only_extract_visible: bool, marker: PhantomData RI>, @@ -53,24 +53,24 @@ where /// Stores all render instances of a type in the render world. #[derive(Resource, Deref, DerefMut)] -pub struct RenderInstances(EntityHashMap) +pub struct ExtractedInstances(EntityHashMap) where - RI: RenderInstance; + RI: ExtractInstance; -impl Default for RenderInstances +impl Default for ExtractedInstances where - RI: RenderInstance, + RI: ExtractInstance, { fn default() -> Self { Self(Default::default()) } } -impl RenderInstancePlugin +impl ExtractInstancePlugin where - RI: RenderInstance, + RI: ExtractInstance, { - /// Creates a new [`RenderInstancePlugin`] that unconditionally extracts to + /// Creates a new [`ExtractInstancePlugin`] that unconditionally extracts to /// the render world, whether the entity is visible or not. pub fn new() -> Self { Self { @@ -80,11 +80,11 @@ where } } -impl RenderInstancePlugin +impl ExtractInstancePlugin where - RI: RenderInstance, + RI: ExtractInstance, { - /// Creates a new [`RenderInstancePlugin`] that extracts to the render world + /// Creates a new [`ExtractInstancePlugin`] 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 +94,60 @@ where } } -impl Plugin for RenderInstancePlugin +impl Plugin for ExtractInstancePlugin where - RI: RenderInstance, + RI: 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>, +fn extract_all( + mut instances: ResMut>, query: Extract>, ) where - RI: RenderInstance, + RI: ExtractInstance, { 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(instance) = RI::extract(other) { + instances.insert(entity, instance); } } } -fn extract_visible_to_render_instances( - mut instances: ResMut>, +fn extract_visible( + mut instances: ResMut>, query: Extract>, ) where - RI: RenderInstance, + RI: ExtractInstance, { 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(instance) = RI::extract(other) { + instances.insert(entity, 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 b5a3ab52d1b645..6a8cff3f20e88b 100644 --- a/crates/bevy_render/src/lib.rs +++ b/crates/bevy_render/src/lib.rs @@ -18,7 +18,7 @@ pub mod pipelined_rendering; pub mod primitives; pub mod render_asset; pub mod render_graph; -pub mod render_instances; +pub mod extract_instances; pub mod render_phase; pub mod render_resource; pub mod renderer;