From e1bbdd4f5f2009ff4794a455a53f2e406d5148e3 Mon Sep 17 00:00:00 2001 From: knokko Date: Sun, 27 Jun 2021 17:36:01 +0200 Subject: [PATCH] Add glfwGetGLXFBConfig native access function This adds the glfwGetGLXFBConfig function for querying the GLXFBConfig the GLXWindow of a window. This commit is a squashed and modified version of PR #1925 by knokko. The following changes were made by elmindreda: The function signature was changed to handle GLXFBConfig being an opaque value in core GLX. The function error checks were fixed and updated. The struct member name was changed. The struct member clearing on context destruction was removed. All documentation snippets were updated. Closes #1925 --- README.md | 1 + docs/news.md | 7 +++++++ include/GLFW/glfw3native.h | 23 +++++++++++++++++++++++ src/glx_context.c | 26 ++++++++++++++++++++++++++ src/x11_platform.h | 1 + 5 files changed, 58 insertions(+) diff --git a/README.md b/README.md index cfb748f9..1c7ced36 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ information on what to include when reporting a bug. - Added `GLFW_UNLIMITED_MOUSE_BUTTONS` input mode that allows mouse buttons beyond the limit of the mouse button tokens to be reported (#2423) - Added `glfwGetEGLConfig` function to query the `EGLConfig` of a window (#2045) + - Added `glfwGetGLXFBConfig` function to query the `GLXFBConfig` of a window (#1925) - Updated minimum CMake version to 3.16 (#2541) - Removed support for building with original MinGW (#2540) - [Win32] Removed support for Windows XP and Vista (#2505) diff --git a/docs/news.md b/docs/news.md index 9cbc5ffa..06a930d5 100644 --- a/docs/news.md +++ b/docs/news.md @@ -21,6 +21,12 @@ GLFW now provides the @ref glfwGetEGLConfig native access function for querying the `EGLConfig` of a window that has a `EGLSurface`. +### GLXFBConfig native access function {#glxfbconfig} + +GLFW now provides the @ref glfwGetGLXFBConfig native access function for +querying the `GLXFBConfig` of a window that has a `GLXWindow`. + + ## Caveats {#caveats} ## Deprecations {#deprecations} @@ -47,6 +53,7 @@ actively maintained and available on many platforms. ### New functions {#new_functions} - @ref glfwGetEGLConfig + - @ref glfwGetGLXFBConfig ### New types {#new_types} diff --git a/include/GLFW/glfw3native.h b/include/GLFW/glfw3native.h index 0071d12b..8db2cfa3 100644 --- a/include/GLFW/glfw3native.h +++ b/include/GLFW/glfw3native.h @@ -478,6 +478,29 @@ GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* window); * @ingroup native */ GLFWAPI GLXWindow glfwGetGLXWindow(GLFWwindow* window); + +/*! @brief Retrieves the `GLXFBConfig` of the specified window's `GLXWindow`. + * + * @param[in] window The window whose `GLXWindow` to query. + * @param[out] config The `GLXFBConfig` of the window `GLXWindow`, if available. + * @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_NO_WINDOW_CONTEXT and @ref GLFW_PLATFORM_UNAVAILABLE. + * + * @remark `GLXFBConfig` is an opaque type. Unlike other GLFW functions, the + * @p config out parameter is not cleared on error, as core GLX does not define + * any invalid value. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.5 + * + * @ingroup native + */ +GLFWAPI int glfwGetGLXFBConfig(GLFWwindow* window, GLXFBConfig* config); #endif #if defined(GLFW_EXPOSE_NATIVE_WAYLAND) diff --git a/src/glx_context.c b/src/glx_context.c index a2464a9d..098c4bad 100644 --- a/src/glx_context.c +++ b/src/glx_context.c @@ -626,6 +626,8 @@ GLFWbool _glfwCreateContextGLX(_GLFWwindow* window, return GLFW_FALSE; } + window->context.glx.fbconfig = native; + window->context.makeCurrent = makeContextCurrentGLX; window->context.swapBuffers = swapBuffersGLX; window->context.swapInterval = swapIntervalGLX; @@ -719,5 +721,29 @@ GLFWAPI GLXWindow glfwGetGLXWindow(GLFWwindow* handle) return window->context.glx.window; } +GLFWAPI int glfwGetGLXFBConfig(GLFWwindow* handle, GLXFBConfig* config) +{ + _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); + + if (_glfw.platform.platformID != GLFW_PLATFORM_X11) + { + _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "GLX: Platform not initialized"); + return GLFW_FALSE; + } + + _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window != NULL); + assert(config != NULL); + + if (window->context.source != GLFW_NATIVE_CONTEXT_API) + { + _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL); + return GLFW_FALSE; + } + + *config = window->context.glx.fbconfig; + return GLFW_TRUE; +} + #endif // _GLFW_X11 diff --git a/src/x11_platform.h b/src/x11_platform.h index 30326c5b..1bfeaab4 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -470,6 +470,7 @@ typedef struct _GLFWcontextGLX { GLXContext handle; GLXWindow window; + GLXFBConfig fbconfig; } _GLFWcontextGLX; // GLX-specific global data