Skip to content

Commit

Permalink
Added pNext chain support for swapchain::get_image_views
Browse files Browse the repository at this point in the history
  • Loading branch information
nickclark2016 authored and charles-lunarg committed Mar 19, 2022
1 parent 65071da commit 4a2984a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/VkBootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1849,16 +1849,19 @@ detail::Result<std::vector<VkImage>> Swapchain::get_images() {
return swapchain_images;
}
detail::Result<std::vector<VkImageView>> Swapchain::get_image_views() {

auto swapchain_images_ret = get_images();
return get_image_views(nullptr);
}
detail::Result<std::vector<VkImageView>> Swapchain::get_image_views(const void* pNext) {
const auto swapchain_images_ret = get_images();
if (!swapchain_images_ret) return swapchain_images_ret.error();
auto swapchain_images = swapchain_images_ret.value();
const auto swapchain_images = swapchain_images_ret.value();

std::vector<VkImageView> views(swapchain_images.size());

for (size_t i = 0; i < swapchain_images.size(); i++) {
VkImageViewCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
createInfo.pNext = pNext;
createInfo.image = swapchain_images[i];
createInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
createInfo.format = image_format;
Expand Down
4 changes: 3 additions & 1 deletion src/VkBootstrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,10 @@ struct Swapchain {
detail::Result<std::vector<VkImage>> get_images();

// Returns a vector of VkImageView's to the VkImage's of the swapchain.
// VkImageViews must be destroyed.
// VkImageViews must be destroyed. The pNext chain must be a nullptr or a valid
// structure.
detail::Result<std::vector<VkImageView>> get_image_views();
detail::Result<std::vector<VkImageView>> get_image_views(const void* pNext);
void destroy_image_views(std::vector<VkImageView> const& image_views);

// A conversion function which allows this Swapchain to be used
Expand Down
17 changes: 17 additions & 0 deletions tests/bootstrap_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,23 @@ TEST_CASE("Swapchain", "[VkBootstrap.bootstrap]") {
REQUIRE(image_views.value().size() > 0);
swapchain.destroy_image_views(image_views.value());
}
AND_THEN("Acquire swapchain images views with nullptr pNext chain") {
auto image_views = swapchain.get_image_views(nullptr);
REQUIRE(image_views.has_value());
REQUIRE(image_views.value().size() > 0);
swapchain.destroy_image_views(image_views.value());
}
AND_THEN("Acquire swapchain image views with valid pNext chain") {
VkImageViewUsageCreateInfo usage = {
VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO,
nullptr,
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
};
auto image_views = swapchain.get_image_views(&usage);
REQUIRE(image_views.has_value());
REQUIRE(image_views.value().size() > 0);
swapchain.destroy_image_views(image_views.value());
}

vkb::destroy_swapchain(swapchain_ret.value());
}
Expand Down

0 comments on commit 4a2984a

Please sign in to comment.