CVDisplayLink alternative for Windows?
Asked Answered
S

1

7

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?

Sven answered 14/5, 2012 at 14:3 Comment(3)
Here's blog post with some background info on the problem: virtualdub.org/blog/pivot/entry.php?id=157Sven
That article seems odd. Isn't the 30/60 interlacing issue a hardware artifact of NTSC video?Goulden
interlacing is still a valid optimisation - it halves your fill rate consumption in the best cases - in the worst cases it doubles it - all depends on hardware. :)Bengal
B
1

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.

Bengal answered 11/12, 2012 at 18:36 Comment(2)
Your answer is only valid in the context of a single render loop per process (e.g. full-screen game). With multiple windows in a process, each having their own OpenGL context and rendering thread, this won't work: ATI drivers will serialize all vsync flushes so the threads/contexts end up waiting for each other.Sven
Why do you assume that I would have multiple loops for multiple windows, and not one that manages all of them? I think you have placed my code at the wrong level of the architecture you imagine it being inside of. Or perhaps I misunderstand you...Bengal

© 2022 - 2024 — McMap. All rights reserved.