Changeset 7865c5b in opengl-game for sdl-game.cpp
- Timestamp:
- Mar 17, 2021, 12:50:49 AM (4 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- aa7e5f0
- Parents:
- 85b5fec
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sdl-game.cpp
r85b5fec r7865c5b 40 40 } 41 41 42 VulkanGame::VulkanGame() { 43 // TODO: Double-check whether initialization should happen in the header, where the variables are declared, or here 44 // Also, decide whether to use this-> for all instance variables, or only when necessary 45 46 debugMessenger = VK_NULL_HANDLE; 47 48 gui = nullptr; 49 window = nullptr; 50 51 swapChainPresentMode = VK_PRESENT_MODE_MAX_ENUM_KHR; 52 swapChainMinImageCount = 0; 53 currentFrame = 0; 54 imageIndex = 0; 55 shouldRecreateSwapChain = false; 56 57 score = 0; 58 fps = 0.0f; 42 VulkanGame::VulkanGame() 43 : swapChainImageCount(0) 44 , swapChainMinImageCount(0) 45 , swapChainSurfaceFormat({}) 46 , swapChainPresentMode(VK_PRESENT_MODE_MAX_ENUM_KHR) 47 , swapChainExtent{ 0, 0 } 48 , swapChain(VK_NULL_HANDLE) 49 , vulkanSurface(VK_NULL_HANDLE) 50 , sdlVersion({ 0, 0, 0 }) 51 , instance(VK_NULL_HANDLE) 52 , physicalDevice(VK_NULL_HANDLE) 53 , device(VK_NULL_HANDLE) 54 , debugMessenger(VK_NULL_HANDLE) 55 , resourceCommandPool(VK_NULL_HANDLE) 56 , renderPass(VK_NULL_HANDLE) 57 , graphicsQueue(VK_NULL_HANDLE) 58 , presentQueue(VK_NULL_HANDLE) 59 , depthImage({}) 60 , shouldRecreateSwapChain(false) 61 , frameCount(0) 62 , currentFrame() 63 , imageIndex(0) 64 , fpsStartTime(0.0f) 65 , curTime(0.0f) 66 , done(false) 67 , currentRenderScreenFn(nullptr) 68 , descriptorPool(VK_NULL_HANDLE) 69 , gui(nullptr) 70 , window(nullptr) 71 , score(0) 72 , fps(0.0f) { 59 73 } 60 74 … … 104 118 105 119 // TODO: Do this in one place and save it instead of redoing it every time I need a queue family index 106 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);120 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface); 107 121 108 122 // Setup Dear ImGui context … … 376 390 377 391 vkDestroyDevice(device, nullptr); 378 vkDestroySurfaceKHR(instance, surface, nullptr);392 vkDestroySurfaceKHR(instance, vulkanSurface, nullptr); 379 393 380 394 if (ENABLE_VALIDATION_LAYERS) { … … 461 475 462 476 void VulkanGame::createVulkanSurface() { 463 if (gui->createVulkanSurface(instance, & surface) == RTWO_ERROR) {477 if (gui->createVulkanSurface(instance, &vulkanSurface) == RTWO_ERROR) { 464 478 throw runtime_error("failed to create window surface!"); 465 479 } … … 507 521 } 508 522 509 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);523 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface); 510 524 bool extensionsSupported = VulkanUtils::checkDeviceExtensionSupport(physicalDevice, deviceExtensions); 511 525 bool swapChainAdequate = false; 512 526 513 527 if (extensionsSupported) { 514 vector<VkSurfaceFormatKHR> formats = VulkanUtils::querySwapChainFormats(physicalDevice, surface);515 vector<VkPresentModeKHR> presentModes = VulkanUtils::querySwapChainPresentModes(physicalDevice, surface);528 vector<VkSurfaceFormatKHR> formats = VulkanUtils::querySwapChainFormats(physicalDevice, vulkanSurface); 529 vector<VkPresentModeKHR> presentModes = VulkanUtils::querySwapChainPresentModes(physicalDevice, vulkanSurface); 516 530 517 531 swapChainAdequate = !formats.empty() && !presentModes.empty(); … … 526 540 void VulkanGame::createLogicalDevice(const vector<const char*>& validationLayers, 527 541 const vector<const char*>& deviceExtensions) { 528 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);542 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface); 529 543 530 544 if (!indices.isComplete()) { … … 582 596 583 597 void VulkanGame::chooseSwapChainProperties() { 584 vector<VkSurfaceFormatKHR> availableFormats = VulkanUtils::querySwapChainFormats(physicalDevice, surface);585 vector<VkPresentModeKHR> availablePresentModes = VulkanUtils::querySwapChainPresentModes(physicalDevice, surface);598 vector<VkSurfaceFormatKHR> availableFormats = VulkanUtils::querySwapChainFormats(physicalDevice, vulkanSurface); 599 vector<VkPresentModeKHR> availablePresentModes = VulkanUtils::querySwapChainPresentModes(physicalDevice, vulkanSurface); 586 600 587 601 // Per Spec Format and View Format are expected to be the same unless VK_IMAGE_CREATE_MUTABLE_BIT was set at image creation … … 605 619 cout << "[vulkan] Selected PresentMode = " << swapChainPresentMode << endl; 606 620 607 VkSurfaceCapabilitiesKHR capabilities = VulkanUtils::querySwapChainCapabilities(physicalDevice, surface);621 VkSurfaceCapabilitiesKHR capabilities = VulkanUtils::querySwapChainCapabilities(physicalDevice, vulkanSurface); 608 622 609 623 // If min image count was not specified, request different count of images dependent on selected present mode … … 632 646 633 647 void VulkanGame::createSwapChain() { 634 VkSurfaceCapabilitiesKHR capabilities = VulkanUtils::querySwapChainCapabilities(physicalDevice, surface);648 VkSurfaceCapabilitiesKHR capabilities = VulkanUtils::querySwapChainCapabilities(physicalDevice, vulkanSurface); 635 649 636 650 swapChainExtent = VulkanUtils::chooseSwapExtent(capabilities, gui->getWindowWidth(), gui->getWindowHeight()); … … 638 652 VkSwapchainCreateInfoKHR createInfo = {}; 639 653 createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; 640 createInfo.surface = surface;654 createInfo.surface = vulkanSurface; 641 655 createInfo.minImageCount = swapChainMinImageCount; 642 656 createInfo.imageFormat = swapChainSurfaceFormat.format; … … 647 661 648 662 // TODO: Maybe save this result so I don't have to recalculate it every time 649 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);663 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface); 650 664 uint32_t queueFamilyIndices[] = { indices.graphicsFamily.value(), indices.presentFamily.value() }; 651 665 … … 762 776 763 777 void VulkanGame::createResourceCommandPool() { 764 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);778 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface); 765 779 766 780 VkCommandPoolCreateInfo poolInfo = {}; … … 777 791 commandPools.resize(swapChainImageCount); 778 792 779 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);793 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface); 780 794 781 795 for (size_t i = 0; i < swapChainImageCount; i++) {
Note:
See TracChangeset
for help on using the changeset viewer.