Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Info for docs - Vsync in different situations with ALLEGRO_SINGLE_BUFFER

This thread is locked; no one can reply to it. rss feed Print
Info for docs - Vsync in different situations with ALLEGRO_SINGLE_BUFFER
Jesse Gordon
Member #15,502
February 2014

Because I wanted less latency between user input and displayed changes, I am using ALLEGRO_SINGLE_BUFFER asa new display option.

On one computer, it worked great (an old intel video card) but on another (an old nvidia card - both in Linux) my program did not work smoothly because al_flip_display() was not waiting for vsync, and my fps was going at over 2000, and this was causing mouse movement events to be delayed/lost.

Upon further investigation, I found that ALLEGRO_VSYNC,1,ALLEGRO_REQUIRE would fail, however if I used _SUGGEST then it would run, but without vsync holdoff.

OK - so my video card driver doesn't support vsync waiting for al_flip_display().

So then I tried al_wait_for_vsync() just before al_flip_display() then my program runs nice again.

So I guess my suggested improvements to the documentation would be along these lines:

Some video card drivers will not allow you to set ALLEGRO_VSYNC as a new display option, in which case al_flip_display() will not wait for vsync but run as fast as your computer can, which can cause lost/delayed allegro events and cpu hogging..

At current time of this posting, there does not seem to be a way to determine cause of display creation failure, and no way to determine whether the request for ALLEGRO_VSYNC was honored. At some point al_get_display_option(display,ALLEGRO_VSYNC) may be able to be called after the display is created to see if the request was honored.

So at present there are two approaches: One is to just set ALLEGRO_VSYNC to 2 (disabled) and always call al_wait_for_vsync() before al_flip_display(). The other method is to attempt to create the display with ALLEGRO_VSYNC,1,ALLEGRO_REQUIRE, and if that fails, then try again with ALLEGRO_VSYNC,2,ALLEGRO_REQUIRE(vsync holdoff disabled) -- and if it succeeds the second time, then your program knows that it needs to call al_wait_for_vsync() before al_flip_display().

Thanks,

~Jesse

l j
Member #10,584
January 2009
avatar

Some video card drivers will not allow you to set ALLEGRO_VSYNC as a new display option, in which case al_flip_display() will not wait for vsync but run as fast as your computer can, which can cause lost/delayed allegro events and cpu hogging..

Structure your main loop in such a way that you'll only render when there are no events left to be processed and the viewable state updated. It's not hard, all the beginner tutorials I've seen so far teach you how to. Use al_wait_for_event.

SiegeLord
Member #7,827
October 2006
avatar

taron  said:

It's not hard, all the beginner tutorials I've seen so far teach you how to. Use al_wait_for_event.

That type of loop is notable because it's simple to set up and always works, but it's not the end-all and be-all of game loops. A loop based on vsync'ing will produce smoother output, but requires gymnastics like the OP described due to hardware differences/Allegro bugs.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

pkrcel
Member #14,001
February 2012

A little bit off topic but...are the display properties tustably "inquirable" (is that even a word?) once the window is created?

I mean, the docs for al_get_display_option seem to imply that regarding VSYNC you should not rely on this option alone to tell if Vsyncing is on or off....

In other words is this following statement true?

At some point al_get_display_option(display,ALLEGRO_VSYNC) may be able to be called after the display is created to see if the request was honored.

Will and ALLEGRO_REQUIRE always fail if the video card driver overrides the vsync setting?

It is unlikely that Google shares your distaste for capitalism. - Derezo
If one had the eternity of time, one would do things later. - Johan Halmén

Go to: