From ba38f48840b41a42b996af14c7a30529b1e00d1d Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 14 Sep 2024 16:42:27 +0200 Subject: [PATCH] Simplify glfw import on mac. --- sfw/render_core/3rd_glfw3.h | 10 +++++++--- sfw/render_gui/imgui_impl_glfw.cpp | 15 ++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/sfw/render_core/3rd_glfw3.h b/sfw/render_core/3rd_glfw3.h index 9be2fdc..4d53af9 100644 --- a/sfw/render_core/3rd_glfw3.h +++ b/sfw/render_core/3rd_glfw3.h @@ -5752,7 +5752,7 @@ GLFWAPI int glfwVulkanSupported(void); */ GLFWAPI const char** glfwGetRequiredInstanceExtensions(uint32_t* count); -/*! @brief Returns the `HWND` of the specified window as a void*, only works on windows +/*! @brief Returns the `HWND` of the specified window as a void*, only works on windows, and osx * * @return The `HWND` of the specified window, or `NULL` if an * [error](@ref error_handling) occurred. @@ -5774,7 +5774,7 @@ GLFWAPI const char** glfwGetRequiredInstanceExtensions(uint32_t* count); * * @ingroup native */ -GLFWAPI void *glfwGetWin32WindowAsVPTR(GLFWwindow* window); +GLFWAPI void *glfwGetNativeWindowHandleAsVPTR(GLFWwindow* window); #if defined(VK_VERSION_1_0) @@ -17070,12 +17070,16 @@ const char* _glfwGetVulkanResultString(VkResult result) ////////////////////////////////////////////////////////////////////////// -GLFWAPI void *glfwGetWin32WindowAsVPTR(GLFWwindow* handle) +GLFWAPI void *glfwGetNativeWindowHandleAsVPTR(GLFWwindow* handle) { #if defined(_WIN64) || defined(_WIN32) _GLFWwindow* window = (_GLFWwindow*) handle; _GLFW_REQUIRE_INIT_OR_RETURN(NULL); return window->win32.handle; +#elif defined(__APPLE__) + _GLFWwindow* window = (_GLFWwindow*) handle; + _GLFW_REQUIRE_INIT_OR_RETURN(nil); + return window->ns.object; #else return NULL; #endif diff --git a/sfw/render_gui/imgui_impl_glfw.cpp b/sfw/render_gui/imgui_impl_glfw.cpp index a98f2f9..cce007e 100644 --- a/sfw/render_gui/imgui_impl_glfw.cpp +++ b/sfw/render_gui/imgui_impl_glfw.cpp @@ -95,19 +95,13 @@ #include #endif -#ifdef __APPLE__ -#ifndef GLFW_EXPOSE_NATIVE_COCOA -#define GLFW_EXPOSE_NATIVE_COCOA -#endif -//#include // for glfwGetCocoaWindow() -#endif - #include "render_core/3rd_glfw3.h" #ifndef _WIN32 #include // for usleep() #endif +/* #ifdef __EMSCRIPTEN__ #include #include @@ -117,6 +111,7 @@ #define EMSCRIPTEN_USE_EMBEDDED_GLFW3 #endif #endif +*/ // We gather version tests as define in order to easily see which features are version-dependent. #define GLFW_VERSION_COMBINED (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 + GLFW_VERSION_REVISION) @@ -625,9 +620,11 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw ImGuiViewport* main_viewport = ImGui::GetMainViewport(); main_viewport->PlatformHandle = (void*)bd->Window; #ifdef _WIN32 - main_viewport->PlatformHandleRaw = glfwGetWin32WindowAsVPTR(bd->Window); + //main_viewport->PlatformHandleRaw = glfwGetWin32Window(bd->Window); + main_viewport->PlatformHandleRaw = glfwGetNativeWindowHandleAsVPTR(bd->Window); #elif defined(__APPLE__) - main_viewport->PlatformHandleRaw = (void*)glfwGetCocoaWindow(bd->Window); + //main_viewport->PlatformHandleRaw = (void*)glfwGetCocoaWindow(bd->Window); + main_viewport->PlatformHandleRaw = glfwGetNativeWindowHandleAsVPTR(bd->Window); #else IM_UNUSED(main_viewport); #endif