I am looking for a portable way to make a non-blocking SwapBuffers() even if VSync is activated.
In other words, is it possible to to be notified by an event or to know the delay until the next VSync ?

- 26,310
- 20
- 70
- 95
-
This is going to be platform-specific, if it's at all possible. So please specify your platform, by tagging at least. – unwind Feb 08 '10 at 15:49
-
I would like to find a portable way to implement this feature (Win32/Linux/MacOSX) – Franck Freiburger Feb 08 '10 at 15:55
-
how does the delay until next vsync help you ? It's not like the swapbuffer call does the swap at the time of the call. – Bahbar Feb 08 '10 at 17:54
-
1If VSync is on, swapbuffer() will block until the next vertical sync. During this time I cannot manage events like network messages, keyboard input, ... If I know when the next VSync will occurs, I can manage everything until the last moment. – Franck Freiburger Feb 08 '10 at 18:26
2 Answers
IIRC this extension helps: http://www.opengl.org/registry/specs/SGI/video_sync.txt, but it is very poorly supported with current drivers.

- 1,153
- 6
- 18
-
Unfortunately you're right, this feature is very poorly supported. – Franck Freiburger Feb 09 '10 at 16:27
Firstly, why don't you just call SwapBuffers() at the start of the frame? Or somehow change the pipeline to
Render();
Update(); //Update before swapping buffers
SwapBuffers();
While OpenGL is working away at all of the commands you just threw at it, you can do all of your update logic.
Otherwise there's a few ways to solve this problem.
I know that XNA has a ScanLine Property, which tells you which scanline the screen is currently up to. I don't know if OpenGL exposes this too, but I'm pretty sure it must. (Right?)
Use multithreaded rendering. Many modern engines dedicate a whole thread just for rendering. If it blocks, it's fine, it doesn't disturb the main thread. Alternitavly an easier way is to just handle input etc. on a new thread, this avoids complications with graphics contexts.
Use triple buffering. Using triple buffering means that you have 2 back buffers. Afer you call SwapBuffers, the screen can continue to scan the front buffer, with your newly finished buffer waiting, and the third buffer for you to render the next frame to. Of course, if you have already prerendered two frames, SwapBuffers() will block.

- 7,256
- 7
- 46
- 80