Swap Interval: Difference between revisions

From OpenGL Wiki
Jump to navigation Jump to search
m (moved SwapInterval aka vsync to Swap Interval: We can use redirects to have vsync point there. No need to put it in the title.)
(Major rewrite; Clear up and add some info, use somewhat more proper wiki style.)
Line 1: Line 1:
In Windows, if WGL_EXT_swap_control is present in the string returned by glGetString(GL_EXTENSIONS), then you can use wglSwapIntervalEXT(0) to disable vsync or you can use wglSwapIntervalEXT(1) to enable vsync (aka vertical synchronization).<br>
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.
For historical reasons, WGL_EXT_swap_control is included in the GL_EXTENSIONS string as returned from glGetString.<br>
 
http://www.opengl.org/registry/specs/EXT/wgl_swap_control.txt<br>
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.
It is also included in the string returned by wglGetExtensionsStringARB(), which is the more correct place for it.<br>
 
You should check for the presence in both locations to make sure it is really present. Either place will do.<br>
Application control of swap interval is provided via platform-specific [[extensions]].
We should also mention that there are duplicate extensions : WGL_EXT_extensions_string, WGL_ARB_extensions_string.<br>
 
http://www.opengl.org/registry/specs/EXT/wgl_extensions_string.txt defines wglGetExtensionsStringEXT<br>
== In Windows ==
http://www.opengl.org/registry/specs/ARB/wgl_extensions_string.txt defines wglGetExtensionsStringARB<br>
 
<br>
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.
Use wglGetExtensionsStringARB. Don't bother with wglGetExtensionsStringEXT.<br>
 
<br>
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, things are much simpler.<br>
 
If GLX_SGI_swap_control is present in the string returned by glGetString(GL_EXTENSIONS), then you can use glXSwapIntervalSGI(0) to disable vsync or you can use glXSwapIntervalSGI(1) to enable vsync (aka vertical synchronization).<br>
== In Linux / GLX ==
Apparently, an EXT or ARB version has not been created.<br>
 
http://www.opengl.org/registry/specs/SGI/swap_control.txt<br>
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 doesn't say it but it is assumed that glGetString(GL_EXTENSIONS) returns GLX_SGI_swap_control.<br>
 
<br>
The extension provides glxSwapIntervalSGI(), which also directly specifies the swap interval.  (e.g.  glxSwapIntervalSGI(1) to enable vsync;  glxSwapIntervalSGI(0) to disable vsync)
Note : It has been reported that in some case (some driver) with ATI, it doesn't give GLX_SGI_swap_control. It gives WGL_EXT_swap_control yet the driver doesn't export wglSwapIntervalEXT but it does export glXSwapIntervalSGI and it works.
 
<br>
== Idiosyncrasies ==
PS : if the driver is configed to ignore application settings, your calls to glXSwapIntervalSGI will get ignored.<br>
 
* 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.
 
== External Links ==
* [http://www.opengl.org/registry/specs/EXT/wgl_swap_control.txt WGL_EXT_swap_control]
* [http://www.opengl.org/registry/specs/SGI/swap_control.txt GLX_SGI_swap_control]
* [http://www.opengl.org/registry/specs/SGI/video_sync.txt GLX_SGI_video_sync]

Revision as of 19:44, 12 December 2010

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.

In Windows

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)

Idiosyncrasies

  • 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.

External Links