#pragma once #include #include #include #include #include namespace orange { static constexpr uint32_t MaxFramesInFlight = 4; class Swapchain { public: ~Swapchain(); static Result Create(RenderContext& context, VkSurfaceKHR surface, bool hdr = false, bool srgbViews = false); VkImage Image() const { return m_images[m_currentImage]; } VkImageView ImageView() const { return m_imageViews[m_currentImage]; } VkCommandBuffer CommandBuffer() const { return m_commandBuffers[m_currentFrame]; } VkFormat Format() const { return m_format; } VkExtent2D Extent() const { return m_extent; } uint32_t CurrentFrame() const { return m_currentFrame; } void Present(); protected: friend class Result; Swapchain(RenderContext& context, VkSurfaceKHR surface, VkFormat format, VkExtent2D extent, VkSwapchainKHR swapchain, Span images, Span imageViews, Span commandBuffers, Span imageAvailableSemaphores, Span renderFinishedSemaphores, Span inFlightFences, uint32_t currentImage) : m_ctx { context } , m_surface { surface } , m_format { format } , m_extent { extent } , m_swapchain { swapchain } , m_images { images } , m_imageViews { imageViews } , m_commandBuffers { commandBuffers } , m_imageAvailableSemaphores { imageAvailableSemaphores } , m_renderFinishedSemaphores { renderFinishedSemaphores } , m_inFlightFences { inFlightFences } , m_currentImage { currentImage } {} private: RenderContext& m_ctx; VkSurfaceKHR m_surface; VkFormat m_format; VkExtent2D m_extent; VkSwapchainKHR m_swapchain; SmallVector m_images; SmallVector m_imageViews; SmallVector m_commandBuffers; SmallVector m_imageAvailableSemaphores; SmallVector m_renderFinishedSemaphores; SmallVector m_inFlightFences; uint32_t m_currentFrame = 0; uint32_t m_currentImage = 0; }; }