2025-12-02 03:16:07 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2025-12-02 17:57:59 +02:00
|
|
|
#include <vector>
|
|
|
|
|
|
2025-12-02 03:16:07 +02:00
|
|
|
#include <SDL3/SDL_video.h>
|
|
|
|
|
#include <VkBootstrap.h>
|
2025-12-02 21:26:53 +02:00
|
|
|
#include <vk_mem_alloc.h>
|
2025-12-02 03:16:07 +02:00
|
|
|
#include <vulkan/vulkan_core.h>
|
|
|
|
|
|
2025-12-02 21:26:53 +02:00
|
|
|
#include "AllocatedImage.h"
|
|
|
|
|
#include "DeletionQueue.h"
|
|
|
|
|
#include "Logger.h"
|
2025-12-03 00:02:17 +02:00
|
|
|
#include "src/DescriptorAllocator.h"
|
2025-12-02 03:16:07 +02:00
|
|
|
|
|
|
|
|
namespace Lunar {
|
|
|
|
|
|
2025-12-02 17:57:59 +02:00
|
|
|
struct FrameData {
|
|
|
|
|
VkCommandPool command_pool;
|
|
|
|
|
VkCommandBuffer main_command_buffer;
|
|
|
|
|
VkSemaphore swapchain_semaphore;
|
|
|
|
|
VkFence render_fence;
|
2025-12-02 21:26:53 +02:00
|
|
|
|
|
|
|
|
DeletionQueue deletion_queue;
|
2025-12-02 17:57:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
constexpr unsigned FRAME_OVERLAP = 2;
|
|
|
|
|
|
2025-12-02 03:16:07 +02:00
|
|
|
struct Application {
|
|
|
|
|
Application();
|
|
|
|
|
~Application();
|
|
|
|
|
|
|
|
|
|
auto run() -> void;
|
|
|
|
|
|
|
|
|
|
private:
|
2025-12-02 17:57:59 +02:00
|
|
|
auto vk_init() -> void;
|
|
|
|
|
auto swapchain_init() -> void;
|
|
|
|
|
auto commands_init() -> void;
|
|
|
|
|
auto sync_init() -> void;
|
2025-12-03 00:02:17 +02:00
|
|
|
auto descriptors_init() -> void;
|
|
|
|
|
auto pipelines_init() -> void;
|
|
|
|
|
auto background_pipelines_init() -> void;
|
2025-12-02 17:57:59 +02:00
|
|
|
|
2025-12-02 21:26:53 +02:00
|
|
|
auto draw_background(VkCommandBuffer cmd) -> void;
|
2025-12-02 17:57:59 +02:00
|
|
|
auto render() -> void;
|
|
|
|
|
|
|
|
|
|
auto create_swapchain(uint32_t width, uint32_t height) -> void;
|
2025-12-02 21:26:53 +02:00
|
|
|
auto create_draw_image(uint32_t width, uint32_t height) -> void;
|
2025-12-03 00:02:17 +02:00
|
|
|
auto update_draw_image_descriptor() -> void;
|
2025-12-02 21:26:53 +02:00
|
|
|
auto destroy_draw_image() -> void;
|
|
|
|
|
auto recreate_swapchain(uint32_t width, uint32_t height) -> void;
|
2025-12-02 17:57:59 +02:00
|
|
|
auto destroy_swapchain() -> void;
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
vkb::Instance instance;
|
|
|
|
|
vkb::PhysicalDevice phys_dev;
|
|
|
|
|
vkb::Device dev;
|
|
|
|
|
vkb::Swapchain swapchain;
|
|
|
|
|
} m_vkb;
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
VkSwapchainKHR swapchain { VK_NULL_HANDLE };
|
|
|
|
|
VkSurfaceKHR surface { nullptr };
|
2025-12-03 00:02:17 +02:00
|
|
|
VkFormat swapchain_image_format;
|
2025-12-02 17:57:59 +02:00
|
|
|
|
|
|
|
|
uint32_t graphics_queue_family { 0 };
|
2025-12-03 00:02:17 +02:00
|
|
|
VkQueue graphics_queue { nullptr };
|
2025-12-02 17:57:59 +02:00
|
|
|
|
|
|
|
|
std::vector<VkImage> swapchain_images;
|
|
|
|
|
std::vector<VkImageView> swapchain_image_views;
|
|
|
|
|
std::vector<VkSemaphore> present_semaphores;
|
|
|
|
|
VkExtent2D swapchain_extent;
|
|
|
|
|
|
|
|
|
|
std::array<FrameData, FRAME_OVERLAP> frames;
|
|
|
|
|
auto get_current_frame() -> FrameData &
|
|
|
|
|
{
|
|
|
|
|
return frames.at(frame_number % frames.size());
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-02 21:26:53 +02:00
|
|
|
AllocatedImage draw_image {};
|
|
|
|
|
VkExtent2D draw_extent {};
|
|
|
|
|
|
|
|
|
|
VmaAllocator allocator;
|
2025-12-03 00:02:17 +02:00
|
|
|
DescriptorAllocator descriptor_allocator;
|
|
|
|
|
|
|
|
|
|
VkDescriptorSet draw_image_descriptors;
|
|
|
|
|
VkDescriptorSetLayout draw_image_descriptor_layout;
|
|
|
|
|
|
|
|
|
|
VkPipeline gradient_pipeline {};
|
|
|
|
|
VkPipelineLayout gradient_pipeline_layout {};
|
2025-12-02 21:26:53 +02:00
|
|
|
|
|
|
|
|
DeletionQueue deletion_queue;
|
|
|
|
|
|
2025-12-02 17:57:59 +02:00
|
|
|
uint64_t frame_number { 0 };
|
|
|
|
|
} m_vk;
|
|
|
|
|
|
2025-12-02 03:16:07 +02:00
|
|
|
SDL_Window *m_window { nullptr };
|
|
|
|
|
Logger m_logger { "Lunar" };
|
|
|
|
|
|
|
|
|
|
bool m_running { true };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Lunar
|