2020-04-01 12:20:22 +00:00
|
|
|
#include <iostream>
|
2021-07-16 00:28:46 +00:00
|
|
|
#include <spdlog/spdlog.h>
|
2020-04-01 11:39:51 +00:00
|
|
|
#include "real_dlsym.h"
|
2020-04-01 12:02:56 +00:00
|
|
|
#include "loaders/loader_glx.h"
|
2020-03-10 05:19:18 +00:00
|
|
|
|
2020-04-01 12:20:22 +00:00
|
|
|
glx_loader::glx_loader() : loaded_(false) {
|
2020-03-10 05:19:18 +00:00
|
|
|
}
|
|
|
|
|
2020-04-01 12:20:22 +00:00
|
|
|
glx_loader::~glx_loader() {
|
2020-03-10 05:19:18 +00:00
|
|
|
CleanUp(loaded_);
|
|
|
|
}
|
|
|
|
|
2020-04-01 12:20:22 +00:00
|
|
|
bool glx_loader::Load() {
|
2020-03-10 05:19:18 +00:00
|
|
|
if (loaded_) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-01 12:20:22 +00:00
|
|
|
// Force load libGL
|
2021-03-31 14:52:38 +00:00
|
|
|
void *handle = nullptr;
|
|
|
|
#ifndef NDEBUG
|
|
|
|
// Use apitrace's glxtrace.so for debugging
|
|
|
|
// Assumes glxtrace.so lives outside of usual library paths and is only preloaded
|
|
|
|
handle = real_dlopen("glxtrace.so", RTLD_LAZY);
|
|
|
|
#endif
|
|
|
|
if (!handle)
|
|
|
|
handle = real_dlopen("libGL.so.1", RTLD_LAZY);
|
2020-04-01 12:20:22 +00:00
|
|
|
if (!handle) {
|
2021-07-21 16:48:45 +00:00
|
|
|
SPDLOG_ERROR("Failed to open " MANGOHUD_ARCH " libGL.so.1: {}", dlerror());
|
2020-04-01 12:20:22 +00:00
|
|
|
return false;
|
2020-03-10 05:19:18 +00:00
|
|
|
}
|
|
|
|
|
2020-04-01 12:20:22 +00:00
|
|
|
GetProcAddress =
|
|
|
|
reinterpret_cast<decltype(this->GetProcAddress)>(
|
2020-03-16 20:35:34 +00:00
|
|
|
real_dlsym(handle, "glXGetProcAddress"));
|
2020-03-10 05:19:18 +00:00
|
|
|
|
2020-04-01 12:20:22 +00:00
|
|
|
GetProcAddressARB =
|
|
|
|
reinterpret_cast<decltype(this->GetProcAddressARB)>(
|
2020-03-16 20:35:34 +00:00
|
|
|
real_dlsym(handle, "glXGetProcAddressARB"));
|
2020-03-10 05:19:18 +00:00
|
|
|
|
2020-04-01 12:20:22 +00:00
|
|
|
if (!GetProcAddress) {
|
2020-03-10 05:19:18 +00:00
|
|
|
CleanUp(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-01 12:20:22 +00:00
|
|
|
CreateContext =
|
|
|
|
reinterpret_cast<decltype(this->CreateContext)>(
|
|
|
|
GetProcAddress((const unsigned char *)"glXCreateContext"));
|
|
|
|
if (!CreateContext) {
|
2020-03-10 05:19:18 +00:00
|
|
|
CleanUp(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-08-18 16:13:27 +00:00
|
|
|
CreateContextAttribs =
|
|
|
|
reinterpret_cast<decltype(this->CreateContextAttribs)>(
|
|
|
|
GetProcAddress((const unsigned char *)"glXCreateContextAttribs"));
|
|
|
|
// if (!CreateContextAttribs) {
|
|
|
|
// CleanUp(true);
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
|
|
|
|
CreateContextAttribsARB =
|
|
|
|
reinterpret_cast<decltype(this->CreateContextAttribsARB)>(
|
|
|
|
GetProcAddress((const unsigned char *)"glXCreateContextAttribsARB"));
|
|
|
|
// if (!CreateContextAttribsARB) {
|
|
|
|
// CleanUp(true);
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
|
2020-04-01 12:20:22 +00:00
|
|
|
DestroyContext =
|
|
|
|
reinterpret_cast<decltype(this->DestroyContext)>(
|
|
|
|
GetProcAddress((const unsigned char *)"glXDestroyContext"));
|
|
|
|
if (!DestroyContext) {
|
2020-03-10 05:19:18 +00:00
|
|
|
CleanUp(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-01 12:20:22 +00:00
|
|
|
GetCurrentContext =
|
|
|
|
reinterpret_cast<decltype(this->GetCurrentContext)>(
|
|
|
|
GetProcAddress((const unsigned char *)"glXGetCurrentContext"));
|
|
|
|
if (!GetCurrentContext) {
|
2020-03-14 16:31:13 +00:00
|
|
|
CleanUp(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-01 12:20:22 +00:00
|
|
|
SwapBuffers =
|
|
|
|
reinterpret_cast<decltype(this->SwapBuffers)>(
|
|
|
|
GetProcAddress((const unsigned char *)"glXSwapBuffers"));
|
|
|
|
if (!SwapBuffers) {
|
2020-03-10 05:19:18 +00:00
|
|
|
CleanUp(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-08 19:53:33 +00:00
|
|
|
SwapBuffersMscOML =
|
|
|
|
reinterpret_cast<decltype(this->SwapBuffersMscOML)>(
|
|
|
|
GetProcAddress((const unsigned char *)"glXSwapBuffersMscOML"));
|
|
|
|
/*if (!SwapBuffersMscOML) {
|
|
|
|
CleanUp(true);
|
|
|
|
return false;
|
|
|
|
}*/
|
|
|
|
|
2020-04-01 12:20:22 +00:00
|
|
|
SwapIntervalEXT =
|
|
|
|
reinterpret_cast<decltype(this->SwapIntervalEXT)>(
|
|
|
|
GetProcAddress((const unsigned char *)"glXSwapIntervalEXT"));
|
2020-03-10 05:19:18 +00:00
|
|
|
|
2020-04-01 12:20:22 +00:00
|
|
|
SwapIntervalSGI =
|
|
|
|
reinterpret_cast<decltype(this->SwapIntervalSGI)>(
|
|
|
|
GetProcAddress((const unsigned char *)"glXSwapIntervalSGI"));
|
2020-03-10 05:19:18 +00:00
|
|
|
|
2020-04-01 12:20:22 +00:00
|
|
|
SwapIntervalMESA =
|
|
|
|
reinterpret_cast<decltype(this->SwapIntervalMESA)>(
|
|
|
|
GetProcAddress((const unsigned char *)"glXSwapIntervalMESA"));
|
2020-03-10 05:19:18 +00:00
|
|
|
|
2020-04-01 12:20:22 +00:00
|
|
|
GetSwapIntervalMESA =
|
|
|
|
reinterpret_cast<decltype(this->GetSwapIntervalMESA)>(
|
|
|
|
GetProcAddress((const unsigned char *)"glXGetSwapIntervalMESA"));
|
2020-03-12 10:11:31 +00:00
|
|
|
|
2020-04-01 12:20:22 +00:00
|
|
|
QueryDrawable =
|
|
|
|
reinterpret_cast<decltype(this->QueryDrawable)>(
|
|
|
|
GetProcAddress((const unsigned char *)"glXQueryDrawable"));
|
2020-04-01 08:21:54 +00:00
|
|
|
|
2020-04-01 12:20:22 +00:00
|
|
|
MakeCurrent =
|
|
|
|
reinterpret_cast<decltype(this->MakeCurrent)>(
|
|
|
|
GetProcAddress((const unsigned char *)"glXMakeCurrent"));
|
|
|
|
if (!MakeCurrent) {
|
2020-03-10 05:19:18 +00:00
|
|
|
CleanUp(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
loaded_ = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-01 12:20:22 +00:00
|
|
|
void glx_loader::CleanUp(bool unload) {
|
2020-03-10 05:19:18 +00:00
|
|
|
loaded_ = false;
|
2020-04-01 12:20:22 +00:00
|
|
|
GetProcAddress = nullptr;
|
|
|
|
GetProcAddressARB = nullptr;
|
|
|
|
CreateContext = nullptr;
|
|
|
|
DestroyContext = nullptr;
|
|
|
|
SwapBuffers = nullptr;
|
|
|
|
SwapIntervalEXT = nullptr;
|
|
|
|
SwapIntervalSGI = nullptr;
|
|
|
|
SwapIntervalMESA = nullptr;
|
|
|
|
QueryDrawable = nullptr;
|
|
|
|
MakeCurrent = nullptr;
|
2020-03-10 05:19:18 +00:00
|
|
|
|
|
|
|
}
|
2020-04-01 12:20:22 +00:00
|
|
|
|
|
|
|
glx_loader glx;
|