From 4b5ca4e23f1dbc169ddd7cb9e292f42b10641ef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Fri, 29 Aug 2025 15:44:34 +0200 Subject: [PATCH] Add glfwGetEGLConfig native access function This adds the glfwGetEGLConfig function for querying the EGLConfig of the EGLSurface of a window. This is a re-implementation of the PR #2045 by knokko, slightly redesigned to handle EGLConfig being an opaque type in core EGL. Closes #2045 --- CONTRIBUTORS.md | 1 + README.md | 1 + docs/news.md | 10 ++++++++++ include/GLFW/glfw3native.h | 23 +++++++++++++++++++++++ src/egl_context.c | 22 ++++++++++++++++++++++ 5 files changed, 57 insertions(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 22ef76d0..cfb4f42c 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -124,6 +124,7 @@ video tutorials. - Josh Kilmer - Byunghoon Kim - Cameron King + - knokko - Peter Knut - Christoph Kubisch - Yuri Kunde Schlesner diff --git a/README.md b/README.md index 5148467a..cfb748f9 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,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) - 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 640ae7a5..9cbc5ffa 100644 --- a/docs/news.md +++ b/docs/news.md @@ -14,6 +14,13 @@ values over 8. For compatibility with older versions, the @ref GLFW_UNLIMITED_MOUSE_BUTTONS input mode needs to be set to make use of this. + +### EGL config native access function {#eglconfig} + +GLFW now provides the @ref glfwGetEGLConfig native access function for querying +the `EGLConfig` of a window that has a `EGLSurface`. + + ## Caveats {#caveats} ## Deprecations {#deprecations} @@ -39,6 +46,9 @@ actively maintained and available on many platforms. ### New functions {#new_functions} + - @ref glfwGetEGLConfig + + ### New types {#new_types} ### New constants {#new_constants} diff --git a/include/GLFW/glfw3native.h b/include/GLFW/glfw3native.h index 011b239c..0071d12b 100644 --- a/include/GLFW/glfw3native.h +++ b/include/GLFW/glfw3native.h @@ -586,6 +586,29 @@ GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* window); * @ingroup native */ GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* window); + +/*! @brief Retrieves the `EGLConfig` of the specified window's `EGLSurface`. + * + * @param[in] window The window whose `EGLSurface` to query. + * @param[out] config The `EGLConfig` of the window `EGLSurface`, 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 and @ref + * GLFW_NO_WINDOW_CONTEXT. + * + * @remark `EGLConfig` is an opaque type. Unlike other GLFW functions, the @p + * config out parameter is not cleared on error, as core EGL 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 glfwGetEGLConfig(GLFWwindow* window, EGLConfig* config); #endif #if defined(GLFW_EXPOSE_NATIVE_OSMESA) diff --git a/src/egl_context.c b/src/egl_context.c index 272e7a4d..0ef7f729 100644 --- a/src/egl_context.c +++ b/src/egl_context.c @@ -946,3 +946,25 @@ GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* handle) return window->context.egl.surface; } +GLFWAPI int glfwGetEGLConfig(GLFWwindow* handle, EGLConfig* config) +{ + _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); + + _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window != NULL); + assert(config != NULL); + + if (window->context.source != GLFW_EGL_CONTEXT_API) + { + if (_glfw.platform.platformID != GLFW_PLATFORM_WAYLAND || + window->context.source != GLFW_NATIVE_CONTEXT_API) + { + _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL); + return GLFW_FALSE; + } + } + + *config = window->context.egl.config; + return GLFW_TRUE; +} +