mirror of
https://github.com/mpv-player/mpv
synced 2025-01-14 02:51:26 +00:00
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.
This commit is contained in:
parent
35c29bdd52
commit
b00c1335c8
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user