diff --git a/window/src/os/windows/connection.rs b/window/src/os/windows/connection.rs index 24a8ecd51..2f43508ec 100644 --- a/window/src/os/windows/connection.rs +++ b/window/src/os/windows/connection.rs @@ -18,6 +18,8 @@ pub struct Connection { event_handle: HANDLE, pub(crate) windows: RefCell>>>, timers: RefCell>, + #[cfg(feature = "opengl")] + pub(crate) gl_connection: RefCell>>, } impl ConnectionOps for Connection { @@ -97,6 +99,8 @@ impl Connection { event_handle, windows: RefCell::new(HashMap::new()), timers: RefCell::new(HashMap::new()), + #[cfg(feature = "opengl")] + gl_connection: RefCell::new(None), }) } diff --git a/window/src/os/windows/window.rs b/window/src/os/windows/window.rs index bb1564e7b..905b469e2 100644 --- a/window/src/os/windows/window.rs +++ b/window/src/os/windows/window.rs @@ -132,14 +132,23 @@ impl WindowInner { #[cfg(feature = "opengl")] fn enable_opengl(&mut self) -> anyhow::Result<()> { let window = Window(self.hwnd); + let conn = Connection::get().unwrap(); let gl_state = if is_egl_preferred() { - crate::egl::GlState::create(None, self.hwnd.0) + match conn.gl_connection.borrow().as_ref() { + None => crate::egl::GlState::create(None, self.hwnd.0), + Some(glconn) => { + crate::egl::GlState::create_with_existing_connection(glconn, self.hwnd.0) + } + } } else { Err(anyhow::anyhow!("Config says to avoid EGL")) } .and_then(|egl| unsafe { log::error!("Initialized EGL!"); + conn.gl_connection + .borrow_mut() + .replace(Rc::clone(egl.get_connection())); let backend = Rc::new(egl); Ok(glium::backend::Context::new( backend,