@@ -63,7 +63,7 @@ class HelloTriangleApplication {
6363 vk::raii::CommandBuffer commandBuffer = nullptr ;
6464
6565 vk::raii::Semaphore presentCompleteSemaphore = nullptr ;
66- std::vector< vk::raii::Semaphore> renderFinishedSemaphores ;
66+ vk::raii::Semaphore renderFinishedSemaphore = nullptr ;
6767 vk::raii::Fence drawFence = nullptr ;
6868
6969 std::vector<const char *> requiredDeviceExtension = {
@@ -106,6 +106,7 @@ class HelloTriangleApplication {
106106
107107 void cleanup () {
108108 glfwDestroyWindow (window);
109+
109110 glfwTerminate ();
110111 }
111112
@@ -449,36 +450,28 @@ class HelloTriangleApplication {
449450
450451 void createSyncObjects () {
451452 presentCompleteSemaphore =vk::raii::Semaphore (device, vk::SemaphoreCreateInfo ());
452- for (size_t i = 0 ; i < swapChainImages.size (); i++)
453- {
454- renderFinishedSemaphores.emplace_back (device, vk::SemaphoreCreateInfo ());
455- }
453+ renderFinishedSemaphore = vk::raii::Semaphore (device, vk::SemaphoreCreateInfo ());
456454 drawFence = vk::raii::Fence (device, {.flags = vk::FenceCreateFlagBits::eSignaled});
457455 }
458456
459457 void drawFrame () {
460- while (vk::Result::eTimeout == device.waitForFences (*drawFence, vk::True, UINT64_MAX))
461- ;
462- device.resetFences (*drawFence);
458+ queue.waitIdle (); // NOTE: for simplicity, wait for the queue to be idle before starting the frame
459+ // In the next chapter you see how to use multiple frames in flight and fences to sync
463460
464461 auto [result, imageIndex] = swapChain.acquireNextImage ( UINT64_MAX, *presentCompleteSemaphore, nullptr );
465462 recordCommandBuffer (imageIndex);
466463
464+ device.resetFences ( *drawFence );
467465 vk::PipelineStageFlags waitDestinationStageMask ( vk::PipelineStageFlagBits::eColorAttachmentOutput );
468- const vk::SubmitInfo submitInfo{ .waitSemaphoreCount = 1 ,
469- .pWaitSemaphores = &*presentCompleteSemaphore,
470- .pWaitDstStageMask = &waitDestinationStageMask,
471- .commandBufferCount = 1 ,
472- .pCommandBuffers = &*commandBuffer,
473- .signalSemaphoreCount = 1 ,
474- .pSignalSemaphores = &*renderFinishedSemaphores[imageIndex]};
466+ const vk::SubmitInfo submitInfo{ .waitSemaphoreCount = 1 , .pWaitSemaphores = &*presentCompleteSemaphore,
467+ .pWaitDstStageMask = &waitDestinationStageMask, .commandBufferCount = 1 , .pCommandBuffers = &*commandBuffer,
468+ .signalSemaphoreCount = 1 , .pSignalSemaphores = &*renderFinishedSemaphore };
475469 queue.submit (submitInfo, *drawFence);
470+ while ( vk::Result::eTimeout == device.waitForFences ( *drawFence, vk::True, UINT64_MAX ) )
471+ ;
476472
477- const vk::PresentInfoKHR presentInfoKHR{ .waitSemaphoreCount = 1 ,
478- .pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
479- .swapchainCount = 1 ,
480- .pSwapchains = &*swapChain,
481- .pImageIndices = &imageIndex };
473+ const vk::PresentInfoKHR presentInfoKHR{ .waitSemaphoreCount = 1 , .pWaitSemaphores = &*renderFinishedSemaphore,
474+ .swapchainCount = 1 , .pSwapchains = &*swapChain, .pImageIndices = &imageIndex };
482475 result = queue.presentKHR ( presentInfoKHR );
483476 switch ( result )
484477 {
0 commit comments