Created
December 29, 2018 21:25
-
-
Save mikroskeem/96d2b1eebf3543321c034abca1ff9798 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* clang -O2 -s -lGL -ldl -shared fake_glvendor.c -fPIC -o fake_glvendor.so | |
*/ | |
#define _GNU_SOURCE | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <dlfcn.h> | |
#include <GL/gl.h> | |
static const GLubyte* (*real_glGetString)(GLenum name) = NULL; | |
static char *vendor = NULL; | |
static char *renderer = NULL; | |
void __attribute__ ((constructor)) ctor(void) { | |
real_glGetString = dlsym(RTLD_NEXT, "glGetString"); | |
if(real_glGetString == NULL) { | |
fprintf(stderr, "[fake_glvendor] Failed to dlsym 'glGetString': %s\n", dlerror()); | |
abort(); | |
} | |
vendor = getenv("FAKE_VENDOR"); | |
renderer = getenv("FAKE_RENDERER"); | |
} | |
const GLubyte* glGetString(GLenum name) { | |
if(name == GL_VENDOR) { | |
return (GLubyte*) vendor; | |
} | |
if(name == GL_RENDERER) { | |
return (GLubyte*) renderer; | |
} | |
return real_glGetString(name); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment