You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
3.1 KiB
C++
119 lines
3.1 KiB
C++
4 years ago
|
#include "real_dlsym.h"
|
||
4 years ago
|
#include "loaders/loader_glx.h"
|
||
4 years ago
|
|
||
|
gl_loader::gl_loader() : loaded_(false) {
|
||
|
}
|
||
|
|
||
|
gl_loader::~gl_loader() {
|
||
|
CleanUp(loaded_);
|
||
|
}
|
||
|
|
||
4 years ago
|
bool gl_loader::Load(void *handle, bool egl_only) {
|
||
4 years ago
|
if (loaded_) {
|
||
|
return true;
|
||
|
}
|
||
|
|
||
4 years ago
|
if (!handle)
|
||
|
handle = RTLD_NEXT;
|
||
|
|
||
4 years ago
|
eglSwapBuffers =
|
||
|
reinterpret_cast<decltype(this->eglSwapBuffers)>(
|
||
4 years ago
|
real_dlsym(handle, "eglSwapBuffers"));
|
||
4 years ago
|
|
||
|
if (egl_only) {
|
||
|
loaded_ = true;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
glXGetProcAddress =
|
||
|
reinterpret_cast<decltype(this->glXGetProcAddress)>(
|
||
4 years ago
|
real_dlsym(handle, "glXGetProcAddress"));
|
||
4 years ago
|
|
||
|
glXGetProcAddressARB =
|
||
|
reinterpret_cast<decltype(this->glXGetProcAddressARB)>(
|
||
4 years ago
|
real_dlsym(handle, "glXGetProcAddressARB"));
|
||
4 years ago
|
|
||
|
if (!glXGetProcAddress) {
|
||
|
CleanUp(true);
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
glXCreateContext =
|
||
|
reinterpret_cast<decltype(this->glXCreateContext)>(
|
||
|
glXGetProcAddress((const unsigned char *)"glXCreateContext"));
|
||
|
if (!glXCreateContext) {
|
||
|
CleanUp(true);
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
glXDestroyContext =
|
||
|
reinterpret_cast<decltype(this->glXDestroyContext)>(
|
||
|
glXGetProcAddress((const unsigned char *)"glXDestroyContext"));
|
||
|
if (!glXDestroyContext) {
|
||
|
CleanUp(true);
|
||
|
return false;
|
||
|
}
|
||
|
|
||
4 years ago
|
glXGetCurrentContext =
|
||
|
reinterpret_cast<decltype(this->glXGetCurrentContext)>(
|
||
|
glXGetProcAddress((const unsigned char *)"glXGetCurrentContext"));
|
||
|
if (!glXGetCurrentContext) {
|
||
|
CleanUp(true);
|
||
|
return false;
|
||
|
}
|
||
|
|
||
4 years ago
|
glXSwapBuffers =
|
||
|
reinterpret_cast<decltype(this->glXSwapBuffers)>(
|
||
|
glXGetProcAddress((const unsigned char *)"glXSwapBuffers"));
|
||
|
if (!glXSwapBuffers) {
|
||
|
CleanUp(true);
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
glXSwapIntervalEXT =
|
||
|
reinterpret_cast<decltype(this->glXSwapIntervalEXT)>(
|
||
|
glXGetProcAddress((const unsigned char *)"glXSwapIntervalEXT"));
|
||
|
|
||
|
glXSwapIntervalSGI =
|
||
|
reinterpret_cast<decltype(this->glXSwapIntervalSGI)>(
|
||
|
glXGetProcAddress((const unsigned char *)"glXSwapIntervalSGI"));
|
||
|
|
||
|
glXSwapIntervalMESA =
|
||
|
reinterpret_cast<decltype(this->glXSwapIntervalMESA)>(
|
||
|
glXGetProcAddress((const unsigned char *)"glXSwapIntervalMESA"));
|
||
|
|
||
4 years ago
|
glXGetSwapIntervalMESA =
|
||
|
reinterpret_cast<decltype(this->glXGetSwapIntervalMESA)>(
|
||
|
glXGetProcAddress((const unsigned char *)"glXGetSwapIntervalMESA"));
|
||
|
|
||
4 years ago
|
glXQueryDrawable =
|
||
|
reinterpret_cast<decltype(this->glXQueryDrawable)>(
|
||
|
glXGetProcAddress((const unsigned char *)"glXQueryDrawable"));
|
||
|
|
||
4 years ago
|
glXMakeCurrent =
|
||
|
reinterpret_cast<decltype(this->glXMakeCurrent)>(
|
||
|
glXGetProcAddress((const unsigned char *)"glXMakeCurrent"));
|
||
|
if (!glXMakeCurrent) {
|
||
|
CleanUp(true);
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
loaded_ = true;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
void gl_loader::CleanUp(bool unload) {
|
||
|
loaded_ = false;
|
||
|
glXGetProcAddress = nullptr;
|
||
|
glXGetProcAddressARB = nullptr;
|
||
|
glXCreateContext = nullptr;
|
||
|
glXDestroyContext = nullptr;
|
||
|
glXSwapBuffers = nullptr;
|
||
|
glXSwapIntervalEXT = nullptr;
|
||
|
glXSwapIntervalSGI = nullptr;
|
||
|
glXSwapIntervalMESA = nullptr;
|
||
4 years ago
|
glXQueryDrawable = nullptr;
|
||
4 years ago
|
glXMakeCurrent = nullptr;
|
||
|
|
||
|
}
|