You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
140 lines
3.1 KiB
140 lines
3.1 KiB
// Copyright 2022 Simon Boyé
|
|
#pragma once
|
|
|
|
#include <Camera.h>
|
|
|
|
#include <vk/Swapchain.h>
|
|
#include <vk/DescriptorSet.h>
|
|
#include <vk/DescriptorPool.h>
|
|
#include <vk/PipelineLayout.h>
|
|
#include <vk/DescriptorSetLayout.h>
|
|
#include <vk/Image.h>
|
|
#include <vk/Buffer.h>
|
|
#include <vk/Pipeline.h>
|
|
#include <vk/Framebuffer.h>
|
|
#include <vk/RenderPass.h>
|
|
#include <vk/Semaphore.h>
|
|
#include <vk/CommandBuffer.h>
|
|
#include <vk/CommandPool.h>
|
|
#include <vk/Context.h>
|
|
|
|
#include <core/math.h>
|
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
#include <vulkan/vulkan.h>
|
|
|
|
#include <Eigen/Dense>
|
|
|
|
#include <vector>
|
|
#include <chrono>
|
|
|
|
|
|
VkVertexInputBindingDescription vertex_binding_description();
|
|
std::array<VkVertexInputAttributeDescription, 4> vertex_attributes_description();
|
|
|
|
|
|
class Renderer {
|
|
public:
|
|
enum QueueIndex {
|
|
GRAPHIC_QUEUE,
|
|
};
|
|
|
|
using Clock = std::chrono::high_resolution_clock;
|
|
using TimePoint = Clock::time_point;
|
|
using Duration = Clock::duration;
|
|
using SecondsD = std::chrono::duration<double>;
|
|
|
|
public:
|
|
Renderer();
|
|
Renderer(const Renderer&) = delete;
|
|
~Renderer();
|
|
|
|
Renderer& operator=(const Renderer&) = delete;
|
|
|
|
void initialize(SDL_Window* window);
|
|
|
|
void set_camera(const Camera& camera);
|
|
|
|
void draw_frame();
|
|
void invalidate_swapchain();
|
|
|
|
private:
|
|
struct SwapchainStates;
|
|
struct ImageStates;
|
|
|
|
private:
|
|
void create_swapchain_objects();
|
|
|
|
void create_command_pool();
|
|
|
|
void create_descriptor_set_layout();
|
|
void create_pipeline_layout();
|
|
void create_render_pass();
|
|
|
|
void create_vertex_buffer();
|
|
void create_index_buffer();
|
|
|
|
void initialize_swapchain_states();
|
|
|
|
void create_descriptor_pool();
|
|
void create_graphic_pipeline();
|
|
|
|
void initialize_image_states(size_t image_index);
|
|
|
|
void create_depth_buffer(ImageStates& image_states);
|
|
void create_framebuffer(ImageStates& image_states);
|
|
|
|
void create_uniform_buffer(ImageStates& image_states);
|
|
void create_descriptor_set(ImageStates& image_states);
|
|
|
|
void create_draw_buffer(ImageStates& image_states);
|
|
|
|
void create_command_buffer(ImageStates& image_states);
|
|
|
|
private:
|
|
static constexpr uint32_t DrawBufferOffset = 4;
|
|
static constexpr uint32_t MaxDrawTileCount = 256;
|
|
|
|
private:
|
|
vk::Context m_context;
|
|
|
|
vk::CommandPool m_command_pool;
|
|
|
|
vk::DescriptorSetLayout m_descriptor_set_layout;
|
|
vk::PipelineLayout m_pipeline_layout;
|
|
vk::RenderPass m_render_pass;
|
|
|
|
vk::Buffer m_vertex_buffer;
|
|
vk::Buffer m_index_buffer;
|
|
|
|
vk::MemoryBlock m_uniform_buffer_memory;
|
|
|
|
vk::Swapchain m_swapchain;
|
|
|
|
struct SwapchainStates {
|
|
vk::DescriptorPool m_descriptor_pool;
|
|
vk::Pipeline m_pipeline;
|
|
};
|
|
SwapchainStates m_swapchain_states;
|
|
|
|
struct ImageStates {
|
|
size_t m_image_index;
|
|
|
|
vk::Image m_depth_buffer;
|
|
vk::ImageView m_depth_buffer_view;
|
|
vk::Framebuffer m_framebuffer;
|
|
|
|
vk::Buffer m_uniform_buffer;
|
|
VkDeviceSize m_uniform_buffer_offset;
|
|
vk::DescriptorSet m_descriptor_set;
|
|
|
|
vk::Buffer m_draw_buffer;
|
|
|
|
vk::CommandBuffer m_command_buffer;
|
|
vk::Semaphore m_render_done;
|
|
};
|
|
std::vector<ImageStates> m_image_states;
|
|
|
|
Camera m_camera;
|
|
};
|
|
|