-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvg.hpp
115 lines (82 loc) · 2.13 KB
/
vg.hpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#ifndef VG_HPP
#define VG_HPP
#include <cstdint>
#include <functional>
#include <string>
#include <vector>
#define VULKAN_HPP_NO_STRUCT_CONSTRUCTORS
#include <vulkan/vulkan.hpp>
#include <GLFW/glfw3.h>
namespace vg {
class Window {
public:
Window(const std::string& title, int width, int height);
void run_continuous(std::function<void()> f);
void destroy();
operator GLFWwindow*() const {
return m_window;
}
private:
GLFWwindow* m_window;
};
struct SurfaceDetails {
std::vector<vk::SurfaceFormatKHR> formats;
std::vector<vk::PresentModeKHR> present_modes;
vk::SurfaceCapabilitiesKHR caps;
};
struct RenderGroup {
vk::PhysicalDevice dev;
std::uint32_t qfam_idx;
SurfaceDetails surf_details;
};
class Renderer {
public:
Renderer(Window window);
void destroy();
void draw();
private:
Window window;
size_t frame_idx {0};
vk::Instance inst;
void createInstance();
vk::SurfaceKHR surf;
void createSurface();
RenderGroup rend_group;
void chooseRenderGroup();
vk::Device dev;
void createDevice();
vk::Queue gfx_q;
vk::SurfaceFormatKHR format;
SurfaceDetails getSurfaceDetails(vk::PhysicalDevice dev);
void chooseSurfaceFormat();
std::uint32_t img_count;
void chooseImageCount();
vk::Extent2D extent;
void chooseSwapExtent();
vk::SwapchainKHR swapchain;
vk::PresentModeKHR choosePresentMode();
void createSwapchain();
void createSwapchainDependents();
void destroySwapchainDependents();
void recreateSwapchain();
std::vector<vk::Image> images;
std::vector<vk::ImageView> image_views;
void createImageViews();
vk::RenderPass render_pass;
void createRenderPass();
vk::Pipeline pipeline;
vk::PipelineLayout layout;
void createPipeline();
std::vector<vk::Framebuffer> framebuffers;
void createFramebuffers();
vk::CommandPool cmd_pool;
std::vector<vk::CommandBuffer> cmd_bufs;
void recordCommandBuffers();
std::vector<vk::Semaphore> image_available;
std::vector<vk::Semaphore> render_finished;
std::vector<vk::Fence> frame_inflight;
std::vector<vk::Fence> image_inflight;
void createSyncPrimitives();
};
} // namespace vg
#endif // VG_HPP