From d76c782f39410fd259f64e788711c6b90864cc58 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Mon, 24 Feb 2025 20:55:30 +0000 Subject: [PATCH] Remove `camera` from UiBatch (#17663) # Objective A `TransparentUI` phase's items all target the same camera so there is no need to store the current camera entity in `UiBatch` and ending the current `UiBatch` on camera changes is pointless as the camera doesn't change. ## Solution Remove the `camera` fields from `UiBatch`, `UiShadowsBatch` and `UiTextureSliceBatch`. Remove the camera changed check from `prepare_uinodes`. ## Testing The `multiple_windows` and `split_screen` examples both render UI elements to multiple cameras and can be used to test these changes. The UI material plugin already didn't store the camera entity per batch and worked fine without it. --- crates/bevy_ui/src/render/mod.rs | 4 ---- crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs | 4 ---- 2 files changed, 8 deletions(-) diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index f41c8f2b81..1e29575007 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -936,7 +936,6 @@ pub(crate) const QUAD_INDICES: [usize; 6] = [0, 2, 3, 0, 1, 2]; pub struct UiBatch { pub range: Range, pub image: AssetId, - pub camera: Entity, } /// The values here should match the values for the constants in `ui.wgsl` @@ -1066,8 +1065,6 @@ pub fn prepare_uinodes( || (batch_image_handle != AssetId::default() && extracted_uinode.image != AssetId::default() && batch_image_handle != extracted_uinode.image) - || existing_batch.as_ref().map(|(_, b)| b.camera) - != Some(extracted_uinode.extracted_camera_entity) { if let Some(gpu_image) = gpu_images.get(extracted_uinode.image) { batch_item_index = item_index; @@ -1076,7 +1073,6 @@ pub fn prepare_uinodes( let new_batch = UiBatch { range: vertices_index..vertices_index, image: extracted_uinode.image, - camera: extracted_uinode.extracted_camera_entity, }; batches.push((item.entity(), new_batch)); diff --git a/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs b/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs index fd9799b679..6e91bcfcfe 100644 --- a/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs +++ b/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs @@ -88,7 +88,6 @@ struct UiTextureSliceVertex { pub struct UiTextureSlicerBatch { pub range: Range, pub image: AssetId, - pub camera: Entity, } #[derive(Resource)] @@ -446,8 +445,6 @@ pub fn prepare_ui_slices( || (batch_image_handle != AssetId::default() && texture_slices.image != AssetId::default() && batch_image_handle != texture_slices.image) - || existing_batch.as_ref().map(|(_, b)| b.camera) - != Some(texture_slices.extracted_camera_entity) { if let Some(gpu_image) = gpu_images.get(texture_slices.image) { batch_item_index = item_index; @@ -457,7 +454,6 @@ pub fn prepare_ui_slices( let new_batch = UiTextureSlicerBatch { range: vertices_index..vertices_index, image: texture_slices.image, - camera: texture_slices.extracted_camera_entity, }; batches.push((item.entity(), new_batch));