views:

331

answers:

3

The WGL_EXT_swap_control extension allows doing this on Windows, but I am unable to find anything even remotely cross-platform doing the same, i.e. syncing my buffer swaps with screen refresh. My application uses GLEW, so something offered by that would be preferable. Cross-platform support for Linux, Mac and Windows is necessary, but my application will not break if the sync cannot be set (e.g. the user has forced it off in his graphics drivers).

I will accept program code to do it on many platforms, with GLEW, as a valid answer.

+2  A: 

This sounds pretty nasty and leaves you on your own to figure which call goes on Mac OS X, but this guy seems to have some sort of solution.

zneak
This didn't quite work with GLEW as-is, but I guess it can be helpful when I find more time to spend on the issue. Congratulations for the extra rep :P
Tronic
+2  A: 

There is a reason it's not easy to find a cross-platform solution. The platform ultimately owns the display (and the swapping behavior). So it necessarily is part of the platform API (if exposed). There can't really be a cross-platform solution. Even glew has some platform specific bits when it comes down to interaction with the platform.

Now you could argue that all the platforms should use the same API for that specific bit of their interface, but I doubt you'd get any traction from them.

Last, not all framebuffers are displayed directly. If you happen to be using a window management system that actually blends the framebuffer pixels to the desktop (like Aero does when active), then you don't get to control the swap behavior anyways.

For reference, the various APIs to do this on major platforms:

  • wglSwapIntervalEXT
  • glXSwapIntervalSGI
  • AGLSetInteger
Bahbar
This. "Cross platform", in OpenGL, almost always means multiple code paths. Vsync is hardly unique in this way.
Alan
A: 

From http://www.opengl.org/wiki/Swap_Interval (and indirectly http://www.opengl.org/registry/specs/SGI/swap_control.txt):

In Linux, things are much simpler. 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).

MSN