Skip to content

Commit

Permalink
macos make current
Browse files Browse the repository at this point in the history
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
  • Loading branch information
sagudev committed Jan 6, 2025
1 parent aee2434 commit df06a2e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/platform/macos/cgl/context.rs
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit df06a2e

Please sign in to comment.