diff options
Diffstat (limited to 'src')
-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; |