Changeset 7865c5b in opengl-game for vulkan-game.cpp
- Timestamp:
- Mar 17, 2021, 12:50:49 AM (3 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- aa7e5f0
- Parents:
- 85b5fec
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
r85b5fec r7865c5b 50 50 } 51 51 52 VulkanGame::VulkanGame() { 53 // TODO: Double-check whether initialization should happen in the header, where the variables are declared, or here 54 // Also, decide whether to use this-> for all instance variables, or only when necessary 55 56 debugMessenger = VK_NULL_HANDLE; 57 58 gui = nullptr; 59 window = nullptr; 60 61 swapChainPresentMode = VK_PRESENT_MODE_MAX_ENUM_KHR; 62 swapChainMinImageCount = 0; 63 currentFrame = 0; 64 imageIndex = 0; 65 shouldRecreateSwapChain = false; 66 52 VulkanGame::VulkanGame() 53 : swapChainImageCount(0) 54 , swapChainMinImageCount(0) 55 , swapChainSurfaceFormat({}) 56 , swapChainPresentMode(VK_PRESENT_MODE_MAX_ENUM_KHR) 57 , swapChainExtent{ 0, 0 } 58 , swapChain(VK_NULL_HANDLE) 59 , vulkanSurface(VK_NULL_HANDLE) 60 , sdlVersion({ 0, 0, 0 }) 61 , instance(VK_NULL_HANDLE) 62 , physicalDevice(VK_NULL_HANDLE) 63 , device(VK_NULL_HANDLE) 64 , debugMessenger(VK_NULL_HANDLE) 65 , resourceCommandPool(VK_NULL_HANDLE) 66 , renderPass(VK_NULL_HANDLE) 67 , graphicsQueue(VK_NULL_HANDLE) 68 , presentQueue(VK_NULL_HANDLE) 69 , depthImage({}) 70 , shouldRecreateSwapChain(false) 71 , frameCount(0) 72 , currentFrame() 73 , imageIndex(0) 74 , fpsStartTime(0.0f) 75 , curTime(0.0f) 76 , done(false) 77 , currentRenderScreenFn(nullptr) 78 , gui(nullptr) 79 , window(nullptr) 80 , score(0) 81 , fps(0.0f) { 67 82 object_VP_mats = {}; 68 83 ship_VP_mats = {}; … … 70 85 laser_VP_mats = {}; 71 86 explosion_UBO = {}; 72 73 score = 0;74 fps = 0.0f;75 87 } 76 88 … … 205 217 206 218 // TODO: Maybe call this once and save the results since it's also called when creating the logical device 207 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);219 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface); 208 220 209 221 ImGui_ImplSDL2_InitForVulkan(window); … … 1149 1161 1150 1162 vkDestroyDevice(device, nullptr); 1151 vkDestroySurfaceKHR(instance, surface, nullptr);1163 vkDestroySurfaceKHR(instance, vulkanSurface, nullptr); 1152 1164 1153 1165 if (ENABLE_VALIDATION_LAYERS) { … … 1244 1256 1245 1257 void VulkanGame::createVulkanSurface() { 1246 if (gui->createVulkanSurface(instance, & surface) == RTWO_ERROR) {1258 if (gui->createVulkanSurface(instance, &vulkanSurface) == RTWO_ERROR) { 1247 1259 throw runtime_error("failed to create window surface!"); 1248 1260 } … … 1290 1302 } 1291 1303 1292 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);1304 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface); 1293 1305 bool extensionsSupported = VulkanUtils::checkDeviceExtensionSupport(physicalDevice, deviceExtensions); 1294 1306 bool swapChainAdequate = false; 1295 1307 1296 1308 if (extensionsSupported) { 1297 vector<VkSurfaceFormatKHR> formats = VulkanUtils::querySwapChainFormats(physicalDevice, surface);1298 vector<VkPresentModeKHR> presentModes = VulkanUtils::querySwapChainPresentModes(physicalDevice, surface);1309 vector<VkSurfaceFormatKHR> formats = VulkanUtils::querySwapChainFormats(physicalDevice, vulkanSurface); 1310 vector<VkPresentModeKHR> presentModes = VulkanUtils::querySwapChainPresentModes(physicalDevice, vulkanSurface); 1299 1311 1300 1312 swapChainAdequate = !formats.empty() && !presentModes.empty(); … … 1309 1321 void VulkanGame::createLogicalDevice(const vector<const char*>& validationLayers, 1310 1322 const vector<const char*>& deviceExtensions) { 1311 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);1323 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface); 1312 1324 1313 1325 if (!indices.isComplete()) { … … 1364 1376 1365 1377 void VulkanGame::chooseSwapChainProperties() { 1366 vector<VkSurfaceFormatKHR> availableFormats = VulkanUtils::querySwapChainFormats(physicalDevice, surface);1367 vector<VkPresentModeKHR> availablePresentModes = VulkanUtils::querySwapChainPresentModes(physicalDevice, surface);1378 vector<VkSurfaceFormatKHR> availableFormats = VulkanUtils::querySwapChainFormats(physicalDevice, vulkanSurface); 1379 vector<VkPresentModeKHR> availablePresentModes = VulkanUtils::querySwapChainPresentModes(physicalDevice, vulkanSurface); 1368 1380 1369 1381 swapChainSurfaceFormat = VulkanUtils::chooseSwapSurfaceFormat(availableFormats, … … 1380 1392 cout << "[vulkan] Selected PresentMode = " << swapChainPresentMode << endl; 1381 1393 1382 VkSurfaceCapabilitiesKHR capabilities = VulkanUtils::querySwapChainCapabilities(physicalDevice, surface);1394 VkSurfaceCapabilitiesKHR capabilities = VulkanUtils::querySwapChainCapabilities(physicalDevice, vulkanSurface); 1383 1395 1384 1396 if (swapChainPresentMode == VK_PRESENT_MODE_MAILBOX_KHR) { … … 1400 1412 1401 1413 void VulkanGame::createSwapChain() { 1402 VkSurfaceCapabilitiesKHR capabilities = VulkanUtils::querySwapChainCapabilities(physicalDevice, surface);1414 VkSurfaceCapabilitiesKHR capabilities = VulkanUtils::querySwapChainCapabilities(physicalDevice, vulkanSurface); 1403 1415 1404 1416 swapChainExtent = VulkanUtils::chooseSwapExtent(capabilities, gui->getWindowWidth(), gui->getWindowHeight()); … … 1406 1418 VkSwapchainCreateInfoKHR createInfo = {}; 1407 1419 createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; 1408 createInfo.surface = surface;1420 createInfo.surface = vulkanSurface; 1409 1421 createInfo.minImageCount = swapChainMinImageCount; 1410 1422 createInfo.imageFormat = swapChainSurfaceFormat.format; … … 1415 1427 1416 1428 // TODO: Maybe save this result so I don't have to recalculate it every time 1417 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);1429 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface); 1418 1430 uint32_t queueFamilyIndices[] = { indices.graphicsFamily.value(), indices.presentFamily.value() }; 1419 1431 … … 1525 1537 1526 1538 void VulkanGame::createResourceCommandPool() { 1527 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);1539 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface); 1528 1540 1529 1541 VkCommandPoolCreateInfo poolInfo = {}; … … 1540 1552 commandPools.resize(swapChainImageCount); 1541 1553 1542 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);1554 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface); 1543 1555 1544 1556 for (size_t i = 0; i < swapChainImageCount; i++) {
Note:
See TracChangeset
for help on using the changeset viewer.