summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2011-12-09 21:25:05 +0100
committerwm4 <wm4@mplayer2.org>2012-03-31 02:58:52 +0200
commitb00c1335c83be933b96de9464779a0e74c34331d (patch)
treea384ac705d47511303d395ee0b0ba6f551ccebef
parent35c29bdd52c04098f928fd7151a7f2e94337bea0 (diff)
downloadmpv-b00c1335c83be933b96de9464779a0e74c34331d.tar.bz2
mpv-b00c1335c83be933b96de9464779a0e74c34331d.tar.xz
gl_common: cocoa: add OpenGL 3.2 context creation code
Add a new option to the cocoa window creation code in order to decide which OpenGL context to create.
-rw-r--r--libvo/cocoa_common.h3
-rw-r--r--libvo/cocoa_common.m47
-rw-r--r--libvo/gl_common.c13
3 files changed, 53 insertions, 10 deletions
diff --git a/libvo/cocoa_common.h b/libvo/cocoa_common.h
index 4fbbb32dd9..1330caacc5 100644
--- a/libvo/cocoa_common.h
+++ b/libvo/cocoa_common.h
@@ -10,7 +10,8 @@ void vo_cocoa_update_xinerama_info(struct vo *vo);
int vo_cocoa_change_attributes(struct vo *vo);
int vo_cocoa_create_window(struct vo *vo, uint32_t d_width,
- uint32_t d_height, uint32_t flags);
+ uint32_t d_height, uint32_t flags,
+ int gl3profile);
void vo_cocoa_swap_buffers(void);
int vo_cocoa_check_events(struct vo *vo);
diff --git a/libvo/cocoa_common.m b/libvo/cocoa_common.m
index 5658ecb7bf..4eccf1a320 100644
--- a/libvo/cocoa_common.m
+++ b/libvo/cocoa_common.m
@@ -1,7 +1,7 @@
#import <Cocoa/Cocoa.h>
#import <OpenGL/OpenGL.h>
#import <QuartzCore/QuartzCore.h>
-#import <CoreServices/CoreServices.h> // for CGDisplayHideCursor
+#import <CoreServices/CoreServices.h> // for CGDisplayHideCursor and Gestalt
#include "cocoa_common.h"
#include "options.h"
@@ -16,6 +16,18 @@
#include "osx_common.h"
#include "mp_msg.h"
+#ifndef NSOpenGLPFAOpenGLProfile
+#define NSOpenGLPFAOpenGLProfile 99
+#endif
+
+#ifndef NSOpenGLProfileVersionLegacy
+#define NSOpenGLProfileVersionLegacy 0x1000
+#endif
+
+#ifndef NSOpenGLProfileVersion3_2Core
+#define NSOpenGLProfileVersion3_2Core 0x3200
+#endif
+
#define NSLeftAlternateKeyMask (0x000020 | NSAlternateKeyMask)
#define NSRightAlternateKeyMask (0x000040 | NSAlternateKeyMask)
@@ -66,6 +78,8 @@ void update_screen_info(void);
void resize_window(struct vo *vo);
void create_menu(void);
+bool is_lion_or_better(void);
+
struct vo_cocoa_state *vo_cocoa_init_state(void)
{
struct vo_cocoa_state *s = talloc_ptrtype(NULL, s);
@@ -142,7 +156,8 @@ void resize_window(struct vo *vo)
}
int vo_cocoa_create_window(struct vo *vo, uint32_t d_width,
- uint32_t d_height, uint32_t flags)
+ uint32_t d_height, uint32_t flags,
+ int gl3profile)
{
if (s->current_video_size.width > 0 || s->current_video_size.height > 0)
s->previous_video_size = s->current_video_size;
@@ -155,13 +170,18 @@ int vo_cocoa_create_window(struct vo *vo, uint32_t d_width,
GLMPlayerOpenGLView *glView = [[GLMPlayerOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
- NSOpenGLPixelFormatAttribute attrs[] = {
- NSOpenGLPFADoubleBuffer, // double buffered
- NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)16, // 16 bit depth buffer
- (NSOpenGLPixelFormatAttribute)0
- };
+ int i = 0;
+ NSOpenGLPixelFormatAttribute attr[32];
+ if (is_lion_or_better()) {
+ attr[i++] = NSOpenGLPFAOpenGLProfile;
+ attr[i++] = (gl3profile ? NSOpenGLProfileVersion3_2Core : NSOpenGLProfileVersionLegacy);
+ }
+ attr[i++] = NSOpenGLPFADoubleBuffer; // double buffered
+ attr[i++] = NSOpenGLPFADepthSize;
+ attr[i++] = (NSOpenGLPixelFormatAttribute)16; // 16 bit depth buffer
+ attr[i] = (NSOpenGLPixelFormatAttribute)0;
- NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
+ NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
s->glContext = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil];
create_menu();
@@ -291,6 +311,17 @@ void create_menu()
[menuItem release];
}
+bool is_lion_or_better(void)
+{
+ SInt32 major, minor;
+ Gestalt(gestaltSystemVersionMajor, &major);
+ Gestalt(gestaltSystemVersionMinor, &minor);
+ if(major >= 10 && minor >= 7)
+ return YES;
+ else
+ return NO;
+}
+
@implementation GLMPlayerWindow
- (void) windowDidResize:(NSNotification *) notification
diff --git a/libvo/gl_common.c b/libvo/gl_common.c
index 223404fd85..230e5dc2bd 100644
--- a/libvo/gl_common.c
+++ b/libvo/gl_common.c
@@ -1769,12 +1769,22 @@ void glDrawTex(GL *gl, GLfloat x, GLfloat y, GLfloat w, GLfloat h,
static int create_window_cocoa(struct MPGLContext *ctx, uint32_t d_width,
uint32_t d_height, uint32_t flags)
{
- if (vo_cocoa_create_window(ctx->vo, d_width, d_height, flags) == 0) {
+ if (vo_cocoa_create_window(ctx->vo, d_width, d_height, flags, 0) == 0) {
return SET_WINDOW_OK;
} else {
return SET_WINDOW_FAILED;
}
}
+
+static int create_window_cocoa_gl3(struct MPGLContext *ctx, int gl_flags,
+ int gl_version, uint32_t d_width,
+ uint32_t d_height, uint32_t flags)
+{
+ int rv = vo_cocoa_create_window(ctx->vo, d_width, d_height, flags, 1);
+ getFunctions(ctx->gl, (void *)getdladdr, NULL, true);
+ return rv;
+}
+
static int setGlWindow_cocoa(MPGLContext *ctx)
{
vo_cocoa_change_attributes(ctx->vo);
@@ -2465,6 +2475,7 @@ MPGLContext *init_mpglcontext(enum MPGLType type, struct vo *vo)
#ifdef CONFIG_GL_COCOA
case GLTYPE_COCOA:
ctx->create_window = create_window_cocoa;
+ ctx->create_window_gl3 = create_window_cocoa_gl3;
ctx->setGlWindow = setGlWindow_cocoa;
ctx->releaseGlContext = releaseGlContext_cocoa;
ctx->swapGlBuffers = swapGlBuffers_cocoa;