# HG changeset patch # User Mike Becker # Date 1769346470 -3600 # Node ID c72df1f06671bf2b28d23469d0b094a664156813 # Parent 4df350dac84f4f082a76aea15364adb1d83bd94e add functions to change fullscreen and vsync during runtime diff -r 4df350dac84f -r c72df1f06671 src/ascension/context.h --- a/src/ascension/context.h Sun Jan 25 13:49:49 2026 +0100 +++ b/src/ascension/context.h Sun Jan 25 14:07:50 2026 +0100 @@ -55,7 +55,7 @@ cxmutstr texture_path; AscInput input; AscWindow windows[ASC_MAX_WINDOWS]; - unsigned char active_window; + unsigned int active_window; float frame_rate; float frame_factor; uint64_t frame_nanos; diff -r 4df350dac84f -r c72df1f06671 src/ascension/window.h --- a/src/ascension/window.h Sun Jan 25 13:49:49 2026 +0100 +++ b/src/ascension/window.h Sun Jan 25 14:07:50 2026 +0100 @@ -102,9 +102,13 @@ * In particular that makes the corresponding OpenGL context "current". * When you only want to draw into one window, you'll never need this. * + * Does nothing when the requested window is already active. + * * @param index the index of the window + * @return the index of the previously activated window or @p index when the + * requested window is already active */ -void asc_window_activate(unsigned int index); +unsigned int asc_window_activate(unsigned int index); /** @@ -199,8 +203,21 @@ */ void asc_window_set_size(unsigned int index, asc_vec2u size); +/** + * Enables / disables fullscreen. + * + * @param index the window index + * @param fullscreen true to enable fullscreen, false to disable + */ +void asc_window_fullscreen(unsigned index, bool fullscreen); -// TODO: add functions to enable/disable fullscreen and vsync during runtime +/** + * Enables / disables vertical synchronization. + * + * @param index the window index + * @param vsync true to enable vsync, false to disable + */ +void asc_window_vsync(unsigned index, bool vsync); #endif /* ASCENSION_WINDOW_H */ diff -r 4df350dac84f -r c72df1f06671 src/window.c --- a/src/window.c Sun Jan 25 13:49:49 2026 +0100 +++ b/src/window.c Sun Jan 25 14:07:50 2026 +0100 @@ -146,11 +146,8 @@ // necessary safeguard if (window->id == 0) return; - // active the window that shall be synced temporarily - unsigned int active_index = asc_context.active_window; - if (index != active_index) { - asc_window_activate(index); - } + // activate the window that shall be synced temporarily + unsigned int active_index = asc_window_activate(index); // Clear the color buffer for the window frame glViewport(0, 0, @@ -196,14 +193,17 @@ window->resized = false; window->moved = false; - if (index != active_index) { - asc_window_activate(active_index); - } + asc_window_activate(active_index); } -void asc_window_activate(unsigned int index) { - asc_context.active_window = index; - asc_gl_context_activate(&asc_active_window->glctx); +unsigned int asc_window_activate(unsigned int index) { + unsigned int active_index = asc_context.active_window; + if (active_index != index) { + asc_context.active_window = index; + asc_gl_context_activate(&asc_active_window->glctx); + return active_index; + } + return index; } unsigned int asc_window_index(Uint32 id) { @@ -273,3 +273,15 @@ // TODO: check what needs to be changed when SDL_WINDOW_ALLOW_HIGHDPI is supported by the engine SDL_SetWindowSize(window->sdl, (int)size.width, (int)size.height); } + +void asc_window_fullscreen(unsigned index, bool fullscreen) { + const AscWindow *window = asc_context.windows + index; + assert(window->sdl != NULL); + SDL_SetWindowFullscreen(window->sdl, fullscreen); +} + +void asc_window_vsync(unsigned index, bool vsync) { + unsigned int active_index = asc_window_activate(index); + SDL_GL_SetSwapInterval(vsync ? 1 : 0); + asc_window_activate(active_index); +}