From eeee1b9314b52f31228d0c3a2309a3a620e88435 Mon Sep 17 00:00:00 2001 From: Brian Schwind Date: Tue, 13 Oct 2020 16:20:54 +0900 Subject: [PATCH 1/2] Allow context sharing for headless contexts --- glutin/src/platform_impl/macos/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/glutin/src/platform_impl/macos/mod.rs b/glutin/src/platform_impl/macos/mod.rs index 6b67085c64..b778bb35a8 100644 --- a/glutin/src/platform_impl/macos/mod.rs +++ b/glutin/src/platform_impl/macos/mod.rs @@ -151,6 +151,8 @@ impl Context { ) -> Result { let gl_profile = helpers::get_gl_profile(gl_attr, pf_reqs)?; let attributes = helpers::build_nsattributes(pf_reqs, gl_profile)?; + let share_ctx = gl_attr.sharing.map_or(nil, |c| *c.get_id()); + let context = unsafe { let pixelformat = NSOpenGLPixelFormat::alloc(nil).initWithAttributes_(&attributes); if pixelformat == nil { @@ -158,8 +160,10 @@ impl Context { "Could not create the pixel format".to_string(), )); } + let context = - NSOpenGLContext::alloc(nil).initWithFormat_shareContext_(pixelformat, nil); + NSOpenGLContext::alloc(nil).initWithFormat_shareContext_(pixelformat, share_ctx); + if context == nil { return Err(CreationError::OsError( "Could not create the rendering context".to_string(), From 245bd99b696b2ce66897dba067aae1b087b6e5d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Laitl?= Date: Sun, 8 Oct 2023 21:38:19 +0200 Subject: [PATCH 2/2] Fix creating windows on non-default X11 screens Needs patched winit to make the screen id public. --- glutin/Cargo.toml | 4 +++- glutin/src/platform_impl/unix/x11.rs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/glutin/Cargo.toml b/glutin/Cargo.toml index 626f76a26b..8fdc042e36 100644 --- a/glutin/Cargo.toml +++ b/glutin/Cargo.toml @@ -25,7 +25,9 @@ wayland-csd-adwaita-notitle = ["winit/wayland-csd-adwaita-notitle"] [dependencies] once_cell = "1.13" -winit = { version = "0.27.1", default-features = false } +# Patch needed to make WindowBuilder platform-specific info public for X11 screen +# https://github.com/tonarino/winit/pull/2 +winit = { version = "0.27.5", git = "https://github.com/tonarino/winit", branch = "fix-and-publish-x11-screen-id", default-features = false } [target.'cfg(target_os = "android")'.dependencies] glutin_egl_sys = { version = "0.1.6", path = "../glutin_egl_sys" } diff --git a/glutin/src/platform_impl/unix/x11.rs b/glutin/src/platform_impl/unix/x11.rs index e85757f3a0..6eadb507b2 100644 --- a/glutin/src/platform_impl/unix/x11.rs +++ b/glutin/src/platform_impl/unix/x11.rs @@ -456,7 +456,9 @@ impl Context { }; // Get the screen_id for the window being built. - let screen_id = unsafe { (xconn.xlib.XDefaultScreen)(xconn.display) }; + let screen_id = wb.platform_specific.screen_id.unwrap_or_else(|| { + unsafe { (xconn.xlib.XDefaultScreen)(xconn.display) } + }); let mut builder_glx_u = None; let mut builder_egl_u = None;