Drop use of GLX and EGL

Only used for hw-report and only when using GLX which is for X11 only.
The usefulness of those reported properties is questionable and X11 is
becoming rarer.

This allows us to drop a direct dependency on X11 delegating the
handling to SDL and wxWidgets respectively GTK.

Further SDL3 wont expose supported video driver at compile time making
this step more meaningful.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
This commit is contained in:
Ralph Sennhauser 2026-05-23 08:19:54 +02:00
parent 37d8b1bfeb
commit 5fa9677474
No known key found for this signature in database
5 changed files with 7 additions and 233 deletions

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -29,34 +29,6 @@
#include <SDL_error.h>
#include <SDL_syswm.h>
#if defined(SDL_VIDEO_DRIVER_X11) && !CONFIG2_GLES
void* GetX11Display(SDL_Window* window)
{
SDL_SysWMinfo wminfo;
SDL_VERSION(&wminfo.version);
const int ret = SDL_GetWindowWMInfo(window, &wminfo);
if (ret && wminfo.subsystem == SDL_SYSWM_X11)
{
return reinterpret_cast<void*>(wminfo.info.x11.display);
}
return nullptr;
}
#endif
#if defined(SDL_VIDEO_DRIVER_WAYLAND) && !CONFIG2_GLES
void* GetWaylandDisplay(SDL_Window* window)
{
SDL_SysWMinfo wminfo;
SDL_VERSION(&wminfo.version);
const int ret = SDL_GetWindowWMInfo(window, &wminfo);
if (ret && wminfo.subsystem == SDL_SYSWM_WAYLAND)
{
return reinterpret_cast<void*>(wminfo.info.wl.display);
}
return nullptr;
}
#endif
const char* GetSDLSubsystem(SDL_Window* window)
{
SDL_SysWMinfo wminfo;

View file

@ -27,8 +27,6 @@
#ifndef INCLUDED_SDL
#define INCLUDED_SDL
#include "lib/config2.h"
# include <SDL.h>
# include <SDL_thread.h>
@ -45,12 +43,4 @@
// Returns a windowing subsystem used for the window.
const char* GetSDLSubsystem(SDL_Window* window);
#if defined(SDL_VIDEO_DRIVER_X11) && !CONFIG2_GLES
void* GetX11Display(SDL_Window* window);
#endif
#if defined(SDL_VIDEO_DRIVER_WAYLAND) && !CONFIG2_GLES
void* GetWaylandDisplay(SDL_Window* window);
#endif
#endif // INCLUDED_SDL

View file

@ -31,21 +31,9 @@
#include <cstdarg>
#include <cstring>
#if !CONFIG2_GLES
# if OS_WIN
# include <glad/wgl.h>
# elif !OS_MACOSX
# include <SDL_config.h>
# include <SDL_syswm.h>
# if defined(SDL_VIDEO_DRIVER_X11)
# include <X11/Xlib.h>
# include <glad/glx.h>
# endif
# if defined(SDL_VIDEO_DRIVER_WAYLAND)
# include <glad/egl.h>
# endif
# endif
#endif // !CONFIG2_GLES
#if OS_WIN
# include <glad/wgl.h>
#endif
//----------------------------------------------------------------------------
// extensions
@ -216,13 +204,6 @@ bool ogl_HaveExtension(const char* ext)
static int GLVersion;
#if OS_WIN
static int WGLVersion;
#elif !CONFIG2_GLES && !OS_MACOSX
#if defined(SDL_VIDEO_DRIVER_X11)
static int GLXVersion;
#endif
#if defined(SDL_VIDEO_DRIVER_WAYLAND)
static int EGLVersion;
#endif
#endif
bool ogl_HaveVersion(int major, int minor)
@ -365,8 +346,6 @@ bool ogl_SquelchError(GLenum err_to_ignore)
#if OS_WIN
bool ogl_Init(void* (load)(const char*), void* hdc)
#elif !CONFIG2_GLES && !OS_MACOSX
bool ogl_Init(void* (load)(const char*), void* display, int subsystem)
#else
bool ogl_Init(void* (load)(const char*))
#endif
@ -395,34 +374,6 @@ bool ogl_Init(void* (load)(const char*))
LOAD_ERROR("Failed to load WGL functions.");
return false;
}
# elif !OS_MACOSX
const SDL_SYSWM_TYPE sysWMType = static_cast<SDL_SYSWM_TYPE>(subsystem);
# if defined(SDL_VIDEO_DRIVER_X11)
if (sysWMType == SDL_SYSWM_X11)
{
GLXVersion = gladLoadGLX(reinterpret_cast<Display*>(display), DefaultScreen(display), loadFunc);
if (!GLXVersion)
{
LOAD_ERROR("Failed to load GLX functions.");
return false;
}
}
# endif
# if defined(SDL_VIDEO_DRIVER_WAYLAND)
if (sysWMType == SDL_SYSWM_WAYLAND)
{
// TODO: investiage do we need Wayland display to load EGL.
// Because without eglGetDisplay we can't get one. But the
// function is loaded inside gladLoadEGL. So maybe we need to
// call it twice.
EGLVersion = gladLoadEGL(nullptr, loadFunc);
if (!EGLVersion)
{
LOAD_ERROR("Failed to load EGL functions.");
return false;
}
}
# endif
# endif
#else
GLVersion = gladLoadGLES2(loadFunc);

