summaryrefslogtreecommitdiffstats
path: root/libvo/cocoa_common.m
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 /libvo/cocoa_common.m
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.
Diffstat (limited to 'libvo/cocoa_common.m')
-rw-r--r--libvo/cocoa_common.m47
1 files changed, 39 insertions, 8 deletions
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