[3b7d497] | 1 | #ifndef _SDL_GAME_H
|
---|
| 2 | #define _SDL_GAME_H
|
---|
| 3 |
|
---|
| 4 | #include <vector>
|
---|
| 5 | #include <vulkan/vulkan.h>
|
---|
| 6 |
|
---|
| 7 | #include <SDL2/SDL.h>
|
---|
[6493e43] | 8 | #include "IMGUI/imgui_impl_vulkan.h"
|
---|
| 9 |
|
---|
[3b7d497] | 10 | #include "consts.hpp"
|
---|
[ce9dc9f] | 11 | #include "vulkan-utils.hpp"
|
---|
[3b7d497] | 12 |
|
---|
| 13 | #include "game-gui-sdl.hpp"
|
---|
| 14 |
|
---|
| 15 | using namespace std;
|
---|
| 16 |
|
---|
| 17 | #define VulkanGame NewVulkanGame
|
---|
| 18 |
|
---|
| 19 | #ifdef NDEBUG
|
---|
| 20 | const bool ENABLE_VALIDATION_LAYERS = false;
|
---|
| 21 | #else
|
---|
| 22 | const bool ENABLE_VALIDATION_LAYERS = true;
|
---|
| 23 | #endif
|
---|
| 24 |
|
---|
| 25 | class VulkanGame {
|
---|
| 26 | public:
|
---|
[ce9dc9f] | 27 | VulkanGame();
|
---|
[3b7d497] | 28 | ~VulkanGame();
|
---|
| 29 |
|
---|
[ce9dc9f] | 30 | void run(int width, int height, unsigned char guiFlags);
|
---|
[3b7d497] | 31 |
|
---|
| 32 | private:
|
---|
| 33 | static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
|
---|
| 34 | VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
---|
| 35 | VkDebugUtilsMessageTypeFlagsEXT messageType,
|
---|
| 36 | const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
|
---|
| 37 | void* pUserData);
|
---|
| 38 |
|
---|
| 39 | // TODO: Good place to start using smart pointers
|
---|
| 40 | GameGui* gui;
|
---|
| 41 |
|
---|
| 42 | SDL_version sdlVersion;
|
---|
| 43 | SDL_Window* window;
|
---|
| 44 |
|
---|
[ce9dc9f] | 45 | VkInstance instance;
|
---|
[3b7d497] | 46 | VkDebugUtilsMessengerEXT debugMessenger = VK_NULL_HANDLE;
|
---|
| 47 | VkSurfaceKHR surface; // TODO: Change the variable name to vulkanSurface
|
---|
[ce9dc9f] | 48 | VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
|
---|
| 49 | VkDevice device;
|
---|
[6493e43] | 50 |
|
---|
| 51 | VkQueue graphicsQueue;
|
---|
| 52 | VkQueue presentQueue;
|
---|
[ce9dc9f] | 53 |
|
---|
| 54 | // TODO: Maybe make a swapchain struct for convenience
|
---|
| 55 | VkSurfaceFormatKHR swapChainSurfaceFormat;
|
---|
| 56 | VkPresentModeKHR swapChainPresentMode;
|
---|
| 57 | VkExtent2D swapChainExtent;
|
---|
| 58 | uint32_t swapChainMinImageCount;
|
---|
| 59 | uint32_t swapChainImageCount;
|
---|
| 60 |
|
---|
| 61 | VkSwapchainKHR swapChain;
|
---|
| 62 | vector<VkImage> swapChainImages;
|
---|
| 63 | vector<VkImageView> swapChainImageViews;
|
---|
| 64 | vector<VkFramebuffer> swapChainFramebuffers;
|
---|
| 65 |
|
---|
| 66 | VkRenderPass renderPass;
|
---|
| 67 |
|
---|
| 68 | VkCommandPool resourceCommandPool;
|
---|
| 69 |
|
---|
| 70 | vector<VkCommandPool> commandPools;
|
---|
| 71 | vector<VkCommandBuffer> commandBuffers;
|
---|
| 72 |
|
---|
| 73 | VulkanImage depthImage;
|
---|
| 74 |
|
---|
| 75 | // These are per frame
|
---|
| 76 | vector<VkSemaphore> imageAcquiredSemaphores;
|
---|
| 77 | vector<VkSemaphore> renderCompleteSemaphores;
|
---|
| 78 |
|
---|
| 79 | // These are per swap chain image
|
---|
| 80 | vector<VkFence> inFlightFences;
|
---|
| 81 |
|
---|
| 82 | uint32_t imageIndex;
|
---|
| 83 | uint32_t currentFrame;
|
---|
| 84 |
|
---|
[3b7d497] | 85 | // My code, but not complete. Skips creating the SDL renderer, probably because it doesn't use hardware acceleration.
|
---|
| 86 | // I should try to get uncapped framerate and compare performance w/ and w/out an SDL renderer
|
---|
| 87 | bool initUI(int width, int height, unsigned char guiFlags);
|
---|
| 88 | void initVulkan(); // Mostly example code
|
---|
| 89 | void cleanup(); // Mostly example
|
---|
| 90 |
|
---|
| 91 | void createVulkanInstance(const vector<const char*>& validationLayers);
|
---|
| 92 | void setupDebugMessenger();
|
---|
| 93 | void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo);
|
---|
| 94 | void createVulkanSurface();
|
---|
[ce9dc9f] | 95 | void pickPhysicalDevice(const vector<const char*>& deviceExtensions);
|
---|
[3b7d497] | 96 | bool isDeviceSuitable(VkPhysicalDevice physicalDevice, const vector<const char*>& deviceExtensions);
|
---|
| 97 | void createLogicalDevice(const vector<const char*>& validationLayers,
|
---|
[ce9dc9f] | 98 | const vector<const char*>& deviceExtensions);
|
---|
| 99 | void chooseSwapChainProperties();
|
---|
| 100 | void createSwapChain();
|
---|
| 101 | void createImageViews();
|
---|
| 102 | void createRenderPass();
|
---|
| 103 | VkFormat findDepthFormat(); // TODO: Declare/define (in the cpp file) this function in some util functions section
|
---|
| 104 | void createResourceCommandPool();
|
---|
| 105 | void createCommandPools();
|
---|
| 106 | void createFramebuffers();
|
---|
| 107 | void createCommandBuffers();
|
---|
| 108 | void createSyncObjects();
|
---|
| 109 |
|
---|
| 110 | void recreateSwapChain();
|
---|
| 111 |
|
---|
| 112 | void cleanupSwapChain();
|
---|
[6493e43] | 113 |
|
---|
| 114 | // Pipeline variables. Hopefully, I can eventually use the GraphicsPipeline_Vulkan class for the imgui pipeline
|
---|
| 115 | VkDescriptorPool descriptorPool;
|
---|
| 116 |
|
---|
[ce9dc9f] | 117 | // Helper methods from imgui_impl_vulkan that were moved into VulkanGame to give them access to class instance variables
|
---|
| 118 | public:
|
---|
| 119 | void FrameRender(ImDrawData* draw_data);
|
---|
| 120 | void FramePresent();
|
---|
[6493e43] | 121 |
|
---|
[ce9dc9f] | 122 | };
|
---|
[6493e43] | 123 |
|
---|
[3b7d497] | 124 | #endif // _SDL_GAME_H
|
---|