Skip to content

Commit

Permalink
Fixed Mac OS X OpenGL context creation to match other backends, where…
Browse files Browse the repository at this point in the history
… we only care about the actual version we request if it's 3.0 or newer or a special profile context.

Eventually we'll probably move the version checking to higher level code and report the actual version of context that got created, but to avoid breakage we'll leave it like this for now.
  • Loading branch information
slouken committed Mar 11, 2014
1 parent e99dc1f commit b677d1d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 44 deletions.
74 changes: 34 additions & 40 deletions src/video/cocoa/SDL_cocoaopengl.m
Expand Up @@ -162,9 +162,6 @@ - (void)setWindow:(SDL_Window *)newWindow
Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
/*
const GLubyte *(APIENTRY * glGetStringFunc)(GLenum) = NULL;
*/
NSAutoreleasePool *pool;
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
Expand Down Expand Up @@ -278,49 +275,46 @@ - (void)setWindow:(SDL_Window *)newWindow
return NULL;
}

/* No other backend does this version checking.
If we enable it, we should consider whether it should be done at a
higher level for all platforms. We'll have to think through the implications
of this.
if (_this->gl_config.major_version < 3 &&
_this->gl_config.profile_mask == 0 &&
_this->gl_config.flags == 0) {
/* This is a legacy profile, so to match other backends, we're done. */
} else {
const GLubyte *(APIENTRY * glGetStringFunc)(GLenum);

For example, Mac OS X 10.6 will only report OpenGL 2.0, but we ask for 2.1
by default. If we don't get 2.1, then the renderer will set the requested
version and try to recreate the window, which causes all kinds of problems.
glGetStringFunc = (const GLubyte *(APIENTRY *)(GLenum)) SDL_GL_GetProcAddress("glGetString");
if (!glGetStringFunc) {
Cocoa_GL_DeleteContext(_this, context);
SDL_SetError ("Failed getting OpenGL glGetString entry point");
return NULL;
}

For now, we'll just disable this code until we can think about it more.
*/
#if 0
glGetStringFunc = (const GLubyte *(APIENTRY *)(GLenum)) SDL_GL_GetProcAddress("glGetString");
if (!glGetStringFunc) {
Cocoa_GL_DeleteContext(_this, context);
SDL_SetError ("Failed getting OpenGL glGetString entry point");
return NULL;
}
glversion = (const char *)glGetStringFunc(GL_VERSION);
if (glversion == NULL) {
Cocoa_GL_DeleteContext(_this, context);
SDL_SetError ("Failed getting OpenGL context version");
return NULL;
}

glversion = (const char *)glGetStringFunc(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 (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;
}

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;
/* In the future we'll want to do this, but to match other platforms
we'll leave the OpenGL version the way it is for now
*/
/*_this->gl_config.major_version = glversion_major;*/
/*_this->gl_config.minor_version = glversion_minor;*/
}

_this->gl_config.major_version = glversion_major;
_this->gl_config.minor_version = glversion_minor;
#endif

return context;
}

Expand Down
8 changes: 4 additions & 4 deletions src/video/windows/SDL_windowsopengl.c
Expand Up @@ -616,13 +616,13 @@ WIN_GL_CreateContext(_THIS, SDL_Window * window)
}

if (_this->gl_config.major_version < 3 &&
_this->gl_config.profile_mask == 0 &&
_this->gl_config.flags == 0) {
_this->gl_config.profile_mask == 0 &&
_this->gl_config.flags == 0) {
/* Create legacy context */
context = _this->gl_data->wglCreateContext(hdc);
if( share_context != 0 ) {
if( share_context != 0 ) {
_this->gl_data->wglShareLists(share_context, context);
}
}
} else {
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
HGLRC temp_context = _this->gl_data->wglCreateContext(hdc);
Expand Down

0 comments on commit b677d1d

Please sign in to comment.