From df06a2ef0e5ecc39804026a89324ec2598398ebc Mon Sep 17 00:00:00 2001 From: sagudev <16504129+sagudev@users.noreply.github.com> Date: Mon, 6 Jan 2025 10:42:50 +0100 Subject: [PATCH] macos make current Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- src/platform/macos/cgl/context.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/platform/macos/cgl/context.rs b/src/platform/macos/cgl/context.rs index 44eaf47c..76d1b7a2 100644 --- a/src/platform/macos/cgl/context.rs +++ b/src/platform/macos/cgl/context.rs @@ -123,6 +123,16 @@ impl Clone for ContextDescriptor { } } +fn make_current(cgl_context: CGLContextObj) -> Result<(), Error> { + unsafe { + let err = CGLSetCurrentContext(cgl_context); + if err != kCGLNoError { + return Err(Error::MakeCurrentFailed(err.to_windowing_api_error())); + } + Ok(()) + } +} + unsafe impl Send for ContextDescriptor {} impl Device { @@ -233,6 +243,7 @@ impl Device { } debug_assert_ne!(cgl_context, ptr::null_mut()); + make_current(cgl_context)?; // Wrap and return the context. let context = Context { cgl_context, @@ -302,13 +313,7 @@ impl Device { /// /// After calling this function, it is valid to use OpenGL rendering commands. pub fn make_context_current(&self, context: &Context) -> Result<(), Error> { - unsafe { - let err = CGLSetCurrentContext(context.cgl_context); - if err != kCGLNoError { - return Err(Error::MakeCurrentFailed(err.to_windowing_api_error())); - } - Ok(()) - } + make_current(context.cgl_context) } /// Removes the current OpenGL context from this thread.