| 504 | } |
| 505 | |
| 506 | void HPPApiVulkanSample::submit_frame() |
| 507 | { |
| 508 | if (get_render_context().has_swapchain()) |
| 509 | { |
| 510 | const auto &queue = get_device().get_queue_by_present(0); |
| 511 | |
| 512 | vk::SwapchainKHR swapchain = get_render_context().get_swapchain().get_handle(); |
| 513 | |
| 514 | vk::PresentInfoKHR present_info{.swapchainCount = 1, .pSwapchains = &swapchain, .pImageIndices = ¤t_buffer}; |
| 515 | // Check if a wait semaphore has been specified to wait for before presenting the image |
| 516 | if (semaphores.render_complete) |
| 517 | { |
| 518 | present_info.setWaitSemaphores(semaphores.render_complete); |
| 519 | } |
| 520 | |
| 521 | vk::DisplayPresentInfoKHR disp_present_info; |
| 522 | if (get_device().get_gpu().is_extension_supported(VK_KHR_DISPLAY_SWAPCHAIN_EXTENSION_NAME) && |
| 523 | window->get_display_present_info(reinterpret_cast<VkDisplayPresentInfoKHR *>(&disp_present_info), extent.width, extent.height)) |
| 524 | { |
| 525 | // Add display present info if supported and wanted |
| 526 | present_info.setPNext(&disp_present_info); |
| 527 | } |
| 528 | |
| 529 | // Shows how to filter an error code from a vulkan function, which is mapped to an exception but should be handled here! |
| 530 | vk::Result present_result; |
| 531 | try |
| 532 | { |
| 533 | present_result = queue.present(present_info); |
| 534 | } |
| 535 | catch (const vk::SystemError &e) |
| 536 | { |
| 537 | if (e.code() == vk::Result::eErrorOutOfDateKHR) |
| 538 | { |
| 539 | // Swap chain is no longer compatible with the surface and needs to be recreated |
| 540 | resize(extent.width, extent.height); |
| 541 | return; |
| 542 | } |
| 543 | else |
| 544 | { |
| 545 | // rethrow this error |
| 546 | throw; |
| 547 | } |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | // DO NOT USE |
| 552 | // vkDeviceWaitIdle and vkQueueWaitIdle are extremely expensive functions, and are used here purely for demonstrating the vulkan API |
| 553 | // without having to concern ourselves with proper syncronization. These functions should NEVER be used inside the render loop like this (every frame). |
| 554 | get_device().get_queue_by_present(0).get_handle().waitIdle(); |
| 555 | } |
| 556 | |
| 557 | HPPApiVulkanSample::~HPPApiVulkanSample() |
| 558 | { |
nothing calls this directly
no test coverage detected