hello-tool: use try_array where applicable
This commit is contained in:
parent
364659b8af
commit
8e882fcc5c
16
except.hpp
16
except.hpp
@ -49,7 +49,7 @@ namespace cruft::vk {
|
|||||||
VkResult
|
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 <
|
||||||
template <typename...> class ContainerT,
|
template <typename...> class ContainerT = std::vector,
|
||||||
typename FuncT,
|
typename FuncT,
|
||||||
typename ...Args
|
typename ...Args
|
||||||
>
|
>
|
||||||
@ -77,18 +77,22 @@ namespace cruft::vk {
|
|||||||
uint32_t expected = 0;
|
uint32_t expected = 0;
|
||||||
try_func (func, args..., &expected, nullptr);
|
try_func (func, args..., &expected, nullptr);
|
||||||
|
|
||||||
using ResultT = std::remove_pointer_t<
|
using ValueT = std::remove_pointer_t<
|
||||||
std::tuple_element_t<
|
std::tuple_element_t<
|
||||||
sizeof...(Args) + 1,
|
sizeof...(Args) + 1,
|
||||||
typename func_traits<FuncT>::argument_types
|
typename func_traits<FuncT>::argument_types
|
||||||
>
|
>
|
||||||
>;
|
>;
|
||||||
|
|
||||||
ContainerT<ResultT> values (expected);
|
ValueT values[expected];
|
||||||
uint32_t found = 0;
|
uint32_t found = 0;
|
||||||
try_func (func, args..., &found, std::data (values));
|
try_func (func, args..., &found, values + 0);
|
||||||
CHECK_EQ (expected, found);
|
CHECK_EQ (expected, found);
|
||||||
return values;
|
|
||||||
|
return ContainerT<ValueT> {
|
||||||
|
values + 0,
|
||||||
|
values + found
|
||||||
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -117,38 +117,14 @@ main (void)
|
|||||||
glfwCreateWindowSurface (instance.id (), window, nullptr, &surface)
|
glfwCreateWindowSurface (instance.id (), window, nullptr, &surface)
|
||||||
);
|
);
|
||||||
|
|
||||||
VkSurfaceCapabilitiesKHR surface_capabilities;
|
auto surface_capabilities = pdevice.surface_capabilities (surface);
|
||||||
std::vector<VkSurfaceFormatKHR> surface_formats;
|
std::vector<VkSurfaceFormatKHR> surface_formats = cruft::vk::error::try_array (
|
||||||
std::vector<VkPresentModeKHR> present_modes;
|
vkGetPhysicalDeviceSurfaceFormatsKHR, pdevice.id (), surface
|
||||||
|
|
||||||
cruft::vk::error::try_func (
|
|
||||||
&vkGetPhysicalDeviceSurfaceCapabilitiesKHR, pdevice.id (), surface, &surface_capabilities
|
|
||||||
);
|
);
|
||||||
{
|
std::vector<VkPresentModeKHR> present_modes = cruft::vk::error::try_array (
|
||||||
uint32_t format_count = 0;
|
vkGetPhysicalDeviceSurfacePresentModesKHR, pdevice.id (), surface
|
||||||
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 ();
|
auto queues = pdevice.queue_families ();
|
||||||
int graphics_queue_id = -1, present_queue_id = -1;
|
int graphics_queue_id = -1, present_queue_id = -1;
|
||||||
for (int i = 0; unsigned (i) != queues.size (); ++i) {
|
for (int i = 0; unsigned (i) != queues.size (); ++i) {
|
||||||
@ -255,9 +231,8 @@ main (void)
|
|||||||
cruft::vk::error::try_code (
|
cruft::vk::error::try_code (
|
||||||
vkGetSwapchainImagesKHR (ldevice.id (), swapchain, &swap_image_count, nullptr)
|
vkGetSwapchainImagesKHR (ldevice.id (), swapchain, &swap_image_count, nullptr)
|
||||||
);
|
);
|
||||||
std::vector<VkImage> swap_images (swap_image_count);
|
std::vector<VkImage> swap_images = cruft::vk::error::try_array (
|
||||||
cruft::vk::error::try_code (
|
vkGetSwapchainImagesKHR, ldevice.id (), swapchain
|
||||||
vkGetSwapchainImagesKHR (ldevice.id (), swapchain, &swap_image_count, swap_images.data ())
|
|
||||||
);
|
);
|
||||||
|
|
||||||
std::vector<VkImageView> swap_image_views (swap_image_count);
|
std::vector<VkImageView> swap_image_views (swap_image_count);
|
||||||
|
Loading…
Reference in New Issue
Block a user