hello-tool: use try_array where applicable

This commit is contained in:
Danny Robson 2017-09-06 15:21:44 +10:00
parent 364659b8af
commit 8e882fcc5c
2 changed files with 18 additions and 39 deletions

View File

@ -49,7 +49,7 @@ namespace cruft::vk {
VkResult
>);
try_code (std::invoke (func, std::forward<Args> (args)...));
try_code (func (std::forward<Args> (args)...));
}
@ -67,7 +67,7 @@ namespace cruft::vk {
template <
template <typename...> class ContainerT,
template <typename...> 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<FuncT>::argument_types
>
>;
ContainerT<ResultT> 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<ValueT> {
values + 0,
values + found
};
}
};

View File

@ -117,38 +117,14 @@ main (void)
glfwCreateWindowSurface (instance.id (), window, nullptr, &surface)
);
VkSurfaceCapabilitiesKHR surface_capabilities;
std::vector<VkSurfaceFormatKHR> surface_formats;
std::vector<VkPresentModeKHR> present_modes;
cruft::vk::error::try_func (
&vkGetPhysicalDeviceSurfaceCapabilitiesKHR, pdevice.id (), surface, &surface_capabilities
auto surface_capabilities = pdevice.surface_capabilities (surface);
std::vector<VkSurfaceFormatKHR> surface_formats = cruft::vk::error::try_array (
vkGetPhysicalDeviceSurfaceFormatsKHR, pdevice.id (), surface
);
{
uint32_t format_count = 0;
cruft::vk::error::try_code (
vkGetPhysicalDeviceSurfaceFormatsKHR (pdevice.id (), surface, &format_count, nullptr)
std::vector<VkPresentModeKHR> present_modes = cruft::vk::error::try_array (
vkGetPhysicalDeviceSurfacePresentModesKHR, pdevice.id (), surface
);
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;
for (int i = 0; unsigned (i) != queues.size (); ++i) {
@ -255,9 +231,8 @@ main (void)
cruft::vk::error::try_code (
vkGetSwapchainImagesKHR (ldevice.id (), swapchain, &swap_image_count, nullptr)
);
std::vector<VkImage> swap_images (swap_image_count);
cruft::vk::error::try_code (
vkGetSwapchainImagesKHR (ldevice.id (), swapchain, &swap_image_count, swap_images.data ())
std::vector<VkImage> swap_images = cruft::vk::error::try_array (
vkGetSwapchainImagesKHR, ldevice.id (), swapchain
);
std::vector<VkImageView> swap_image_views (swap_image_count);