Orange/include/Orange/Render/Swapchain.h

68 lines
2.7 KiB
C
Raw Normal View History

2022-08-04 03:00:54 +01:00
#pragma once
#include <Orange/Core/Span.h>
#include <Orange/Core/Result.h>
2022-08-07 00:15:47 +01:00
#include <Orange/Core/Vector.h>
2022-08-04 03:00:54 +01:00
#include <Orange/Render/RenderContext.h>
2022-08-04 20:00:53 +01:00
#include <vulkan/vulkan_core.h>
2022-08-04 03:00:54 +01:00
namespace orange
{
2022-08-04 20:00:53 +01:00
static constexpr uint32_t MaxFramesInFlight = 4;
2022-08-04 03:00:54 +01:00
class Swapchain
{
public:
~Swapchain();
static Result<Swapchain> Create(RenderContext& context, VkSurfaceKHR surface, bool hdr = false, bool srgbViews = false);
2022-08-04 20:00:53 +01:00
2022-08-04 22:18:11 +01:00
VkImage Image() const { return m_images[m_currentImage]; }
VkImageView ImageView() const { return m_imageViews[m_currentImage]; }
VkCommandBuffer CommandBuffer() const { return m_commandBuffers[m_currentFrame]; }
2022-08-07 06:09:59 +01:00
VkFormat Format() const { return m_format; }
2022-08-04 22:18:11 +01:00
VkExtent2D Extent() const { return m_extent; }
2022-08-13 22:15:23 +01:00
uint32_t CurrentFrame() const { return m_currentFrame; }
2022-08-04 22:18:11 +01:00
void Present();
2022-08-04 03:00:54 +01:00
protected:
friend class Result<Swapchain>;
2022-08-04 20:00:53 +01:00
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 }
2022-08-04 18:23:08 +01:00
{}
2022-08-04 20:00:53 +01:00
2022-08-04 03:00:54 +01:00
private:
2022-08-04 20:00:53 +01:00
RenderContext& m_ctx;
2022-08-04 03:00:54 +01:00
VkSurfaceKHR m_surface;
2022-08-04 18:23:08 +01:00
VkFormat m_format;
2022-08-04 03:00:54 +01:00
VkExtent2D m_extent;
VkSwapchainKHR m_swapchain;
2022-08-07 00:15:47 +01:00
SmallVector<VkImage, 6> m_images;
SmallVector<VkImageView, 6> m_imageViews;
2022-08-04 20:00:53 +01:00
2022-08-07 00:15:47 +01:00
SmallVector<VkCommandBuffer, MaxFramesInFlight> m_commandBuffers;
SmallVector<VkSemaphore, MaxFramesInFlight> m_imageAvailableSemaphores;
SmallVector<VkSemaphore, MaxFramesInFlight> m_renderFinishedSemaphores;
SmallVector<VkFence, MaxFramesInFlight> m_inFlightFences;
2022-08-04 20:00:53 +01:00
uint32_t m_currentFrame = 0;
uint32_t m_currentImage = 0;
2022-08-04 03:00:54 +01:00
};
}