Detect Vertical Blank

BlitzMax Forums/BlitzMax OpenGL Programming/Detect Vertical Blank

Could anyone point me to a method for detecting an imminent hardware refresh?

For some reason, I can't get FlipHook to work. Do you need a Max2d context? I'm using OGL in a MaxGUI Canvas.


In case you're wondering why I need it, I plan on doing the following:

Detect Vertical Blank
Flip current buffer
Draw updated graphics (to backbuffer)
While drawing, set "IS_DRAWING" = True
DO NOT FLIP once done drawing. Set "IS_DRAWING" = False
Upon next Vertical Blank, check status of "IS_DRAWING"
If False, flip and repeat the whole process

If True, DO NOT FLIP. Allow the draw function to continue drawing
Wait for the next Vertical Blank and check again.


The idea is that, with a 60hz refresh rate, the system will attempt to draw once every 1/60th of a second. A buffer will already be 'ready' as soon as the system detects a vertical blank, and thus will be able to dump that completed buffer to the screen with no tearing. If the draw function hasn't finished drawing the buffer, it skips the flip until the next 1/60th of a second cycle. In this case of just one flip 'skip', the true flip rate would be 30 flips per second for that short period of time.

This is probably how "Flip 1" works, but for whatever reason Flip 1 locks up my app and hogs CPU.


Thanks for your assistance in advance.