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

feature/imgui-sdl points-test
Last change on this file since 1908591 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
RevLine 
[99d44b2]1#ifndef _VULKAN_GAME_H
2#define _VULKAN_GAME_H
[e8ebc76]3
[771b33a]4#include <glm/glm.hpp>
[15104a8]5#include <glm/gtc/matrix_transform.hpp>
[771b33a]6
[0df3c9a]7#include "game-gui-sdl.hpp"
[7d2b0b9]8#include "graphics-pipeline_vulkan.hpp"
[0df3c9a]9
[b794178]10#include "vulkan-utils.hpp"
11
[15104a8]12using namespace glm;
13
[2e77b3f]14#ifdef NDEBUG
15 const bool ENABLE_VALIDATION_LAYERS = false;
16#else
17 const bool ENABLE_VALIDATION_LAYERS = true;
18#endif
19
[b8777b7]20struct ModelVertex {
[15104a8]21 vec3 pos;
22 vec3 color;
23 vec2 texCoord;
[771b33a]24};
25
26struct OverlayVertex {
[15104a8]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;
[771b33a]35};
36
[99d44b2]37class VulkanGame {
[e8ebc76]38 public:
[34bdf3a]39 VulkanGame(int maxFramesInFlight);
[99d44b2]40 ~VulkanGame();
[0df3c9a]41
[b6e60b4]42 void run(int width, int height, unsigned char guiFlags);
[0df3c9a]43
44 private:
[34bdf3a]45 const int MAX_FRAMES_IN_FLIGHT;
46
[5ab1b20]47 const float NEAR_CLIP = 0.1f;
48 const float FAR_CLIP = 100.0f;
49 const float FOV_ANGLE = 67.0f;
50
[15104a8]51 vec3 cam_pos;
52
53 UniformBufferObject ubo;
54
[0df3c9a]55 GameGui* gui;
[c559904]56
[b8777b7]57 GraphicsPipeline_Vulkan<ModelVertex> modelPipeline;
58 GraphicsPipeline_Vulkan<OverlayVertex> overlayPipeline;
[7d2b0b9]59
[c559904]60 SDL_version sdlVersion;
[b794178]61 SDL_Window* window = nullptr;
62 SDL_Renderer* renderer = nullptr;
63
64 SDL_Texture* uiOverlay = nullptr;
[c1d9b2a]65
66 VkInstance instance;
67 VkDebugUtilsMessengerEXT debugMessenger;
[fe5c3ba]68 VkSurfaceKHR surface; // TODO: Change the variable name to vulkanSurface
[90a424f]69 VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
[c1c2021]70 VkDevice device;
71
72 VkQueue graphicsQueue;
73 VkQueue presentQueue;
[0df3c9a]74
[502bd0b]75 VkSwapchainKHR swapChain;
76 vector<VkImage> swapChainImages;
77 VkFormat swapChainImageFormat;
[603b5bc]78 VkExtent2D swapChainExtent;
[f94eea9]79 vector<VkImageView> swapChainImageViews;
[603b5bc]80 vector<VkFramebuffer> swapChainFramebuffers;
[fa9fa1c]81
[6fc24c7]82 VkRenderPass renderPass;
[fa9fa1c]83 VkCommandPool commandPool;
[603b5bc]84 vector<VkCommandBuffer> commandBuffers;
[502bd0b]85
[603b5bc]86 VulkanImage depthImage;
[b794178]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
[1f25a71]105 TTF_Font* font;
106 SDL_Texture* fontSDLTexture;
107
108 SDL_Texture* imageSDLTexture;
109
[34bdf3a]110 vector<VkSemaphore> imageAvailableSemaphores;
111 vector<VkSemaphore> renderFinishedSemaphores;
112 vector<VkFence> inFlightFences;
113
[87c8f1a]114 size_t currentFrame;
[e3bef3a]115 size_t numPlanes = 0; // temp
[87c8f1a]116
117 bool framebufferResized;
[0e09340]118
[b6e60b4]119 bool initWindow(int width, int height, unsigned char guiFlags);
[0df3c9a]120 void initVulkan();
[15104a8]121 void initMatrices();
[0df3c9a]122 void mainLoop();
[a0c5f28]123 void renderUI();
124 void renderScene();
[0df3c9a]125 void cleanup();
[c1d9b2a]126
127 void createVulkanInstance(const vector<const char*> &validationLayers);
128 void setupDebugMessenger();
129 void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo);
[90a424f]130 void createVulkanSurface();
[fe5c3ba]131 void pickPhysicalDevice(const vector<const char*>& deviceExtensions);
[fa9fa1c]132 bool isDeviceSuitable(VkPhysicalDevice physicalDevice, const vector<const char*>& deviceExtensions);
[c1c2021]133 void createLogicalDevice(
134 const vector<const char*> validationLayers,
135 const vector<const char*>& deviceExtensions);
[502bd0b]136 void createSwapChain();
[f94eea9]137 void createImageViews();
[6fc24c7]138 void createRenderPass();
139 VkFormat findDepthFormat();
[fa9fa1c]140 void createCommandPool();
[603b5bc]141 void createImageResources();
142
[b794178]143 void createTextureSampler();
[603b5bc]144 void createFramebuffers();
[b794178]145 void createUniformBuffers();
[603b5bc]146 void createCommandBuffers();
[34bdf3a]147 void createSyncObjects();
[f94eea9]148
[d2d9286]149 void recreateSwapChain();
[f985231]150 void updateUniformBuffer(uint32_t currentImage);
[d2d9286]151
[c1c2021]152 void cleanupSwapChain();
[c1d9b2a]153
154 static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
155 VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
156 VkDebugUtilsMessageTypeFlagsEXT messageType,
157 const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
158 void* pUserData);
[e8ebc76]159};
160
[99d44b2]161#endif // _VULKAN_GAME_H
Note: See TracBrowser for help on using the repository browser.