source: opengl-game/vulkan-game.hpp@ 5a0242e

feature/imgui-sdl points-test
Last change on this file since 5a0242e was b8777b7, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 5 years ago

Templatize GraphicsPipeline_Vulkan by adding a VertexType parameter and moving all the function definitions into the header file, separate the model and overlay pipelines into separate variables in VulkanGame instead of storing them in a vector

  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[99d44b2]1#ifndef _VULKAN_GAME_H
2#define _VULKAN_GAME_H
[e8ebc76]3
[771b33a]4#include <glm/glm.hpp>
5
[0df3c9a]6#include "game-gui-sdl.hpp"
[7d2b0b9]7#include "graphics-pipeline_vulkan.hpp"
[0df3c9a]8
[b794178]9#include "vulkan-utils.hpp"
10
[2e77b3f]11#ifdef NDEBUG
12 const bool ENABLE_VALIDATION_LAYERS = false;
13#else
14 const bool ENABLE_VALIDATION_LAYERS = true;
15#endif
16
[b8777b7]17struct ModelVertex {
[771b33a]18 glm::vec3 pos;
19 glm::vec3 color;
20 glm::vec2 texCoord;
21};
22
23struct OverlayVertex {
24 glm::vec3 pos;
25 glm::vec2 texCoord;
26};
27
[99d44b2]28class VulkanGame {
[e8ebc76]29 public:
[34bdf3a]30 VulkanGame(int maxFramesInFlight);
[99d44b2]31 ~VulkanGame();
[0df3c9a]32
[b6e60b4]33 void run(int width, int height, unsigned char guiFlags);
[0df3c9a]34
35 private:
[34bdf3a]36 const int MAX_FRAMES_IN_FLIGHT;
37
[0df3c9a]38 GameGui* gui;
[c559904]39
[b8777b7]40 GraphicsPipeline_Vulkan<ModelVertex> modelPipeline;
41 GraphicsPipeline_Vulkan<OverlayVertex> overlayPipeline;
[7d2b0b9]42
[c559904]43 SDL_version sdlVersion;
[b794178]44 SDL_Window* window = nullptr;
45 SDL_Renderer* renderer = nullptr;
46
47 SDL_Texture* uiOverlay = nullptr;
[c1d9b2a]48
49 VkInstance instance;
50 VkDebugUtilsMessengerEXT debugMessenger;
[fe5c3ba]51 VkSurfaceKHR surface; // TODO: Change the variable name to vulkanSurface
[90a424f]52 VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
[c1c2021]53 VkDevice device;
54
55 VkQueue graphicsQueue;
56 VkQueue presentQueue;
[0df3c9a]57
[502bd0b]58 VkSwapchainKHR swapChain;
59 vector<VkImage> swapChainImages;
60 VkFormat swapChainImageFormat;
[603b5bc]61 VkExtent2D swapChainExtent;
[f94eea9]62 vector<VkImageView> swapChainImageViews;
[603b5bc]63 vector<VkFramebuffer> swapChainFramebuffers;
[fa9fa1c]64
[6fc24c7]65 VkRenderPass renderPass;
[fa9fa1c]66 VkCommandPool commandPool;
[603b5bc]67 vector<VkCommandBuffer> commandBuffers;
[502bd0b]68
[603b5bc]69 VulkanImage depthImage;
[b794178]70
71 VkSampler textureSampler;
72
73 vector<VkDescriptorBufferInfo> uniformBufferInfoList;
74
75 // These are currently to store the MVP matrix
76 // I should figure out if it makes sense to use them for other uniforms in the future
77 // If not, I should rename them to better indicate their purpose.
78 // I should also decide if I can use these for all shaders, or if I need a separapte set of buffers for each one
79 vector<VkBuffer> uniformBuffers;
80 vector<VkDeviceMemory> uniformBuffersMemory;
81
82 VulkanImage floorTextureImage;
83 VkDescriptorImageInfo floorTextureImageDescriptor;
84
85 VulkanImage sdlOverlayImage;
86 VkDescriptorImageInfo sdlOverlayImageDescriptor;
87
[1f25a71]88 TTF_Font* font;
89 SDL_Texture* fontSDLTexture;
90
91 SDL_Texture* imageSDLTexture;
92
[34bdf3a]93 vector<VkSemaphore> imageAvailableSemaphores;
94 vector<VkSemaphore> renderFinishedSemaphores;
95 vector<VkFence> inFlightFences;
96
[87c8f1a]97 size_t currentFrame;
[e3bef3a]98 size_t numPlanes = 0; // temp
[87c8f1a]99
100 bool framebufferResized;
[0e09340]101
[b6e60b4]102 bool initWindow(int width, int height, unsigned char guiFlags);
[0df3c9a]103 void initVulkan();
104 void mainLoop();
[a0c5f28]105 void renderUI();
106 void renderScene();
[0df3c9a]107 void cleanup();
[c1d9b2a]108
109 void createVulkanInstance(const vector<const char*> &validationLayers);
110 void setupDebugMessenger();
111 void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo);
[90a424f]112 void createVulkanSurface();
[fe5c3ba]113 void pickPhysicalDevice(const vector<const char*>& deviceExtensions);
[fa9fa1c]114 bool isDeviceSuitable(VkPhysicalDevice physicalDevice, const vector<const char*>& deviceExtensions);
[c1c2021]115 void createLogicalDevice(
116 const vector<const char*> validationLayers,
117 const vector<const char*>& deviceExtensions);
[502bd0b]118 void createSwapChain();
[f94eea9]119 void createImageViews();
[6fc24c7]120 void createRenderPass();
121 VkFormat findDepthFormat();
[fa9fa1c]122 void createCommandPool();
[603b5bc]123 void createImageResources();
124
[b794178]125 void createTextureSampler();
[603b5bc]126 void createFramebuffers();
[b794178]127 void createUniformBuffers();
[603b5bc]128 void createCommandBuffers();
[34bdf3a]129 void createSyncObjects();
[f94eea9]130
[d2d9286]131 void recreateSwapChain();
[f985231]132 void updateUniformBuffer(uint32_t currentImage);
[d2d9286]133
[c1c2021]134 void cleanupSwapChain();
[c1d9b2a]135
136 static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
137 VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
138 VkDebugUtilsMessageTypeFlagsEXT messageType,
139 const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
140 void* pUserData);
[e8ebc76]141};
142
[99d44b2]143#endif // _VULKAN_GAME_H
Note: See TracBrowser for help on using the repository browser.