When using double-buffered OpenGL, Swap Interval is a means of synchronizing the swapping of front and back frame buffers with a video card's vertical blanking period, AKA Vsync.
The term "swap interval" itself refers to the number of vblank periods that must occur between buffer swaps. A swap interval of 1 specifies that at the very least, the GPU must wait for a single vblank before swapping the front and back buffers. A swap interval of 0 specifies that the GPU should not wait for any vblanks, thus perform buffer swaps immediately.
Application control of swap interval is provided via platform-specific extensions.
Use the WGL_EXT_swap_control extension to control swap interval. Check both the standard extensions string via glGetString(GL_EXTENSIONS) and the WGL-specific extensions string via wglGetExtensionsStringARB() to verify that WGL_EXT_swap_control is actually present.
The extension provides the wglSwapIntervalEXT() function, which directly specifies the swap interval. (e.g. wglSwapIntervalEXT(1) to enable vsync; wglSwapIntervalEXT(0) to disable vsync)
In Linux / GLX
Use the GLX_SGI_swap_control extension to control swap interval. Check both the standard extensions string via glGetString(GL_EXTENSIONS) and the GLX-specific extensions string via glXQueryExtensionsString() to verify that the extension is actually present.
The extension provides glxSwapIntervalSGI(), which also directly specifies the swap interval. (e.g. glxSwapIntervalSGI(1) to enable vsync; glxSwapIntervalSGI(0) to disable vsync)
- Some ATI GLX drivers may report WGL_EXT_swap_control yet actually export glxSwapIntervalSGI.
- Your application's use of swap interval may be overridden by external, driver-specific configuration. For example, forcing Vsync Off in a driver's control panel will prevent Vsync, even if swap interval is set to 1 in your application.
- If swap interval is non-zero, drivers traditionally caused the calling thread to block SwapBuffers until the actual buffer swap was completed. In more recent drivers, the block occurs on the GPU, allowing the application thread to continue execution and even render and enqueue subsequent frames before the first swap occurs. This behavior could cause significant transport delay if the application expects traditional behavior. If the application requires either more deterministic behavior associated with vblank or minimal transport delay, the GLX_SGI_video_sync extension can be used in conjunction with swap interval. GLX_SGI_video_sync provides a method to synchronize CPU thread execution to vblank.