diff --git a/except.hpp b/except.hpp index d6b305e..f8c4c48 100644 --- a/except.hpp +++ b/except.hpp @@ -49,7 +49,7 @@ namespace cruft::vk { VkResult >); - try_code (std::invoke (func, std::forward (args)...)); + try_code (func (std::forward (args)...)); } @@ -67,7 +67,7 @@ namespace cruft::vk { template < - template class ContainerT, + template class ContainerT = std::vector, typename FuncT, typename ...Args > @@ -77,18 +77,22 @@ namespace cruft::vk { uint32_t expected = 0; try_func (func, args..., &expected, nullptr); - using ResultT = std::remove_pointer_t< + using ValueT = std::remove_pointer_t< std::tuple_element_t< sizeof...(Args) + 1, typename func_traits::argument_types > >; - ContainerT values (expected); + ValueT values[expected]; uint32_t found = 0; - try_func (func, args..., &found, std::data (values)); + try_func (func, args..., &found, values + 0); CHECK_EQ (expected, found); - return values; + + return ContainerT { + values + 0, + values + found + }; } }; diff --git a/tools/hello.cpp b/tools/hello.cpp index 70f4166..80936f6 100644 --- a/tools/hello.cpp +++ b/tools/hello.cpp @@ -117,37 +117,13 @@ main (void) glfwCreateWindowSurface (instance.id (), window, nullptr, &surface) ); - VkSurfaceCapabilitiesKHR surface_capabilities; - std::vector surface_formats; - std::vector present_modes; - - cruft::vk::error::try_func ( - &vkGetPhysicalDeviceSurfaceCapabilitiesKHR, pdevice.id (), surface, &surface_capabilities + auto surface_capabilities = pdevice.surface_capabilities (surface); + std::vector surface_formats = cruft::vk::error::try_array ( + vkGetPhysicalDeviceSurfaceFormatsKHR, pdevice.id (), surface + ); + std::vector present_modes = cruft::vk::error::try_array ( + vkGetPhysicalDeviceSurfacePresentModesKHR, pdevice.id (), surface ); - { - uint32_t format_count = 0; - cruft::vk::error::try_code ( - vkGetPhysicalDeviceSurfaceFormatsKHR (pdevice.id (), surface, &format_count, nullptr) - ); - - surface_formats.resize (format_count); - cruft::vk::error::try_code ( - vkGetPhysicalDeviceSurfaceFormatsKHR ( - pdevice.id (), surface, &format_count, surface_formats.data () - ) - ); - - - uint32_t present_count = 0; - cruft::vk::error::try_code ( - vkGetPhysicalDeviceSurfacePresentModesKHR (pdevice.id (), surface, &present_count, nullptr) - ); - - present_modes.resize (present_count); - cruft::vk::error::try_code ( - vkGetPhysicalDeviceSurfacePresentModesKHR (pdevice.id (), surface, &present_count, nullptr) - ); - } auto queues = pdevice.queue_families (); int graphics_queue_id = -1, present_queue_id = -1; @@ -255,9 +231,8 @@ main (void) cruft::vk::error::try_code ( vkGetSwapchainImagesKHR (ldevice.id (), swapchain, &swap_image_count, nullptr) ); - std::vector swap_images (swap_image_count); - cruft::vk::error::try_code ( - vkGetSwapchainImagesKHR (ldevice.id (), swapchain, &swap_image_count, swap_images.data ()) + std::vector swap_images = cruft::vk::error::try_array ( + vkGetSwapchainImagesKHR, ldevice.id (), swapchain ); std::vector swap_image_views (swap_image_count);