sdlGlSetSwapInterval function

bool sdlGlSetSwapInterval(
  1. int interval
)

Set the swap interval for the current OpenGL context.

Some systems allow specifying -1 for the interval, to enable adaptive vsync. Adaptive vsync works the same as vsync, but if you've already missed the vertical retrace for a given frame, it swaps buffers immediately, which might be less jarring for the user during occasional framerate drops. If an application requests adaptive vsync and the system does not support it, this function will fail and return false. In such a case, you should probably retry the call with 1 for the interval.

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.

Read more on the Khronos wiki: https://www.khronos.org/opengl/wiki/Swap_Interval#Adaptive_Vsync

\param interval 0 for immediate updates, 1 for updates synchronized with the vertical retrace, -1 for adaptive vsync. \returns true on success or false on failure; call SDL_GetError() for more information.

\threadsafety This function should only be called on the main thread.

\since This function is available since SDL 3.1.3.

\sa SDL_GL_GetSwapInterval

extern SDL_DECLSPEC bool SDLCALL SDL_GL_SetSwapInterval(int interval)

Implementation

bool sdlGlSetSwapInterval(int interval) {
  final sdlGlSetSwapIntervalLookupFunction = libSdl3.lookupFunction<
      Uint8 Function(Int32 interval),
      int Function(int interval)>('SDL_GL_SetSwapInterval');
  return sdlGlSetSwapIntervalLookupFunction(interval) == 1;
}