Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fix for recent GLX error bug
Browse files Browse the repository at this point in the history
Lee Salzman

I messed up in the patch I sent you regarding gobbling up the GLX error codes signaled when trying to create a context. After reading the spec I realized those error codes are relative to a base error that needs to be queried when setting up the GLX extension...

So I have made a patch that fixes it for a user I had who was still getting the bug with my old patch.

Without this patch my previous one won't work, so it is recommended to merge this...
  • Loading branch information
slouken committed Jul 24, 2013
1 parent b3e9b35 commit e566fc8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/video/x11/SDL_x11opengl.c
Expand Up @@ -133,6 +133,7 @@ static void X11_GL_InitExtensions(_THIS);
int
X11_GL_LoadLibrary(_THIS, const char *path)
{
Display *display;
void *handle;

if (_this->gl_data) {
Expand Down Expand Up @@ -186,6 +187,9 @@ X11_GL_LoadLibrary(_THIS, const char *path)

/* Load function pointers */
handle = _this->gl_config.dll_handle;
_this->gl_data->glXQueryExtension =
(Bool (*)(Display *, int *, int *))
GL_LoadFunction(handle, "glXQueryExtension");
_this->gl_data->glXGetProcAddress =
(void *(*)(const GLubyte *))
GL_LoadFunction(handle, "glXGetProcAddressARB");
Expand All @@ -208,14 +212,20 @@ X11_GL_LoadLibrary(_THIS, const char *path)
(void (*)(Display*,GLXDrawable,int,unsigned int*))
X11_GL_GetProcAddress(_this, "glXQueryDrawable");

if (!_this->gl_data->glXChooseVisual ||
if (!_this->gl_data->glXQueryExtension ||
!_this->gl_data->glXChooseVisual ||
!_this->gl_data->glXCreateContext ||
!_this->gl_data->glXDestroyContext ||
!_this->gl_data->glXMakeCurrent ||
!_this->gl_data->glXSwapBuffers) {
return SDL_SetError("Could not retrieve OpenGL functions");
}

display = ((SDL_VideoData *) _this->driverdata)->display;
if (!_this->gl_data->glXQueryExtension(display, &_this->gl_data->errorBase, &_this->gl_data->eventBase)) {
return SDL_SetError("GLX is not supported");
}

/* Initialize extensions */
X11_GL_InitExtensions(_this);

Expand Down Expand Up @@ -504,19 +514,23 @@ X11_GL_GetVisual(_THIS, Display * display, int screen)
#define GLXBadProfileARB 13
#endif
static int (*handler) (Display *, XErrorEvent *) = NULL;
static int errorBase = 0;
static int
X11_GL_CreateContextErrorHandler(Display * d, XErrorEvent * e)
{
switch (e->error_code) {
case GLXBadContext:
case GLXBadFBConfig:
case GLXBadProfileARB:
case BadRequest:
case BadMatch:
case BadValue:
case BadAlloc:
return (0);
default:
if (errorBase &&
(e->error_code == errorBase + GLXBadContext ||
e->error_code == errorBase + GLXBadFBConfig ||
e->error_code == errorBase + GLXBadProfileARB)) {
return (0);
}
return (handler(d, e));
}
}
Expand All @@ -541,6 +555,7 @@ X11_GL_CreateContext(_THIS, SDL_Window * window)

/* We do this to create a clean separation between X and GLX errors. */
XSync(display, False);
errorBase = _this->gl_data->errorBase;
handler = XSetErrorHandler(X11_GL_CreateContextErrorHandler);
XGetWindowAttributes(display, data->xwindow, &xattr);
v.screen = screen;
Expand Down
3 changes: 3 additions & 0 deletions src/video/x11/SDL_x11opengl.h
Expand Up @@ -29,10 +29,13 @@

struct SDL_GLDriverData
{
int errorBase, eventBase;

SDL_bool HAS_GLX_EXT_visual_rating;
SDL_bool HAS_GLX_EXT_visual_info;
SDL_bool HAS_GLX_EXT_swap_control_tear;

Bool (*glXQueryExtension) (Display*,int*,int*);
void *(*glXGetProcAddress) (const GLubyte*);
XVisualInfo *(*glXChooseVisual) (Display*,int,int*);
GLXContext (*glXCreateContext) (Display*,XVisualInfo*,GLXContext,Bool);
Expand Down

0 comments on commit e566fc8

Please sign in to comment.