The best way to preserve the backbuffer?

BlitzMax Forums/BlitzMax Beginners Area/The best way to preserve the backbuffer?

Juiceter(Posted 2015) [#1]
Well, I'm new to Blitzmax, and got a shock coming from blitz 2d in that the backbuffer does not preserve what was written to it previously (something to do with gfxcards all being different, I suppose).

Is there any fast way to do this, as it seems obvious not to waste time redrawing everything again if nothing changes and you are just adding to what was there already after every flip?

I've tried grabbing the backbuffer to an image and redrawing it to the backbuffer after a flip before adding to it, but this method is just too slow (@ 1280x1024).

Perhaps someone has written a snippet of code that can be included to work as the blitz 2d method did?


Juiceter(Posted 2015) [#2]
Note: I need to use fullscreen. The buffer does seem to be preserved if you use windowed mode, though.


Yasha(Posted 2015) [#3]
as it seems obvious not to waste time redrawing everything again if nothing changes


Does it?

Your application needs to be written so that it doesn't drop frames even under the highest expected load. That means that, considered on its own, a frame where stuff happpens and then also it gets drawn needs to complete within a fixed allowable amount of time.

If the above, which is demanding in two places, can happen quickly enough to fit within a single frame's millisecond budget, then it stands to reason that a different frame where nothing happens and also it gets drawn will almost always be safely under budget as well, since the cost is the same in the latter part but significantly less in the former part.

In other words, barring radically unusual program design, this optimization isn't worth making because it only affects parts of your program that don't need optimization. What you really need is to ensure that redrawing your entire scene is still fast enough to be under time budget even when things actually did happen; if you can do that, everything else will work perfectly.


Juiceter(Posted 2015) [#4]
To me it does! I don't really understand why there isn't a mechanism to prevent the backbuffer from being trashed (either built-in or 3rd party).

It's just a simple line demo where I'm drawing a diamond to the screen, progressively thickening it each frame, whilst also displaying a small logo at the bottom of the screen. Why have to redraw the logo repeatedly after every flip? It just doesn't make sense.

It's just a difficult concept to grasp having used blitz 2d for so many years; something that was as easy as pie in 2d.


Juiceter(Posted 2015) [#5]
Further - in windowed mode the demo works fine and is very fast. But I don't want windowed mode. If there isn't an easier way to do it then it looks like I will just have to:

1. flip & cls after saving the previous diamond image via grabimage, redisplay it & the logo and update rather than

2. just drawing the lines update to the backbuffer and flipping it (which windowed mode seems to be fine with, at least on my machine).

I read somewhere that openGL preserves the backbuffer. Is this true?


xlsior(Posted 2015) [#6]
Well, I'm new to Blitzmax, and got a shock coming from blitz 2d in that the backbuffer does not preserve what was written to it previously (something to do with gfxcards all being different, I suppose).


FWIW, this is not a limitation of Blitz itself: both the OpenGL spec and the DirectX Direct3D specs specifically mention that you cannot count on the backbuffer remaining in place -- after a flip, the contents will be undefined. On some cards it remains, on some of them it's gone, and on some of them it alternates between 2,3 or even 4 backbuffers so after a flip the contents of the backbuffer may 'rewind' one of more frames.

Grabbing a copy of the image before drawing it to the screen is the only way to guarantee the outcome on all machines, unfortunate as it may be.

(Blitz 2D maty behave different, but that's because the videocard itself handles 2D different than 3D -- and even though you may be dealing with 2D style data in bltizmax, it's still 2D-in-3D, and the card uses its 3D environment to render everything. The adcvantage of that is that you essentially get 'free' blending, scaling, and rotation, which is extremely resource intensive to do in 2D blitz.)


Juiceter(Posted 2015) [#7]
Thanks to both of you for your replies.