source: opengl-game/vulkan-game.hpp@ 15104a8

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

In vulkangame, nitialize the view and projection metrices to what they were in the original OpenGL game

  • 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 size_t numPlanes = 0; // temp
116
117 bool framebufferResized;
118
119 bool initWindow(int width, int height, unsigned char guiFlags);
120 void initVulkan();
121 void initMatrices();
122 void mainLoop();
123 void renderUI();
124 void renderScene();
125 void cleanup();
126
127 void createVulkanInstance(const vector<const char*> &validationLayers);
128 void setupDebugMessenger();
129 void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo);
130 void createVulkanSurface();
131 void pickPhysicalDevice(const vector<const char*>& deviceExtensions);
132 bool isDeviceSuitable(VkPhysicalDevice physicalDevice, const vector<const char*>& deviceExtensions);
133 void createLogicalDevice(
134 const vector<const char*> validationLayers,
135 const vector<const char*>& deviceExtensions);
136 void createSwapChain();
137 void createImageViews();
138 void createRenderPass();
139 VkFormat findDepthFormat();
140 void createCommandPool();
141 void createImageResources();
142
143 void createTextureSampler();
144 void createFramebuffers();
145 void createUniformBuffers();
146 void createCommandBuffers();
147 void createSyncObjects();
148
149 void recreateSwapChain();
150 void updateUniformBuffer(uint32_t currentImage);
151
152 void cleanupSwapChain();
153
154 static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
155 VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
156 VkDebugUtilsMessageTypeFlagsEXT messageType,
157 const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
158 void* pUserData);
159};
160
161#endif // _VULKAN_GAME_H
Note: See TracBrowser for help on using the repository browser.