From fa25ebf037993a452b306d2e9a897bd0b1772af3 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sat, 16 Oct 2021 17:34:16 -0700 Subject: [PATCH] glfw: add glfw.vulkanSupported Signed-off-by: Stephen Gutekanst --- glfw/src/vulkan.zig | 50 +++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/glfw/src/vulkan.zig b/glfw/src/vulkan.zig index b7a99e5..02a5f98 100644 --- a/glfw/src/vulkan.zig +++ b/glfw/src/vulkan.zig @@ -6,26 +6,28 @@ const getError = @import("errors.zig").getError; // TODO(vulkan): -// /// 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 -// /// found. -// /// -// /// The availability of a Vulkan loader and even an ICD does not by itself guarantee that surface -// /// creation or even instance creation is possible. For example, on Fermi systems Nvidia will -// /// install an ICD that provides no actual Vulkan support. Call glfw.getRequiredInstanceExtensions -// /// to check whether the extensions necessary for Vulkan surface creation are available and -// /// glfw.getPhysicalDevicePresentationSupport to check whether a queue family of a physical device -// /// supports image presentation. -// /// -// /// @return `GLFW_TRUE` if Vulkan is minimally available, or `GLFW_FALSE` otherwise. -// /// -// /// Possible errors include glfw.Error.NotInitialized. -// /// -// /// @thread_safety This function may be called from any thread. -// /// -// /// see also: vulkan_support -// GLFWAPI int glfwVulkanSupported(void); +/// 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 +/// found. +/// +/// The availability of a Vulkan loader and even an ICD does not by itself guarantee that surface +/// creation or even instance creation is possible. For example, on Fermi systems Nvidia will +/// install an ICD that provides no actual Vulkan support. Call glfw.getRequiredInstanceExtensions +/// to check whether the extensions necessary for Vulkan surface creation are available and +/// glfw.getPhysicalDevicePresentationSupport to check whether a queue family of a physical device +/// supports image presentation. +/// +/// @return `true` if Vulkan is minimally available, or `false` otherwise. +/// +/// Possible errors include glfw.Error.NotInitialized. +/// +/// @thread_safety This function may be called from any thread. +pub inline fn vulkanSupported() Error!bool { + const supported = c.glfwVulkanSupported(); + try getError(); + return supported == c.GLFW_TRUE; +} // /// Returns the Vulkan instance extensions required by GLFW. // /// @@ -181,6 +183,14 @@ pub inline fn getInstanceProcAddress(vk_instance: ?*opaque {}, proc_name: [*c]co // /// see also: vulkan_surface, glfw.getRequiredInstanceExtensions // GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface); +test "vulkanSupported" { + const glfw = @import("main.zig"); + try glfw.init(); + defer glfw.terminate(); + + _ = try glfw.vulkanSupported(); +} + test "getInstanceProcAddress" { const glfw = @import("main.zig"); try glfw.init();