#ifndef SWAPCHAIN_H #define SWAPCHAIN_H #include #include #include #include #include #include class Swapchain { public: struct AcquireResult { VkResult result{VK_SUCCESS}; VkImage image{VK_NULL_HANDLE}; std::uint32_t imageIndex{0}; [[nodiscard]] bool hasImage() const { return image != VK_NULL_HANDLE && (result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR); } }; void initSync(VkDevice device); //Ye ye, passing a pointer is bad bla bla @Kobe void createSwapchain( VkDevice device, vkb::Device vkbDevice, VkSurfaceKHR surface, VkFormat format, std::uint32_t width, std::uint32_t height, bool vSync); [[nodiscard]] bool recreateSwapchain( VkDevice device, vkb::Device vkbDevice, VkSurfaceKHR surface, VkFormat format, std::uint32_t width, std::uint32_t height, bool vSync); void cleanup(VkDevice device); [[nodiscard]] VkExtent2D getExtent() const { return extent; } [[nodiscard]] const std::vector& getImages() const { return images; } [[nodiscard]] std::uint32_t getImageCount() const { return static_cast(images.size()); } void beginFrame(VkDevice device, int index) const; void resetFences(VkDevice device, int index) const; AcquireResult acquireNextImage(VkDevice device, std::uint32_t index); void submitAndPresent( VkDevice device, VkCommandBuffer cmd, VkQueue graphicsQueue, VkQueue presentQueue, std::uint32_t imageIndex, std::uint32_t frameIndex); [[nodiscard]] bool isDirty() const { return dirty; } [[nodiscard]] VkImageView getImageView(int index) const { return imageViews[index]; } [[nodiscard]] VkImageView getImageView(std::uint32_t imageIndex) const { return imageViews.at(imageIndex); } [[nodiscard]] VkSurfaceKHR getSurface() const { return surface; } [[nodiscard]] vkb::Swapchain getVkbSwapchain() const { return m_swapchain; } [[nodiscard]] VkFormat getFormat() const { return m_swapchain.image_format; } private: void nameSwapchainObjects(VkDevice device) const; struct FrameData { VkSemaphore swapchainSemaphore{VK_NULL_HANDLE}; VkFence renderFence{VK_NULL_HANDLE}; }; std::vector imageRenderSemaphores; std::array frames; vkb::Swapchain m_swapchain; std::vector images; std::vector imageViews; bool dirty{false}; VkSurfaceKHR surface{VK_NULL_HANDLE}; VkExtent2D extent{}; }; #endif