From 2db01e1a327729ccff972b0020cbd6022bfb8ec3 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sat, 11 Jun 2022 15:45:30 -0700 Subject: [PATCH] glfw: update native APIs to glfw@master Signed-off-by: Stephen Gutekanst --- glfw/src/native.zig | 3 +++ glfw/src/opengl.zig | 2 +- glfw/src/vulkan.zig | 42 +++++++++++++++++++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/glfw/src/native.zig b/glfw/src/native.zig index 452ebcf8..cc9bdc3f 100644 --- a/glfw/src/native.zig +++ b/glfw/src/native.zig @@ -385,6 +385,9 @@ pub fn Native(comptime options: BackendOptions) type { /// /// Possible errors include glfw.Error.NotInitalized. /// + /// remark: Because EGL is initialized on demand, this function will return `EGL_NO_DISPLAY` + /// until the first context has been created via EGL. + /// /// thread_safety: This function may be called from any thread. Access is not synchronized. pub fn getEGLDisplay() *anyopaque { internal_debug.assertInitialized(); diff --git a/glfw/src/opengl.zig b/glfw/src/opengl.zig index 12127335..125aaf70 100644 --- a/glfw/src/opengl.zig +++ b/glfw/src/opengl.zig @@ -86,7 +86,7 @@ pub inline fn getCurrentContext() ?Window { /// Possible errors include glfw.Error.NotInitialized, glfw.Error.NoCurrentContext and glfw.Error.PlatformError. /// /// This function is not called during context creation, leaving the swap interval set to whatever -/// is the default on that platform. This is done because some swap interval extensions used by +/// is the default for that API. This is done because some swap interval extensions used by /// GLFW do not allow the swap interval to be reset to zero once it has been set to a non-zero /// value. /// diff --git a/glfw/src/vulkan.zig b/glfw/src/vulkan.zig index 4dd95a99..fe5bb908 100644 --- a/glfw/src/vulkan.zig +++ b/glfw/src/vulkan.zig @@ -7,6 +7,35 @@ const Window = @import("Window.zig"); const internal_debug = @import("internal_debug.zig"); +/// Sets the desired Vulkan `vkGetInstanceProcAddr` function. +/// +/// This function sets the `vkGetInstanceProcAddr` function that GLFW will use for all +/// Vulkan related entry point queries. +/// +/// This feature is mostly useful on macOS, if your copy of the Vulkan loader is in +/// a location where GLFW cannot find it through dynamic loading, or if you are still +/// using the static library version of the loader. +/// +/// If set to `NULL`, GLFW will try to load the Vulkan loader dynamically by its standard +/// name and get this function from there. This is the default behavior. +/// +/// The standard name of the loader is `vulkan-1.dll` on Windows, `libvulkan.so.1` on +/// Linux and other Unix-like systems and `libvulkan.1.dylib` on macOS. If your code is +/// also loading it via these names then you probably don't need to use this function. +/// +/// The function address you set is never reset by GLFW, but it only takes effect during +/// initialization. Once GLFW has been initialized, any updates will be ignored until the +/// library is terminated and initialized again. +/// +/// remark: This function may be called before glfw.Init. +/// +/// thread_safety: This function must only be called from the main thread. +pub fn initVulkanLoader(loader_function: ?VKGetInstanceProcAddr) void { + c.glfwInitVulkanLoader(loader_function orelse null); +} + +pub const VKGetInstanceProcAddr = fn (vk_instance: c.VkInstance, name: [*c]const u8) callconv(.C) ?VKProc; + /// Returns whether the Vulkan loader and an ICD have been found. /// /// This function returns whether the Vulkan loader and any minimally functional ICD have been @@ -50,9 +79,6 @@ pub inline fn vulkanSupported() bool { /// extensions you wish to enable are already in the returned array, as it is an error to specify /// an extension more than once in the `VkInstanceCreateInfo` struct. /// -/// macos: GLFW currently supports both the `VK_MVK_macos_surface` and the newer -/// `VK_EXT_metal_surface` extensions. -/// /// @pointer_lifetime The returned array is allocated and freed by GLFW. You should not free it /// yourself. It is guaranteed to be valid only until the library is terminated. /// @@ -197,11 +223,20 @@ pub inline fn getPhysicalDevicePresentationSupport( /// appropriate for the error. Appropriate use of glfw.vulkanSupported and glfw.getRequiredInstanceExtensions /// should eliminate almost all occurrences of these errors. /// +/// macos: GLFW prefers the `VK_EXT_metal_surface` extension, with the `VK_MVK_macos_surface` +/// extension as a fallback. The name of the selected extension, if any, is included in the array +/// returned by glfw.getRequiredInstanceExtensions. +/// /// macos: This function currently only supports the `VK_MVK_macos_surface` extension from MoltenVK. /// /// macos: This function creates and sets a `CAMetalLayer` instance for the window content view, /// which is required for MoltenVK to function. /// +/// x11: By default GLFW prefers the `VK_KHR_xcb_surface` extension, with the `VK_KHR_xlib_surface` +/// extension as a fallback. You can make `VK_KHR_xlib_surface` the preferred extension by setting +/// glfw.InitHints.x11_xcb_vulkan_surface. The name of the selected extension, if any, is included +/// in the array returned by glfw.getRequiredInstanceExtensions. +/// /// @thread_safety This function may be called from any thread. For synchronization details of /// Vulkan objects, see the Vulkan specification. /// @@ -262,4 +297,5 @@ test "syntax" { // context. _ = getPhysicalDevicePresentationSupport; _ = createWindowSurface; + _ = initVulkanLoader; }