Flip not waiting for Vertical Blank

BlitzMax Forums/BlitzMax Programming/Flip not waiting for Vertical Blank

Rico(Posted 2008) [#1]
Hi I am using Box2d with Blitzmax. I am using Framework BaH.Box2d near the start of the program and then Import other modules I use. I use the Flip 1 command (to sync with my display in the main loop. (I will eventually use delta-time, but I want to use 'Flip 1' on on my laptop which has a 60Hz display).
The problem is - although the program runs - it is clearly not waiting for a vertical blank and is running uninhibited. I have done tests by starting a new program and printing Frames per sec and it is definitely because of the Framework format I am using.

I presume I need to Import a module that I am missing to fix this, but I don't which one would deal with this. I have already done Import BRL.graphics but I still have this problem.

Any help would be appreciated. Thank you.


Sledge(Posted 2008) [#2]
Try Flip -1 without having specified a refresh rate. EDIT: Oh, also, try a different GFX driver... OGL simply won't render without tearing on my machine so for a properly synced display I have to go with DX.


MGE(Posted 2008) [#3]
Also make sure your advanced GPU driver settings have something like "wait for vertical blank" or similar option set as "application controlled".


ImaginaryHuman(Posted 2008) [#4]
Actually you're supposed to use Flip 1, not -1, to sync with the vertical blank. Flip -1 is a software-based timer, not vertically synced.


Sledge(Posted 2008) [#5]
I suggest only to try it. We can all read the manual.


MGE(Posted 2008) [#6]
"Flip -1 is a software-based timer"

Can someone point out the source code in the module that handles this? Thanks.


Rico(Posted 2008) [#7]
Sorry I forgot to mention that I normally use Flip 1 in my main loops - to sync to the display and it works fine (though my FPS counter says 55 when it should say 60 - cos I have a 60Hz display) - it looks very smooth.

Its only when using the Framework command and Import -ing the Modules I need - it doesn't wait for the VBlank. I did one program with a full module build and the same with the Framework version to test and the Framework version wasn't waiting for the VBlank. This is why I think I need to import a module to fix the problem - but I don't know which one I'm missing.

MGE - Yes that option is enabled

Sledge - I will try Flip-1. Thank you.


Sledge(Posted 2008) [#8]
Sorry -- I came across a bit snippy there, IH. Rico without importing the required modules I can't see how it would compile at all... perhaps you can run Framework Assistant over it if you haven't already. I can only think that you must be specifying a different driver to the default when manually importing?


Brucey(Posted 2008) [#9]
The only graphics-based ones that are available are the GL or DX ones. If you don't specify a Framework at the start, you will get both. I'm not sure which is on by default on Windows if you have both, but I'd assume that whichever it is, is not the same one you are using when you are using Framework.

I always just use Flip without a number.
Also note that you should be passing in the correct delta timing into Box2D for the physics to update at the correct speed. For example, if your framerate dropped to 30fps and you were telling Box2D to updated at 60fps, your physics would appear to slow down. The same would apply if your framerate went higher.


MGE(Posted 2008) [#10]
"I always just use Flip without a number."

Flip(1) - should be used to flip and wait for vblank
Flip(0) - is used to to rest render speed at full speed
Flip() - is actually Flip(-1) which according to the docs:

"If sync is -1 and the current graphics object was created with the Graphics command, then flips will occur at the graphics object's refresh rate regardless of whether or not the graphics hardware supports such a refresh rate.

If sync is -1 and the current graphics object was NOT created with the Graphics command, then the flip will occur on the next vertical blank. "

-1 is confusing. If you use the Graphics() command and then Flip(-1) then apparently Bmax will do some internal timing to tie it into the hz you set up in the graphics command.

If you created a graphics screen without using Graphics() and then flip(-1) it apparently will wait for vblank before flipping.

If you're doing your own timing in your code, I would only use Flip(0) or Flip(1).


TomToad(Posted 2008) [#11]
Check your video card's driver settings. You might have OpenGL set to ignore vertical blank and DirectX set to application controled. So when you don't use Framework command, D3D7Max2D is being used by default, and when you use FrameWork, something you are including is setting the Max2D driver to OpenGLMax2D.