Disable camera on window close (#8802)
# Objective - When a window is closed, the associated camera keeps rendering even if the RenderTarget isn't valid anymore. - This is essentially just wasting a lot of performance. ## Solution - Detect the window close event and disable any camera that used the window has a RenderTarget. ## Notes It's possible a similar thing could be done for camera that use an image handle, but I would fix that in a separate PR.
This commit is contained in:
parent
c1fd505f9c
commit
75da2e7adf
@ -31,12 +31,24 @@ impl Node for CameraDriverNode {
|
|||||||
world: &World,
|
world: &World,
|
||||||
) -> Result<(), NodeRunError> {
|
) -> Result<(), NodeRunError> {
|
||||||
let sorted_cameras = world.resource::<SortedCameras>();
|
let sorted_cameras = world.resource::<SortedCameras>();
|
||||||
|
let windows = world.resource::<ExtractedWindows>();
|
||||||
let mut camera_windows = HashSet::new();
|
let mut camera_windows = HashSet::new();
|
||||||
for sorted_camera in &sorted_cameras.0 {
|
for sorted_camera in &sorted_cameras.0 {
|
||||||
if let Ok(camera) = self.cameras.get_manual(world, sorted_camera.entity) {
|
let Ok(camera) = self.cameras.get_manual(world, sorted_camera.entity) else {
|
||||||
if let Some(NormalizedRenderTarget::Window(window_ref)) = camera.target {
|
continue;
|
||||||
camera_windows.insert(window_ref.entity());
|
};
|
||||||
|
|
||||||
|
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(
|
graph.run_sub_graph(
|
||||||
camera.render_graph.clone(),
|
camera.render_graph.clone(),
|
||||||
vec![],
|
vec![],
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user