Changeset 7865c5b in opengl-game for vulkan-game.cpp


Ignore:
Timestamp:
Mar 17, 2021, 12:50:49 AM (3 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
aa7e5f0
Parents:
85b5fec
Message:

Rename surface to vulkanSurface and add an initializer list to the VulkanGame constructor

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.cpp

    r85b5fec r7865c5b  
    5050}
    5151
    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 
     52VulkanGame::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) {
    6782   object_VP_mats = {};
    6883   ship_VP_mats = {};
     
    7085   laser_VP_mats = {};
    7186   explosion_UBO = {};
    72 
    73    score = 0;
    74    fps = 0.0f;
    7587}
    7688
     
    205217
    206218   // 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);
    208220
    209221   ImGui_ImplSDL2_InitForVulkan(window);
     
    11491161
    11501162   vkDestroyDevice(device, nullptr);
    1151    vkDestroySurfaceKHR(instance, surface, nullptr);
     1163   vkDestroySurfaceKHR(instance, vulkanSurface, nullptr);
    11521164
    11531165   if (ENABLE_VALIDATION_LAYERS) {
     
    12441256
    12451257void VulkanGame::createVulkanSurface() {
    1246    if (gui->createVulkanSurface(instance, &surface) == RTWO_ERROR) {
     1258   if (gui->createVulkanSurface(instance, &vulkanSurface) == RTWO_ERROR) {
    12471259      throw runtime_error("failed to create window surface!");
    12481260   }
     
    12901302   }
    12911303
    1292    QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);
     1304   QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface);
    12931305   bool extensionsSupported = VulkanUtils::checkDeviceExtensionSupport(physicalDevice, deviceExtensions);
    12941306   bool swapChainAdequate = false;
    12951307
    12961308   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);
    12991311
    13001312      swapChainAdequate = !formats.empty() && !presentModes.empty();
     
    13091321void VulkanGame::createLogicalDevice(const vector<const char*>& validationLayers,
    13101322      const vector<const char*>& deviceExtensions) {
    1311    QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);
     1323   QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface);
    13121324
    13131325   if (!indices.isComplete()) {
     
    13641376
    13651377void 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);
    13681380
    13691381   swapChainSurfaceFormat = VulkanUtils::chooseSwapSurfaceFormat(availableFormats,
     
    13801392   cout << "[vulkan] Selected PresentMode = " << swapChainPresentMode << endl;
    13811393
    1382    VkSurfaceCapabilitiesKHR capabilities = VulkanUtils::querySwapChainCapabilities(physicalDevice, surface);
     1394   VkSurfaceCapabilitiesKHR capabilities = VulkanUtils::querySwapChainCapabilities(physicalDevice, vulkanSurface);
    13831395
    13841396   if (swapChainPresentMode == VK_PRESENT_MODE_MAILBOX_KHR) {
     
    14001412
    14011413void VulkanGame::createSwapChain() {
    1402    VkSurfaceCapabilitiesKHR capabilities = VulkanUtils::querySwapChainCapabilities(physicalDevice, surface);
     1414   VkSurfaceCapabilitiesKHR capabilities = VulkanUtils::querySwapChainCapabilities(physicalDevice, vulkanSurface);
    14031415
    14041416   swapChainExtent = VulkanUtils::chooseSwapExtent(capabilities, gui->getWindowWidth(), gui->getWindowHeight());
     
    14061418   VkSwapchainCreateInfoKHR createInfo = {};
    14071419   createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
    1408    createInfo.surface = surface;
     1420   createInfo.surface = vulkanSurface;
    14091421   createInfo.minImageCount = swapChainMinImageCount;
    14101422   createInfo.imageFormat = swapChainSurfaceFormat.format;
     
    14151427
    14161428   // 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);
    14181430   uint32_t queueFamilyIndices[] = { indices.graphicsFamily.value(), indices.presentFamily.value() };
    14191431
     
    15251537
    15261538void VulkanGame::createResourceCommandPool() {
    1527    QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);
     1539   QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface);
    15281540
    15291541   VkCommandPoolCreateInfo poolInfo = {};
     
    15401552   commandPools.resize(swapChainImageCount);
    15411553
    1542    QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);
     1554   QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface);
    15431555
    15441556   for (size_t i = 0; i < swapChainImageCount; i++) {
Note: See TracChangeset for help on using the changeset viewer.