-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvulkan_base.h
133 lines (115 loc) · 3.37 KB
/
vulkan_base.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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#pragma once
#include <wayland-client.h>
#include "xdg-shell-client-protocol.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <vector>
#include <array>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <iostream>
#include <chrono>
#include <random>
#include <algorithm>
#include <sys/stat.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/matrix_inverse.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <string>
#include <numeric>
#include <array>
#include "vulkan/vulkan.h"
#include "vulkan/vulkan_wayland.h"
#include "vulkan_swap_chain.h"
#include "vulkan_device.h"
class VulkanBase
{
private:
void createPipelineCache();
void createCommandPool();
void createSynchronizationPrimitives();
void initSwapchain();
void setupSwapChain();
void createCommandBuffers();
void destroyCommandBuffers();
protected:
std::string getShadersPath() const;
VkInstance instance;
std::vector<std::string> supportedInstanceExtensions;
VkPhysicalDevice physicalDevice;
VkPhysicalDeviceProperties deviceProperties;
VkPhysicalDeviceFeatures deviceFeatures;
VkPhysicalDeviceMemoryProperties deviceMemoryProperties;
VkPhysicalDeviceFeatures enabledFeatures{};
std::vector<const char*> enabledDeviceExtensions;
void* deviceCreatepNextChain = nullptr;
VkDevice device;
VkQueue queue;
VkFormat depthFormat;
VkCommandPool cmdPool;
VkPipelineStageFlags submitPipelineStages = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
VkSubmitInfo submitInfo;
std::vector<VkCommandBuffer> drawCmdBuffers;
VkRenderPass renderPass = VK_NULL_HANDLE;
std::vector<VkFramebuffer>frameBuffers;
uint32_t currentBuffer = 0;
VkDescriptorPool descriptorPool = VK_NULL_HANDLE;
std::vector<VkShaderModule> shaderModules;
VkPipelineCache pipelineCache;
vulkan_swap_chain swapChain;
struct {
// Swap chain image presentation
VkSemaphore presentComplete;
// Command buffer submission and execution
VkSemaphore renderComplete;
} semaphores;
std::vector<VkFence> waitFences;
public:
bool prepared = false;
uint32_t width = 1280;
uint32_t height = 720;
vulkan_device *vulkanDevice;
glm::mat4 perspective;
glm::mat4 view;
glm::vec2 mousePos;
std::string title = "Vulkan Example";
std::string name = "vulkanExample";
struct {
VkImage image;
VkDeviceMemory mem;
VkImageView view;
} depthStencil;
wl_display *display = nullptr;
wl_registry *registry = nullptr;
wl_compositor *compositor = nullptr;
struct xdg_wm_base *shell = nullptr;
wl_seat *seat = nullptr;
wl_surface *surface = nullptr;
struct xdg_surface *xdg_surface;
struct xdg_toplevel *xdg_toplevel;
bool quit = false;
bool configured = false;
VulkanBase();
virtual ~VulkanBase();
bool initVulkan();
struct xdg_surface *setupWindow();
void initWaylandConnection();
static void registryGlobalCb(void *data, struct wl_registry *registry,
uint32_t name, const char *interface, uint32_t version);
void registryGlobal(struct wl_registry *registry, uint32_t name,
const char *interface, uint32_t version);
static void registryGlobalRemoveCb(void *data, struct wl_registry *registry,
uint32_t name);
virtual VkResult createInstance();
virtual void render() = 0;
virtual void buildCommandBuffers();
virtual void setupDepthStencil();
virtual void setupFrameBuffer();
virtual void setupRenderPass();
virtual void prepare();
void renderLoop();
};