Skip to content

Commit

Permalink
disable the graph instead
Browse files Browse the repository at this point in the history
  • Loading branch information
IceSentry committed Jun 10, 2023
1 parent 4b64035 commit d515786
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
20 changes: 1 addition & 19 deletions crates/bevy_render/src/camera/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ use bevy_reflect::FromReflect;
use bevy_transform::components::GlobalTransform;
use bevy_utils::{HashMap, HashSet};
use bevy_window::{
NormalizedWindowRef, PrimaryWindow, Window, WindowClosed, WindowCreated, WindowRef,
WindowResized,
NormalizedWindowRef, PrimaryWindow, Window, WindowCreated, WindowRef, WindowResized,
};

use std::{borrow::Cow, ops::Range};
Expand Down Expand Up @@ -493,9 +492,6 @@ impl NormalizedRenderTarget {

/// System in charge of updating a [`Camera`] when its window or projection changes.
///
/// The system will detect when a [`Window`] is closed and it disables any [`Camera`] that used that
/// [`Window`] has a [`RenderTarget`].
///
/// The system detects window creation and resize events to update the camera projection if
/// needed. It also queries any [`CameraProjection`] component associated with the same entity
/// as the [`Camera`] one, to automatically update the camera projection matrix.
Expand All @@ -513,11 +509,9 @@ impl NormalizedRenderTarget {
/// [`OrthographicProjection`]: crate::camera::OrthographicProjection
/// [`PerspectiveProjection`]: crate::camera::PerspectiveProjection
/// [`Projection`]: crate::camera::Projection
#[allow(clippy::too_many_arguments)]
pub fn camera_system<T: CameraProjection + Component>(
mut window_resized_events: EventReader<WindowResized>,
mut window_created_events: EventReader<WindowCreated>,
mut window_close_events: EventReader<WindowClosed>,
mut image_asset_events: EventReader<AssetEvent<Image>>,
primary_window: Query<Entity, With<PrimaryWindow>>,
windows: Query<(Entity, &Window)>,
Expand All @@ -526,18 +520,6 @@ pub fn camera_system<T: CameraProjection + Component>(
) {
let primary_window = primary_window.iter().next();

// Disable the camera associated to a window that's just been closed
for ev in window_close_events.iter() {
for (mut camera, _) in &mut cameras {
let Some(NormalizedRenderTarget::Window(window_ref)) = camera.target.normalize(primary_window)
else { continue; };

if window_ref.entity() == ev.window {
camera.is_active = false;
}
}
}

let mut changed_window_ids = HashSet::new();
changed_window_ids.extend(window_created_events.iter().map(|event| event.window));
changed_window_ids.extend(window_resized_events.iter().map(|event| event.window));
Expand Down
18 changes: 15 additions & 3 deletions crates/bevy_render/src/camera/camera_driver_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,24 @@ impl Node for CameraDriverNode {
world: &World,
) -> Result<(), NodeRunError> {
let sorted_cameras = world.resource::<SortedCameras>();
let windows = world.resource::<ExtractedWindows>();
let mut camera_windows = HashSet::new();
for sorted_camera in &sorted_cameras.0 {
if let Ok(camera) = self.cameras.get_manual(world, sorted_camera.entity) {
if let Some(NormalizedRenderTarget::Window(window_ref)) = camera.target {
camera_windows.insert(window_ref.entity());
let Ok(camera) = self.cameras.get_manual(world, sorted_camera.entity) else {
continue;
};

let mut run_graph = true;
if let Some(NormalizedRenderTarget::Window(window_ref)) = camera.target {
let window_entity = window_ref.entity();
if windows.windows.get(&window_entity).is_some() {
camera_windows.insert(window_entity);
} else {
// The window doesn't exist anymore so we don't need to run the graph
run_graph = false;
}
}
if run_graph {
graph.run_sub_graph(
camera.render_graph.clone(),
vec![],
Expand Down

0 comments on commit d515786

Please sign in to comment.