1//! An offscreen OpenGL context, current on this thread.
2use objc2::{MainThreadMarker, rc::Retained};
3use objc2_app_kit::{NSOpenGLContext, NSOpenGLPFAAccelerated, NSOpenGLPFAColorSize, NSOpenGLPixelFormat};
4
5pub fn current() -> Retained<NSOpenGLContext> {
6 let mtm = MainThreadMarker::new().unwrap();
7 let attributes = [NSOpenGLPFAAccelerated, NSOpenGLPFAColorSize, 24, 0];
8 let format = unsafe {
9 NSOpenGLPixelFormat::initWithAttributes(mtm.alloc(), std::ptr::NonNull::new(attributes.as_ptr().cast_mut()).unwrap())
10 }
11 .expect("pixel format");
12 let context = NSOpenGLContext::initWithFormat_shareContext(mtm.alloc(), &format, None).expect("context");
13 context.makeCurrentContext();
14 context
15}