Question

I'm using OpenGL to optimize GUI rendering. When rendering the whole scene it works fine, but that's not optimal, since often only a small part is changed. So I tried this:

    glReadBuffer (GL_FRONT);
    glDrawBuffer (GL_BACK);
    glCopyPixels (0, 0, sz.X, sz.Y, GL_COLOR);
    glFlush();

This should copy front buffer to back buffer, so that afterwards I can change just a portion limited using glViewport. Unfortunately when a scene is changed, it looks like the glCopyPixels command is performed after the actual rendering, so that the original content sort of alphablends with the new graphics.

What is wrong? Or is there a better way to do this? (for the record, when I do nothing, the front buffer starts blinking with back buffer and stuff like that...)

Was it helpful?

Solution

but that's not optimal

What makes you think that? OpenGL and modern GPUs are designed on the grounds, that in the worst case you have to redraw the whole thing anyway and things should perform well in that situation, too.

Or is there a better way to do this?

Yes: Redraw the whole scene. (Or what I suggest below)

To a modern low-end GPU which easily capable of throwing tens of millions of triangles to the screen per second, the few hundred to a thousand triangles of a 2D GUI are neglectible.

In fact your copying-stuff-around will probably a worse performance hit, than redrawing everything, because copying from the front to the back buffer is not a very performant operation and causes serious synchronization issues.

If you want to cache things you might split your GUI into separate widgets of content, which you draw to individually using FBOs into textures – design it in a way that widgets may overlap. You redraw a widget if its contents change. For drawing the whole window you just redraw the full window contents from the textures into the main framebuffer.

OTHER TIPS

Ok so it seems this solves the problem:

    glDisable( GL_BLEND ); 

I don't know why, but it looks like before it was blending the data, despite I didn't find anything about it in docs and "glCopyPixels" doesn't seem it should do that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top