diff --git a/voxygen/src/lib.rs b/voxygen/src/lib.rs index 595777559f..055318dcb0 100644 --- a/voxygen/src/lib.rs +++ b/voxygen/src/lib.rs @@ -144,4 +144,7 @@ pub trait PlayState { /// Draw the play state. fn render<'a>(&'a self, drawer: &mut Drawer<'a>, settings: &Settings); + + /// Determines whether egui will be rendered for this play state + fn egui_enabled(&self) -> bool; } diff --git a/voxygen/src/menu/char_selection/mod.rs b/voxygen/src/menu/char_selection/mod.rs index 763bbbf8ef..10a55443b3 100644 --- a/voxygen/src/menu/char_selection/mod.rs +++ b/voxygen/src/menu/char_selection/mod.rs @@ -20,7 +20,6 @@ pub struct CharSelectionState { char_selection_ui: CharSelectionUi, client: Rc>, scene: Scene, - need_shadow_clear: RefCell, } impl CharSelectionState { @@ -37,7 +36,6 @@ impl CharSelectionState { char_selection_ui, client, scene, - need_shadow_clear: RefCell::new(false), } } @@ -75,7 +73,7 @@ impl PlayState for CharSelectionState { .set_scale_mode(global_state.settings.interface.ui_scale); // Clear shadow textures since we don't render to them here - *self.need_shadow_clear.borrow_mut() = true; + global_state.window.clear_shadows_next_frame = true; } fn tick(&mut self, global_state: &mut GlobalState, events: Vec) -> PlayStateResult { @@ -237,11 +235,6 @@ impl PlayState for CharSelectionState { fn globals_bind_group(&self) -> &GlobalsBindGroup { self.scene.global_bind_group() } fn render<'a>(&'a self, drawer: &mut Drawer<'a>, _: &Settings) { - if *self.need_shadow_clear.borrow() { - drawer.clear_shadows(); - *self.need_shadow_clear.borrow_mut() = false; - } - let client = self.client.borrow(); let (humanoid_body, loadout) = Self::get_humanoid_body_inventory(&self.char_selection_ui, &client); @@ -263,4 +256,6 @@ impl PlayState for CharSelectionState { self.char_selection_ui.render(&mut ui_drawer); }; } + + fn egui_enabled(&self) -> bool { false } } diff --git a/voxygen/src/menu/main/mod.rs b/voxygen/src/menu/main/mod.rs index f90130b44d..46ca64595c 100644 --- a/voxygen/src/menu/main/mod.rs +++ b/voxygen/src/menu/main/mod.rs @@ -332,6 +332,8 @@ impl PlayState for MainMenuState { self.main_menu_ui.render(&mut ui_drawer); }; } + + fn egui_enabled(&self) -> bool { false } } fn get_client_msg_error( diff --git a/voxygen/src/run.rs b/voxygen/src/run.rs index 1b710421d2..3d881cccb4 100644 --- a/voxygen/src/run.rs +++ b/voxygen/src/run.rs @@ -179,19 +179,28 @@ fn handle_main_events_cleared( span!(guard, "Render"); // Render the screen using the global renderer + let clear_shadows = global_state.window.clear_shadows_next_frame; if let Some(mut drawer) = global_state .window .renderer_mut() .start_recording_frame(last.globals_bind_group()) .expect("Unrecoverable render error when starting a new frame!") { + if clear_shadows { + drawer.clear_shadows(); + } + last.render(&mut drawer, &global_state.settings); #[cfg(feature = "egui-ui")] - if global_state.settings.interface.toggle_debug { + if last.egui_enabled() && global_state.settings.interface.toggle_debug { + span!(guard, "Draw egui"); drawer.draw_egui(&mut global_state.egui_state.platform, scale_factor); } }; + if clear_shadows { + global_state.window.clear_shadows_next_frame = false; + } drop(guard); } diff --git a/voxygen/src/session/mod.rs b/voxygen/src/session/mod.rs index dbe0ddd25e..647a89d5a9 100644 --- a/voxygen/src/session/mod.rs +++ b/voxygen/src/session/mod.rs @@ -1460,6 +1460,8 @@ impl PlayState for SessionState { self.hud.render(&mut ui_drawer); }; // Note: this semicolon is needed for the third_pass borrow to be dropped before it's lifetime ends } + + fn egui_enabled(&self) -> bool { true } } /// Max distance an entity can be "targeted" diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index 118fe109e9..7f28ecbab8 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -544,6 +544,8 @@ pub struct Window { message_receiver: channel::Receiver, // Used for screenshots & fullscreen toggle to deduplicate/postpone to after event handler take_screenshot: bool, + // Used to clear the shadow textures when entering a PlayState that doesn't utilise shadows + pub clear_shadows_next_frame: bool, toggle_fullscreen: bool, pub key_layout: Option, } @@ -640,6 +642,7 @@ impl Window { message_sender, message_receiver, take_screenshot: false, + clear_shadows_next_frame: false, toggle_fullscreen: false, key_layout, };