Reworked UI overlay class (no longer using separate render pass + submits)
Updated to support ImGui 1.62 Refs #496
This commit is contained in:
parent
3bbf0d8f29
commit
8a61105ec6
4 changed files with 76 additions and 288 deletions
|
|
@ -199,9 +199,6 @@ void VulkanExampleBase::prepare()
|
|||
// Setup default overlay creation info
|
||||
overlayCreateInfo.device = vulkanDevice;
|
||||
overlayCreateInfo.copyQueue = queue;
|
||||
overlayCreateInfo.framebuffers = frameBuffers;
|
||||
overlayCreateInfo.colorformat = swapChain.colorFormat;
|
||||
overlayCreateInfo.depthformat = depthFormat;
|
||||
overlayCreateInfo.width = width;
|
||||
overlayCreateInfo.height = height;
|
||||
// Virtual function call for example to customize overlay creation
|
||||
|
|
@ -214,6 +211,7 @@ void VulkanExampleBase::prepare()
|
|||
};
|
||||
}
|
||||
UIOverlay = new vks::UIOverlay(overlayCreateInfo);
|
||||
UIOverlay->preparePipeline(pipelineCache, renderPass);
|
||||
updateOverlay();
|
||||
}
|
||||
}
|
||||
|
|
@ -603,7 +601,9 @@ void VulkanExampleBase::updateOverlay()
|
|||
ImGui::PopStyleVar();
|
||||
ImGui::Render();
|
||||
|
||||
UIOverlay->update();
|
||||
if (UIOverlay->update()) {
|
||||
buildCommandBuffers();
|
||||
}
|
||||
|
||||
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
|
||||
if (mouseButtons.left) {
|
||||
|
|
@ -612,6 +612,13 @@ void VulkanExampleBase::updateOverlay()
|
|||
#endif
|
||||
}
|
||||
|
||||
void VulkanExampleBase::drawUI(const VkCommandBuffer commandBuffer)
|
||||
{
|
||||
if (settings.overlay) {
|
||||
UIOverlay->draw(commandBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
void VulkanExampleBase::prepareFrame()
|
||||
{
|
||||
// Acquire the next image from the swap chain
|
||||
|
|
@ -627,38 +634,7 @@ void VulkanExampleBase::prepareFrame()
|
|||
|
||||
void VulkanExampleBase::submitFrame()
|
||||
{
|
||||
bool submitOverlay = settings.overlay && UIOverlay->visible;
|
||||
|
||||
if (submitOverlay) {
|
||||
// Wait for color attachment output to finish before rendering the text overlay
|
||||
VkPipelineStageFlags stageFlags = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
submitInfo.pWaitDstStageMask = &stageFlags;
|
||||
|
||||
// Set semaphores
|
||||
// Wait for render complete semaphore
|
||||
submitInfo.waitSemaphoreCount = 1;
|
||||
submitInfo.pWaitSemaphores = &semaphores.renderComplete;
|
||||
// Signal ready with UI overlay complete semaphpre
|
||||
submitInfo.signalSemaphoreCount = 1;
|
||||
submitInfo.pSignalSemaphores = &semaphores.overlayComplete;
|
||||
|
||||
// Submit current UI overlay command buffer
|
||||
submitInfo.commandBufferCount = 1;
|
||||
submitInfo.pCommandBuffers = &UIOverlay->cmdBuffers[currentBuffer];
|
||||
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
|
||||
|
||||
// Reset stage mask
|
||||
submitInfo.pWaitDstStageMask = &submitPipelineStages;
|
||||
// Reset wait and signal semaphores for rendering next frame
|
||||
// Wait for swap chain presentation to finish
|
||||
submitInfo.waitSemaphoreCount = 1;
|
||||
submitInfo.pWaitSemaphores = &semaphores.presentComplete;
|
||||
// Signal ready with offscreen semaphore
|
||||
submitInfo.signalSemaphoreCount = 1;
|
||||
submitInfo.pSignalSemaphores = &semaphores.renderComplete;
|
||||
}
|
||||
|
||||
VkResult res = swapChain.queuePresent(queue, currentBuffer, submitOverlay ? semaphores.overlayComplete : semaphores.renderComplete);
|
||||
VkResult res = swapChain.queuePresent(queue, currentBuffer, semaphores.renderComplete);
|
||||
if (!((res == VK_SUCCESS) || (res == VK_SUBOPTIMAL_KHR))) {
|
||||
if (res == VK_ERROR_OUT_OF_DATE_KHR) {
|
||||
// Swap chain is no longer compatible with the surface and needs to be recreated
|
||||
|
|
@ -668,7 +644,6 @@ void VulkanExampleBase::submitFrame()
|
|||
VK_CHECK_RESULT(res);
|
||||
}
|
||||
}
|
||||
|
||||
VK_CHECK_RESULT(vkQueueWaitIdle(queue));
|
||||
}
|
||||
|
||||
|
|
@ -809,7 +784,6 @@ VulkanExampleBase::~VulkanExampleBase()
|
|||
|
||||
vkDestroySemaphore(device, semaphores.presentComplete, nullptr);
|
||||
vkDestroySemaphore(device, semaphores.renderComplete, nullptr);
|
||||
vkDestroySemaphore(device, semaphores.overlayComplete, nullptr);
|
||||
for (auto& fence : waitFences) {
|
||||
vkDestroyFence(device, fence, nullptr);
|
||||
}
|
||||
|
|
@ -981,10 +955,6 @@ bool VulkanExampleBase::initVulkan()
|
|||
// Create a semaphore used to synchronize command submission
|
||||
// Ensures that the image is not presented until all commands have been sumbitted and executed
|
||||
VK_CHECK_RESULT(vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &semaphores.renderComplete));
|
||||
// Create a semaphore used to synchronize command submission
|
||||
// Ensures that the image is not presented until all commands for the UI overlay have been sumbitted and executed
|
||||
// Will be inserted after the render complete semaphore if the UI overlay is enabled
|
||||
VK_CHECK_RESULT(vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &semaphores.overlayComplete));
|
||||
|
||||
// Set up submit info structure
|
||||
// Semaphores will stay the same during application lifetime
|
||||
|
|
@ -2166,6 +2136,12 @@ void VulkanExampleBase::windowResize()
|
|||
}
|
||||
setupFrameBuffer();
|
||||
|
||||
if ((width > 0.0f) && (height > 0.0f)) {
|
||||
if (settings.overlay) {
|
||||
UIOverlay->resize(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
// Command buffers need to be recreated as they may store
|
||||
// references to the recreated frame buffer
|
||||
destroyCommandBuffers();
|
||||
|
|
@ -2175,9 +2151,6 @@ void VulkanExampleBase::windowResize()
|
|||
vkDeviceWaitIdle(device);
|
||||
|
||||
if ((width > 0.0f) && (height > 0.0f)) {
|
||||
if (settings.overlay) {
|
||||
UIOverlay->resize(width, height, frameBuffers);
|
||||
}
|
||||
camera.updateAspectRatio((float)width / (float)height);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue