source: opengl-game/vulkan-game.hpp@ e83b155

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

In vulkangame, add the ability to create vulkan resoirces and descriptor sets for shader uniforms (images and ubos)

  • Property mode set to 100644
File size: 3.6 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
[771b33a]17// TODO: Figure out if these structs should be defined in the VulkanGame class
18
19struct Vertex {
20 glm::vec3 pos;
21 glm::vec3 color;
22 glm::vec2 texCoord;
23};
24
25struct OverlayVertex {
26 glm::vec3 pos;
27 glm::vec2 texCoord;
28};
29
[99d44b2]30class VulkanGame {
[e8ebc76]31 public:
[99d44b2]32 VulkanGame();
33 ~VulkanGame();
[0df3c9a]34
[b6e60b4]35 void run(int width, int height, unsigned char guiFlags);
[0df3c9a]36
37 private:
38 GameGui* gui;
[771b33a]39 Viewport viewport;
[c559904]40
[7d2b0b9]41 vector<GraphicsPipeline_Vulkan> graphicsPipelines;
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;
[f94eea9]61 vector<VkImageView> swapChainImageViews;
[fa9fa1c]62
[6fc24c7]63 VkRenderPass renderPass;
[fa9fa1c]64 VkCommandPool commandPool;
[502bd0b]65
[b794178]66 // TODO: Create these (and wrap them inside a VulkanImage)
67 VkImage depthImage;
68 VkDeviceMemory depthImageMemory;
69 VkImageView depthImageView;
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
[0e09340]88 bool framebufferResized = false;
89
[b6e60b4]90 bool initWindow(int width, int height, unsigned char guiFlags);
[0df3c9a]91 void initVulkan();
92 void mainLoop();
[a0c5f28]93 void renderUI();
94 void renderScene();
[0df3c9a]95 void cleanup();
[c1d9b2a]96
97 void createVulkanInstance(const vector<const char*> &validationLayers);
98 void setupDebugMessenger();
99 void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo);
[90a424f]100 void createVulkanSurface();
[fe5c3ba]101 void pickPhysicalDevice(const vector<const char*>& deviceExtensions);
[fa9fa1c]102 bool isDeviceSuitable(VkPhysicalDevice physicalDevice, const vector<const char*>& deviceExtensions);
[c1c2021]103 void createLogicalDevice(
104 const vector<const char*> validationLayers,
105 const vector<const char*>& deviceExtensions);
[502bd0b]106 void createSwapChain();
[f94eea9]107 void createImageViews();
[6fc24c7]108 void createRenderPass();
109 VkFormat findDepthFormat();
[fa9fa1c]110 void createCommandPool();
[b794178]111 void createVulkanResources();
112 void createTextureSampler();
113 void createUniformBuffers();
[f94eea9]114
[c1c2021]115 void cleanupSwapChain();
[c1d9b2a]116
117 static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
118 VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
119 VkDebugUtilsMessageTypeFlagsEXT messageType,
120 const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
121 void* pUserData);
[e8ebc76]122};
123
[99d44b2]124#endif // _VULKAN_GAME_H
Note: See TracBrowser for help on using the repository browser.