diff --git a/README.md b/README.md index fe5a2c76..a990d108 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,7 @@ information on what to include when reporting a bug. ## Changelog + - Added `glfwAddCocoaMTKSubview` function for better metal support - Added `GLFW_PLATFORM` init hint for runtime platform selection (#1958) - Added `GLFW_ANY_PLATFORM`, `GLFW_PLATFORM_WIN32`, `GLFW_PLATFORM_COCOA`, `GLFW_PLATFORM_WAYLAND`, `GLFW_PLATFORM_X11` and `GLFW_PLATFORM_NULL` symbols to diff --git a/include/GLFW/glfw3native.h b/include/GLFW/glfw3native.h index 36934120..2669603e 100644 --- a/include/GLFW/glfw3native.h +++ b/include/GLFW/glfw3native.h @@ -275,6 +275,20 @@ GLFWAPI CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* monitor); * @ingroup native */ GLFWAPI id glfwGetCocoaWindow(GLFWwindow* window); + +/*! @brief Adds an 'MTKView' to the window's main NSView as a subview + * + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety Call this function from the main thread. + * + * @since Added in version 3.3. + * + * @ingroup native + */ +GLFWAPI void glfwAddCocoaMTKSubview(GLFWwindow* window, void* view); + #endif #if defined(GLFW_EXPOSE_NATIVE_NSGL) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 3726f782..81bd9aec 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -30,6 +30,7 @@ #include #include +#import // Returns the style mask corresponding to the window settings // @@ -1950,3 +1951,20 @@ GLFWAPI id glfwGetCocoaWindow(GLFWwindow* handle) return window->ns.object; } +GLFWAPI void glfwAddCocoaMTKSubview(GLFWwindow* handle, void* view) { + + _GLFWwindow* window = (_GLFWwindow*) handle; + _GLFW_REQUIRE_INIT_OR_RETURN(); + + if (_glfw.platform.platformID != GLFW_PLATFORM_COCOA) + { + _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, + "Cocoa: Platform not initialized"); + return; + } + + [window->ns.view addSubview: (MTKView*) view]; + + +} +