Removed swapchain recreation from draw_frame

main
noah metz 2024-01-08 19:50:45 -07:00
parent 3bb460d05c
commit 1df48f247e
1 changed files with 13 additions and 9 deletions

@ -1924,7 +1924,7 @@ VkResult update_scene_ubo(void** buffers, uint32_t frame_index, vec3 world_posit
return VK_SUCCESS; return VK_SUCCESS;
} }
VkResult draw_frame(GLFWwindow* window, VulkanContext* context) { VkResult draw_frame(VulkanContext* context) {
update_scene_ubo(context->scene_ubo_ptrs, context->current_frame, world_position, &rotation, (float)context->swapchain_extent.width/(float)context->swapchain_extent.height, 0.01); update_scene_ubo(context->scene_ubo_ptrs, context->current_frame, world_position, &rotation, (float)context->swapchain_extent.width/(float)context->swapchain_extent.height, 0.01);
VkResult result; VkResult result;
@ -1935,13 +1935,7 @@ VkResult draw_frame(GLFWwindow* window, VulkanContext* context) {
uint32_t image_index; uint32_t image_index;
result = vkAcquireNextImageKHR(context->device, context->swapchain, UINT64_MAX, context->image_available_semaphores[context->current_frame], VK_NULL_HANDLE, &image_index); result = vkAcquireNextImageKHR(context->device, context->swapchain, UINT64_MAX, context->image_available_semaphores[context->current_frame], VK_NULL_HANDLE, &image_index);
if(result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR) { if(result != VK_SUCCESS) {
int width, height;
glfwGetWindowSize(window, &width, &height);
VkExtent2D window_extent = {width, height};
recreate_swap_chain(context, window_extent);
return result;
} else if(result != VK_SUCCESS) {
return result; return result;
} }
@ -1995,7 +1989,17 @@ void main_loop(GLFWwindow* window, VulkanContext* context) {
while(!glfwWindowShouldClose(window)) { while(!glfwWindowShouldClose(window)) {
glfwPollEvents(); glfwPollEvents();
draw_frame(window, context); VkResult result = draw_frame(context);
if(result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR) {
int width, height;
glfwGetWindowSize(window, &width, &height);
VkExtent2D window_extent = {width, height};
recreate_swap_chain(context, window_extent);
} else if(result != VK_SUCCESS) {
fprintf(stderr, "draw_frame error %d\n", result);
return;
}
context->current_frame += 1; context->current_frame += 1;
if(context->current_frame >= context->max_frames_in_flight) { if(context->current_frame >= context->max_frames_in_flight) {
context->current_frame = 0; context->current_frame = 0;