Buffer quetsion?!

BlitzMax Forums/BlitzMax Programming/Buffer quetsion?!

Trader3564(Posted 2008) [#1]
Let me just throw at you what i found in the helpfile:

GRAPHICS_BACKBUFFER :: Create graphics with a back buffer
GRAPHICS_ALPHABUFFER :: Create graphics with an alpha buffer
GRAPHICS_DEPTHBUFFER :: Create graphics with a depth buffer
GRAPHICS_STENCILBUFFER :: Create graphics with a stencil buffer
GRAPHICS_ACCUMBUFFER :: Create graphics with an accumulation buffer

I have set my graphics mode for my 2D game that uses PNG (with alpha) altough i use alpha not many times.
Knowing the BACKBUFFER from Blitz3D, and its purpose, i have defined this flag.

However, Blitzmax has a bunch of other buffers. I can only guess what the ALHPA buffer is for, and then i get lost. Does anyone know in detail what is the prupose of them and how to use them?


Trader3564(Posted 2008) [#2]
Hmm, having asked that, can someone also explain why we have more then 1 GL drivers, etc...?

Whats the difference between:
BRL.D3D7Max2D Direct3D7 Max2D
BRL.GLGraphics OpenGL Graphics
BRL.GLMax2D OpenGL Max2D
BRL.Graphics Graphics
Pub.OpenGL OpenGL 1.1

I am using the GLMax2D driver as it is faster then the default graphics driver..


degac(Posted 2008) [#3]
Well, if I have understood correctly there are '3' drivers to manage graphics:

Direct3d 7 (via D3D7Max2D), every gfx command will use Direct library

GLmax2d (via GLMax2D)
GLGraphics (via GLgraphics)
OpenGL

will use OpenGL driver.
The difference is the way they managed OpenGL commands. GLMax2d is the 'higher' level, OpenGL is the 'lower', raw command set. You need - in this case - do all the things (setup context, matrix and so on) by yourself.


MGE(Posted 2008) [#4]
I've never used the command, have no idea why I would want to. ? ?


Dreamora(Posted 2008) [#5]
The other Buffers are needed depending on what you do.

Depth Buffer: To prevent z fights in the depth
Stencil Buffer: Shadows, Reflections and the like
Accum Buffer: a usefull buffer for different special effects ... fredborg has shown one of it by using it for a light system in Max2D


Trader3564(Posted 2008) [#6]
And why would i want to do shadows in the Stencil Buffer and not the Back Buffer?
And the accum buffer sound fun, but how to use it? and why not apply effects on the Back Buffer?
Depth Buffer doesnt make sence.


Dreamora(Posted 2008) [#7]
You totally missunderstand it.

The part you will see on the screen is always and only the BackBuffer.
The other buffers are combined into that.

Read 3D programming basics papers and articles to understand their use etc.
Its far above your current knowledge so the simple rule is: don't use what you do not know what it does at all


Trader3564(Posted 2008) [#8]
I see. Well, that is good to know. Any idea where i can read those papers?


ImaginaryHuman(Posted 2008) [#9]
The buffers you see mentioned in Graphics() are mainly OpenGL buffers as far as I know, although maybe DX has some of them too.

Using the Max2D GL driver means that you can use Max2D commands and they will run under OpenGL. It's up to you whether you then add extra OpenGL or not - you can, but it may interfere with Max2D's state unless you preserve and restore it on some kind of stack.

Alternatively, GLGraphics means you cannot use any Max2D commands and should ONLY use OpenGL commands that you code yourself.

GRAPHICS_BACKBUFFER is not actually compulsory, because you can set which buffers are the default when you set the driver. You can actually create a single-buffered display if you'd like. Generally speaking you want a backbuffer so that rendering processes are hidden from the user until the whole frame is complete.

GRAPHICS_ALPHABUFFER indicates that you want an alpha channel in the backbuffer and screen itself. It has nothing to do with drawing using alphablending in the way Blitz does it. It means that the display mode must include at least 1 bit for alpha data per pixel. Usually it means you have a 32-bit display mode like RGBA and the alpha channel is usually 8-bit, although sometime with a 15-bit display you get a 1-bit alpha channel. With a destination alpha channel you can draw stuff to the screen and the alpha values can be stored in the screen, to set up things like fancy masks and crossfades and stuff. I used destination alpha in an older version of my blobby objects engine to accumulate blob energies in the screen and turn the levels into colors. You DO NOT need an ALPHABUFFER in order to do alphablending of PNG images, alphablending uses the *source* alpha channel, not the destination.

GRAPHICS_DEPTHBUFFER gives you an extra channel of data per pixel in the screen. Depending on how the graphics card arranges memory in the display, you could get anything from a 16-bit to a 32-bit depth buffer. Usually I find that if I ask for a 32-bit display I get a 24-bit depth buffer and an 8-bit stencil buffer - the card pads each 4-byte group with a stencil byte. The depth buffer generally stores Z coordinate information when you draw 3D geometry for various purposes like occlusion. It records what the Z coordinate was for a piece of geometry that created a given pixel, and usually helps you know not to draw something if the Z coordinate of the new object is further away than what the depth buffer recorded from previous objects.

GRAPHICS_STENCILBUFFER gives you a stencil buffer. Typically OpenGL says it only has to be a 1-bit buffer by 8-bit is much more common as far as I know. The stencil buffer does similar things to what stencils did in the old BlitzBasic days (remember those anyone?). As you draw stuff to the screen you can have it also draw values into the stencil buffer for each pixel and then you can later use those stencil settings to prevent certain areas of the screen from being drawn to, etc. It does what it says - stencilling.

GRAPHICS_ACCUMBUFFER is the accumulation buffer. It's a special buffer, often 32-bit RGBA similar to the backbuffer but it can also have higher precision, even a floating-point value per color component. The idea is that if you want to accumulate (add up, or multiply etc) the values of multiple frames or stages in rendering, it can add them up with greater precision than the backbuffer and not lose so much color resolution. You can also use it for motion blur and feedback effects, etc.

You can use all these buffers by writing your own OpenGL code. Max2D only uses the `color buffer`, which people refer to as the backbuffer. It doesn't use any of the others, not even the alpha. But you can ask for an alpha channel to force the use of a 32-bit mode rather than a 24-bit mode if you like - some graphics cards have 24-bit RGB as well as 32-bit RGBA.

There are MANY MANY uses for these extra buffers and you can do lots of interseting things with them graphically and computationally.

You could kind of say that for every pixel on the screen, you can have a Red component, a Green component, a Blue component, an Alpha component, a Stencil component, a Depth component and an Accumulation component.

In OpenGL there are also some other buffers. For example some cards support AUXiliary buffers - like extra back buffers. But support is not widespread.

If you want extra backbuffers you might investigate the BufferObjects, which require using an OpenGL extension.


Trader3564(Posted 2008) [#10]
Cool, i totaly get it. Heh. amazing. thanks!