From 794044e5be546a273c9e80ad9c07568bc9719ee9 Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 15 Aug 2017 17:10:02 +0100 Subject: [PATCH] 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. --- renderdoc/driver/gl/gl_hooks_linux.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/renderdoc/driver/gl/gl_hooks_linux.cpp b/renderdoc/driver/gl/gl_hooks_linux.cpp index ed79f2935..ba8acef33 100644 --- a/renderdoc/driver/gl/gl_hooks_linux.cpp +++ b/renderdoc/driver/gl/gl_hooks_linux.cpp @@ -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; }