diff --git a/src/Swapchain.cpp b/src/Swapchain.cpp index e9de203..c920e49 100644 --- a/src/Swapchain.cpp +++ b/src/Swapchain.cpp @@ -6,6 +6,7 @@ Swapchain::Swapchain(Device* device) : device_(device) { (void)createSwapchain(); + (void)createImageViews(); } @@ -44,7 +45,7 @@ bool Swapchain::createSwapchain() { swapchainCreateInfo.oldSwapchain = nullptr; vkSwapchain_ = vk::raii::SwapchainKHR(*logicalDevice, swapchainCreateInfo); - swapchainImages_ = vkSwapchain_.getImages(); + images_ = vkSwapchain_.getImages(); if(vkSwapchain_ == nullptr) { std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] Error: could not create the Vulkan Swapchain!" << std::endl; @@ -118,3 +119,24 @@ uint32_t Swapchain::chooseMinImageCount(vk::SurfaceCapabilitiesKHR const& capabi return minImageCount; } } + +bool Swapchain::createImageViews() { + + if(!imageViews_.empty()) { + return false; + } + + vk::ImageViewCreateInfo imageViewCreateInfo { + .viewType = vk::ImageViewType::e2D, + .format = surfaceFormat_.format, + .components = { vk::ComponentSwizzle::eIdentity, vk::ComponentSwizzle::eIdentity, vk::ComponentSwizzle::eIdentity, vk::ComponentSwizzle::eIdentity }, // default rgba + .subresourceRange = { vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1}, // aspect mask, baseMipLevel, levelCount, baseArrayLayer, layerCount + }; + + for(vk::Image &image : images_) { + imageViewCreateInfo.image = image; + imageViews_.emplace_back(*(device_->logicalDevice()), imageViewCreateInfo); + } + + return true; +} diff --git a/src/Swapchain.hpp b/src/Swapchain.hpp index 3d3c145..565126a 100644 --- a/src/Swapchain.hpp +++ b/src/Swapchain.hpp @@ -16,7 +16,8 @@ class Swapchain { private: vk::raii::SwapchainKHR vkSwapchain_ = nullptr; - std::vector swapchainImages_; + std::vector images_; + std::vector imageViews_; Device* device_ = nullptr; vk::SurfaceFormatKHR surfaceFormat_; @@ -29,4 +30,6 @@ class Swapchain { uint32_t chooseMinImageCount(vk::SurfaceCapabilitiesKHR const& capabilities); bool createSwapchain(); + bool createImageViews(); + }; \ No newline at end of file