#pragma once #include #include #include #include #include "vulkan/device.hpp" #include "vulkan/image.hpp" namespace sophia { class Swapchain { public: Swapchain(const Swapchain&) = delete; Swapchain& operator=(const Swapchain&) = delete; Swapchain(Device& device, vk::Extent2D extent); Swapchain(Device& device, vk::Extent2D extent, std::shared_ptr previous); ~Swapchain(); Image& getImage(int index) const { return *this->images.at(index); } Image& getDepthImage(int index) const { return *this->depthImages.at(index); } vk::ImageView getDepthImageView(int index) const { return this->depthImages.at(index)->getView(); } size_t imageCount() { return this->images.size(); } vk::Format getImageFormat() { return this->imageFormat; } vk::Extent2D getExtent() { return this->extent; } u32 width() { return this->extent.width; } u32 height() { return this->extent.height; } float extentAspectRatio() { return static_cast(this->extent.width) / static_cast(this->extent.height); } vk::Result acquireNextImage(vk::Semaphore signalSemaphore, u32& imageIndex); vk::Result present(vk::Queue presentQueue, u32 imageIndex, vk::Semaphore waitSemaphore); bool compareSwapchainFormats(const Swapchain& swapchain) const { return swapchain.depthFormat == this->depthFormat && swapchain.imageFormat == this->imageFormat; } private: void initialize(); void setDefaultCreateInfo(); void createSwapchain(); void createImages(); void createDepthImages(); vk::SurfaceFormatKHR chooseSurfaceFormat( const std::vector& availableFormats); vk::PresentModeKHR choosePresentMode( const std::vector availablePresentModes); vk::Extent2D chooseExtent(const vk::SurfaceCapabilitiesKHR& capabilities); vk::Format findDepthFormat(); Device& device; vk::Extent2D extent; vk::SwapchainKHR swapchain; vk::SwapchainCreateInfoKHR swapchainCreateInfo; std::shared_ptr oldSwapchain; vk::Format imageFormat; std::vector> images; vk::Format depthFormat; std::vector> depthImages; }; } // namespace sophia