SDL_GL_SetSwapInterval(3)

πŸ’– SDL_GL_SetSwapInterval(3) πŸ’–

okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual, where we're talking about your swap interval for the current OpenGL context. yes, that swap interval. the vsync one. sit down, hydrate, let's go 🫢


✨ NAME ✨

SDL_GL_SetSwapInterval β€” set the swap interval for the current OpenGL context. that's it, that's the whole job, and she does it flawlessly πŸ’…


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_video.h>

bool SDL_GL_SetSwapInterval(int interval);

πŸ¦‹ DESCRIPTION πŸ¦‹

so like, some systems let you pass -1 for the interval, which turns on adaptive vsync. iconic behavior honestly. adaptive vsync does the same thing as regular vsync, except β€” and this is the key part β€” if you've already missed the vertical retrace for a given frame, it just swaps buffers immediately. which lowkey might be less jarring for the user during occasional framerate drops. it's giving "we tried our best, here's your frame anyway" 😭

but here's the tea: if an application asks for adaptive vsync and the system does not support it, this function will fail and return false. no cap. in that situation you should probably retry the call with 1 for the interval. like, just fall back, bestie, it's fine.

adaptive vsync is implemented for some glX drivers with GLX_EXT_swap_control_tear, and for some Windows drivers with WGL_EXT_swap_control_tear. so that's the vibe check on where it actually works.

want to read more? the Khronos wiki has you covered, and yes we're linking it verbatim because it's literally the source:

https://www.khronos.org/opengl/wiki/Swap_Interval#Adaptive_Vsync


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • interval β€” 0 for immediate updates, 1 for updates synchronized with the vertical retrace, -1 for adaptive vsync. those are the three moods, pick one 🌈

πŸ‘‘ RETURN VALUE πŸ‘‘

returns true on success or false on failure. and if it's a failure, call SDL_GetError() for more information β€” she'll tell you what went wrong, she's not shy πŸ’œ


πŸ”₯ THREAD SAFETY πŸ”₯

this function should only be called on the main thread. main character energy only, no side quests, no other threads, periodt ⭐


🌟 AVAILABILITY 🌟

this function is available since SDL 3.2.0. so if you're on anything older... yeah. upgrade, bestie πŸ’€


πŸ’« SEE ALSO πŸ’«


mwah πŸ’‹ that's the whole page. sourced from Simple Directmedia Layer, version SDL 3.4.18, and yes this is the SDL_GL_SetSwapInterval(3) page, we been knew. go set that swap interval and slay ✨🧚

πŸ“¦ where this page comes from