Renamed Vulkan namespace as vk.
This commit is contained in:
109
src/vk/Swapchain.h
Normal file
109
src/vk/Swapchain.h
Normal file
@@ -0,0 +1,109 @@
|
||||
#pragma once
|
||||
|
||||
#include <vk/Context.h>
|
||||
#include <utils.h>
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
#include <optional>
|
||||
#include <initializer_list>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
|
||||
namespace vk {
|
||||
|
||||
|
||||
class Swapchain;
|
||||
|
||||
class SwapchainSettings {
|
||||
public:
|
||||
SwapchainSettings(Context* context);
|
||||
~SwapchainSettings();
|
||||
|
||||
Context* context() const;
|
||||
|
||||
std::vector<uint32_t> queue_families() const;
|
||||
SwapchainSettings& with_queue(uint32_t queue_family);
|
||||
|
||||
private:
|
||||
Context* m_context;
|
||||
std::vector<uint32_t> m_queue_families;
|
||||
};
|
||||
|
||||
class Swapchain {
|
||||
public:
|
||||
static constexpr uint32_t CURRENT_IMAGE_INDEX = UINT32_MAX;
|
||||
static constexpr uint32_t MAX_FRAMES_IN_FLIGHT = 2;
|
||||
|
||||
using CreationCallback = std::function<void(uint32_t)>;
|
||||
using DestructionCallback = std::function<void()>;
|
||||
|
||||
public:
|
||||
Swapchain();
|
||||
Swapchain(const Swapchain&) = delete;
|
||||
~Swapchain();
|
||||
|
||||
Swapchain& operator=(const Swapchain&) = delete;
|
||||
|
||||
VkSwapchainKHR swapchain();
|
||||
VkExtent2D extent() const;
|
||||
size_t image_count() const;
|
||||
uint32_t current_image_index() const;
|
||||
VkImage image();
|
||||
VkImage image(size_t image_index);
|
||||
VkImageView image_view();
|
||||
VkImageView image_view(size_t image_index);
|
||||
VkSemaphore ready_to_render();
|
||||
VkFence render_done();
|
||||
|
||||
void initialize(const SwapchainSettings& settings);
|
||||
void shutdown();
|
||||
|
||||
void begin_frame();
|
||||
void swap_buffers(Array<VkSemaphore> wait_semaphores);
|
||||
|
||||
void invalidate();
|
||||
|
||||
void register_creation_callback(CreationCallback callback);
|
||||
void register_destruction_callback(DestructionCallback callback);
|
||||
|
||||
private:
|
||||
struct ImageResources {
|
||||
VkImage image = VK_NULL_HANDLE;
|
||||
VkImageView view = VK_NULL_HANDLE;
|
||||
VkFence render_done = VK_NULL_HANDLE;
|
||||
};
|
||||
|
||||
struct FrameResources {
|
||||
VkSemaphore ready_to_render = VK_NULL_HANDLE;
|
||||
VkFence render_done = VK_NULL_HANDLE;
|
||||
};
|
||||
|
||||
private:
|
||||
void create(const SwapchainSettings& settings);
|
||||
void create();
|
||||
void destroy();
|
||||
void recreate();
|
||||
|
||||
private:
|
||||
Context* m_context = nullptr;
|
||||
|
||||
VkSwapchainKHR m_swapchain = VK_NULL_HANDLE;
|
||||
VkExtent2D m_extent;
|
||||
std::vector<uint32_t> m_queue_families;
|
||||
std::vector<ImageResources> m_image_resources;
|
||||
std::vector<FrameResources> m_frame_resources;
|
||||
bool m_invalid = false;
|
||||
|
||||
std::vector<CreationCallback> m_creation_callbacks;
|
||||
std::vector<DestructionCallback> m_destruction_callbacks;
|
||||
|
||||
uint32_t m_current_image_index = CURRENT_IMAGE_INDEX;
|
||||
size_t m_frame_index = 0;
|
||||
size_t m_frame_resources_index = 0;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user