private static VkSurfaceKHR CreateNSWindowSurface(VkInstance instance, NSWindowSwapchainSource nsWindowSource) { CAMetalLayer metalLayer = CAMetalLayer.New(); NSWindow nswindow = new NSWindow(nsWindowSource.NSWindow); NSView contentView = nswindow.contentView; contentView.wantsLayer = true; contentView.layer = metalLayer.NativePtr; VkMacOSSurfaceCreateInfoMVK surfaceCI = VkMacOSSurfaceCreateInfoMVK.New(); surfaceCI.pView = contentView.NativePtr.ToPointer(); VkResult result = vkCreateMacOSSurfaceMVK(instance, ref surfaceCI, null, out VkSurfaceKHR surface); CheckResult(result); return(surface); }
private static unsafe VkSurfaceKHR CreateNSWindowSurface(VkGraphicsDevice gd, VkInstance instance, NSWindowSwapchainSource nsWindowSource, bool hasExtMetalSurface) { CAMetalLayer metalLayer = CAMetalLayer.New(); NSWindow nswindow = new NSWindow(nsWindowSource.NSWindow); NSView contentView = nswindow.contentView; contentView.wantsLayer = true; contentView.layer = metalLayer.NativePtr; if (hasExtMetalSurface) { VkMetalSurfaceCreateInfoEXT surfaceCI = new VkMetalSurfaceCreateInfoEXT(); surfaceCI.sType = VkMetalSurfaceCreateInfoEXT.VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT; surfaceCI.pLayer = metalLayer.NativePtr.ToPointer(); VkSurfaceKHR surface; VkResult result = gd.CreateMetalSurfaceEXT(instance, &surfaceCI, null, &surface); CheckResult(result); return(surface); } else { VkMacOSSurfaceCreateInfoMVK surfaceCI = VkMacOSSurfaceCreateInfoMVK.New(); surfaceCI.pView = contentView.NativePtr.ToPointer(); VkResult result = vkCreateMacOSSurfaceMVK(instance, ref surfaceCI, null, out VkSurfaceKHR surface); CheckResult(result); return(surface); } }