summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-05-28 20:18:35 +0200
committerHampusM <hampus@hampusmat.com>2026-05-28 20:18:35 +0200
commitf9759cb536f67d78e26d77b448c1940abcfa33c8 (patch)
treed7edc4b72e04258cf5f769d2b74c629621992596
parentea0e368379270cfbc10c28a1e63446a6f1c46c43 (diff)
feat(opengl-bindings): add fn to make context current without surface
-rw-r--r--opengl-bindings/src/lib.rs38
1 files changed, 37 insertions, 1 deletions
diff --git a/opengl-bindings/src/lib.rs b/opengl-bindings/src/lib.rs
index e4ae27d..3dcd61d 100644
--- a/opengl-bindings/src/lib.rs
+++ b/opengl-bindings/src/lib.rs
@@ -51,7 +51,7 @@ impl MaybeCurrentContextWithFns
Ok(Self { context, fns: Box::new(gl) })
}
- /// Attempts to make this context & the specified surface current in the current
+ /// Attempts to make this context & the specified surface current in the calling
/// thread.
///
/// # Errors
@@ -70,6 +70,20 @@ impl MaybeCurrentContextWithFns
Ok(())
}
+ /// Attempts to make this context current on the calling thread.
+ ///
+ /// # Errors
+ /// Returns `Err` if making this context current fails.
+ pub fn make_current_surfaceless(&self) -> Result<(), MakeContextCurrentError>
+ {
+ if !self.context.is_current() {
+ make_glutin_context_current_surfaceless(&self.context)
+ .map_err(MakeContextCurrentError)?;
+ }
+
+ Ok(())
+ }
+
#[must_use]
pub fn context(&self) -> &PossiblyCurrentContext
{
@@ -89,6 +103,28 @@ impl MaybeCurrentContextWithFns
#[error("Failed to make context current")]
pub struct MakeContextCurrentError(#[source] glutin::error::Error);
+fn make_glutin_context_current_surfaceless(
+ context: &PossiblyCurrentContext,
+) -> Result<(), glutin::error::Error>
+{
+ #[cfg(not(any(target_os = "linux", target_os = "windows", target_os = "macos")))]
+ compile_error!("Unsupported target OS");
+
+ match context {
+ #[cfg(any(target_os = "windows", target_os = "linux"))]
+ PossiblyCurrentContext::Egl(context) => context.make_current_surfaceless(),
+
+ #[cfg(target_os = "linux")]
+ PossiblyCurrentContext::Glx(context) => context.make_current_surfaceless(),
+
+ #[cfg(target_os = "windows")]
+ PossiblyCurrentContext::Wgl(context) => context.make_current_surfaceless(),
+
+ #[cfg(target_os = "macos")]
+ PossiblyCurrentContext::Cgl(context) => context.make_current_surfaceless(),
+ }
+}
+
mod sys
{
#![allow(