Vertical synchronization

Reporter: RobertBColton  |  Status: open  |  Last Modified: August 16, 2016, 05:14:58 AM

The global setting is not implemented but the functions work fine. I recall somewhere polygonz trying to add this and either failing or doing it wrong. The OpenGL and Direct3D bridges should initialize the presentation parameters with the global setting, and iirc polygonz implemented it by calling the function which is not a good idea because then it does it essentially twice.

I also finally figured out how to add screen_wait_vsync which a lot of old games use. The function is WaitForVBlank in DirectX but I have not found the equivalent for OpenGL.
https://msdn.microsoft.com/en-us/library/windows/desktop/bb174349(v=vs.85).aspx

TheExDeus  
set_synchronization() works and does what you want in GL1/GL3 and probably DX.

RobertBColton  

Yeah it does but I was mentioning the global game setting.

BlackDoomer  

I also finally figured out how to add screen_wait_vsync which a lot of old games use. The function is WaitForVBlank in DirectX but I have not found the equivalent for OpenGL.

There's no such a function in the standard OpenGL because it is very system and/or platform specific. Vertical blank control only available as GL extension.

As an example I can give the GfxLib2 graphics library from FreeBASIC, and if specifically, it's implementation of VSync check.
On DirectDraw | On Win32 GDI | On X11

As you can note, GDI and X11 drivers doesn't check vertical blank actually, they only pause the calling thread to a fixed amount of time. This is semi-emulated behavior of proper vsync check, because it is a common practice to use monitor framerate timer for keeping game speed, for example. For much more correct emulation, the driver has to remember the time of last pseudo-VSync check and wait (using While-loop with sleep(<minimal_possible_value_here>), to prevent 100% CPU usage on some systems) on the next check, if the time between two frames (assume that we can get monitor frame rate) has not passed yet.

Next is OpenGL wiki page with description of vertical blank control:
https://www.opengl.org/wiki/Swap_Interval
This also may be interesting for you:

Swap interval = 1 with glFinish: The CPU thread can be synchronized with the buffer swap by calling glFinish() after issuing the swap.

Please sign in to post comments, or you can view this issue on GitHub.