glfw: add glfw.getRequiredInstanceExtensions

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2021-10-18 20:08:46 -07:00 committed by Stephen Gutekanst
parent 8f7d3ef5bb
commit 6cfc46077f

View file

@ -27,44 +27,43 @@ pub inline fn vulkanSupported() Error!bool {
return supported == c.GLFW_TRUE; return supported == c.GLFW_TRUE;
} }
// TODO(vulkan): /// Returns the Vulkan instance extensions required by GLFW.
// /// Returns the Vulkan instance extensions required by GLFW. ///
// /// /// This function returns an array of names of Vulkan instance extensions required by GLFW for
// /// This function returns an array of names of Vulkan instance extensions required by GLFW for /// creating Vulkan surfaces for GLFW windows. If successful, the list will always contain
// /// creating Vulkan surfaces for GLFW windows. If successful, the list will always contain /// `VK_KHR_surface`, so if you don't require any additional extensions you can pass this list
// /// `VK_KHR_surface`, so if you don't require any additional extensions you can pass this list /// directly to the `VkInstanceCreateInfo` struct.
// /// directly to the `VkInstanceCreateInfo` struct. ///
// /// /// If Vulkan is not available on the machine, this function returns null and generates a
// /// If Vulkan is not available on the machine, this function returns null and generates a /// glfw.Error.APIUnavailable error. Call glfw.vulkanSupported to check whether Vulkan is at least
// /// glfw.Error.APIUnavailable error. Call glfw.vulkanSupported to check whether Vulkan is at least /// minimally available.
// /// minimally available. ///
// /// /// If Vulkan is available but no set of extensions allowing window surface creation was found,
// /// If Vulkan is available but no set of extensions allowing window surface /// this function returns null. You may still use Vulkan for off-screen rendering and compute work.
// /// creation was found, this function returns null. You may still use Vulkan ///
// /// for off-screen rendering and compute work. /// Possible errors include glfw.Error.NotInitialized and glfw.Error.APIUnavailable.
// /// ///
// /// @param[out] count Where to store the number of extensions in the returned /// Additional extensions may be required by future versions of GLFW. You should check if any
// /// array. This is set to zero if an error occurred. /// extensions you wish to enable are already in the returned array, as it is an error to specify
// /// @return An array of ASCII encoded extension names, or null if an /// an extension more than once in the `VkInstanceCreateInfo` struct.
// /// error occurred. ///
// /// /// macos: This function currently supports either the `VK_MVK_macos_surface` extension from
// /// Possible errors include glfw.Error.NotInitialized and glfw.Error.APIUnavailable. /// MoltenVK or `VK_EXT_metal_surface` extension.
// /// ///
// /// Additional extensions may be required by future versions of GLFW. You should check if any /// @pointer_lifetime The returned array is allocated and freed by GLFW. You should not free it
// /// extensions you wish to enable are already in the returned array, as it is an error to specify /// yourself. It is guaranteed to be valid only until the library is terminated.
// /// an extension more than once in the `VkInstanceCreateInfo` struct. ///
// /// /// @thread_safety This function may be called from any thread.
// /// macos: This function currently supports either the `VK_MVK_macos_surface` extension from ///
// /// MoltenVK or `VK_EXT_metal_surface` extension. /// see also: vulkan_ext, glfwCreateWindowSurface
// /// pub inline fn getRequiredInstanceExtensions() Error![][*c]const u8 {
// /// @pointer_lifetime The returned array is allocated and freed by GLFW. You should not free it var count: u32 = 0;
// /// yourself. It is guaranteed to be valid only until the library is terminated. const extensions = c.glfwGetRequiredInstanceExtensions(&count);
// /// try getError();
// /// @thread_safety This function may be called from any thread. return extensions[0..count];
// /// }
// /// see also: vulkan_ext, glfwCreateWindowSurface
// GLFWAPI const char** glfwGetRequiredInstanceExtensions(uint32_t* count);
// TODO(vulkan):
/// Vulkan API function pointer type. /// Vulkan API function pointer type.
/// ///
/// Generic function pointer used for returning Vulkan API function pointers. /// Generic function pointer used for returning Vulkan API function pointers.
@ -192,11 +191,19 @@ test "vulkanSupported" {
_ = try glfw.vulkanSupported(); _ = try glfw.vulkanSupported();
} }
test "getRequiredInstanceExtensions" {
const glfw = @import("main.zig");
try glfw.init();
defer glfw.terminate();
_ = glfw.getRequiredInstanceExtensions() catch |err| std.debug.print("failed to get vulkan instance extensions, error={}\n", .{err});
}
test "getInstanceProcAddress" { test "getInstanceProcAddress" {
const glfw = @import("main.zig"); const glfw = @import("main.zig");
try glfw.init(); try glfw.init();
defer glfw.terminate(); defer glfw.terminate();
// syntax check only, we don't have a real vulkan instance. // syntax check only, we don't have a real vulkan instance.
_ = glfw.getInstanceProcAddress(null, "foobar") catch |err| std.debug.print("failed to get instance proc address, error={}\n", .{err}); _ = glfw.getInstanceProcAddress(null, "foobar") catch |err| std.debug.print("failed to get vulkan instance proc address, error={}\n", .{err});
} }