diff options
| author | gramanas <anastasis.gramm2@gmail.com> | 2024-05-21 13:07:00 +0300 | 
|---|---|---|
| committer | gramanas <anastasis.gramm2@gmail.com> | 2024-05-21 13:07:00 +0300 | 
| commit | a6eefcc1d2dd2479b44dbd0bb3732e8568725277 (patch) | |
| tree | 5c9045977cd7c47064dd4061250f9e8546b0ece8 /src/game.c | |
| parent | 477455bcaa2f038452b35ec7727b6f24c4ec774f (diff) | |
| download | cgame-a6eefcc1d2dd2479b44dbd0bb3732e8568725277.tar.gz cgame-a6eefcc1d2dd2479b44dbd0bb3732e8568725277.tar.bz2 cgame-a6eefcc1d2dd2479b44dbd0bb3732e8568725277.zip  | |
Handle resize in all cases
Diffstat (limited to 'src/game.c')
| -rw-r--r-- | src/game.c | 17 | 
1 files changed, 14 insertions, 3 deletions
@@ -88,6 +88,14 @@ const uint16_t indices[] = {  };  const int INDICES_SIZE = VK_ARRAY_LEN(indices); +static int resizing_event_watcher(void* data, SDL_Event* event) { +  if (event->type == SDL_WINDOWEVENT && +      event->window.event == SDL_WINDOWEVENT_RESIZED) { +    s.sdl_window_resized = 1; +  } +  return 0; +} +  bool  init()  { @@ -107,6 +115,8 @@ init()      return false;    } +  SDL_AddEventWatch(resizing_event_watcher,NULL); +    return true;  } @@ -552,7 +562,7 @@ void  vulkan_create_surface()  {    if (SDL_Vulkan_CreateSurface(s.sdl_window, s.vk_instance, &s.vk_surface) == SDL_FALSE) { -    vk_log(VK_INFO, "Failed to create surface\n"); +    vk_log(VK_ERROR, "Failed to create surface\n");    } else {      vk_log(VK_INFO, "Vulkan surface created\n");    } @@ -1599,7 +1609,8 @@ draw_frame() {    result = vkQueuePresentKHR(s.vk_present_queue, &presentInfo); -  if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR) { +  if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || s.sdl_window_resized) { +    s.sdl_window_resized = 0;      recreateSwapChain();    } else if (result != VK_SUCCESS) {      vk_log(VK_ERROR, "failed to present swap chain image!\n"); @@ -1647,7 +1658,7 @@ main(int argc, char* args[])      while (!quit) {        handle_input(&quit);        draw_frame(); -      SDL_Delay(16); +      //SDL_Delay(16);      }      close_vulkan();  | 
