source: opengl-game/vulkan-game.hpp@ 683dd55

feature/imgui-sdl points-test
Last change on this file since 683dd55 was 683dd55, checked in by Dmitry Portnoy <dmp1488@…>, 5 years ago

Add a getObjects() method to the GraphicsPipeline_Vulkan class that returns a reference to the list of objects added to the pipeline, and use that method instead of the numPlanes variable to keep track of the number of textured planes. Also, update the shader compilation batch file and add header files as dependencies to the vulkangame target in the makefile.

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