[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:
|
---|
[34bdf3a] | 32 | VulkanGame(int maxFramesInFlight);
|
---|
[99d44b2] | 33 | ~VulkanGame();
|
---|
[0df3c9a] | 34 |
|
---|
[b6e60b4] | 35 | void run(int width, int height, unsigned char guiFlags);
|
---|
[0df3c9a] | 36 |
|
---|
| 37 | private:
|
---|
[34bdf3a] | 38 | const int MAX_FRAMES_IN_FLIGHT;
|
---|
| 39 |
|
---|
[0df3c9a] | 40 | GameGui* gui;
|
---|
[c559904] | 41 |
|
---|
[7d2b0b9] | 42 | vector<GraphicsPipeline_Vulkan> graphicsPipelines;
|
---|
| 43 |
|
---|
[c559904] | 44 | SDL_version sdlVersion;
|
---|
[b794178] | 45 | SDL_Window* window = nullptr;
|
---|
| 46 | SDL_Renderer* renderer = nullptr;
|
---|
| 47 |
|
---|
| 48 | SDL_Texture* uiOverlay = nullptr;
|
---|
[c1d9b2a] | 49 |
|
---|
| 50 | VkInstance instance;
|
---|
| 51 | VkDebugUtilsMessengerEXT debugMessenger;
|
---|
[fe5c3ba] | 52 | VkSurfaceKHR surface; // TODO: Change the variable name to vulkanSurface
|
---|
[90a424f] | 53 | VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
|
---|
[c1c2021] | 54 | VkDevice device;
|
---|
| 55 |
|
---|
| 56 | VkQueue graphicsQueue;
|
---|
| 57 | VkQueue presentQueue;
|
---|
[0df3c9a] | 58 |
|
---|
[502bd0b] | 59 | VkSwapchainKHR swapChain;
|
---|
| 60 | vector<VkImage> swapChainImages;
|
---|
| 61 | VkFormat swapChainImageFormat;
|
---|
[603b5bc] | 62 | VkExtent2D swapChainExtent;
|
---|
[f94eea9] | 63 | vector<VkImageView> swapChainImageViews;
|
---|
[603b5bc] | 64 | vector<VkFramebuffer> swapChainFramebuffers;
|
---|
[fa9fa1c] | 65 |
|
---|
[6fc24c7] | 66 | VkRenderPass renderPass;
|
---|
[fa9fa1c] | 67 | VkCommandPool commandPool;
|
---|
[603b5bc] | 68 | vector<VkCommandBuffer> commandBuffers;
|
---|
[502bd0b] | 69 |
|
---|
[603b5bc] | 70 | VulkanImage depthImage;
|
---|
[b794178] | 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 |
|
---|
[34bdf3a] | 89 | vector<VkSemaphore> imageAvailableSemaphores;
|
---|
| 90 | vector<VkSemaphore> renderFinishedSemaphores;
|
---|
| 91 | vector<VkFence> inFlightFences;
|
---|
| 92 |
|
---|
[87c8f1a] | 93 | size_t currentFrame;
|
---|
| 94 |
|
---|
| 95 | bool framebufferResized;
|
---|
[0e09340] | 96 |
|
---|
[b6e60b4] | 97 | bool initWindow(int width, int height, unsigned char guiFlags);
|
---|
[0df3c9a] | 98 | void initVulkan();
|
---|
| 99 | void mainLoop();
|
---|
[a0c5f28] | 100 | void renderUI();
|
---|
| 101 | void renderScene();
|
---|
[0df3c9a] | 102 | void cleanup();
|
---|
[c1d9b2a] | 103 |
|
---|
| 104 | void createVulkanInstance(const vector<const char*> &validationLayers);
|
---|
| 105 | void setupDebugMessenger();
|
---|
| 106 | void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo);
|
---|
[90a424f] | 107 | void createVulkanSurface();
|
---|
[fe5c3ba] | 108 | void pickPhysicalDevice(const vector<const char*>& deviceExtensions);
|
---|
[fa9fa1c] | 109 | bool isDeviceSuitable(VkPhysicalDevice physicalDevice, const vector<const char*>& deviceExtensions);
|
---|
[c1c2021] | 110 | void createLogicalDevice(
|
---|
| 111 | const vector<const char*> validationLayers,
|
---|
| 112 | const vector<const char*>& deviceExtensions);
|
---|
[502bd0b] | 113 | void createSwapChain();
|
---|
[f94eea9] | 114 | void createImageViews();
|
---|
[6fc24c7] | 115 | void createRenderPass();
|
---|
| 116 | VkFormat findDepthFormat();
|
---|
[fa9fa1c] | 117 | void createCommandPool();
|
---|
[603b5bc] | 118 | void createImageResources();
|
---|
| 119 |
|
---|
[b794178] | 120 | void createTextureSampler();
|
---|
[603b5bc] | 121 | void createFramebuffers();
|
---|
[b794178] | 122 | void createUniformBuffers();
|
---|
[603b5bc] | 123 | void createCommandBuffers();
|
---|
[34bdf3a] | 124 | void createSyncObjects();
|
---|
[f94eea9] | 125 |
|
---|
[d2d9286] | 126 | void recreateSwapChain();
|
---|
[f985231] | 127 | void updateUniformBuffer(uint32_t currentImage);
|
---|
[d2d9286] | 128 |
|
---|
[c1c2021] | 129 | void cleanupSwapChain();
|
---|
[c1d9b2a] | 130 |
|
---|
| 131 | static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
|
---|
| 132 | VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
---|
| 133 | VkDebugUtilsMessageTypeFlagsEXT messageType,
|
---|
| 134 | const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
|
---|
| 135 | void* pUserData);
|
---|
[e8ebc76] | 136 | };
|
---|
| 137 |
|
---|
[99d44b2] | 138 | #endif // _VULKAN_GAME_H |
---|