Changeset 34bdf3a in opengl-game for vulkan-game.cpp


Ignore:
Timestamp:
Oct 24, 2019, 3:35:49 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
87c8f1a
Parents:
603b5bc
Message:

In vulkangame, create Vulkan synchronization objects for rendering

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.cpp

    r603b5bc r34bdf3a  
    1818};
    1919
    20 VulkanGame::VulkanGame() {
     20VulkanGame::VulkanGame(int maxFramesInFlight) : MAX_FRAMES_IN_FLIGHT(maxFramesInFlight) {
    2121   gui = nullptr;
    2222   window = nullptr;
     
    169169   graphicsPipelines.back().createDescriptorSets(swapChainImages);
    170170
    171    createCommandBuffers();
    172 
    173171   // TODO: Creating the descriptor pool and descriptor sets might need to be redone when the
    174172   // swap chain is recreated
    175173
    176174   cout << "Created " << graphicsPipelines.size() << " graphics pipelines" << endl;
     175
     176   createCommandBuffers();
     177
     178   createSyncObjects();
    177179}
    178180
     
    250252   }
    251253
     254   for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
     255      vkDestroySemaphore(device, renderFinishedSemaphores[i], nullptr);
     256      vkDestroySemaphore(device, imageAvailableSemaphores[i], nullptr);
     257      vkDestroyFence(device, inFlightFences[i], nullptr);
     258   }
     259
    252260   vkDestroyCommandPool(device, commandPool, nullptr);
    253261   vkDestroyDevice(device, nullptr);
     
    741749}
    742750
     751void VulkanGame::createSyncObjects() {
     752   imageAvailableSemaphores.resize(MAX_FRAMES_IN_FLIGHT);
     753   renderFinishedSemaphores.resize(MAX_FRAMES_IN_FLIGHT);
     754   inFlightFences.resize(MAX_FRAMES_IN_FLIGHT);
     755
     756   VkSemaphoreCreateInfo semaphoreInfo = {};
     757   semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
     758
     759   VkFenceCreateInfo fenceInfo = {};
     760   fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
     761   fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
     762
     763   for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
     764      if (vkCreateSemaphore(device, &semaphoreInfo, nullptr, &imageAvailableSemaphores[i]) != VK_SUCCESS ||
     765            vkCreateSemaphore(device, &semaphoreInfo, nullptr, &renderFinishedSemaphores[i]) != VK_SUCCESS ||
     766            vkCreateFence(device, &fenceInfo, nullptr, &inFlightFences[i]) != VK_SUCCESS) {
     767         throw runtime_error("failed to create synchronization objects for a frame!");
     768      }
     769   }
     770}
     771
    743772void VulkanGame::cleanupSwapChain() {
    744773   VulkanUtils::destroyVulkanImage(device, depthImage);
Note: See TracChangeset for help on using the changeset viewer.