From 3f5c5d969fe90d6b9af883d5f41a85aedd21b1f1 Mon Sep 17 00:00:00 2001 From: David Snopek Date: Fri, 13 Feb 2026 11:44:57 -0600 Subject: [PATCH] OpenXR: Fix OpenGL initialization with Monado on X11 --- doc/classes/DisplayServer.xml | 8 +++++++ .../platform/openxr_opengl_extension.cpp | 8 +++---- platform/linuxbsd/x11/display_server_x11.cpp | 12 ++++++++++ platform/linuxbsd/x11/gl_manager_x11.cpp | 23 +++++++++++++++++++ platform/linuxbsd/x11/gl_manager_x11.h | 3 +++ servers/display/display_server.cpp | 2 ++ servers/display/display_server.h | 2 ++ 7 files changed, 54 insertions(+), 4 deletions(-) diff --git a/doc/classes/DisplayServer.xml b/doc/classes/DisplayServer.xml index 4386716c14..cfdc685dec 100644 --- a/doc/classes/DisplayServer.xml +++ b/doc/classes/DisplayServer.xml @@ -3373,6 +3373,14 @@ - macOS: [code]EGLConfig[/code] for the window (ANGLE). - Linux (Wayland): [code]EGLConfig[/code] for the window. + + The GLX [code]VisualID[/code] for the window. + [b]Note:[/b] Only available on Linux when using X11. + + + The [code]GLXFBConfig[/code] for the window. + [b]Note:[/b] Only available on Linux when using X11. + Utterance has begun to be spoken. diff --git a/modules/openxr/extensions/platform/openxr_opengl_extension.cpp b/modules/openxr/extensions/platform/openxr_opengl_extension.cpp index 3b3da1eb06..c7ee189818 100644 --- a/modules/openxr/extensions/platform/openxr_opengl_extension.cpp +++ b/modules/openxr/extensions/platform/openxr_opengl_extension.cpp @@ -191,14 +191,14 @@ void *OpenXROpenGLExtension::set_session_create_and_get_next_pointer(void *p_nex void *display_handle = (void *)display_server->window_get_native_handle(DisplayServer::DISPLAY_HANDLE); void *glxcontext_handle = (void *)display_server->window_get_native_handle(DisplayServer::OPENGL_CONTEXT); void *glxdrawable_handle = (void *)display_server->window_get_native_handle(DisplayServer::WINDOW_HANDLE); + void *glx_fbconfig_handle = (void *)display_server->window_get_native_handle(DisplayServer::GLX_FBCONFIG); + VisualID glx_visualid = (VisualID)display_server->window_get_native_handle(DisplayServer::GLX_VISUALID); graphics_binding_gl.xDisplay = (Display *)display_handle; graphics_binding_gl.glxContext = (GLXContext)glxcontext_handle; graphics_binding_gl.glxDrawable = (GLXDrawable)glxdrawable_handle; - - // spec says to use proper values but runtimes don't care - graphics_binding_gl.visualid = 0; - graphics_binding_gl.glxFBConfig = nullptr; + graphics_binding_gl.glxFBConfig = (GLXFBConfig)glx_fbconfig_handle; + graphics_binding_gl.visualid = glx_visualid; #endif #endif diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp index 19a65e3a13..f5d55df826 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -2149,6 +2149,18 @@ int64_t DisplayServerX11::window_get_native_handle(HandleType p_handle_type, Win } return 0; } + case GLX_VISUALID: { + if (gl_manager) { + return (int64_t)gl_manager->get_glx_visualid(p_window); + } + return 0; + } + case GLX_FBCONFIG: { + if (gl_manager) { + return (int64_t)gl_manager->get_glx_fbconfig(p_window); + } + return 0; + } #endif default: { return 0; diff --git a/platform/linuxbsd/x11/gl_manager_x11.cpp b/platform/linuxbsd/x11/gl_manager_x11.cpp index 151730b9a2..cbcce3c73a 100644 --- a/platform/linuxbsd/x11/gl_manager_x11.cpp +++ b/platform/linuxbsd/x11/gl_manager_x11.cpp @@ -195,6 +195,7 @@ Error GLManager_X11::_create_context(GLDisplay &gl_display) { // for later creating windows using this display if (vi) { gl_display.x_vi = *vi; + gl_display.x_fbconfig = fbconfig; } XFree(vi); @@ -382,6 +383,28 @@ void *GLManager_X11::get_glx_context(DisplayServer::WindowID p_window_id) { return (void *)disp.context->glx_context; } +VisualID GLManager_X11::get_glx_visualid(DisplayServer::WindowID p_window_id) { + if (p_window_id == -1) { + return (VisualID)0; + } + + const GLWindow &win = _windows[p_window_id]; + const GLDisplay &disp = get_display(win.gldisplay_id); + + return disp.x_vi.visualid; +} + +void *GLManager_X11::get_glx_fbconfig(DisplayServer::WindowID p_window_id) { + if (p_window_id == -1) { + return nullptr; + } + + const GLWindow &win = _windows[p_window_id]; + const GLDisplay &disp = get_display(win.gldisplay_id); + + return disp.x_fbconfig; +} + GLManager_X11::GLManager_X11(const Vector2i &p_size, ContextType p_context_type) { context_type = p_context_type; diff --git a/platform/linuxbsd/x11/gl_manager_x11.h b/platform/linuxbsd/x11/gl_manager_x11.h index 3bd956b232..01598a38ca 100644 --- a/platform/linuxbsd/x11/gl_manager_x11.h +++ b/platform/linuxbsd/x11/gl_manager_x11.h @@ -78,6 +78,7 @@ private: GLManager_X11_Private *context = nullptr; ::Display *x11_display = nullptr; XVisualInfo x_vi = {}; + void *x_fbconfig = nullptr; }; // just for convenience, window and display struct @@ -126,6 +127,8 @@ public: bool is_using_vsync() const; void *get_glx_context(DisplayServer::WindowID p_window_id); + void *get_glx_fbconfig(DisplayServer::WindowID p_window_id); + VisualID get_glx_visualid(DisplayServer::WindowID p_window_id); Error open_display(Display *p_display); GLManager_X11(const Vector2i &p_size, ContextType p_context_type); diff --git a/servers/display/display_server.cpp b/servers/display/display_server.cpp index c776964089..3f15f56bfc 100644 --- a/servers/display/display_server.cpp +++ b/servers/display/display_server.cpp @@ -1944,6 +1944,8 @@ void DisplayServer::_bind_methods() { BIND_ENUM_CONSTANT(OPENGL_CONTEXT); BIND_ENUM_CONSTANT(EGL_DISPLAY); BIND_ENUM_CONSTANT(EGL_CONFIG); + BIND_ENUM_CONSTANT(GLX_VISUALID); + BIND_ENUM_CONSTANT(GLX_FBCONFIG); BIND_ENUM_CONSTANT(TTS_UTTERANCE_STARTED); BIND_ENUM_CONSTANT(TTS_UTTERANCE_ENDED); diff --git a/servers/display/display_server.h b/servers/display/display_server.h index cb40f81e5d..7bd973bd4e 100644 --- a/servers/display/display_server.h +++ b/servers/display/display_server.h @@ -92,6 +92,8 @@ public: OPENGL_CONTEXT, EGL_DISPLAY, EGL_CONFIG, + GLX_VISUALID, + GLX_FBCONFIG, }; enum Context {