Experimentation using Vulkan.
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.
 
 
 

98 lines
2.7 KiB

// Copyright 2022 Simon Boyé
#pragma once
#include <vk/Framebuffer.h>
#include <vk/Semaphore.h>
#include <vk/RenderPass.h>
#include <vk/Pipeline.h>
#include <vk/Buffer.h>
#include <vk/Swapchain.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 VulkanTutorial {
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:
VulkanTutorial();
VulkanTutorial(const VulkanTutorial&) = delete;
~VulkanTutorial();
VulkanTutorial& operator=(const VulkanTutorial&) = delete;
void initialize(SDL_Window* window);
void shutdown();
void set_camera(const Vector3& camera_position, const Vector3& camera_z, const Vector3& camera_y);
void draw_frame();
void invalidate_swapchain();
private:
void create_swapchain_objects(uint32_t image_count);
void destroy_swapchain_objects();
void create_render_pass();
void create_descriptor_set_layout();
void create_graphic_pipeline();
void create_framebuffers();
void create_command_pool();
void create_vertex_buffer();
void create_index_buffer();
void create_uniform_buffer();
void create_descriptor_pool();
void create_descriptor_sets();
void create_command_buffers();
private:
vk::Context m_context;
vk::Swapchain m_swapchain;
VkQueue m_graphic_queue = nullptr;
VkQueue m_presentation_queue = nullptr;
vk::RenderPass m_render_pass;
VkDescriptorSetLayout m_descriptor_set_layout = VK_NULL_HANDLE;
VkPipelineLayout m_pipeline_layout = VK_NULL_HANDLE;
vk::Pipeline m_pipeline;
std::vector<vk::Framebuffer> m_framebuffers;
VkCommandPool m_command_pool = VK_NULL_HANDLE;
vk::Buffer m_vertex_buffer;
vk::Buffer m_index_buffer;
std::vector<vk::Buffer> m_uniform_buffers;
std::vector<VkDeviceSize> m_uniform_buffer_offsets;
vk::MemoryBlock m_uniform_buffer_memory;
VkDescriptorPool m_descriptor_pool = VK_NULL_HANDLE;
std::vector<VkDescriptorSet> m_descriptor_sets;
std::vector<VkCommandBuffer> m_command_buffers;
std::vector<vk::Semaphore> m_render_done;
Vector3 m_camera_position = Vector3(0.0f, 0.0f, -3.0f);
Vector3 m_camera_z = Vector3(0.0f, 0.0f, 1.0f);
Vector3 m_camera_y = Vector3(0.0f, 1.0f, 0.0f);
TimePoint m_last_frame_time;
Duration m_time = Duration(0);
};