Skip to content

Commit

Permalink
cgl: add make_current_surfaceless
Browse files Browse the repository at this point in the history
This follows the EGL api to make surfaceless platforms.
  • Loading branch information
bschwind authored Oct 28, 2024
1 parent d8e7569 commit 9c58fbb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
27 changes: 27 additions & 0 deletions glutin/src/api/cgl/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PossiblyCurrentContext> {
self.inner.make_current_surfaceless()?;
Ok(PossiblyCurrentContext { inner: self.inner, _nosendsync: PhantomData })
}

fn new(inner: ContextInner) -> Self {
Self { inner, _nosync: PhantomData }
}
Expand Down Expand Up @@ -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<T: SurfaceTypeTrait> = Surface<T>;
Expand Down Expand Up @@ -236,6 +250,19 @@ impl ContextInner {
})
}

fn make_current_surfaceless(&self) -> Result<()> {
autoreleasepool(|_| {
self.update();
self.raw.makeCurrentContext();

run_on_main(|_mtm| unsafe {
self.raw.setView(None);
});

Ok(())
})
}

fn context_api(&self) -> ContextApi {
ContextApi::OpenGl(None)
}
Expand Down

0 comments on commit 9c58fbb

Please sign in to comment.