source: opengl-game/vulkan-game.hpp@ 603b5bc

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

In vulkangame, add code to create the frame buffers and command buffers

  • Property mode set to 100644
File size: 3.7 KB
Line 
1#ifndef _VULKAN_GAME_H
2#define _VULKAN_GAME_H
3
4#include <glm/glm.hpp>
5
6#include "game-gui-sdl.hpp"
7#include "graphics-pipeline_vulkan.hpp"
8
9#include "vulkan-utils.hpp"
10
11#ifdef NDEBUG
12 const bool ENABLE_VALIDATION_LAYERS = false;
13#else
14 const bool ENABLE_VALIDATION_LAYERS = true;
15#endif
16
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
30class VulkanGame {
31 public:
32 VulkanGame();
33 ~VulkanGame();
34
35 void run(int width, int height, unsigned char guiFlags);
36
37 private:
38 GameGui* gui;
39
40 vector<GraphicsPipeline_Vulkan> graphicsPipelines;
41
42 SDL_version sdlVersion;
43 SDL_Window* window = nullptr;
44 SDL_Renderer* renderer = nullptr;
45
46 SDL_Texture* uiOverlay = nullptr;
47
48 VkInstance instance;
49 VkDebugUtilsMessengerEXT debugMessenger;
50 VkSurfaceKHR surface; // TODO: Change the variable name to vulkanSurface
51 VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
52 VkDevice device;
53
54 VkQueue graphicsQueue;
55 VkQueue presentQueue;
56
57 VkSwapchainKHR swapChain;
58 vector<VkImage> swapChainImages;
59 VkFormat swapChainImageFormat;
60 VkExtent2D swapChainExtent;
61 vector<VkImageView> swapChainImageViews;
62 vector<VkFramebuffer> swapChainFramebuffers;
63
64 VkRenderPass renderPass;
65 VkCommandPool commandPool;
66 vector<VkCommandBuffer> commandBuffers;
67
68 VulkanImage depthImage;
69
70 VkSampler textureSampler;
71
72 vector<VkDescriptorBufferInfo> uniformBufferInfoList;
73
74 // These are currently to store the MVP matrix
75 // I should figure out if it makes sense to use them for other uniforms in the future
76 // If not, I should rename them to better indicate their purpose.
77 // I should also decide if I can use these for all shaders, or if I need a separapte set of buffers for each one
78 vector<VkBuffer> uniformBuffers;
79 vector<VkDeviceMemory> uniformBuffersMemory;
80
81 VulkanImage floorTextureImage;
82 VkDescriptorImageInfo floorTextureImageDescriptor;
83
84 VulkanImage sdlOverlayImage;
85 VkDescriptorImageInfo sdlOverlayImageDescriptor;
86
87 bool framebufferResized = false;
88
89 bool initWindow(int width, int height, unsigned char guiFlags);
90 void initVulkan();
91 void mainLoop();
92 void renderUI();
93 void renderScene();
94 void cleanup();
95
96 void createVulkanInstance(const vector<const char*> &validationLayers);
97 void setupDebugMessenger();
98 void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo);
99 void createVulkanSurface();
100 void pickPhysicalDevice(const vector<const char*>& deviceExtensions);
101 bool isDeviceSuitable(VkPhysicalDevice physicalDevice, const vector<const char*>& deviceExtensions);
102 void createLogicalDevice(
103 const vector<const char*> validationLayers,
104 const vector<const char*>& deviceExtensions);
105 void createSwapChain();
106 void createImageViews();
107 void createRenderPass();
108 VkFormat findDepthFormat();
109 void createCommandPool();
110 void createImageResources();
111
112 void createTextureSampler();
113 void createFramebuffers();
114 void createUniformBuffers();
115 void createCommandBuffers();
116
117 void cleanupSwapChain();
118
119 static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
120 VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
121 VkDebugUtilsMessageTypeFlagsEXT messageType,
122 const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
123 void* pUserData);
124};
125
126#endif // _VULKAN_GAME_H
Note: See TracBrowser for help on using the repository browser.