84 lines
2.3 KiB
C++
84 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include <memory>
|
|
#include <sophia/types.hpp>
|
|
#include <vector>
|
|
#include <vulkan/vulkan.hpp>
|
|
|
|
#include "device.hpp"
|
|
#include "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<Swapchain> previous);
|
|
~Swapchain();
|
|
|
|
Image& getImage(int index) const { return *this->images.at(index); }
|
|
Image& getDepthImage(int index) const { return *this->depthImages.at(index); }
|
|
|
|
vk::ImageView getImageView(int index) const {
|
|
return this->images.at(index)->getView();
|
|
}
|
|
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<float>(this->extent.width) /
|
|
static_cast<float>(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<vk::SurfaceFormatKHR>& availableFormats);
|
|
vk::PresentModeKHR choosePresentMode(
|
|
const std::vector<vk::PresentModeKHR> 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<Swapchain> oldSwapchain;
|
|
|
|
vk::Format imageFormat;
|
|
std::vector<std::unique_ptr<Image>> images;
|
|
|
|
vk::Format depthFormat;
|
|
std::vector<std::unique_ptr<Image>> depthImages;
|
|
};
|
|
|
|
} // namespace sophia
|