source: opengl-game/sdl-game.hpp@ c6f0793

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

Use done instead of quit as the game loop flag and change it to an instance variable in SDLGame

  • Property mode set to 100644
File size: 3.9 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 // My code, but not complete. Skips creating the SDL renderer, probably because it doesn't use hardware acceleration.
89 // I should try to get uncapped framerate and compare performance w/ and w/out an SDL renderer
90 bool initUI(int width, int height, unsigned char guiFlags);
91 void initVulkan(); // Mostly example code
92 void cleanup(); // Mostly example
93
94 void createVulkanInstance(const vector<const char*>& validationLayers);
95 void setupDebugMessenger();
96 void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo);
97 void createVulkanSurface();
98 void pickPhysicalDevice(const vector<const char*>& deviceExtensions);
99 bool isDeviceSuitable(VkPhysicalDevice physicalDevice, const vector<const char*>& deviceExtensions);
100 void createLogicalDevice(const vector<const char*>& validationLayers,
101 const vector<const char*>& deviceExtensions);
102 void chooseSwapChainProperties();
103 void createSwapChain();
104 void createImageViews();
105 void createRenderPass();
106 VkFormat findDepthFormat(); // TODO: Declare/define (in the cpp file) this function in some util functions section
107 void createResourceCommandPool();
108 void createCommandPools();
109 void createFramebuffers();
110 void createCommandBuffers();
111 void createSyncObjects();
112
113 void recreateSwapChain();
114
115 void cleanupSwapChain();
116
117 // Pipeline variables. Hopefully, I can eventually use the GraphicsPipeline_Vulkan class for the imgui pipeline
118 VkDescriptorPool descriptorPool;
119
120 // Helper methods from imgui_impl_vulkan that were moved into VulkanGame to give them access to class instance variables
121 public:
122 void FrameRender(ImDrawData* draw_data);
123 void FramePresent();
124
125};
126
127#endif // _SDL_GAME_H
Note: See TracBrowser for help on using the repository browser.