How many Backbuffers?

BlitzMax Forums/BlitzMax Programming/How many Backbuffers?

Grey Alien(Posted 2006) [#1]
Hmm, in windowed mode, it seems there is only one backbuffer (this was the case in BlitzPlus as well). So if you draw an image, flip, the current backbuffer isn't blank, it's the exact one you just drew.

However, in full-screen mode there are two backbuffers, so if you call flip, the current backbuffer is blank, call flip again and you return back to the original one you drew. When I say blank, I'm just talking about the first time the app/game is run, not later on when you've drawn on both buffers.

Is this correct?

So, the GrabImage example in the doc has this line:

Graphics 800,600,0'640,480,32
inferring you can run the code in full-screen mode. But you jsut get a black screen because Flip is called before GrabImage thus Grab Image is getting a blank backbuffer (the 2nd backbuffer).


ImaginaryHuman(Posted 2006) [#2]
It's probably down to the OpenGL/DirectX driver as to whether it keeps the front buffer when you flip it or whether it trashes it. You can't rely on it being always preserved, it's not meant to be. When you flip the backbuffer to the front the front is lost. You have to physically draw stuff on the backbuffer before you can grab it and before you flip it. Flip=Trash the buffer.


Grey Alien(Posted 2006) [#3]
that's what I thought (generally), which is why the grabimage example is weird, as if grabs AFTER the flip.

Mind you my Bonus games reply on the backbuffer not being trashed each frame for the dirty rects system to work, and it does work perfectly.


ImaginaryHuman(Posted 2006) [#4]
According to the OpenGL docs you can't ever expect the flipped front buffer to be preserved. It could be trashed entirely by other graphics or a totally new unrelated backbuffer could be allocated in a different memory space for the next frame. If you are getting it to be preserved at the moment, it also doesn't mean it will work that way for all people because there are differences across the various OpenGL drivers. It's more of an exception than the rule.

You would be better of probably just redrawing the whole display - that's more of the mindset of modern game construction, although the old-school ways are cool.


Grey Alien(Posted 2006) [#5]
Well my Xmas Bonus games were in BlitzPLus which was DirectX not OpenGL so that must be why it worked. Origianlly I did redraw the whole screen, but then I realised this was too slow for some PCs, thus implemented the old-school Amiga-style dirty rects system, then the game worked on 300MHz PCs :-)


xlsior(Posted 2006) [#6]
However, in full-screen mode there are two backbuffers, so if you call flip, the current backbuffer is blank, call flip again and you return back to the original one you drew. When I say blank, I'm just talking about the first time the app/game is run, not later on when you've drawn on both buffers.

Is this correct?


Worse.

It's dependend on your video adapter and/or drivers -- I have three computers and a laptop, and found that one of them uses one backbuffer, two of them use two backbuffers, and the last one uses *three* backbuffers.

There was a thread about this a year ago: http://blitzbasic.com/Community/posts.php?topic=43274&hl=three%20backbuffers

Bottom line: you can never count on what's on your backbuffer. Depending on what it is you're changing, you can end up with flickering on some systems.


Grey Alien(Posted 2006) [#7]
hmm, well lucky I won't be using that method anymore. But noone has reported back problems with my Bonus game. However, now I think on it, I have seen some weird things on some old test machines like some cards with only one buffer in full-screen mode, perhaps. I also used the method of drawing the same thing on two buffers to matain a static image too, but this would look crap on a 3 buffer system, according to that thread. Also as I assumed windowed mode has only one buffer, I hope that's correct, otherwise some players may be having graphical anomalies, bummer. It's a bummer really, I assumed what happened on my system happened on ALL systems, how naive :-(


xlsior(Posted 2006) [#8]
It's a bummer really, I assumed what happened on my system happened on ALL systems, how naive :-(


Heh. I'm sure that indiepath can tell you all about graphics anomalies on varying systems. he had some code floating around that was supposed to draw things in black and white -- worked great on some systems, but went horribly wrong in all kind of interesting ways on others.


Dreamora(Posted 2006) [#9]
DX: Up to 8 Backbuffers in FlipChain
OpenGL: Up to 2 Backbuffers in FlipChain if activated in the driver (At least on ATIs)


ImaginaryHuman(Posted 2006) [#10]
I know this is an old thread but it's intersting, as I'm having some troubles with detecting whether the display actually flips (ie if it is single-buffered), and maybe the presence of extra backbuffers has something to do with it. A test for double buffering seems to work in fullscreen mode, maybe because there are triple buffers, but fails in window mode (double?).


Grey Alien(Posted 2006) [#11]
My experience on my PC at least (in BlitzPlus) was only one buffer in windowed mode and two in full-screen mode. I had to change my dirty rects system accordingly. Only much later I found this varied on other systems, great...


ImaginaryHuman(Posted 2006) [#12]
Hmm. We'll it's all good stuff to know. I didn't realize there were so many `issues` on modern computers, back in the Amiga days things were straightforward. Now we have to take care of all this tearing, flipping, buffer availability, backbuffers, driver support, cross-platform malarky.


TartanTangerine (was Indiepath)(Posted 2006) [#13]
Read the source, the Fullscreen backbuffer count is 1.

		ddsd=New DDSURFACEDESC2
		ddsd.dwSize=SizeOf(ddsd)
		fullscreen=state&DX7FULLSCREEN
		flipflags=DDFLIP_WAIT
		If fullscreen
			ddsd.dwFlags=DDSD_CAPS|DDSD_BACKBUFFERCOUNT
			ddsd.ddsCaps=DDSCAPS_PRIMARYSURFACE|DDSCAPS_FLIP|DDSCAPS_COMPLEX|DDSCAPS_3DDEVICE
			ddsd.dwBackBufferCount=1
		Else
			ddsd.dwFlags=DDSD_CAPS
			ddsd.ddsCaps=DDSCAPS_PRIMARYSURFACE|DDSCAPS_3DDEVICE
		EndIf



ImaginaryHuman(Posted 2006) [#14]
That applies to directx, maybe not opengl


TartanTangerine (was Indiepath)(Posted 2006) [#15]
All the modes are double buffered and from what I can glean from the source there is only 1 backbuffer in OGL or DX or Windowed or Fullscreen.


ImaginaryHuman(Posted 2006) [#16]
I seem to be able to open a single-buffered display in OpenGL no problem, no backbuffer. Drawing to the back draws to the front.


Grey Alien(Posted 2006) [#17]
EVen in Max on my PC there is only one buffer in windowed mode and two in full-screen. You can see this by drawing a shape, the calling flip, no clsm then another shape then flip Are there two or one on screen? I get two in windowed mode and one in full-screen mode.


TartanTangerine (was Indiepath)(Posted 2006) [#18]
I seem to be able to open a single-buffered display in OpenGL no problem, no backbuffer. Drawing to the back draws to the front.

Are you telling me that you can see your drawing results without a flip?

-----------------------------------------------

I think that there is some confusion here about how all this flipping works.

Windowed Mode
Blits Backbuffer to Primary Surface (No Flipping) - Backbuffer remains as backbuffer

FullScreen Mode
Flips BackBuffer with Primary Surface - BackBuffer becomes primary and primary becomes BackBuffer.

So in fullscreen when you draw shape 1 it gets drawn to the Backbuffer, you flip, shape 1 is now in the primary buffer, you draw shape 2 and it's now drawn to the new backbuffer (old primary), do a flip and you draw shape 3 and it will be in the same buffer as shape 1.

Make sense?


Grey Alien(Posted 2006) [#19]
yep that's what I said...


TartanTangerine (was Indiepath)(Posted 2006) [#20]
You said there are two backbuffers, that is not correct.


Grey Alien(Posted 2006) [#21]
OK bad terminolgy :-p Two "screens" you are drawing to in full-screen mode (they alternate on flip), only one in windowed mode.


Dreamora(Posted 2006) [#22]
In fullscreen you can have more. DX flipchain length depends on the GPUs speed ... the faster, the further it renders ahead (-> mouse lag)


ImaginaryHuman(Posted 2006) [#23]
Yah in OpenGL if you ask for a singlebuffered display you can see the drawing results immediately without a flip.

I didn't realize, though, that in window mode the backbuffers stays being the backbuffer. That would account for some of my problems.