Skip to content

Commit 699a077

Browse files
committed
Windows can now be resized in the vulkan renderer
1 parent f42edf0 commit 699a077

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

Framework/Renderer/Vulkan/Components/VKDraw.cpp

+26-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include "VKDraw.hpp"
2+
3+
#include "GLFW/glfw3.h"
24
#ifndef __EMSCRIPTEN__
35
#include <Interfaces/WindowInterface.hpp>
46
#include <Interfaces/RendererInterface.hpp>
@@ -77,12 +79,21 @@ void UImGui::VKDraw::ImGuiInit() const noexcept
7779

7880
void UImGui::VKDraw::ImGuiPreDraw() noexcept
7981
{
80-
const auto size = Window::windowSize();
81-
const auto width = CAST(int, size.x);
82-
const auto height = CAST(int, size.y);
82+
auto size = Window::windowSize();
83+
auto width = CAST(int, size.x);
84+
auto height = CAST(int, size.y);
8385

84-
if (width > 0 && height > 0 && (bRebuildSwapchain || window.Width != width || window.Height != height))
86+
if (bRebuildSwapchain || window.Width != width || window.Height != height)
8587
{
88+
while (width == 0 || height == 0)
89+
{
90+
size = Window::windowSize();
91+
width = CAST(int, size.x);
92+
height = CAST(int, size.y);
93+
glfwWaitEvents();
94+
}
95+
96+
device->device.waitIdle();
8697
ImGui_ImplVulkan_SetMinImageCount(minimalImageCount);
8798
ImGui_ImplVulkanH_CreateOrResizeWindow(instance->data(), device->physicalDevice, device->device,
8899
&window, device->indices.graphicsFamily, nullptr, width, height,
@@ -96,21 +107,24 @@ void UImGui::VKDraw::ImGuiDraw(void* drawData) noexcept
96107
{
97108
VkSemaphore imageAcquired = window.FrameSemaphores[window.SemaphoreIndex].ImageAcquiredSemaphore;
98109
VkSemaphore renderComplete = window.FrameSemaphores[window.SemaphoreIndex].RenderCompleteSemaphore;
99-
VkResult result = vkAcquireNextImageKHR(device->device, window.Swapchain, UINT64_MAX, imageAcquired, VK_NULL_HANDLE, &window.FrameIndex);
100-
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR)
101-
{
102-
bRebuildSwapchain = true;
103-
return;
104-
}
105110

106111
const ImGui_ImplVulkanH_Frame* fd = &window.Frames[window.FrameIndex];
107-
result = vkWaitForFences(device->device, 1, &fd->Fence, VK_TRUE, UINT64_MAX);
112+
VkResult result = vkWaitForFences(device->device, 1, &fd->Fence, VK_TRUE, UINT64_MAX);
108113
if (result != VK_SUCCESS)
109114
{
110115
Logger::log("Couldn't wait on fences. Error code: ", ULOG_LOG_TYPE_ERROR, result);
111116
std::terminate();
112117
}
113118

119+
result = vkAcquireNextImageKHR(device->device, window.Swapchain, UINT64_MAX, imageAcquired, VK_NULL_HANDLE, &window.FrameIndex);
120+
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR)
121+
{
122+
bRebuildSwapchain = true;
123+
ImGuiPreDraw();
124+
return;
125+
}
126+
ImGuiPreDraw();
127+
114128
result = vkResetFences(device->device, 1, &fd->Fence);
115129
if (result != VK_SUCCESS)
116130
{
@@ -217,6 +231,7 @@ void UImGui::VKDraw::present() noexcept
217231
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR)
218232
{
219233
bRebuildSwapchain = true;
234+
ImGuiPreDraw();
220235
return;
221236
}
222237
window.SemaphoreIndex = (window.SemaphoreIndex + 1) % window.SemaphoreCount;

0 commit comments

Comments
 (0)