#ifndef _SDL_GAME_H #define _SDL_GAME_H #include #include #include #include "IMGUI/imgui_impl_vulkan.h" #include "consts.hpp" #include "vulkan-utils.hpp" #include "game-gui-sdl.hpp" using namespace std; #define VulkanGame NewVulkanGame #ifdef NDEBUG const bool ENABLE_VALIDATION_LAYERS = false; #else const bool ENABLE_VALIDATION_LAYERS = true; #endif class VulkanGame { public: VulkanGame(); ~VulkanGame(); void run(int width, int height, unsigned char guiFlags); private: static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback( VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, void* pUserData); // TODO: Good place to start using smart pointers GameGui* gui; SDL_version sdlVersion; SDL_Window* window; VkInstance instance; VkDebugUtilsMessengerEXT debugMessenger = VK_NULL_HANDLE; VkSurfaceKHR surface; // TODO: Change the variable name to vulkanSurface VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; VkDevice device; VkQueue graphicsQueue; VkQueue presentQueue; // TODO: Maybe make a swapchain struct for convenience VkSurfaceFormatKHR swapChainSurfaceFormat; VkPresentModeKHR swapChainPresentMode; VkExtent2D swapChainExtent; uint32_t swapChainMinImageCount; uint32_t swapChainImageCount; VkSwapchainKHR swapChain; vector swapChainImages; vector swapChainImageViews; vector swapChainFramebuffers; VkRenderPass renderPass; VkCommandPool resourceCommandPool; vector commandPools; vector commandBuffers; VulkanImage depthImage; // These are per frame vector imageAcquiredSemaphores; vector renderCompleteSemaphores; // These are per swap chain image vector inFlightFences; uint32_t imageIndex; uint32_t currentFrame; // My code, but not complete. Skips creating the SDL renderer, probably because it doesn't use hardware acceleration. // I should try to get uncapped framerate and compare performance w/ and w/out an SDL renderer bool initUI(int width, int height, unsigned char guiFlags); void initVulkan(); // Mostly example code void cleanup(); // Mostly example void createVulkanInstance(const vector& validationLayers); void setupDebugMessenger(); void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo); void createVulkanSurface(); void pickPhysicalDevice(const vector& deviceExtensions); bool isDeviceSuitable(VkPhysicalDevice physicalDevice, const vector& deviceExtensions); void createLogicalDevice(const vector& validationLayers, const vector& deviceExtensions); void chooseSwapChainProperties(); void createSwapChain(); void createImageViews(); void createRenderPass(); VkFormat findDepthFormat(); // TODO: Declare/define (in the cpp file) this function in some util functions section void createResourceCommandPool(); void createCommandPools(); void createFramebuffers(); void createCommandBuffers(); void createSyncObjects(); void recreateSwapChain(); void cleanupSwapChain(); // Pipeline variables. Hopefully, I can eventually use the GraphicsPipeline_Vulkan class for the imgui pipeline VkDescriptorPool descriptorPool; // Helper methods from imgui_impl_vulkan that were moved into VulkanGame to give them access to class instance variables public: void FrameRender(ImDrawData* draw_data); void FramePresent(); }; #endif // _SDL_GAME_H