From 5fa9677474f07677c42ed4e664e6350b5b2821aa Mon Sep 17 00:00:00 2001 From: Ralph Sennhauser Date: Sat, 23 May 2026 08:19:54 +0200 Subject: [PATCH] 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 --- source/lib/external_libraries/libsdl.cpp | 30 +---- source/lib/external_libraries/libsdl.h | 10 -- source/lib/ogl.cpp | 55 +-------- source/lib/ogl.h | 2 - source/renderer/backend/gl/Device.cpp | 143 +---------------------- 5 files changed, 7 insertions(+), 233 deletions(-) diff --git a/source/lib/external_libraries/libsdl.cpp b/source/lib/external_libraries/libsdl.cpp index f74917af22..3e332e0f86 100644 --- a/source/lib/external_libraries/libsdl.cpp +++ b/source/lib/external_libraries/libsdl.cpp @@ -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 #include -#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(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(wminfo.info.wl.display); - } - return nullptr; -} -#endif - const char* GetSDLSubsystem(SDL_Window* window) { SDL_SysWMinfo wminfo; diff --git a/source/lib/external_libraries/libsdl.h b/source/lib/external_libraries/libsdl.h index f4cf48e46e..0487d70fc1 100644 --- a/source/lib/external_libraries/libsdl.h +++ b/source/lib/external_libraries/libsdl.h @@ -27,8 +27,6 @@ #ifndef INCLUDED_SDL #define INCLUDED_SDL -#include "lib/config2.h" - # include # include @@ -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 diff --git a/source/lib/ogl.cpp b/source/lib/ogl.cpp index a38110b4ab..acc723bc29 100644 --- a/source/lib/ogl.cpp +++ b/source/lib/ogl.cpp @@ -31,21 +31,9 @@ #include #include -#if !CONFIG2_GLES -# if OS_WIN -# include -# elif !OS_MACOSX -# include -# include -# if defined(SDL_VIDEO_DRIVER_X11) -# include -# include -# endif -# if defined(SDL_VIDEO_DRIVER_WAYLAND) -# include -# endif -# endif -#endif // !CONFIG2_GLES +#if OS_WIN +# include +#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(subsystem); -# if defined(SDL_VIDEO_DRIVER_X11) - if (sysWMType == SDL_SYSWM_X11) - { - GLXVersion = gladLoadGLX(reinterpret_cast(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); diff --git a/source/lib/ogl.h b/source/lib/ogl.h index 23b98a37b6..477b4a67a0 100644 --- a/source/lib/ogl.h +++ b/source/lib/ogl.h @@ -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 diff --git a/source/renderer/backend/gl/Device.cpp b/source/renderer/backend/gl/Device.cpp index c6db23ee49..500dc90aa2 100644 --- a/source/renderer/backend/gl/Device.cpp +++ b/source/renderer/backend/gl/Device.cpp @@ -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 -#include -#endif - -#include - -#endif // !CONFIG2_GLES && (defined(SDL_VIDEO_DRIVER_X11) || defined(SDL_VIDEO_DRIVER_WAYLAND)) - namespace Renderer { @@ -241,76 +230,12 @@ std::unique_ptr 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(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(wminfo.subsystem)); - break; -#endif - default: - ogl_Init(SDL_GL_GetProcAddress, nullptr, - static_cast(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(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(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 CDevice::CreateCommandContext()