1 | #ifndef _VULKAN_GAME_H
|
---|
2 | #define _VULKAN_GAME_H
|
---|
3 |
|
---|
4 | #include <glm/glm.hpp>
|
---|
5 |
|
---|
6 | #include "game-gui-sdl.hpp"
|
---|
7 | #include "graphics-pipeline_vulkan.hpp"
|
---|
8 |
|
---|
9 | #include "vulkan-utils.hpp"
|
---|
10 |
|
---|
11 | #ifdef NDEBUG
|
---|
12 | const bool ENABLE_VALIDATION_LAYERS = false;
|
---|
13 | #else
|
---|
14 | const bool ENABLE_VALIDATION_LAYERS = true;
|
---|
15 | #endif
|
---|
16 |
|
---|
17 | // TODO: Figure out if these structs should be defined in the VulkanGame class
|
---|
18 |
|
---|
19 | struct Vertex {
|
---|
20 | glm::vec3 pos;
|
---|
21 | glm::vec3 color;
|
---|
22 | glm::vec2 texCoord;
|
---|
23 | };
|
---|
24 |
|
---|
25 | struct OverlayVertex {
|
---|
26 | glm::vec3 pos;
|
---|
27 | glm::vec2 texCoord;
|
---|
28 | };
|
---|
29 |
|
---|
30 | class VulkanGame {
|
---|
31 | public:
|
---|
32 | VulkanGame();
|
---|
33 | ~VulkanGame();
|
---|
34 |
|
---|
35 | void run(int width, int height, unsigned char guiFlags);
|
---|
36 |
|
---|
37 | private:
|
---|
38 | GameGui* gui;
|
---|
39 | Viewport viewport;
|
---|
40 |
|
---|
41 | vector<GraphicsPipeline_Vulkan> graphicsPipelines;
|
---|
42 |
|
---|
43 | SDL_version sdlVersion;
|
---|
44 | SDL_Window* window = nullptr;
|
---|
45 | SDL_Renderer* renderer = nullptr;
|
---|
46 |
|
---|
47 | SDL_Texture* uiOverlay = nullptr;
|
---|
48 |
|
---|
49 | VkInstance instance;
|
---|
50 | VkDebugUtilsMessengerEXT debugMessenger;
|
---|
51 | VkSurfaceKHR surface; // TODO: Change the variable name to vulkanSurface
|
---|
52 | VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
|
---|
53 | VkDevice device;
|
---|
54 |
|
---|
55 | VkQueue graphicsQueue;
|
---|
56 | VkQueue presentQueue;
|
---|
57 |
|
---|
58 | VkSwapchainKHR swapChain;
|
---|
59 | vector<VkImage> swapChainImages;
|
---|
60 | VkFormat swapChainImageFormat;
|
---|
61 | vector<VkImageView> swapChainImageViews;
|
---|
62 |
|
---|
63 | VkRenderPass renderPass;
|
---|
64 | VkCommandPool commandPool;
|
---|
65 |
|
---|
66 | // TODO: Create these (and wrap them inside a VulkanImage)
|
---|
67 | VkImage depthImage;
|
---|
68 | VkDeviceMemory depthImageMemory;
|
---|
69 | VkImageView depthImageView;
|
---|
70 |
|
---|
71 | VkSampler textureSampler;
|
---|
72 |
|
---|
73 | vector<VkDescriptorBufferInfo> uniformBufferInfoList;
|
---|
74 |
|
---|
75 | // These are currently to store the MVP matrix
|
---|
76 | // I should figure out if it makes sense to use them for other uniforms in the future
|
---|
77 | // If not, I should rename them to better indicate their purpose.
|
---|
78 | // I should also decide if I can use these for all shaders, or if I need a separapte set of buffers for each one
|
---|
79 | vector<VkBuffer> uniformBuffers;
|
---|
80 | vector<VkDeviceMemory> uniformBuffersMemory;
|
---|
81 |
|
---|
82 | VulkanImage floorTextureImage;
|
---|
83 | VkDescriptorImageInfo floorTextureImageDescriptor;
|
---|
84 |
|
---|
85 | VulkanImage sdlOverlayImage;
|
---|
86 | VkDescriptorImageInfo sdlOverlayImageDescriptor;
|
---|
87 |
|
---|
88 | bool framebufferResized = false;
|
---|
89 |
|
---|
90 | bool initWindow(int width, int height, unsigned char guiFlags);
|
---|
91 | void initVulkan();
|
---|
92 | void mainLoop();
|
---|
93 | void renderUI();
|
---|
94 | void renderScene();
|
---|
95 | void cleanup();
|
---|
96 |
|
---|
97 | void createVulkanInstance(const vector<const char*> &validationLayers);
|
---|
98 | void setupDebugMessenger();
|
---|
99 | void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo);
|
---|
100 | void createVulkanSurface();
|
---|
101 | void pickPhysicalDevice(const vector<const char*>& deviceExtensions);
|
---|
102 | bool isDeviceSuitable(VkPhysicalDevice physicalDevice, const vector<const char*>& deviceExtensions);
|
---|
103 | void createLogicalDevice(
|
---|
104 | const vector<const char*> validationLayers,
|
---|
105 | const vector<const char*>& deviceExtensions);
|
---|
106 | void createSwapChain();
|
---|
107 | void createImageViews();
|
---|
108 | void createRenderPass();
|
---|
109 | VkFormat findDepthFormat();
|
---|
110 | void createCommandPool();
|
---|
111 | void createVulkanResources();
|
---|
112 | void createTextureSampler();
|
---|
113 | void createUniformBuffers();
|
---|
114 |
|
---|
115 | void cleanupSwapChain();
|
---|
116 |
|
---|
117 | static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
|
---|
118 | VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
---|
119 | VkDebugUtilsMessageTypeFlagsEXT messageType,
|
---|
120 | const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
|
---|
121 | void* pUserData);
|
---|
122 | };
|
---|
123 |
|
---|
124 | #endif // _VULKAN_GAME_H
|
---|