From e83d227639d6bc2c074df15afe3da7bfaea98847 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sun, 12 Nov 2023 15:20:44 +0100 Subject: [PATCH] Create helper `make_viewport_current` --- crates/eframe/src/native/run.rs | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/crates/eframe/src/native/run.rs b/crates/eframe/src/native/run.rs index 52265c997..646a24fad 100644 --- a/crates/eframe/src/native/run.rs +++ b/crates/eframe/src/native/run.rs @@ -878,6 +878,20 @@ mod glow_integration { fn get_proc_address(&self, addr: &std::ffi::CStr) -> *const std::ffi::c_void { self.gl_config.display().get_proc_address(addr) } + + pub fn make_viewport_current(&mut self, viewport: &Viewport) { + if let Some(gl_surface) = &viewport.gl_surface { + self.current_gl_context = Some( + self.current_gl_context + .take() + .unwrap() + .make_not_current() + .unwrap() + .make_current(gl_surface) + .unwrap(), + ); + } + } } struct GlowWinitApp { @@ -1508,19 +1522,10 @@ mod glow_integration { } let clipped_primitives = integration.egui_ctx.tessellate(shapes); - { - let mut glutin = glutin.borrow_mut(); - glutin.current_gl_context = Some( - glutin - .current_gl_context - .take() - .unwrap() - .make_not_current() - .unwrap() - .make_current(viewport.borrow().gl_surface.as_ref().unwrap()) - .unwrap(), - ); - }; + + glutin + .borrow_mut() + .make_viewport_current(&viewport.borrow()); egui_glow::painter::clear( &gl,