Changeset ce9dc9f in opengl-game for sdl-game.hpp
- Timestamp:
- Jan 24, 2021, 6:15:32 PM (4 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- 8b823e7
- Parents:
- 3f32dfd
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sdl-game.hpp
r3f32dfd rce9dc9f 3 3 4 4 #include <vector> 5 6 5 #include <vulkan/vulkan.h> 7 6 8 7 #include <SDL2/SDL.h> 9 10 8 #include "IMGUI/imgui_impl_vulkan.h" 11 9 12 10 #include "consts.hpp" 11 #include "vulkan-utils.hpp" 13 12 14 13 #include "game-gui-sdl.hpp" … … 26 25 class VulkanGame { 27 26 public: 28 VulkanGame( int maxFramesInFlight);27 VulkanGame(); 29 28 ~VulkanGame(); 30 29 31 void run(int width, int height, unsigned char guiFlags); // Mostly example code30 void run(int width, int height, unsigned char guiFlags); 32 31 33 32 private: … … 38 37 void* pUserData); 39 38 40 // TODO: Make these consts static41 // Also, maybe move them into consts.hpp42 43 const int MAX_FRAMES_IN_FLIGHT; // Unused right now44 45 39 // TODO: Good place to start using smart pointers 46 40 GameGui* gui; … … 49 43 SDL_Window* window; 50 44 45 VkInstance instance; 51 46 VkDebugUtilsMessengerEXT debugMessenger = VK_NULL_HANDLE; 52 47 VkSurfaceKHR surface; // TODO: Change the variable name to vulkanSurface 48 VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; 49 VkDevice device; 53 50 54 51 VkQueue graphicsQueue; 55 52 VkQueue presentQueue; 56 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 57 85 // My code, but not complete. Skips creating the SDL renderer, probably because it doesn't use hardware acceleration. 58 86 // I should try to get uncapped framerate and compare performance w/ and w/out an SDL renderer … … 65 93 void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo); 66 94 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 though95 void pickPhysicalDevice(const vector<const char*>& deviceExtensions); 68 96 bool isDeviceSuitable(VkPhysicalDevice physicalDevice, const vector<const char*>& deviceExtensions); 69 97 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 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(); 71 113 72 114 // Pipeline variables. Hopefully, I can eventually use the GraphicsPipeline_Vulkan class for the imgui pipeline 73 115 VkDescriptorPool descriptorPool; 74 116 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(); 121 75 122 }; 76 123 77 // These functions are helper functions that were used in the ImGui Vulkan+SDL example78 79 void 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 83 void 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 functions87 88 124 #endif // _SDL_GAME_H
Note:
See TracChangeset
for help on using the changeset viewer.