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