2°) And still if i understand well the fact that page flipping and triple buffering is slower is comming from the vsync thing ?
You kidding? triple buffering you don't have to wait around for the vsync. Anyway, what you're really doing is page flipping with 3 pages, which isnt triple buffering. Anyway, before you can do anything with page flipping or triple buffering you have to check gfx_capabilities.
Ok, so to understand if page flipping will be faster for you you have to understand the relationship between the graphics card and the CPU. The CPU sends pictures through the 'bus' to the graphics card. Now that is slow. The graphics card can also send picutres back through the 'bus' to the CPU. Thats even slower, don't do that.
So, there a few allegro routines that require reading from the desination picture. One of these routines is blending. If you blend something with the screen image it will have to read in the pixels that are on the screen, which is slow and bad. don't do it.
Anyway, I'm just babbling on at this point. I'll get to the point.
So, to do triple buffering:
So here we check if gfx_capabilities can do triple buffering, if not we try to cheat and see if we can enable it. If that works we set pagecount to 3, which means we're going to do triple buffering. If it doesnt we set it to 2 which means we're going to do page flipping.
ok, so since you already get page flipping, im just going to explain how to do triple buffering:
|3||... init code ...|
|10|| page = ++page % pagecount;|
|12|| if(request_video_bitmap(pages[page]) != 0)|
|13|| shit("Shit! we're fucked. Time to quit the program.");|
|15|| destination = pages[(page + 1) % pagecount];|
request_video_bitmap returns immediately. Use poll_scroll to check when the BITMAP has been successfully moved to center-screen. We do rest(0) while checking poll_scroll so we don't waste CPU cycles.
Next we advance the page variable, wrapping back to 0 if we've gone over pagecount.
Next we request that the given page is moved center-screen.
Then we set the destination bitmap (the bitmap that should be drawn to) to the next page in the list (again wrapping down to 0 if the page is bigger then pagecount).