-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.h
58 lines (49 loc) · 1.68 KB
/
renderer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once
#include <vulkan/vulkan.hpp>
#include <GLFW/glfw3.h>
#include <glm/ext/matrix_float4x4.hpp>
#include <glm/ext/vector_float4.hpp>
#include <glm/ext/vector_float3.hpp>
class Renderer {
public:
explicit Renderer(GLFWwindow* window);
~Renderer();
void begin(glm::vec4 clearColor);
void setColor(glm::vec3 color);
void drawQuad(const glm::mat4& transform);
void end();
private:
void createInstance(std::span<const char*> extensions);
void pickPhysicalDevice();
void createLogicalDevice();
void createSwapChain(GLFWwindow *window);
void createImageViews();
void createGraphicsPipeline();
void createCommandPool();
private:
static constexpr size_t MAX_FRAMES_IN_FLIGHT = 2;
static constexpr auto IMAGE_FORMAT = vk::Format::eB8G8R8A8Unorm;
static constexpr auto COLOR_SPACE = vk::ColorSpaceKHR::eSrgbNonlinear;
struct FrameData {
vk::UniqueSemaphore imageAcquired, renderFinished;
vk::UniqueFence fence;
};
vk::DynamicLoader m_dynamicLoader {};
vk::UniqueInstance m_instance;
vk::UniqueSurfaceKHR m_surface;
vk::PhysicalDevice m_physicalDevice;
vk::UniqueDevice m_device;
uint32_t m_queueFamily{};
vk::Queue m_queue;
vk::UniqueSwapchainKHR m_swapchain;
vk::Extent2D m_swapchainExtent;
std::vector<vk::Image> m_images;
std::vector<vk::UniqueImageView> m_imageViews;
vk::UniquePipelineLayout m_pipelineLayout;
vk::UniquePipeline m_pipeline;
vk::UniqueCommandPool m_commandPool;
std::vector<vk::UniqueCommandBuffer> m_commandBuffers;
std::array<FrameData, MAX_FRAMES_IN_FLIGHT> m_frames;
uint32_t m_currentFrame = 0;
uint32_t m_currentImage = 0;
};