#pragma once #include #include #include #include #include #include "device.hpp" #include "swapchain.hpp" #include "window.hpp" namespace sophia { struct FrameData { vk::CommandBuffer commandBuffer; vk::UniqueSemaphore imageAvailable; vk::UniqueFence inFlight; }; class RenderContext { public: static constexpr u32 MAX_FRAMES_IN_FLIGHT = 2; RenderContext(const RenderContext&) = delete; RenderContext& operator=(const RenderContext&) = delete; RenderContext(Window& window, Device& device); ~RenderContext(); vk::CommandBuffer beginFrame(); void endFrame(); Image& getCurrentImage() const { return this->swapchain->getImage(static_cast(this->currentImageIndex)); } vk::Extent2D getExtent() const { return this->swapchain->getExtent(); } vk::Format getImageFormat() const { return this->swapchain->getImageFormat(); } u32 getImageCount() const { return static_cast(this->swapchain->imageCount()); } private: void recreateSwapchain(); void createFrames(); Window& window; Device& device; std::unique_ptr swapchain; std::array frames; std::vector renderFinishedSemaphores; std::vector imagesInFlight; u32 currentFrameIndex = 0; u32 currentImageIndex = 0; bool isFrameStarted = false; }; } // namespace sophia