2022-06-15 00:09:51 +00:00
|
|
|
#pragma once
|
|
|
|
|
2024-04-13 16:06:14 +00:00
|
|
|
#include "vulkan/vulkan_hpp_wrapper.hpp"
|
2023-04-14 20:37:38 +00:00
|
|
|
#include <functional>
|
2022-06-15 00:09:51 +00:00
|
|
|
|
|
|
|
namespace Vulkan
|
|
|
|
{
|
|
|
|
|
|
|
|
class Swapchain
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Swapchain(vk::Device device,
|
|
|
|
vk::PhysicalDevice physical_device,
|
|
|
|
vk::Queue queue,
|
|
|
|
vk::SurfaceKHR surface,
|
|
|
|
vk::CommandPool command_pool);
|
|
|
|
~Swapchain();
|
2023-01-24 23:33:46 +00:00
|
|
|
bool create(unsigned int num_frames, int width = -1, int height = -1);
|
|
|
|
bool recreate(int width = -1, int height = -1);
|
2024-06-12 21:51:12 +00:00
|
|
|
bool create_resources();
|
2023-07-16 00:14:44 +00:00
|
|
|
bool check_and_resize(int width = -1, int height = -1);
|
2022-06-15 00:09:51 +00:00
|
|
|
bool begin_frame();
|
|
|
|
void begin_render_pass();
|
|
|
|
void end_render_pass();
|
|
|
|
bool wait_on_frame(int frame_num);
|
2023-01-25 20:03:21 +00:00
|
|
|
bool end_frame();
|
2023-02-23 21:24:01 +00:00
|
|
|
void end_frame_without_swap();
|
|
|
|
bool swap();
|
2024-06-12 21:51:12 +00:00
|
|
|
void wait_on_frames();
|
2022-06-15 00:09:51 +00:00
|
|
|
// Returns true if vsync setting was changed, false if it was the same
|
|
|
|
bool set_vsync(bool on);
|
2023-04-14 20:37:38 +00:00
|
|
|
void on_render_pass_end(std::function<void()> function);
|
2023-07-03 22:19:54 +00:00
|
|
|
int get_num_frames() { return num_swapchain_images; }
|
2024-06-13 16:37:00 +00:00
|
|
|
vk::PresentModeKHR get_present_mode();
|
2022-06-15 00:09:51 +00:00
|
|
|
|
|
|
|
vk::Image get_image();
|
|
|
|
vk::Framebuffer get_framebuffer();
|
|
|
|
vk::CommandBuffer &get_cmd();
|
|
|
|
vk::Extent2D get_extents();
|
|
|
|
vk::RenderPass &get_render_pass();
|
|
|
|
|
|
|
|
private:
|
2023-04-14 20:37:38 +00:00
|
|
|
std::function<void()> end_render_pass_function;
|
2022-06-15 00:09:51 +00:00
|
|
|
void create_render_pass();
|
|
|
|
|
|
|
|
struct Frame
|
|
|
|
{
|
|
|
|
vk::UniqueFence fence;
|
|
|
|
vk::UniqueSemaphore acquire;
|
|
|
|
vk::UniqueSemaphore complete;
|
|
|
|
vk::UniqueCommandBuffer command_buffer;
|
|
|
|
};
|
|
|
|
|
2024-06-13 16:16:36 +00:00
|
|
|
struct ImageData
|
2022-06-15 00:09:51 +00:00
|
|
|
{
|
|
|
|
vk::Image image;
|
2024-06-13 16:16:36 +00:00
|
|
|
vk::UniqueFence fence;
|
2022-06-15 00:09:51 +00:00
|
|
|
vk::UniqueImageView image_view;
|
|
|
|
vk::UniqueFramebuffer framebuffer;
|
|
|
|
};
|
|
|
|
|
2023-01-24 23:33:46 +00:00
|
|
|
vk::UniqueSwapchainKHR swapchain_object;
|
2022-06-15 00:09:51 +00:00
|
|
|
vk::Extent2D extents;
|
|
|
|
|
|
|
|
vk::UniqueRenderPass render_pass;
|
|
|
|
|
|
|
|
unsigned int current_frame = 0;
|
|
|
|
unsigned int current_swapchain_image = 0;
|
2023-01-25 20:03:21 +00:00
|
|
|
unsigned int num_swapchain_images = 0;
|
2022-06-15 00:09:51 +00:00
|
|
|
bool vsync = true;
|
2024-06-12 21:51:12 +00:00
|
|
|
bool supports_immediate = false;
|
|
|
|
bool supports_mailbox = false;
|
2024-06-13 16:37:00 +00:00
|
|
|
bool supports_relaxed = false;
|
2022-06-15 00:09:51 +00:00
|
|
|
std::vector<Frame> frames;
|
2024-06-13 16:16:36 +00:00
|
|
|
std::vector<ImageData> image_data;
|
2022-06-15 00:09:51 +00:00
|
|
|
|
|
|
|
vk::Device device;
|
|
|
|
vk::SurfaceKHR surface;
|
|
|
|
vk::CommandPool command_pool;
|
|
|
|
vk::PhysicalDevice physical_device;
|
|
|
|
vk::Queue queue;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Vulkan
|