mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-29 20:27:12 +01:00
Mac OS X: Make OpenGL context selection more robust, avoid software fallback.
Fixes Bugzilla #2197.
This commit is contained in:
parent
3e541f306d
commit
99583397e6
@ -35,17 +35,14 @@
|
|||||||
|
|
||||||
#define DEFAULT_OPENGL "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
|
#define DEFAULT_OPENGL "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
|
||||||
|
|
||||||
#ifndef kCGLPFAOpenGLProfile
|
#ifndef NSOpenGLPFAOpenGLProfile
|
||||||
#define kCGLPFAOpenGLProfile 99
|
#define NSOpenGLPFAOpenGLProfile 99
|
||||||
#endif
|
#endif
|
||||||
#ifndef kCGLOGLPVersion_Legacy
|
#ifndef NSOpenGLProfileVersionLegacy
|
||||||
#define kCGLOGLPVersion_Legacy 0x1000
|
#define NSOpenGLProfileVersionLegacy 0x1000
|
||||||
#endif
|
#endif
|
||||||
#ifndef kCGLOGLPVersion_GL3_Core
|
#ifndef NSOpenGLProfileVersion3_2Core
|
||||||
#define kCGLOGLPVersion_GL3_Core 0x3200
|
#define NSOpenGLProfileVersion3_2Core 0x3200
|
||||||
#endif
|
|
||||||
#ifndef kCGLOGLPVersion_GL4_Core
|
|
||||||
#define kCGLOGLPVersion_GL4_Core 0x4100
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@implementation SDLOpenGLContext : NSOpenGLContext
|
@implementation SDLOpenGLContext : NSOpenGLContext
|
||||||
@ -164,8 +161,6 @@ Cocoa_GL_UnloadLibrary(_THIS)
|
|||||||
SDL_GLContext
|
SDL_GLContext
|
||||||
Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
|
Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
|
||||||
{
|
{
|
||||||
const int wantver = (_this->gl_config.major_version << 8) |
|
|
||||||
(_this->gl_config.minor_version);
|
|
||||||
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
||||||
NSAutoreleasePool *pool;
|
NSAutoreleasePool *pool;
|
||||||
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
||||||
@ -175,16 +170,16 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
|
|||||||
SDLOpenGLContext *context;
|
SDLOpenGLContext *context;
|
||||||
NSOpenGLContext *share_context = nil;
|
NSOpenGLContext *share_context = nil;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
const char *glversion;
|
||||||
|
int glversion_major;
|
||||||
|
int glversion_minor;
|
||||||
|
|
||||||
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
|
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
|
||||||
SDL_SetError ("OpenGL ES is not supported on this platform");
|
SDL_SetError ("OpenGL ES is not supported on this platform");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
if ((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) && (data->osversion < 0x1070)) {
|
||||||
/* Sadly, we'll have to update this as life progresses, since we need to
|
SDL_SetError ("OpenGL Core Profile is not supported on this platform version");
|
||||||
set an enum for context profiles, not a context version number */
|
|
||||||
if (wantver > 0x0401) {
|
|
||||||
SDL_SetError ("OpenGL > 4.1 is not supported on this platform");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,19 +187,11 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
|
|||||||
|
|
||||||
/* specify a profile if we're on Lion (10.7) or later. */
|
/* specify a profile if we're on Lion (10.7) or later. */
|
||||||
if (data->osversion >= 0x1070) {
|
if (data->osversion >= 0x1070) {
|
||||||
NSOpenGLPixelFormatAttribute profile = kCGLOGLPVersion_Legacy;
|
NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy;
|
||||||
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
|
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
|
||||||
if (wantver == 0x0302) {
|
profile = NSOpenGLProfileVersion3_2Core;
|
||||||
profile = kCGLOGLPVersion_GL3_Core;
|
|
||||||
} else if ((wantver == 0x0401) && (data->osversion >= 0x1090)) {
|
|
||||||
profile = kCGLOGLPVersion_GL4_Core;
|
|
||||||
} else {
|
|
||||||
SDL_SetError("Requested GL version is not supported on this platform");
|
|
||||||
[pool release];
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
}
|
attr[i++] = NSOpenGLPFAOpenGLProfile;
|
||||||
attr[i++] = kCGLPFAOpenGLProfile;
|
|
||||||
attr[i++] = profile;
|
attr[i++] = profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,9 +271,33 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
|
|||||||
|
|
||||||
if ( Cocoa_GL_MakeCurrent(_this, window, context) < 0 ) {
|
if ( Cocoa_GL_MakeCurrent(_this, window, context) < 0 ) {
|
||||||
Cocoa_GL_DeleteContext(_this, context);
|
Cocoa_GL_DeleteContext(_this, context);
|
||||||
|
SDL_SetError ("Failed making OpenGL context current");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glversion = (const char *)glGetString(GL_VERSION);
|
||||||
|
if (glversion == NULL) {
|
||||||
|
Cocoa_GL_DeleteContext(_this, context);
|
||||||
|
SDL_SetError ("Failed getting OpenGL context version");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SDL_sscanf(glversion, "%d.%d", &glversion_major, &glversion_minor) != 2) {
|
||||||
|
Cocoa_GL_DeleteContext(_this, context);
|
||||||
|
SDL_SetError ("Failed parsing OpenGL context version");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((glversion_major < _this->gl_config.major_version) ||
|
||||||
|
((glversion_major == _this->gl_config.major_version) && (glversion_minor < _this->gl_config.minor_version))) {
|
||||||
|
Cocoa_GL_DeleteContext(_this, context);
|
||||||
|
SDL_SetError ("Failed creating OpenGL context at version requested");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
_this->gl_config.major_version = glversion_major;
|
||||||
|
_this->gl_config.minor_version = glversion_minor;
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user