![]() |
|
Double / Triple Buffering? |
maxpoz
Member #10,014
July 2008
|
Hi there, I'm quite new to allegro and try to fooling around with the library now. Let me explain my situation here. I'm trying to make a game that (currently) runs in Windows XP with a tile based background that can scroll. So, for every frame I will (mostly) have to redraw every tile in the background since they are scrolling, thus i'm filling the entire screen with bitmaps. Since I'm redrawing entire screen everytime, I feel like I'm already doing a double buffering. My question is, does directy drawing/blit the tiles to a triple buffer video bitmap will be faster? Would someone care to explain me what's the difference if I draw using a double buffering way? ---- Another question..for some unknown reason when I try to clear() a video bitmap in my screen some part of the screen isn't clear. This happens when I trying with triple buffering. What I did is put a bitmap on the screen and try moving it around the screen. What I means by part of the screen is that all the vertical(up / down) movement have such problem, leaving a trail of the bitmap when i move. While the same time if I try moving the box Left/Right. The more weird problem is that when I move the box down, then move back up again the old trail will be "cleared" as if i'm using an eraser but it leaves another new trail of oppsite direction. And, it only happens when i using set_gfx_mode(GFX_AUTODETECT_WINDOWED). It works fine when this is under full screen (GFX_AUTODETECT). Can anyone tell me what actually caused the problem? Btw this problem will dissapear when I start filling up the screen full of stuffs. Again all this happens under Windows XP SP2 Sorry for the long question. EDIT: Typos |
Hyena_
Member #8,852
July 2007
![]() |
Have you ever played doom I or II with no clip cheat? When you go inside a wall, there are trails of everything at the places where nothing is drawn. It seems to me like a similar issue. I don't know what's exactly in there, but it has something to do with video bitmaps. Anyway, if you have a lot to redraw each frame, maybe consider page flipping? In my projects page flipping has always given a very good result.
|
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Double buffering means using a bitmap that is the size of the screen and drawing everything to it. When it is ready, blit the buffer to the screen. This way the entire screen is updated at the same time. Simply drawing everything directly to the screen is not double buffering. Quote: Another question..for some unknown reason when I try to clear() a video bitmap in my screen some part of the screen isn't clear. Are you clearing the screen bitmap or another video bitmap that you blit to the screen? If you're clearing a non-screen bitmap and drawing that to the screen and move it around, it will leave a trail. You have to clear the screen bitmap if you don't want the trail to be seen. This however would mean that you are clearing the screen directly and drawing a bitmap to it as well. That would produce flickering of the screen back and forth between a cleared screen and one with your bitmap drawn on it. This is what double buffering is for - to allow you to clear your bitmap without clearing the screen. Show us some of your code and we can give you more specific advice. The forum has nice code tags you can use. <code> Code goes here.. </code>
My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Neil Walker
Member #210
April 2000
![]() |
Hello, As for your question about buffering: When you create a memory bitmap (create_bitmap) you are creating a bitmap in memory, when you create a video bitmap (create_video_bitmap) you are creating a bitmap in video memory on the card. When you use double buffering you draw to the memory bitmap (well, you could draw to a video bitmap but don't) and then when finished you copy the bitmap to the screen. If you are drawing directly to the screen (screen) you aren't using double buffering. When you use video bitmaps you can employ paging or triple buffering - these aren't bitmaps they are techniques for handling video bitmaps to update your screen. With paging you create two video bitmaps, one can be thought of as pointing at the screen and the other is to a back buffer (think of it like the buffer in the double buffer example above, or perhaps a bitmap twice the height of your screen and only one is visible to the screen), then you draw to the back buffer and ask allegro to flip it (i.e. change the pointer from one video bitmap to the other). You then repeat this process and hopefully achieve a far smoother and faster technique than double buffering. With triple buffering you create three video bitmaps. It works a bit like video bitmaps but you have a third so that instead of waiting for the screen refresh (as hopefully your code is quicker) you ask allegro to flip the buffer, asynchronously in effect, then you continue with your code. In windows triple buffering only works in fullscreen mode but is even smoother and even fast than paging. paging is shown here: triple buffering is shown here: Remember though, video bitmaps may not work so you have to code for this in your game. Simply write a method that checks this and passes back the relevant bitmap for drawing on. Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
maxpoz
Member #10,014
July 2008
|
Thanks for the quick respond. Actually my question is what's the different by drawing everything to a screen_sized bitmap(Double Buffering) and then draw the entire bitmap to a screen comparing to drawing everything to a page for tripple buffer / page flipping and flip them? (Am I using the correct term here?) in terms of speed (assuming the things to be draw is filling up the whole buffer/page) EDIT: Didnt notice the new reply when typing this And does that means that Triple buffer is the fastest way as long as video memory is enough? Yes the trail is like those Doom I or II situation. I don't have the code right now ( this is a public pc ). I can't fully remember the code but what I did is something like this. basically i just copying the code from the manual to test them out. /* main loop */ clear(video_page[current_page]); // Get the mouse location and draw a sprite on the position draw_mouse_cursor(video_page[current_page]); do { } while (!poll_scroll()) request_video_bitmap(video_page[current_page]); current_page = (current_page + 1) % 3; by reading your post is the reason caused because i didn't call clear(screen)? |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Quote: by reading your post is the reason caused because i didn't call clear(screen)? If you do all your drawing to an off screen bitmap and you fill the entire screen when you blit the off screen bitmap onto the screen, you don't need to clear the screen. Basically, just clear your buffer while it's not being displayed. I think you're doing that already according to your example. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Neil Walker
Member #210
April 2000
![]() |
Quote: drawing everything to a screen_sized bitmap(Double Buffering) and then draw the entire bitmap to a screen That is double buffering Think about it another way. When you use a memory bitmap you draw to that then potentially whack all that data to the video card when you want to display it. When you use video bitmaps, they are already on the card all you do is change the address pointer. Triple should be faster, but more importantly you can usually get it far smoother. Beware though, while memory to video is quite a fast process (e.g. copying sprites in memory to video) copying from video memory to standard memory is ridiculously slow. At the minute there are only a handful of the bitmap operations that are hardware accelerated as well. But regardless, I would always choose video over memory. As for your coding problem, no the screen object has nothing to do with what you're doing, it's more like due to not clearing your video_page bitmap. Unless you are using the screen as that shouldn't be touched if you're using paging/triple buffering. Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
maxpoz
Member #10,014
July 2008
|
So whenever it is possible triple buffering will be the best option then? And for the "trailing problem" that happens only in windowed mode, i suppose that's what you meant that triple buffering only works in full screen. Am I correct? In fact when running in windowed mode the frame run incredibly fast compared to full screen, it's part of the reason that triple buffering doesn't work on windowed mode? Anyway when I use full screen mode everything seems to be solved. Many thanks for the answer for clarifying the differences between them. |
Neil Walker
Member #210
April 2000
![]() |
You need to check the result (enable_triple_buffer() if ANDing GFX_CAN_TRIPLE_BUFFER bit in the gfx_capabilities flag fails) to see if triple buffering was allowed. Why it's working when it hasn't got it I don't know, perhaps it's just internally just flipping a page. Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Quote: And for the "trailing problem" that happens only in windowed mode, Post an example screenshot showing the trailing problem that you are having. png's and jpg's are nice. You can attach the picture to your post and then use the forum's img tags to display it. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
amber
Member #6,783
January 2006
![]() |
Quote: So whenever it is possible triple buffering will be the best option then? Not always. If you're doing anything with transparency or blending, i.e., something that needs to read from the memory and not just write to it, you don't want to be trying to draw directly into a video bitmap. Of course, there's always OpenGL... then the GPU, not your CPU, is doing the blending stuff, and you don't have this problem. |
maxpoz
Member #10,014
July 2008
|
Looks like I forget to do the GFX_CAN_TRIPLE_BUFFER check. It seems that the trailing problem happens because Windowed mode does not support tripple buffer when i do the (gfx_capabilities & GFX_CAN_TRIPLE_BUFFER) it returns 0. I never thought that the request_video_page still running (resulting the trailing problem) even though the check fails. I'll have to stick with double buffer / page flipping for windowed mode then? EDIT: I Noticed a terrible slowdown when trying to draw some transparent sprite with draw_trans_sprite() in triple buffer mode. Should I just stick to double buffering if i'm using alot trans sprite? Or is there a way to counter this problem? |
amber
Member #6,783
January 2006
![]() |
Quote: I Noticed a terrible slowdown when trying to draw some transparent sprite with draw_trans_sprite() in triple buffer mode.
Read my post just above yours. |
|