PDA

View Full Version : Auxiliary buffer



Lumanior
08-08-2011, 11:59 PM
Hi

I faced the following problem:
My graphic scene consists of a lot of rectangles (about 500'000), which are in the background, and some few graphic objects, which are in the foreground. The rectangles in the background do hardly ever change their positions. The graphic objects in the foreground move really often.
At the moment, the whole scene is rendered each time the graphic objects in the foreground have to be moved.
My question: Is there a simple way that allows me to render the background rectangles only once and to copy them afterwards into the back buffer, before rendering the foreground objects.
I thought about a invisible auxiliary buffer.
The thing is, that the whole thing should be compatible with OpenGL 1.1...

Thank you for any help

_arts_
08-09-2011, 02:38 AM
Render the background in a texture. Simply call the texture for each rendering and draw other objects on top of it. Change the texture data when the background changes.

I think this is the only solution you can do with GL 1.1.

BionicBytes
08-09-2011, 04:11 AM
You can't really render directly to a texture in GL 1.1.
The way to do it is to render the background obejcts to the back buffer and then copy that buffer to a texture using glCopyTexSubImage2D.
Repeat this process each time the background changes. Meanwhile, each frame draw a full screen quad using this texture and draw the foreground objects on top. This is what _ARTS_ was saying in a short hand way.

Lumanior
08-09-2011, 05:50 AM
The back buffer, in which I have to draw before coping it to a texture would be the same as in which I usually draw before swapping it to the front buffer, right?
Or is there the opportunity to create another auxiliary buffer, from which I can generate the texture?

BionicBytes
08-09-2011, 07:35 AM
The back buffer, in which I have to draw before coping it to a texture would be the same as in which I usually draw before swapping it to the front buffer, right?
Yes.


Or is there the opportunity to create another auxiliary buffer, from which I can generate the texture?
On some implementations yes, on others not necessarily.

Honestly, it's really easy to just draw on to the the usual back buffer all those background triangles and then copy the back buffer to a texture. This should not cause your rendering pipeline to break or require any redesign.

_arts_
08-09-2011, 08:59 AM
You can't really render directly to a texture in GL 1.1.
The way to do it is to render the background obejcts to the back buffer and then copy that buffer to a texture using glCopyTexSubImage2D.

That's what I meant. But I agree it wasn't that clear :)

Lumanior
08-09-2011, 11:09 PM
Ok, thanks for your help. I think this solution is going to work for the most uses cases.
Unfortunately I haven't thought about one specific use case which also requires an often update of the rectangles that are in the background. Since only the color of one rectangle needs to be changed each time, my initial thought was to simply overdraw the existing scene in the back buffer. With the approach above, I would have to do the following things in each rendering loop:

1. Clear back guffer
2. Load previously saved background texture into back buffer
3. Overdraw the specific rectangle in the backbuffer
4. Save back buffer as texture with glCopyTexSubImage2D
5. Draw the foreground objects

I'm afraid, that this would be really time consuming...
What do you think?

BionicBytes
08-10-2011, 01:50 AM
1. Clear back guffer
2. Load previously saved background texture into back buffer
3. Overdraw the specific rectangle in the backbuffer
4. Save back buffer as texture with glCopyTexSubImage2D
5. Draw the foreground objects

Seems reasonable.

I'm afraid, that this would be really time consuming...

Not at all - and much faster than drawing all the background items. Many engines draw to offscreen buffers and then overlay onto the main buffer using full screen quads. It's all hardware accelerated and is very fast. You don't even have the overhead of switching framebuffers, so the draw background is just a full screen quad. On top of that you don't even necessarily have to clear the color buffer as the full screen quad is replacing the contents anyway.