Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CVDisplayLink alternative for Windows?

On Mac OS X, CVDisplayLink provides a great way to reliably update the screen to achieve 60 fps animation without tearing. Is there a similar interface on Windows, compatible with OpenGL?

It's of course possible to block while waiting for vsync, but this doesn't scale for multiple windows that need to animate simultaneously. On Windows, they'll all wait for each other (so two windows that each wait for vsync will drop to 30 fps), unlike on OS X.

How does e.g. a video player accomplish a smooth screen update?

like image 211
Frederik Slijkerman Avatar asked May 14 '12 14:05

Frederik Slijkerman


1 Answers

The typical architecture for Windows differs from Mac since you have control of the main loop rather than the OS libraries - there is no need for a CVDisplayLink equivalent (although certainly, if the APIs were better you wouldn't need to know as much specific information to achieve this).

If you are using a loop that spins endlessly then waiting for vsync at the end of the loop is fine. If you have multiple windows you need to schedule your rendering accordingly so that your 'main update loop' ends with waiting for vsync after all rendering is submitted.

normally I have something like this:

while(!toldToQuit)
{
    Render();
    Update();

    WaitForVsync();
}

which allows the CPU work for update (for the next frame) to happen alongside the GPU work for rendering...

SwapBuffers( HDC ) will wait for vsync if the driver has this as its default behaviour, otherwise there is a wgl extension for setting the vsync - wglSwapIntervalEXT( int ):

http://www.opengl.org/registry/specs/EXT/wgl_swap_control.txt

the way i've always achieved 'not vsyncing' is by rendering single buffered and not calling SwapBuffers... since wglSwapIntervalEXT( 0 ) does not achieve this on any hardware I have tested it on.

like image 154
jheriko Avatar answered Sep 21 '22 21:09

jheriko