gsdx ogl: install a GLX error handler before the context creation. Allow to print a nice message when the user doesn't support opengl 3.3

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@5607 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gregory.hainaut 2013-04-07 14:37:14 +00:00
parent a28ca6554d
commit fa7d10cfb1
1 changed files with 22 additions and 1 deletions

View File

@ -225,6 +225,13 @@ GSWnd::~GSWnd()
}
}
static bool ctxError = false;
static int ctxErrorHandler(Display *dpy, XErrorEvent *ev)
{
ctxError = true;
return 0;
}
bool GSWnd::CreateContext(int major, int minor)
{
if ( !m_XDisplay || !m_Xwindow )
@ -255,6 +262,11 @@ bool GSWnd::CreateContext(int major, int minor)
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress((const GLubyte*) "glXCreateContextAttribsARB");
if (!glXCreateContextAttribsARB) return false;
// Install a dummy handler to handle gracefully (aka not segfault) the support of GL version
int (*oldHandler)(Display*, XErrorEvent*) = XSetErrorHandler(&ctxErrorHandler);
// Be sure the handler is installed
XSync( m_XDisplay, false);
// Create a context
int context_attribs[] =
{
@ -268,9 +280,18 @@ bool GSWnd::CreateContext(int major, int minor)
};
m_context = glXCreateContextAttribsARB(m_XDisplay, fbc[0], 0, true, context_attribs);
if (!m_context) return false;
// Don't forget to reinstall the older Handler
XSetErrorHandler(oldHandler);
// Get latest error
XSync( m_XDisplay, false);
if (!m_context || ctxError) {
fprintf(stderr, "Failed to create the opengl context. Check your drivers support openGL %d.%d. Hint: opensource drivers don't\n", major, minor );
return false;
}
return true;
}