65 lines
2.6 KiB
C++
65 lines
2.6 KiB
C++
#pragma once
|
|
|
|
#include <Orange/Core/Span.h>
|
|
#include <Orange/Core/Result.h>
|
|
#include <Orange/Core/Vector.h>
|
|
|
|
#include <Orange/Render/RenderContext.h>
|
|
#include <vulkan/vulkan_core.h>
|
|
|
|
namespace orange
|
|
{
|
|
static constexpr uint32_t MaxFramesInFlight = 4;
|
|
|
|
class Swapchain
|
|
{
|
|
public:
|
|
~Swapchain();
|
|
|
|
static Result<Swapchain> Create(RenderContext& context, VkSurfaceKHR surface);
|
|
|
|
VkImage Image() const { return m_images[m_currentImage]; }
|
|
VkImageView ImageView() const { return m_imageViews[m_currentImage]; }
|
|
VkCommandBuffer CommandBuffer() const { return m_commandBuffers[m_currentFrame]; }
|
|
VkExtent2D Extent() const { return m_extent; }
|
|
|
|
void Present();
|
|
protected:
|
|
friend class Result<Swapchain>;
|
|
Swapchain(RenderContext& context, VkSurfaceKHR surface, VkFormat format, VkExtent2D extent, VkSwapchainKHR swapchain,
|
|
Span<VkImage> images, Span<VkImageView> imageViews, Span<VkCommandBuffer> commandBuffers,
|
|
Span<VkSemaphore> imageAvailableSemaphores, Span<VkSemaphore> renderFinishedSemaphores, Span<VkFence> 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<VkImage, 6> m_images;
|
|
SmallVector<VkImageView, 6> m_imageViews;
|
|
|
|
SmallVector<VkCommandBuffer, MaxFramesInFlight> m_commandBuffers;
|
|
SmallVector<VkSemaphore, MaxFramesInFlight> m_imageAvailableSemaphores;
|
|
SmallVector<VkSemaphore, MaxFramesInFlight> m_renderFinishedSemaphores;
|
|
SmallVector<VkFence, MaxFramesInFlight> m_inFlightFences;
|
|
|
|
uint32_t m_currentFrame = 0;
|
|
uint32_t m_currentImage = 0;
|
|
};
|
|
} |