mirror of
https://github.com/glfw/glfw.git
synced 2025-06-08 16:54:57 +00:00
Merge 6bf254f940
into 6b57e08bb0
This commit is contained in:
commit
d9a8b03354
@ -281,6 +281,20 @@ GLFWAPI CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* monitor);
|
|||||||
* @ingroup native
|
* @ingroup native
|
||||||
*/
|
*/
|
||||||
GLFWAPI id glfwGetCocoaWindow(GLFWwindow* window);
|
GLFWAPI id glfwGetCocoaWindow(GLFWwindow* window);
|
||||||
|
|
||||||
|
/*! @brief Returns the `CAMetalLayer` for the specified window.
|
||||||
|
*
|
||||||
|
* @return The `CAMetalLayer` of the specified window, or `nil` if an
|
||||||
|
* [error](@ref error_handling) occurred.
|
||||||
|
*
|
||||||
|
* @thread_safety This function may be called from any thread. Access is not
|
||||||
|
* synchronized.
|
||||||
|
*
|
||||||
|
* @since Added in version 3.0.
|
||||||
|
*
|
||||||
|
* @ingroup native
|
||||||
|
*/
|
||||||
|
GLFWAPI id glfwGetMetalLayer(GLFWwindow* window);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(GLFW_EXPOSE_NATIVE_NSGL)
|
#if defined(GLFW_EXPOSE_NATIVE_NSGL)
|
||||||
|
@ -894,6 +894,48 @@ static GLFWbool createNativeWindow(_GLFWwindow* window,
|
|||||||
return GLFW_TRUE;
|
return GLFW_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GLFWbool createMetalLayer(_GLFWwindow* window)
|
||||||
|
{
|
||||||
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101100
|
||||||
|
|
||||||
|
@autoreleasepool {
|
||||||
|
|
||||||
|
// HACK: Dynamically load Core Animation to avoid adding an extra
|
||||||
|
// dependency for the majority who don't use MoltenVK
|
||||||
|
NSBundle* bundle = [NSBundle bundleWithPath:@"/System/Library/Frameworks/QuartzCore.framework"];
|
||||||
|
if (!bundle)
|
||||||
|
{
|
||||||
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||||
|
"Cocoa: Failed to find QuartzCore.framework");
|
||||||
|
return GLFW_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: Create the layer here as makeBackingLayer should not return nil
|
||||||
|
window->ns.layer = [[bundle classNamed:@"CAMetalLayer"] layer];
|
||||||
|
if (!window->ns.layer)
|
||||||
|
{
|
||||||
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||||
|
"Cocoa: Failed to create layer for view");
|
||||||
|
return GLFW_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window->ns.retina)
|
||||||
|
[window->ns.layer setContentsScale:[window->ns.object backingScaleFactor]];
|
||||||
|
|
||||||
|
[window->ns.view setLayer:window->ns.layer];
|
||||||
|
[window->ns.view setWantsLayer:YES];
|
||||||
|
|
||||||
|
} // autoreleasepool
|
||||||
|
|
||||||
|
return GLFW_TRUE;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
return GLFW_FALSE;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
////// GLFW internal API //////
|
////// GLFW internal API //////
|
||||||
@ -1941,33 +1983,8 @@ VkResult _glfwCreateWindowSurfaceCocoa(VkInstance instance,
|
|||||||
const VkAllocationCallbacks* allocator,
|
const VkAllocationCallbacks* allocator,
|
||||||
VkSurfaceKHR* surface)
|
VkSurfaceKHR* surface)
|
||||||
{
|
{
|
||||||
@autoreleasepool {
|
if (!createMetalLayer(window))
|
||||||
|
|
||||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101100
|
|
||||||
// HACK: Dynamically load Core Animation to avoid adding an extra
|
|
||||||
// dependency for the majority who don't use MoltenVK
|
|
||||||
NSBundle* bundle = [NSBundle bundleWithPath:@"/System/Library/Frameworks/QuartzCore.framework"];
|
|
||||||
if (!bundle)
|
|
||||||
{
|
|
||||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
||||||
"Cocoa: Failed to find QuartzCore.framework");
|
|
||||||
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: Create the layer here as makeBackingLayer should not return nil
|
|
||||||
window->ns.layer = [[bundle classNamed:@"CAMetalLayer"] layer];
|
|
||||||
if (!window->ns.layer)
|
|
||||||
{
|
|
||||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
||||||
"Cocoa: Failed to create layer for view");
|
|
||||||
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (window->ns.retina)
|
|
||||||
[window->ns.layer setContentsScale:[window->ns.object backingScaleFactor]];
|
|
||||||
|
|
||||||
[window->ns.view setLayer:window->ns.layer];
|
|
||||||
[window->ns.view setWantsLayer:YES];
|
|
||||||
|
|
||||||
VkResult err;
|
VkResult err;
|
||||||
|
|
||||||
@ -2020,11 +2037,6 @@ VkResult _glfwCreateWindowSurfaceCocoa(VkInstance instance,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
#else
|
|
||||||
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // autoreleasepool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2047,3 +2059,17 @@ GLFWAPI id glfwGetCocoaWindow(GLFWwindow* handle)
|
|||||||
return window->ns.object;
|
return window->ns.object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GLFWAPI id glfwGetMetalLayer(GLFWwindow* handle)
|
||||||
|
{
|
||||||
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
|
_GLFW_REQUIRE_INIT_OR_RETURN(nil);
|
||||||
|
|
||||||
|
if (!window->ns.layer)
|
||||||
|
{
|
||||||
|
if (!createMetalLayer(window))
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
return window->ns.layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user