summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2014-06-02 09:57:15 +0200
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2014-06-15 08:18:48 +0200
commitc3d17ece7b1c73dd57d2777299bdb333ae012770 (patch)
tree64e79b2031c51825d6512f84bddaa712f1ab427d /video
parent3a998e5b1e3448cb6396a6f316d3aa79002ae41f (diff)
downloadmpv-c3d17ece7b1c73dd57d2777299bdb333ae012770.tar.bz2
mpv-c3d17ece7b1c73dd57d2777299bdb333ae012770.tar.xz
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.
Diffstat (limited to 'video')
-rw-r--r--video/out/cocoa_common.m39
1 files changed, 23 insertions, 16 deletions
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;
}