| [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 |
|
|---|
| [2e77b3f] | 9 | #ifdef NDEBUG
|
|---|
| 10 | const bool ENABLE_VALIDATION_LAYERS = false;
|
|---|
| 11 | #else
|
|---|
| 12 | const bool ENABLE_VALIDATION_LAYERS = true;
|
|---|
| 13 | #endif
|
|---|
| 14 |
|
|---|
| [771b33a] | 15 | // TODO: Figure out if these structs should be defined in the VulkanGame class
|
|---|
| 16 |
|
|---|
| 17 | struct Vertex {
|
|---|
| 18 | glm::vec3 pos;
|
|---|
| 19 | glm::vec3 color;
|
|---|
| 20 | glm::vec2 texCoord;
|
|---|
| 21 | };
|
|---|
| 22 |
|
|---|
| 23 | struct OverlayVertex {
|
|---|
| 24 | glm::vec3 pos;
|
|---|
| 25 | glm::vec2 texCoord;
|
|---|
| 26 | };
|
|---|
| 27 |
|
|---|
| [99d44b2] | 28 | class VulkanGame {
|
|---|
| [e8ebc76] | 29 | public:
|
|---|
| [99d44b2] | 30 | VulkanGame();
|
|---|
| 31 | ~VulkanGame();
|
|---|
| [0df3c9a] | 32 |
|
|---|
| [b6e60b4] | 33 | void run(int width, int height, unsigned char guiFlags);
|
|---|
| [0df3c9a] | 34 |
|
|---|
| 35 | private:
|
|---|
| 36 | GameGui* gui;
|
|---|
| [771b33a] | 37 | Viewport viewport;
|
|---|
| [c559904] | 38 |
|
|---|
| [7d2b0b9] | 39 | vector<GraphicsPipeline_Vulkan> graphicsPipelines;
|
|---|
| 40 |
|
|---|
| [c559904] | 41 | SDL_version sdlVersion;
|
|---|
| [0df3c9a] | 42 | SDL_Window* window;
|
|---|
| [c1d9b2a] | 43 | SDL_Renderer* renderer;
|
|---|
| 44 |
|
|---|
| 45 | VkInstance instance;
|
|---|
| 46 | VkDebugUtilsMessengerEXT debugMessenger;
|
|---|
| [fe5c3ba] | 47 | VkSurfaceKHR surface; // TODO: Change the variable name to vulkanSurface
|
|---|
| [90a424f] | 48 | VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
|
|---|
| [c1c2021] | 49 | VkDevice device;
|
|---|
| 50 |
|
|---|
| 51 | VkQueue graphicsQueue;
|
|---|
| 52 | VkQueue presentQueue;
|
|---|
| [0df3c9a] | 53 |
|
|---|
| [502bd0b] | 54 | VkSwapchainKHR swapChain;
|
|---|
| 55 | vector<VkImage> swapChainImages;
|
|---|
| 56 | VkFormat swapChainImageFormat;
|
|---|
| [f94eea9] | 57 | vector<VkImageView> swapChainImageViews;
|
|---|
| [fa9fa1c] | 58 |
|
|---|
| [6fc24c7] | 59 | VkRenderPass renderPass;
|
|---|
| [fa9fa1c] | 60 | VkCommandPool commandPool;
|
|---|
| [502bd0b] | 61 |
|
|---|
| [0e09340] | 62 | bool framebufferResized = false;
|
|---|
| 63 |
|
|---|
| [b6e60b4] | 64 | bool initWindow(int width, int height, unsigned char guiFlags);
|
|---|
| [0df3c9a] | 65 | void initVulkan();
|
|---|
| 66 | void mainLoop();
|
|---|
| [a0c5f28] | 67 | void renderUI();
|
|---|
| 68 | void renderScene();
|
|---|
| [0df3c9a] | 69 | void cleanup();
|
|---|
| [c1d9b2a] | 70 |
|
|---|
| 71 | void createVulkanInstance(const vector<const char*> &validationLayers);
|
|---|
| 72 | void setupDebugMessenger();
|
|---|
| 73 | void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo);
|
|---|
| [90a424f] | 74 | void createVulkanSurface();
|
|---|
| [fe5c3ba] | 75 | void pickPhysicalDevice(const vector<const char*>& deviceExtensions);
|
|---|
| [fa9fa1c] | 76 | bool isDeviceSuitable(VkPhysicalDevice physicalDevice, const vector<const char*>& deviceExtensions);
|
|---|
| [c1c2021] | 77 | void createLogicalDevice(
|
|---|
| 78 | const vector<const char*> validationLayers,
|
|---|
| 79 | const vector<const char*>& deviceExtensions);
|
|---|
| [502bd0b] | 80 | void createSwapChain();
|
|---|
| [f94eea9] | 81 | void createImageViews();
|
|---|
| [6fc24c7] | 82 | void createRenderPass();
|
|---|
| 83 | VkFormat findDepthFormat();
|
|---|
| [fa9fa1c] | 84 | void createCommandPool();
|
|---|
| [f94eea9] | 85 |
|
|---|
| [c1c2021] | 86 | void cleanupSwapChain();
|
|---|
| [c1d9b2a] | 87 |
|
|---|
| 88 | static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
|
|---|
| 89 | VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
|---|
| 90 | VkDebugUtilsMessageTypeFlagsEXT messageType,
|
|---|
| 91 | const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
|
|---|
| 92 | void* pUserData);
|
|---|
| [e8ebc76] | 93 | };
|
|---|
| 94 |
|
|---|
| [99d44b2] | 95 | #endif // _VULKAN_GAME_H
|
|---|