SwapBuffers: copy or swap?

When using SwapBuffers() on the Windows platform, it seems that what actually happens on most hardware is that the contents of the back buffer get copied to the front buffer, leaving the back buffer unchanged. I have taken advantage of this to nicely show incremental building of scenes; that is, I draw each additional object in the scene to the back buffer, then call SwapBuffers(), which results in the scene being incrementally populated on-screen.

It seems I can’t make this assumption. On a recently-acquired Voodoo 3 card, SwapBuffers seems to actually do just that–the front buffer contents end up in the back buffer. This totally invalidates the approach I am using above.

My questions are:

  1. Is there any way to simply copy back buffer to front, rather than swap? If so, would this be slower than SwapBuffers() ?
  2. If not, what approach would you suggest for incrementally building up (and displaying at each step) a complex scene?
    Are there efficient (and free of flashing)
    ways to do this without double-buffering?

You can just keep a copy of your backbuffer before the swap in the accumulation buffer or any other auxialary buffer and reload it.

[This message has been edited by Gorg (edited 09-28-2000).]

Originally posted by senor_aggie:
[b]
When using SwapBuffers() on the Windows platform, it seems that what actually happens on most hardware is that the contents of the back buffer get copied to the front buffer, leaving the back buffer unchanged. I have taken advantage of this to nicely show incremental building of scenes; that is, I draw each additional object in the scene to the back buffer, then call SwapBuffers(), which results in the scene being incrementally populated on-screen.

It seems I can’t make this assumption. On a recently-acquired Voodoo 3 card, SwapBuffers seems to actually do just that–the front buffer contents end up in the back buffer. This totally invalidates the approach I am using above.

My questions are:

  1. Is there any way to simply copy back buffer to front, rather than swap? If so, would this be slower than SwapBuffers() ?
  2. If not, what approach would you suggest for incrementally building up (and displaying at each step) a complex scene?
    Are there efficient (and free of flashing)
    ways to do this without double-buffering?[/b]

It is never safe to assume anything about the contents of the back buffer after SwapBuffers.

I’d suggest one of two alternatives:

  • use actual front-buffered rendering
  • CopyPixels from back buffer to front buffer
  • Matt

The accumulation buffer would only keep color info; I need the back depth buffer contents preserved as well. What other buffer might I use for this, and how would the transfer occur? I could use Read/WritePixels I guess…

Originally posted by Gorg:
[b]You can just keep a copy of your backbuffer before the swap in the accumulation buffer or any other auxialary buffer and reload it.

[This message has been edited by Gorg (edited 09-28-2000).][/b]

Thanks; however, does CopyPixels work between multiple buffers? I thought it operated between regions in a single buffer…

Originally posted by mcraighead:
[b] It is never safe to assume anything about the contents of the back buffer after SwapBuffers.

I’d suggest one of two alternatives:

  • use actual front-buffered rendering
  • CopyPixels from back buffer to front buffer
  • Matt[/b]

Originally posted by senor_aggie:
[b]
It seems I can’t make this assumption. On a recently-acquired Voodoo 3 card, SwapBuffers seems to actually do just that–the front buffer contents end up in the back buffer. This totally invalidates the approach I am using above.

That might have something to do with rendering in fullscreen mode or not. When you render in a window, swapping the buffers has to copy the contents back to front - swapping the buffers in fullscreen mode just swaps memory addresses of a visible are of your video memory (front buffer) and an invisible area of the video memory (back buffer).
I believe to recall that Voodoo hardware is not able to render into a window, only fullscreen mode (correct me if I’m wrong).

To your questions:

  1. It would definitely be slower, cause copying has to transfer a memory block as big as the screen from one buffer to another, swapping the buffers simply swaps 2 memory addresses.

  2. You could render the scene parts into an offscreen buffer, copy this offscreen buffer into the back buffer and then swap the buffers.
    Technically you could do that directly:

GLubyte *offScreen, *back, *front;

renderScenePartIntoOffscreenBuffer();
memcpy(back, offScreen, widthheightbytesPerPixel); // copy screen from offScreen to back
swapBuffers();

That involves a little more hassle setting up OpenGL and video card for the buffers.

Originally posted by senor_aggie:

Thanks; however, does CopyPixels work between multiple buffers? I thought it operated between regions in a single buffer…

It can do both. Do this:

glReadBuffer(GL_BACK);
glDrawBuffer(GL_FRONT);
// set up raster pos
glCopyPixels(…);

CopyPixels reads from the current ReadBuffer and writes to the current DrawBuffer.

  • Matt