Skip to content

Commit

Permalink
support multiple lib paths (for 32 bit)
Browse files Browse the repository at this point in the history
  • Loading branch information
Etaash-mathamsetty authored and flightlessmango committed Dec 26, 2024
1 parent 9556404 commit 5559616
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
39 changes: 23 additions & 16 deletions src/gl/shim.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,42 @@
static void* handle = NULL;
static bool mangoHudLoaded = false;

// Load MangoHud after EGL/GLX functions have been intercepted
static void loadMangoHud(void);
static void loadMangoHud() {
if (mangoHudLoaded) return;

//allow user to load custom mangohud libs (useful for testing)
char *libdir = getenv("MANGOHUD_OPENGL_LIB");
// allow user to load custom mangohud libs (useful for testing)
char *libs = getenv("MANGOHUD_OPENGL_LIBS");
char *lib = NULL;

if (libdir)
if (libs)
{
handle = dlopen(libdir, RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND);
lib = strtok(libs, ":");

if (handle) mangoHudLoaded = true;
else {
fprintf(stderr, "shim: Failed to load from: %s\n", libdir);
libdir = NULL;
// when user specifies only one path
if (!lib) lib = libs;

while (lib != NULL)
{
handle = dlopen(lib, RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND);

if (handle)
{
mangoHudLoaded = true;
break;
}
else fprintf(stderr, "shim: Failed to load from: %s\n", lib);

lib = strtok(NULL, ":");
}
}

// Load MangoHud after GLX functions have been intercepted
if(!mangoHudLoaded)
if (!mangoHudLoaded)
{
handle = dlopen("${ORIGIN}/libMangoHud_opengl.so", RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND);
if (handle) mangoHudLoaded = true;
}

if (mangoHudLoaded) {
printf("shim: Loaded mangohud library\n");
if (libdir) printf("from custom location: %s\n", libdir);
}
}

void glXSwapBuffers(void* dpy, void* drawable) {
Expand Down Expand Up @@ -90,7 +97,7 @@ unsigned int eglSwapBuffers(void* dpy, void* surf) {
// Get the hooked eglSwapBuffers function from the loaded library if available
unsigned int (*peglSwapBuffers)(void*, void*) = dlsym(handle, "eglSwapBuffers");
if (peglSwapBuffers) {
return peglSwapBuffers(dpy, surf);;
return peglSwapBuffers(dpy, surf);
} else {
// Fall back to the original eglSwapBuffers function
peglSwapBuffers = dlsym(RTLD_NEXT, "eglSwapBuffers");
Expand Down
4 changes: 3 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ mangohud_opengl_shared_lib = shared_library(
opengl_files,
vklayer_files,
util_files,
gnu_symbol_visibility : 'hidden',
c_args : [
pre_args,
vulkan_wsi_args
Expand Down Expand Up @@ -330,6 +329,9 @@ if is_unixy
files(
'gl/shim.c',
),
dependencies : [
dep_dl
],
install_dir : libdir_mangohud,
install: true
)
Expand Down

0 comments on commit 5559616

Please sign in to comment.