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 | |
parent | 477455bcaa2f038452b35ec7727b6f24c4ec774f (diff) | |
download | cgame-a6eefcc1d2dd2479b44dbd0bb3732e8568725277.tar.gz cgame-a6eefcc1d2dd2479b44dbd0bb3732e8568725277.tar.bz2 cgame-a6eefcc1d2dd2479b44dbd0bb3732e8568725277.zip |
Handle resize in all cases
-rw-r--r-- | src/game.c | 17 | ||||
-rw-r--r-- | src/state.h | 5 |
2 files changed, 18 insertions, 4 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(); diff --git a/src/state.h b/src/state.h index 17be1c0..6feb9d1 100644 --- a/src/state.h +++ b/src/state.h @@ -59,7 +59,8 @@ typedef struct state { float x; int zoom; - SDL_Window* sdl_window; + SDL_Window *sdl_window; + int sdl_window_resized; VkInstance vk_instance; VkDebugUtilsMessengerEXT vk_debug_messenger; @@ -131,6 +132,8 @@ init_state(state_t * s) s->rotate = 0; s->mouse_pressed = 0; + s->sdl_window_resized = 0; + s->window_w = 800; s->window_h = 600; s->cell_w = 10; |