From c3d17ece7b1c73dd57d2777299bdb333ae012770 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 2 Jun 2014 09:57:15 +0200 Subject: cocoa: switch to CGL APIs for GL context creation CGL APIs are lower level thus giving us better control and more options for the context creation. --- video/out/cocoa_common.m | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'video') diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m index 6f375fa5dd..e53868d5a6 100644 --- a/video/out/cocoa_common.m +++ b/video/out/cocoa_common.m @@ -54,7 +54,6 @@ struct vo_cocoa_state { MpvVideoWindow *window; MpvVideoView *view; NSOpenGLContext *gl_ctx; - NSOpenGLPixelFormat *gl_pixfmt; NSScreen *current_screen; NSScreen *fs_screen; @@ -331,39 +330,47 @@ static void create_window(struct vo *vo, struct mp_rect *win, int geo_flags) } } -static NSOpenGLPixelFormatAttribute get_nsopengl_profile(int gl3profile) { +static CGLOpenGLProfile cgl_profile(int gl3profile) { if (gl3profile) { - return NSOpenGLProfileVersion3_2Core; + return kCGLOGLPVersion_3_2_Core; } else { - return NSOpenGLProfileVersionLegacy; + return kCGLOGLPVersion_Legacy; } } static int create_gl_context(struct vo *vo, int gl3profile) { struct vo_cocoa_state *s = vo->cocoa; + CGLError err; - NSOpenGLPixelFormatAttribute attr[] = { - NSOpenGLPFAOpenGLProfile, - get_nsopengl_profile(gl3profile), - NSOpenGLPFADoubleBuffer, + CGLPixelFormatAttribute attrs[] = { + kCGLPFAOpenGLProfile, + (CGLPixelFormatAttribute) cgl_profile(gl3profile), + kCGLPFADoubleBuffer, + kCGLPFAAccelerated, 0 }; - s->gl_pixfmt = - [[[NSOpenGLPixelFormat alloc] initWithAttributes:attr] autorelease]; + CGLPixelFormatObj pix; + GLint npix; + if ((err = CGLChoosePixelFormat(attrs, &pix, &npix)) != kCGLNoError) { + MP_FATAL(s, "error creating CGL pixel format: %s (%d)\n", + CGLErrorString(err), err); + } - if (!s->gl_pixfmt) { - MP_ERR(s, "Trying to build invalid OpenGL pixel format\n"); + CGLContextObj ctx; + if ((err = CGLCreateContext(pix, 0, &ctx)) != kCGLNoError) { + MP_FATAL(s, "error creating CGL context: %s (%d)\n", + CGLErrorString(err), err); return -1; } - s->gl_ctx = - [[NSOpenGLContext alloc] initWithFormat:s->gl_pixfmt - shareContext:nil]; - + s->gl_ctx = [[NSOpenGLContext alloc] initWithCGLContextObj:ctx]; [s->gl_ctx makeCurrentContext]; + CGLReleasePixelFormat(pix); + CGLReleaseContext(ctx); + return 0; } -- cgit v1.2.3