1
1
#include " VKDraw.hpp"
2
+
3
+ #include " GLFW/glfw3.h"
2
4
#ifndef __EMSCRIPTEN__
3
5
#include < Interfaces/WindowInterface.hpp>
4
6
#include < Interfaces/RendererInterface.hpp>
@@ -77,12 +79,21 @@ void UImGui::VKDraw::ImGuiInit() const noexcept
77
79
78
80
void UImGui::VKDraw::ImGuiPreDraw () noexcept
79
81
{
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 );
83
85
84
- if (width > 0 && height > 0 && ( bRebuildSwapchain || window.Width != width || window.Height != height) )
86
+ if (bRebuildSwapchain || window.Width != width || window.Height != height)
85
87
{
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 ();
86
97
ImGui_ImplVulkan_SetMinImageCount (minimalImageCount);
87
98
ImGui_ImplVulkanH_CreateOrResizeWindow (instance->data (), device->physicalDevice , device->device ,
88
99
&window, device->indices .graphicsFamily , nullptr , width, height,
@@ -96,21 +107,24 @@ void UImGui::VKDraw::ImGuiDraw(void* drawData) noexcept
96
107
{
97
108
VkSemaphore imageAcquired = window.FrameSemaphores [window.SemaphoreIndex ].ImageAcquiredSemaphore ;
98
109
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
- }
105
110
106
111
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);
108
113
if (result != VK_SUCCESS)
109
114
{
110
115
Logger::log (" Couldn't wait on fences. Error code: " , ULOG_LOG_TYPE_ERROR, result);
111
116
std::terminate ();
112
117
}
113
118
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
+
114
128
result = vkResetFences (device->device , 1 , &fd->Fence );
115
129
if (result != VK_SUCCESS)
116
130
{
@@ -217,6 +231,7 @@ void UImGui::VKDraw::present() noexcept
217
231
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR)
218
232
{
219
233
bRebuildSwapchain = true ;
234
+ ImGuiPreDraw ();
220
235
return ;
221
236
}
222
237
window.SemaphoreIndex = (window.SemaphoreIndex + 1 ) % window.SemaphoreCount ;
0 commit comments