From 4035f2e69700f5cb7547925519799c8b7f3171df Mon Sep 17 00:00:00 2001 From: Brian Schwind Date: Tue, 22 Oct 2024 10:47:04 +0900 Subject: [PATCH 1/3] Support making a context current on MacOS without a surface --- glutin/src/api/cgl/context.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/glutin/src/api/cgl/context.rs b/glutin/src/api/cgl/context.rs index 2b5d04f791..ee032e33be 100644 --- a/glutin/src/api/cgl/context.rs +++ b/glutin/src/api/cgl/context.rs @@ -74,6 +74,13 @@ pub struct NotCurrentContext { } impl NotCurrentContext { + /// Make a [`Self::PossiblyCurrentContext`] indicating that the context + /// could be current on the thread. + pub fn make_current_surfaceless(self) -> Result { + self.inner.make_current_surfaceless()?; + Ok(PossiblyCurrentContext { inner: self.inner, _nosendsync: PhantomData }) + } + fn new(inner: ContextInner) -> Self { Self { inner, _nosync: PhantomData } } @@ -143,6 +150,13 @@ pub struct PossiblyCurrentContext { _nosendsync: PhantomData<*mut ()>, } +impl PossiblyCurrentContext { + /// Make this context current on the calling thread. + pub fn make_current_surfaceless(&self) -> Result<()> { + self.inner.make_current_surfaceless() + } +} + impl PossiblyCurrentGlContext for PossiblyCurrentContext { type NotCurrentContext = NotCurrentContext; type Surface = Surface; @@ -236,6 +250,15 @@ impl ContextInner { }) } + fn make_current_surfaceless(&self) -> Result<()> { + autoreleasepool(|_| { + self.update(); + self.raw.makeCurrentContext(); + + Ok(()) + }) + } + fn context_api(&self) -> ContextApi { ContextApi::OpenGl(None) } From fdbb0dcaa28ce5ba2115f25e4ca75dd0cbabb589 Mon Sep 17 00:00:00 2001 From: Brian Schwind Date: Thu, 24 Oct 2024 15:21:21 +0900 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfc3032ce9..4c2865336d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Unreleased - Add `PossiblyCurrentContext::make_not_current_in_place(&self)` for when `Send` capability of `NotCurrentContext` is not required. +- Add `NotCurrentContext::make_current_surfaceless(self)` and `PossiblyCurrentContext::make_current_surfaceless(&self)` in the `Cgl` implementation to allow the use of surfaceless contexts on MacOS. # Version 0.32.1 From bebdeed264e4277c0b004e2e707cf0a873af9485 Mon Sep 17 00:00:00 2001 From: Brian Schwind Date: Thu, 24 Oct 2024 17:44:36 +0900 Subject: [PATCH 3/3] Explicitly call NSOpenGLContext::setView(None) in make_current_surfaceless() --- glutin/src/api/cgl/context.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/glutin/src/api/cgl/context.rs b/glutin/src/api/cgl/context.rs index ee032e33be..8450286709 100644 --- a/glutin/src/api/cgl/context.rs +++ b/glutin/src/api/cgl/context.rs @@ -255,6 +255,10 @@ impl ContextInner { self.update(); self.raw.makeCurrentContext(); + run_on_main(|_mtm| unsafe { + self.raw.setView(None); + }); + Ok(()) }) }