source: opengl-game/vulkan-game.hpp@ e3bef3a

feature/imgui-sdl points-test
Last change on this file since e3bef3a was e3bef3a, checked in by Dmitry Portnoy <dmp1488@…>, 5 years ago

Finish the rewrite of the original vulkangame project

  • Property mode set to 100644
File size: 4.1 KB
Line 
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
19struct Vertex {
20 glm::vec3 pos;
21 glm::vec3 color;
22 glm::vec2 texCoord;
23};
24
25struct OverlayVertex {
26 glm::vec3 pos;
27 glm::vec2 texCoord;
28};
29
30class VulkanGame {
31 public:
32 VulkanGame(int maxFramesInFlight);
33 ~VulkanGame();
34
35 void run(int width, int height, unsigned char guiFlags);
36
37 private:
38 const int MAX_FRAMES_IN_FLIGHT;
39
40 GameGui* gui;
41
42 vector<GraphicsPipeline_Vulkan> graphicsPipelines;
43
44 SDL_version sdlVersion;
45 SDL_Window* window = nullptr;
46 SDL_Renderer* renderer = nullptr;
47
48 SDL_Texture* uiOverlay = nullptr;
49
50 VkInstance instance;
51 VkDebugUtilsMessengerEXT debugMessenger;
52 VkSurfaceKHR surface; // TODO: Change the variable name to vulkanSurface
53 VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
54 VkDevice device;
55
56 VkQueue graphicsQueue;
57 VkQueue presentQueue;
58
59 VkSwapchainKHR swapChain;
60 vector<VkImage> swapChainImages;
61 VkFormat swapChainImageFormat;
62 VkExtent2D swapChainExtent;
63 vector<VkImageView> swapChainImageViews;
64 vector<VkFramebuffer> swapChainFramebuffers;
65
66 VkRenderPass renderPass;
67 VkCommandPool commandPool;
68 vector<VkCommandBuffer> commandBuffers;
69
70 VulkanImage depthImage;
71
72 VkSampler textureSampler;
73
74 vector<VkDescriptorBufferInfo> uniformBufferInfoList;
75
76 // These are currently to store the MVP matrix
77 // I should figure out if it makes sense to use them for other uniforms in the future
78 // If not, I should rename them to better indicate their purpose.
79 // I should also decide if I can use these for all shaders, or if I need a separapte set of buffers for each one
80 vector<VkBuffer> uniformBuffers;
81 vector<VkDeviceMemory> uniformBuffersMemory;
82
83 VulkanImage floorTextureImage;
84 VkDescriptorImageInfo floorTextureImageDescriptor;
85
86 VulkanImage sdlOverlayImage;
87 VkDescriptorImageInfo sdlOverlayImageDescriptor;
88
89 TTF_Font* font;
90 SDL_Texture* fontSDLTexture;
91
92 SDL_Texture* imageSDLTexture;
93
94 vector<VkSemaphore> imageAvailableSemaphores;
95 vector<VkSemaphore> renderFinishedSemaphores;
96 vector<VkFence> inFlightFences;
97
98 size_t currentFrame;
99 size_t numPlanes = 0; // temp
100
101 bool framebufferResized;
102
103 bool initWindow(int width, int height, unsigned char guiFlags);
104 void initVulkan();
105 void mainLoop();
106 void renderUI();
107 void renderScene();
108 void cleanup();
109
110 void createVulkanInstance(const vector<const char*> &validationLayers);
111 void setupDebugMessenger();
112 void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo);
113 void createVulkanSurface();
114 void pickPhysicalDevice(const vector<const char*>& deviceExtensions);
115 bool isDeviceSuitable(VkPhysicalDevice physicalDevice, const vector<const char*>& deviceExtensions);
116 void createLogicalDevice(
117 const vector<const char*> validationLayers,
118 const vector<const char*>& deviceExtensions);
119 void createSwapChain();
120 void createImageViews();
121 void createRenderPass();
122 VkFormat findDepthFormat();
123 void createCommandPool();
124 void createImageResources();
125
126 void createTextureSampler();
127 void createFramebuffers();
128 void createUniformBuffers();
129 void createCommandBuffers();
130 void createSyncObjects();
131
132 void recreateSwapChain();
133 void updateUniformBuffer(uint32_t currentImage);
134
135 void cleanupSwapChain();
136
137 static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
138 VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
139 VkDebugUtilsMessageTypeFlagsEXT messageType,
140 const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
141 void* pUserData);
142};
143
144#endif // _VULKAN_GAME_H
Note: See TracBrowser for help on using the repository browser.