source: opengl-game/sdl-game.hpp@ 6493e43

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

In sdl-game, add support for using separate graphics and present queues, and move the example ImGui code for (re)creating the swapchain into my own files

  • Property mode set to 100644
File size: 3.2 KB
Line 
1#ifndef _SDL_GAME_H
2#define _SDL_GAME_H
3
4#include <vector>
5
6#include <vulkan/vulkan.h>
7
8#include <SDL2/SDL.h>
9
10#include "IMGUI/imgui_impl_vulkan.h"
11
12#include "consts.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(int maxFramesInFlight);
29 ~VulkanGame();
30
31 void run(int width, int height, unsigned char guiFlags); // Mostly example code
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 // TODO: Make these consts static
41 // Also, maybe move them into consts.hpp
42
43 const int MAX_FRAMES_IN_FLIGHT; // Unused right now
44
45 // TODO: Good place to start using smart pointers
46 GameGui* gui;
47
48 SDL_version sdlVersion;
49 SDL_Window* window;
50
51 VkDebugUtilsMessengerEXT debugMessenger = VK_NULL_HANDLE;
52 VkSurfaceKHR surface; // TODO: Change the variable name to vulkanSurface
53
54 VkQueue graphicsQueue;
55 VkQueue presentQueue;
56
57 // My code, but not complete. Skips creating the SDL renderer, probably because it doesn't use hardware acceleration.
58 // I should try to get uncapped framerate and compare performance w/ and w/out an SDL renderer
59 bool initUI(int width, int height, unsigned char guiFlags);
60 void initVulkan(); // Mostly example code
61 void cleanup(); // Mostly example
62
63 void createVulkanInstance(const vector<const char*>& validationLayers);
64 void setupDebugMessenger();
65 void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo);
66 void createVulkanSurface();
67 void pickPhysicalDevice(const vector<const char*>& deviceExtensions); // Double-check, but it should be a copy of my code. Still uses g_Instance and g_Physical device though
68 bool isDeviceSuitable(VkPhysicalDevice physicalDevice, const vector<const char*>& deviceExtensions);
69 void createLogicalDevice(const vector<const char*>& validationLayers,
70 const vector<const char*>& deviceExtensions); // Only creates the graphics queue. Later, checks that this queue also supports presenting, but this codebase does not seem to support a separate present queue
71
72 // Pipeline variables. Hopefully, I can eventually use the GraphicsPipeline_Vulkan class for the imgui pipeline
73 VkDescriptorPool descriptorPool;
74
75};
76
77// These functions are helper functions that were used in the ImGui Vulkan+SDL example
78
79void ImGui_ImplVulkanH_CreateOrResizeWindow(VkInstance instance, VkPhysicalDevice physical_device, VkDevice device,
80 ImGui_ImplVulkanH_Window* wnd, uint32_t queue_family, const VkAllocationCallbacks* allocator, int w, int h,
81 uint32_t min_image_count);
82
83void ImGui_ImplVulkanH_CreateWindowSwapChain(VkPhysicalDevice physical_device, VkDevice device,
84 ImGui_ImplVulkanH_Window* wd, const VkAllocationCallbacks* allocator, int w, int h, uint32_t min_image_count);
85
86// End helper functions
87
88#endif // _SDL_GAME_H
Note: See TracBrowser for help on using the repository browser.