--- divos-hack.c 2016-07-25 15:55:11.074622100 +0300 +++ divos-hack-f.c 2016-07-25 16:03:32.064520300 +0300 @@ -2,7 +2,9 @@ * LD_PRELOAD shim which applies two patches necesary to get the game * Divinity: Original Sin Enhanded Edition for Linux to work with Mesa (12+) * - * Build with: gcc -s -O2 -shared -fPIC -o divos-hack.{so,c} -ldl + * Build with: + * gcc -c -O2 -fPIC -o divos-hack.{o,c} + * ld -shared -o divos-hack.{so,o} -ldl */ /* for RTLD_NEXT */ @@ -15,6 +17,16 @@ #define _GLX_PUBLIC +const char* vendor = "ATI Technologies Inc."; +const GLubyte* (*o_glGetString)(GLenum name); +void (*(*o_glXGetProcAddressARB)(const GLubyte*)) (void); + +void _init(void) +{ + o_glGetString = dlsym(RTLD_NEXT, "glGetString"); + o_glXGetProcAddressARB = dlsym(RTLD_NEXT, "glXGetProcAddressARB"); +} + /* * https://github.com/karolherbst/mesa/commit/aad2543bf6cfbd7df795d836e5ff4ec8686e4fdf * - allow env override of vendor string. I actually just hard-coded @@ -22,13 +34,9 @@ */ const GLubyte *GLAPIENTRY glGetString( GLenum name ) { - static void *next = NULL; - static const char *vendor = "ATI Technologies, Inc."; if(name == GL_VENDOR) return (const GLubyte *)vendor; - if(!next) - next = dlsym(RTLD_NEXT, "glGetString"); - return ((const GLubyte *GLAPIENTRY (*)(GLenum))next)(name); + return o_glGetString(name); } /* @@ -36,7 +44,6 @@ */ _GLX_PUBLIC void (*glXGetProcAddressARB(const GLubyte * procName)) (void) { - static void *next = NULL; if (strcmp((const char *) procName, "glNamedStringARB") == 0 || strcmp((const char *) procName, "glDeleteNamedStringARB") == 0 || strcmp((const char *) procName, "glCompileShaderIncludeARB") == 0 || @@ -44,8 +51,6 @@ strcmp((const char *) procName, "glGetNamedStringARB") == 0 || strcmp((const char *) procName, "glGetNamedStringivARB") == 0) return NULL; - if(!next) - next = dlsym(RTLD_NEXT, "glXGetProcAddressARB"); - return ((_GLX_PUBLIC void (*(*)(const GLubyte *))(void))next)(procName); + return o_glXGetProcAddressARB(procName); }