Changeset ce9dc9f in opengl-game for sdl-game.hpp


Ignore:
Timestamp:
Jan 24, 2021, 6:15:32 PM (4 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
8b823e7
Parents:
3f32dfd
Message:

Remove all dependencies on VulkanH functions and structures from SDLGame

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sdl-game.hpp

    r3f32dfd rce9dc9f  
    33
    44#include <vector>
    5 
    65#include <vulkan/vulkan.h>
    76
    87#include <SDL2/SDL.h>
    9 
    108#include "IMGUI/imgui_impl_vulkan.h"
    119
    1210#include "consts.hpp"
     11#include "vulkan-utils.hpp"
    1312
    1413#include "game-gui-sdl.hpp"
     
    2625class VulkanGame {
    2726   public:
    28       VulkanGame(int maxFramesInFlight);
     27      VulkanGame();
    2928      ~VulkanGame();
    3029
    31       void run(int width, int height, unsigned char guiFlags); // Mostly example code
     30      void run(int width, int height, unsigned char guiFlags);
    3231
    3332   private:
     
    3837         void* pUserData);
    3938
    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 
    4539      // TODO: Good place to start using smart pointers
    4640      GameGui* gui;
     
    4943      SDL_Window* window;
    5044
     45      VkInstance instance;
    5146      VkDebugUtilsMessengerEXT debugMessenger = VK_NULL_HANDLE;
    5247      VkSurfaceKHR surface; // TODO: Change the variable name to vulkanSurface
     48      VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
     49      VkDevice device;
    5350
    5451      VkQueue graphicsQueue;
    5552      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
    5785      // My code, but not complete. Skips creating the SDL renderer, probably because it doesn't use hardware acceleration.
    5886      // I should try to get uncapped framerate and compare performance w/ and w/out an SDL renderer
     
    6593      void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo);
    6694      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
     95      void pickPhysicalDevice(const vector<const char*>& deviceExtensions);
    6896      bool isDeviceSuitable(VkPhysicalDevice physicalDevice, const vector<const char*>& deviceExtensions);
    6997      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();
    71113
    72114      // Pipeline variables. Hopefully, I can eventually use the GraphicsPipeline_Vulkan class for the imgui pipeline
    73115      VkDescriptorPool descriptorPool;
    74116
     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
    75122};
    76123
    77 // These functions are helper functions that were used in the ImGui Vulkan+SDL example
    78 
    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 functions
    87 
    88124#endif // _SDL_GAME_H
Note: See TracChangeset for help on using the changeset viewer.