source: opengl-game/vulkan-game.hpp@ 8e02b6b

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

To move to a more generic way of updating the scene, rename updateUniformBuffers() to updateScene() in VulkanGame and move the code to copy the data into a new copyDataToMemory() function in VulkanUtils.

  • 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
[8e02b6b]31struct UBO_MvpMat {
[15104a8]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
[8e02b6b]53 UBO_MvpMat modelMvpMats;
[15104a8]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;
115
116 bool framebufferResized;
[0e09340]117
[b6e60b4]118 bool initWindow(int width, int height, unsigned char guiFlags);
[0df3c9a]119 void initVulkan();
[15104a8]120 void initMatrices();
[0df3c9a]121 void mainLoop();
[8e02b6b]122 void updateScene(uint32_t currentImage);
[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();
150
[c1c2021]151 void cleanupSwapChain();
[c1d9b2a]152
153 static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
154 VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
155 VkDebugUtilsMessageTypeFlagsEXT messageType,
156 const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
157 void* pUserData);
[e8ebc76]158};
159
[99d44b2]160#endif // _VULKAN_GAME_H
Note: See TracBrowser for help on using the repository browser.