source: opengl-game/vulkan-game.hpp@ 5ab1b20

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

Make VulkanGame use the same projection matrix as the original OpenGL game

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