source: opengl-game/sdl-game.hpp@ 28ea92f

feature/imgui-sdl
Last change on this file since 28ea92f was 28ea92f, checked in by Dmitry Portnoy <dportnoy@…>, 4 years ago

Rename the flag for recreating the swap chain to shouldRecreateSwapChain in both VulkanGame and SDLGame

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