From 50726a3efc93449b7381ad6120cb3981d6767b5f Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 18 Dec 2023 10:17:11 +0100 Subject: [PATCH] Fix framebuffer clear in egui_glow with multi-viewports --- crates/eframe/src/native/glow_integration.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index bc3bb1e174c..967ff640ffa 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -532,12 +532,16 @@ impl GlowWinitRunning { (raw_input, viewport_ui_cb) }; - { + let clear_color = self + .app + .clear_color(&self.integration.egui_ctx.style().visuals); + + let has_many_viewports = self.glutin.borrow().viewports.len() > 1; + let clear_before_update = !has_many_viewports; // HACK: for some reason, an early clear doesn't "take" on Mac with multiple viewports. + + if clear_before_update { // clear before we call update, so users can paint between clear-color and egui windows: - let clear_color = self - .app - .clear_color(&self.integration.egui_ctx.style().visuals); let mut glutin = self.glutin.borrow_mut(); let GlutinWindowContext { viewports, @@ -608,6 +612,10 @@ impl GlowWinitRunning { let screen_size_in_pixels: [u32; 2] = window.inner_size().into(); + if !clear_before_update { + painter.clear(screen_size_in_pixels, clear_color); + } + painter.paint_and_update_textures( screen_size_in_pixels, pixels_per_point,