[OpenGL] Use MESA_query_renderer if avail; GL "WSI" enum

pull/1011/head
jackun 2 years ago
parent 85fd1c97fd
commit e61321717e
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -16,6 +16,11 @@
#include <glad/glad.h>
#define GLX_RENDERER_VENDOR_ID_MESA 0x8183
#define GLX_RENDERER_DEVICE_ID_MESA 0x8184
bool glx_mesa_queryInteger(int attrib, unsigned int *value);
namespace MangoHud { namespace GL {
struct GLVec
@ -93,7 +98,7 @@ void imgui_init()
}
//static
void imgui_create(void *ctx)
void imgui_create(void *ctx, const gl_wsi plat)
{
if (inited)
return;
@ -134,7 +139,13 @@ void imgui_create(void *ctx)
}
if (deviceName.find("zink") != std::string::npos)
sw_stats.engine = EngineTypes::ZINK;
init_gpu_stats(vendorID, 0, params);
uint32_t device_id = 0;
if (plat == gl_wsi::GL_WSI_GLX)
glx_mesa_queryInteger(GLX_RENDERER_DEVICE_ID_MESA, &device_id);
SPDLOG_DEBUG("GL device id: {:04X}", device_id);
init_gpu_stats(vendorID, device_id, params);
sw_stats.gpuName = gpu = get_device_name(vendorID, deviceID);
SPDLOG_DEBUG("gpu: {}", gpu);
// Setup Dear ImGui context
@ -176,11 +187,11 @@ void imgui_shutdown()
inited = false;
}
void imgui_set_context(void *ctx)
void imgui_set_context(void *ctx, const gl_wsi plat)
{
if (!ctx)
return;
imgui_create(ctx);
imgui_create(ctx, plat);
}
void imgui_render(unsigned int width, unsigned int height)

@ -7,11 +7,18 @@
namespace MangoHud { namespace GL {
enum gl_wsi
{
GL_WSI_UNKNOWN,
GL_WSI_GLX,
GL_WSI_EGL,
};
extern overlay_params params;
void imgui_init();
void imgui_create(void *ctx);
void imgui_create(void *ctx, const gl_wsi plat);
void imgui_shutdown();
void imgui_set_context(void *ctx);
void imgui_set_context(void *ctx, const gl_wsi plat);
void imgui_render(unsigned int width, unsigned int height);
}} // namespace

@ -53,7 +53,7 @@ EXPORT_C_(unsigned int) eglSwapBuffers( void* dpy, void* surf)
if (!pfn_eglQuerySurface)
pfn_eglQuerySurface = reinterpret_cast<decltype(pfn_eglQuerySurface)>(get_egl_proc_address("eglQuerySurface"));
imgui_create(surf);
imgui_create(surf, gl_wsi::GL_WSI_EGL);
int width=0, height=0;
if (pfn_eglQuerySurface(dpy, surf, 0x3056, &height) &&

@ -51,6 +51,17 @@ static void* get_glx_proc_address(const char* name) {
return func;
}
bool glx_mesa_queryInteger(int attrib, unsigned int *value);
bool glx_mesa_queryInteger(int attrib, unsigned int *value)
{
static int (*pfn_queryInteger)(int attribute, unsigned int *value) =
reinterpret_cast<decltype(pfn_queryInteger)>(get_glx_proc_address(
"glXQueryCurrentRendererIntegerMESA"));
if (pfn_queryInteger)
return !!pfn_queryInteger(attrib, value);
return false;
}
EXPORT_C_(void *) glXCreateContext(void *dpy, void *vis, void *shareList, int direct)
{
glx.Load();
@ -99,7 +110,7 @@ EXPORT_C_(int) glXMakeCurrent(void* dpy, void* drawable, void* ctx) {
if (!is_blacklisted()) {
if (ret) {
imgui_set_context(ctx);
imgui_set_context(ctx, gl_wsi::GL_WSI_GLX);
SPDLOG_DEBUG("GL ref count: {}", refcnt);
}
@ -123,7 +134,7 @@ static void do_imgui_swap(void *dpy, void *drawable)
{
GLint vp[4];
if (!is_blacklisted()) {
imgui_create(glx.GetCurrentContext());
imgui_create(glx.GetCurrentContext(), gl_wsi::GL_WSI_GLX);
unsigned int width = -1, height = -1;

Loading…
Cancel
Save