View file

@ -46,8 +46,6 @@
**/
#if OS_WIN
extern bool ogl_Init(void* (load)(const char*), void* hdc);
#elif !OS_MACOSX && !CONFIG2_GLES
extern bool ogl_Init(void* (load)(const char*), void* display, int subsystem);
#else
extern bool ogl_Init(void* (load)(const char*));
#endif

View file

@ -62,17 +62,6 @@
extern void* wutil_GetAppHDC();
#endif
#if !CONFIG2_GLES && (defined(SDL_VIDEO_DRIVER_X11) || defined(SDL_VIDEO_DRIVER_WAYLAND))
#if defined(SDL_VIDEO_DRIVER_X11)
#include <X11/Xlib.h>
#include <glad/glx.h>
#endif
#include <SDL_syswm.h>
#endif // !CONFIG2_GLES && (defined(SDL_VIDEO_DRIVER_X11) || defined(SDL_VIDEO_DRIVER_WAYLAND))
namespace Renderer
{
@ -241,76 +230,12 @@ std::unique_ptr<IDevice> CDevice::Create(SDL_Window* window)
LOGERROR("SDL_GL_CreateContext failed: '%s'", SDL_GetError());
return nullptr;
}
}
#if OS_WIN
ogl_Init(SDL_GL_GetProcAddress, wutil_GetAppHDC());
#elif (defined(SDL_VIDEO_DRIVER_X11) || defined(SDL_VIDEO_DRIVER_WAYLAND)) && !CONFIG2_GLES
SDL_SysWMinfo wminfo;
// The info structure must be initialized with the SDL version.
SDL_VERSION(&wminfo.version);
if (!SDL_GetWindowWMInfo(window, &wminfo))
{
LOGERROR("Failed to query SDL WM info: %s", SDL_GetError());
return nullptr;
}
switch (wminfo.subsystem)
{
#if defined(SDL_VIDEO_DRIVER_WAYLAND)
case SDL_SYSWM_WAYLAND:
// TODO: maybe we need to load X11 functions
// dynamically as well.
ogl_Init(SDL_GL_GetProcAddress,
GetWaylandDisplay(device->m_Window),
static_cast<int>(wminfo.subsystem));
break;
#endif
#if defined(SDL_VIDEO_DRIVER_X11)
case SDL_SYSWM_X11:
ogl_Init(SDL_GL_GetProcAddress,
GetX11Display(device->m_Window),
static_cast<int>(wminfo.subsystem));
break;
#endif
default:
ogl_Init(SDL_GL_GetProcAddress, nullptr,
static_cast<int>(wminfo.subsystem));
break;
}
ogl_Init(SDL_GL_GetProcAddress, wutil_GetAppHDC());
#else
ogl_Init(SDL_GL_GetProcAddress);
#endif
}
else
{
#if OS_WIN
ogl_Init(SDL_GL_GetProcAddress, wutil_GetAppHDC());
#elif (defined(SDL_VIDEO_DRIVER_X11) || defined(SDL_VIDEO_DRIVER_WAYLAND)) && !CONFIG2_GLES
bool initialized = false;
// Currently we don't have access to the backend type without
// the window. So we use hack to detect X11.
#if defined(SDL_VIDEO_DRIVER_X11)
Display* display = XOpenDisplay(NULL);
if (display)
{
ogl_Init(SDL_GL_GetProcAddress, display, static_cast<int>(SDL_SYSWM_X11));
initialized = true;
}
#endif
#if defined(SDL_VIDEO_DRIVER_WAYLAND)
if (!initialized)
{
// glad will find default EGLDisplay internally.
ogl_Init(SDL_GL_GetProcAddress, nullptr, static_cast<int>(SDL_SYSWM_WAYLAND));
initialized = true;
}
#endif
if (!initialized)
{
LOGERROR("Can't initialize GL");
return nullptr;
}
#else
ogl_Init(SDL_GL_GetProcAddress);
ogl_Init(SDL_GL_GetProcAddress);
#endif
if (!ogl_HaveVersion(2, 0)
@ -723,68 +648,6 @@ void CDevice::Report(const ScriptRequest& rq, JS::HandleValue settings)
// TODO: Support OpenGL platforms which don't use GLX as well.
#if defined(SDL_VIDEO_DRIVER_X11) && !CONFIG2_GLES
#define GLXQCR_INTEGER(id) do { \
unsigned int i = UINT_MAX; \
if (glXQueryCurrentRendererIntegerMESA(id, &i)) \
Script::SetProperty(rq, settings, #id, i); \
} while (false)
#define GLXQCR_INTEGER2(id) do { \
unsigned int i[2] = { UINT_MAX, UINT_MAX }; \
if (glXQueryCurrentRendererIntegerMESA(id, i)) { \
Script::SetProperty(rq, settings, #id "[0]", i[0]); \
Script::SetProperty(rq, settings, #id "[1]", i[1]); \
} \
} while (false)
#define GLXQCR_INTEGER3(id) do { \
unsigned int i[3] = { UINT_MAX, UINT_MAX, UINT_MAX }; \
if (glXQueryCurrentRendererIntegerMESA(id, i)) { \
Script::SetProperty(rq, settings, #id "[0]", i[0]); \
Script::SetProperty(rq, settings, #id "[1]", i[1]); \
Script::SetProperty(rq, settings, #id "[2]", i[2]); \
} \
} while (false)
#define GLXQCR_STRING(id) do { \
const char* str = glXQueryCurrentRendererStringMESA(id); \
if (str) \
Script::SetProperty(rq, settings, #id ".string", str); \
} while (false)
SDL_SysWMinfo wminfo;
SDL_VERSION(&wminfo.version);
const int ret = SDL_GetWindowWMInfo(m_Window, &wminfo);
if (ret && wminfo.subsystem == SDL_SYSWM_X11)
{
Display* dpy = wminfo.info.x11.display;
int scrnum = DefaultScreen(dpy);
const char* glxexts = glXQueryExtensionsString(dpy, scrnum);
Script::SetProperty(rq, settings, "GLX_EXTENSIONS", glxexts);
if (strstr(glxexts, "GLX_MESA_query_renderer") && glXQueryCurrentRendererIntegerMESA && glXQueryCurrentRendererStringMESA)
{
GLXQCR_INTEGER(GLX_RENDERER_VENDOR_ID_MESA);
GLXQCR_INTEGER(GLX_RENDERER_DEVICE_ID_MESA);
GLXQCR_INTEGER3(GLX_RENDERER_VERSION_MESA);
GLXQCR_INTEGER(GLX_RENDERER_ACCELERATED_MESA);
GLXQCR_INTEGER(GLX_RENDERER_VIDEO_MEMORY_MESA);
GLXQCR_INTEGER(GLX_RENDERER_UNIFIED_MEMORY_ARCHITECTURE_MESA);
GLXQCR_INTEGER(GLX_RENDERER_PREFERRED_PROFILE_MESA);
GLXQCR_INTEGER2(GLX_RENDERER_OPENGL_CORE_PROFILE_VERSION_MESA);
GLXQCR_INTEGER2(GLX_RENDERER_OPENGL_COMPATIBILITY_PROFILE_VERSION_MESA);
GLXQCR_INTEGER2(GLX_RENDERER_OPENGL_ES_PROFILE_VERSION_MESA);
GLXQCR_INTEGER2(GLX_RENDERER_OPENGL_ES2_PROFILE_VERSION_MESA);
GLXQCR_STRING(GLX_RENDERER_VENDOR_ID_MESA);
GLXQCR_STRING(GLX_RENDERER_DEVICE_ID_MESA);
}
}
#endif // SDL_VIDEO_DRIVER_X11
}
std::unique_ptr<IDeviceCommandContext> CDevice::CreateCommandContext()