Skip to content

Commit

Permalink
renderdiff: allow for explicit (compile-time) linking of osmesa (#8301)
Browse files Browse the repository at this point in the history
If the shared osmesa lib is not found, then we assume that the
library has been compile-time linked via the linker.  This is to
accommodate build frameworks where compile-time linking is
preferred.
  • Loading branch information
poweifeng committed Dec 12, 2024
1 parent 2cc375e commit aaac6e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
14 changes: 10 additions & 4 deletions filament/backend/src/opengl/platforms/PlatformOSMesa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@ struct OSMesaAPI {
break;
}
}
FILAMENT_CHECK_PRECONDITION(mLib)
<< "Unable to dlopen libOSMesa to create a software GL context";
if (mLib) {
OSMesaGetProcAddress = (GetProcAddressFunc) dlsym(mLib, "OSMesaGetProcAddress");
} else {
OSMesaGetProcAddress = (GetProcAddressFunc) dlsym(RTLD_LOCAL, "OSMesaGetProcAddress");
}

OSMesaGetProcAddress = (GetProcAddressFunc) dlsym(mLib, "OSMesaGetProcAddress");
FILAMENT_CHECK_PRECONDITION(OSMesaGetProcAddress)
<< "Unable to against libOSMesa to create a software GL context";

OSMesaCreateContext = (CreateContextFunc) OSMesaGetProcAddress("OSMesaCreateContext");
OSMesaDestroyContext =
Expand All @@ -76,7 +80,9 @@ struct OSMesaAPI {
}

~OSMesaAPI() {
dlclose(mLib);
if (mLib) {
dlclose(mLib);
}
}
private:
void* mLib = nullptr;
Expand Down
13 changes: 8 additions & 5 deletions libs/bluegl/src/BlueGLLinuxOSMesa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ bool initBinder() {
}
}
if (!g_driver.library) {
return false;
// The library has been linked explicitly during compile.
g_driver.OSMesaGetProcAddress = (ProcAddressFunc) dlsym(RTLD_LOCAL, "OSMesaGetProcAddress");
} else {
g_driver.OSMesaGetProcAddress =
(ProcAddressFunc) dlsym(g_driver.library, "OSMesaGetProcAddress");
}

g_driver.OSMesaGetProcAddress = (ProcAddressFunc)
dlsym(g_driver.library, "OSMesaGetProcAddress");

return g_driver.OSMesaGetProcAddress;
}

Expand All @@ -52,7 +53,9 @@ void* loadFunction(const char* name) {
}

void shutdownBinder() {
dlclose(g_driver.library);
if (g_driver.library) {
dlclose(g_driver.library);
}
memset(&g_driver, 0, sizeof(g_driver));
}

Expand Down

0 comments on commit aaac6e7

Please sign in to comment.