Changeset c324d6a in opengl-game for vulkan-game.cpp
- Timestamp:
- Jan 2, 2021, 4:07:45 PM (4 years ago)
- Branches:
- feature/imgui-sdl, master
- Children:
- 3b7d497, ca188cc
- Parents:
- a2f62d7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
ra2f62d7 rc324d6a 5 5 #include <numeric> 6 6 #include <set> 7 8 #include "consts.hpp" 7 #include <stdexcept> 8 9 9 #include "logger.hpp" 10 10 … … 16 16 using namespace std; 17 17 18 // TODO: Update all occurances of instance variables to use this-> 18 // TODO: Update all occurances of instance variables to use this-> (Actually, not sure if I really want to do this) 19 20 /* TODO: Try doing the following tasks based on the Vulkan implementation of IMGUI (Also maybe looks at Sascha Willems' code to see how he does these things) 21 * 22 * - When recreating the swapchain, pass the old one in and destroy the old one after the new one is created 23 * - Recreate semaphores when recreating the swapchain 24 * - imgui uses one image acquired and one render complete sem and once fence per frame\ 25 * - IMGUI creates one command pool per framebuffer 26 */ 19 27 20 28 VulkanGame::VulkanGame(int maxFramesInFlight) : MAX_FRAMES_IN_FLIGHT(maxFramesInFlight) { 21 29 this->gui = nullptr; 22 30 this->window = nullptr; 31 32 this->debugMessenger = VK_NULL_HANDLE; 23 33 24 34 this->currentFrame = 0; … … 85 95 86 96 // TODO: Refactor the logger api to be more flexible, 87 // esp. since gl_log() and gl_log_err() have issues printing anything besides st irngs97 // esp. since gl_log() and gl_log_err() have issues printing anything besides strings 88 98 restart_gl_log(); 89 99 gl_log("starting SDL\n%s.%s.%s", … … 93 103 94 104 // TODO: Use open_Log() and related functions instead of gl_log ones 105 // TODO: In addition, delete the gl_log functions 95 106 open_log(); 96 107 get_log() << "starting SDL" << endl; … … 807 818 } 808 819 820 // TODO: Should probably check the returned result 809 821 vkDeviceWaitIdle(device); 810 822 } … … 1131 1143 } 1132 1144 1133 void VulkanGame::createVulkanInstance(const vector<const char*> &validationLayers) {1145 void VulkanGame::createVulkanInstance(const vector<const char*>& validationLayers) { 1134 1146 if (ENABLE_VALIDATION_LAYERS && !VulkanUtils::checkValidationLayerSupport(validationLayers)) { 1135 1147 throw runtime_error("validation layers requested, but not available!"); … … 1181 1193 1182 1194 void VulkanGame::setupDebugMessenger() { 1183 if (!ENABLE_VALIDATION_LAYERS) return; 1195 if (!ENABLE_VALIDATION_LAYERS) { 1196 return; 1197 } 1184 1198 1185 1199 VkDebugUtilsMessengerCreateInfoEXT createInfo; … … 1217 1231 void VulkanGame::pickPhysicalDevice(const vector<const char*>& deviceExtensions) { 1218 1232 uint32_t deviceCount = 0; 1233 // TODO: Check VkResult 1219 1234 vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr); 1220 1235 … … 1224 1239 1225 1240 vector<VkPhysicalDevice> devices(deviceCount); 1241 // TODO: Check VkResult 1226 1242 vkEnumeratePhysicalDevices(instance, &deviceCount, devices.data()); 1227 1243 … … 1262 1278 } 1263 1279 1264 void VulkanGame::createLogicalDevice( 1265 const vector<const char*> validationLayers, const vector<const char*>& deviceExtensions) {1280 void VulkanGame::createLogicalDevice(const vector<const char*>& validationLayers, 1281 const vector<const char*>& deviceExtensions) { 1266 1282 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface); 1267 1283 … … 1285 1301 VkDeviceCreateInfo createInfo = {}; 1286 1302 createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; 1303 1287 1304 createInfo.queueCreateInfoCount = static_cast<uint32_t>(queueCreateInfoList.size()); 1288 1305 createInfo.pQueueCreateInfos = queueCreateInfoList.data(); … … 1317 1334 VkExtent2D extent = VulkanUtils::chooseSwapExtent(swapChainSupport.capabilities, gui->getWindowWidth(), gui->getWindowHeight()); 1318 1335 1319 uint32_t imageCount = swapChainSupport.capabilities.minImageCount + 1;1320 if (swapChainSupport.capabilities.maxImageCount > 0 && imageCount > swapChainSupport.capabilities.maxImageCount) {1321 imageCount = swapChainSupport.capabilities.maxImageCount;1336 swapChainImageCount = swapChainSupport.capabilities.minImageCount + 1; 1337 if (swapChainSupport.capabilities.maxImageCount > 0 && swapChainImageCount > swapChainSupport.capabilities.maxImageCount) { 1338 swapChainImageCount = swapChainSupport.capabilities.maxImageCount; 1322 1339 } 1323 1340 … … 1325 1342 createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; 1326 1343 createInfo.surface = surface; 1327 createInfo.minImageCount = imageCount;1344 createInfo.minImageCount = swapChainImageCount; 1328 1345 createInfo.imageFormat = surfaceFormat.format; 1329 1346 createInfo.imageColorSpace = surfaceFormat.colorSpace; … … 1355 1372 } 1356 1373 1357 vkGetSwapchainImagesKHR(device, swapChain, & imageCount, nullptr);1358 swapChainImages.resize( imageCount);1359 vkGetSwapchainImagesKHR(device, swapChain, & imageCount, swapChainImages.data());1374 vkGetSwapchainImagesKHR(device, swapChain, &swapChainImageCount, nullptr); 1375 swapChainImages.resize(swapChainImageCount); 1376 vkGetSwapchainImagesKHR(device, swapChain, &swapChainImageCount, swapChainImages.data()); 1360 1377 1361 1378 swapChainImageFormat = surfaceFormat.format;
Note:
See TracChangeset
for help on using the changeset viewer.