Use glXGetProcAddress to fetch glXCreateContextAttribsARB. Refs #716

* Most functions we hook and then jump to the real driver we can fetch
  just with dlsym to the library, but the ARB context creation function
  is an extension and may not be directly exported.
* It's safe to call glXGetProcAddress(ARB) without a context current
  though and it's guaranteed to be directly exported, so we can use this
  to fetch the function if we don't find it with dlsym.
This commit is contained in:
baldurk
2017-08-15 17:10:02 +01:00
parent 3587411c4a
commit 794044e5be
+14
View File
@@ -42,6 +42,7 @@ typedef XVisualInfo *(*PFNGLXGETVISUALFROMFBCONFIGPROC)(Display *dpy, GLXFBConfi
typedef int (*PFNGLXGETCONFIGPROC)(Display *dpy, XVisualInfo *vis, int attrib, int *value);
typedef Bool (*PFNGLXQUERYEXTENSIONPROC)(Display *dpy, int *errorBase, int *eventBase);
typedef Bool (*PFNGLXISDIRECTPROC)(Display *dpy, GLXContext ctx);
typedef __GLXextFuncPtr (*PFNGLXGETPROCADDRESSARBPROC)(const GLubyte *procName);
class OpenGLHook : LibraryHook, public GLPlatform
{
@@ -363,6 +364,7 @@ public:
PFNGLXDESTROYCONTEXTPROC glXDestroyContext_real;
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB_real;
PFNGLXGETPROCADDRESSPROC glXGetProcAddress_real;
PFNGLXGETPROCADDRESSARBPROC glXGetProcAddressARB_real;
PFNGLXMAKECURRENTPROC glXMakeCurrent_real;
PFNGLXMAKECONTEXTCURRENTPROC glXMakeContextCurrent_real;
PFNGLXSWAPBUFFERSPROC glXSwapBuffers_real;
@@ -388,6 +390,9 @@ public:
if(glXGetProcAddress_real == NULL)
glXGetProcAddress_real =
(PFNGLXGETPROCADDRESSPROC)dlsym(libGLdlsymHandle, "glXGetProcAddress");
if(glXGetProcAddressARB_real == NULL)
glXGetProcAddressARB_real =
(PFNGLXGETPROCADDRESSPROC)dlsym(libGLdlsymHandle, "glXGetProcAddressARB");
if(glXCreateContext_real == NULL)
glXCreateContext_real = (PFNGLXCREATECONTEXTPROC)dlsym(libGLdlsymHandle, "glXCreateContext");
if(glXDestroyContext_real == NULL)
@@ -418,6 +423,15 @@ public:
if(glXQueryDrawable_real == NULL)
glXQueryDrawable_real = (PFNGLXQUERYDRAWABLEPROC)dlsym(RTLD_NEXT, "glXQueryDrawable");
// glXCreateContextAttribsARB may not be directly exported by libGL.so, so try to fetch it
// through the glXGetProcAddress function, favouring the ARB variant.
if(glXCreateContextAttribsARB_real == NULL && glXGetProcAddressARB_real)
glXCreateContextAttribsARB_real = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddressARB_real(
(const GLubyte *)"glXCreateContextAttribsARB");
if(glXCreateContextAttribsARB_real == NULL && glXGetProcAddress_real)
glXCreateContextAttribsARB_real = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress_real(
(const GLubyte *)"glXCreateContextAttribsARB");
return success;
}