Skip to content

Commit

Permalink
Rename DefaultCameraView (#17235)
Browse files Browse the repository at this point in the history
# Objective

The name `DefaultCameraView` is confusing and misleading:
* It isn't the default UI camera, which is either the camera with the
`IsDefaultUiCamera` marker component or, if no such camera is found, the
camera with the highest order which has the primary window as its render
target.
* It doesn't make sense to call it a "default", every active 2d and 3d
camera is given its own `DefaultCameraView`.
* The name doesn't make it clear that it's UI specific component.

## Solution

Rename `DefaultCameraView` to `UiCameraView`, add a doc comment for it
and rename a few other fields and variables.

## Migration Guide

`DefaultCameraView` has been renamed to `UiCameraView`
  • Loading branch information
ickshonpe authored Jan 8, 2025
1 parent 020d082 commit e896c36
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
23 changes: 12 additions & 11 deletions crates/bevy_ui/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub fn build_ui_render(app: &mut App) {
.add_systems(
ExtractSchedule,
(
extract_default_ui_camera_view,
extract_ui_camera_view,
extract_uinode_background_colors.in_set(RenderUiSystem::ExtractBackgrounds),
extract_uinode_images.in_set(RenderUiSystem::ExtractImages),
extract_uinode_borders.in_set(RenderUiSystem::ExtractBorders),
Expand Down Expand Up @@ -532,10 +532,11 @@ const UI_CAMERA_FAR: f32 = 1000.0;
const UI_CAMERA_TRANSFORM_OFFSET: f32 = -0.1;

#[derive(Component)]
pub struct DefaultCameraView(pub Entity);
/// Entity id of the temporary render entity with the corresponding extracted UI view.
pub struct UiCameraView(pub Entity);

/// Extracts all UI elements associated with a camera into the render world.
pub fn extract_default_ui_camera_view(
pub fn extract_ui_camera_view(
mut commands: Commands,
mut transparent_render_phases: ResMut<ViewSortedRenderPhases<TransparentUi>>,
query: Extract<
Expand All @@ -553,13 +554,13 @@ pub fn extract_default_ui_camera_view(
) {
live_entities.clear();

for (entity, camera, ui_anti_alias, shadow_samples) in &query {
for (render_entity, camera, ui_anti_alias, shadow_samples) in &query {
// ignore inactive cameras
if !camera.is_active {
commands
.get_entity(entity)
.get_entity(render_entity)
.expect("Camera entity wasn't synced.")
.remove::<(DefaultCameraView, UiAntiAlias, BoxShadowSamples)>();
.remove::<(UiCameraView, UiAntiAlias, BoxShadowSamples)>();
continue;
}

Expand All @@ -573,7 +574,7 @@ pub fn extract_default_ui_camera_view(
0.0,
UI_CAMERA_FAR,
);
let default_camera_view = commands
let ui_camera_view = commands
.spawn((
ExtractedView {
clip_from_view: projection_matrix,
Expand All @@ -594,18 +595,18 @@ pub fn extract_default_ui_camera_view(
))
.id();
let mut entity_commands = commands
.get_entity(entity)
.get_entity(render_entity)
.expect("Camera entity wasn't synced.");
entity_commands.insert(DefaultCameraView(default_camera_view));
entity_commands.insert(UiCameraView(ui_camera_view));
if let Some(ui_anti_alias) = ui_anti_alias {
entity_commands.insert(*ui_anti_alias);
}
if let Some(shadow_samples) = shadow_samples {
entity_commands.insert(*shadow_samples);
}
transparent_render_phases.insert_or_clear(entity);
transparent_render_phases.insert_or_clear(render_entity);

live_entities.insert(entity);
live_entities.insert(render_entity);
}
}

Expand Down
26 changes: 14 additions & 12 deletions crates/bevy_ui/src/render/render_pass.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::ops::Range;

use super::{ImageNodeBindGroups, UiBatch, UiMeta};
use crate::DefaultCameraView;
use crate::UiCameraView;
use bevy_ecs::{
prelude::*,
system::{lifetimeless::*, SystemParamItem},
Expand All @@ -19,23 +19,24 @@ use bevy_render::{
use tracing::error;

pub struct UiPassNode {
ui_view_query: QueryState<(&'static ViewTarget, &'static ExtractedCamera), With<ExtractedView>>,
default_camera_view_query: QueryState<&'static DefaultCameraView>,
camera_view_query:
QueryState<(&'static ViewTarget, &'static ExtractedCamera), With<ExtractedView>>,
ui_camera_view_query: QueryState<&'static UiCameraView>,
}

impl UiPassNode {
pub fn new(world: &mut World) -> Self {
Self {
ui_view_query: world.query_filtered(),
default_camera_view_query: world.query(),
camera_view_query: world.query_filtered(),
ui_camera_view_query: world.query(),
}
}
}

impl Node for UiPassNode {
fn update(&mut self, world: &mut World) {
self.ui_view_query.update_archetypes(world);
self.default_camera_view_query.update_archetypes(world);
self.camera_view_query.update_archetypes(world);
self.ui_camera_view_query.update_archetypes(world);
}

fn run(
Expand All @@ -56,19 +57,20 @@ impl Node for UiPassNode {
return Ok(());
};

let Ok((target, camera)) = self.ui_view_query.get_manual(world, input_view_entity) else {
let Ok((target, camera)) = self.camera_view_query.get_manual(world, input_view_entity)
else {
return Ok(());
};
if transparent_phase.items.is_empty() {
return Ok(());
}

// use the "default" view entity if it is defined
let view_entity = if let Ok(default_view) = self
.default_camera_view_query
// use the UI view entity if it is defined
let view_entity = if let Ok(ui_camera_view) = self
.ui_camera_view_query
.get_manual(world, input_view_entity)
{
default_view.0
ui_camera_view.0
} else {
input_view_entity
};
Expand Down

0 comments on commit e896c36

Please sign in to comment.