I’m working on a 3D chemistry application using OpenGL on the Windows platform. My program renders complex scenes and only animates when the user rotates the scene with the mouse. I’m using OpenGL double-buffering.
I’d like to be able to have the window refresh quickly after an obscured region gets exposed. I’ve tried to figure out a way to do this with some kind of an offscreen buffer, since re-rendering the image can be slow when the scene is complex.
Using BitBlt to copy the window image to system memory is too slow. I am assuming that this is because access to video memory is constrained.
I’ve considered the possibility of using DirectX to create an offscreen surface in video memory, but this looks like a pain.
I’ve also read a few things about the p-buffer extensions. This looks like an appropriate solution, but I’m not sure how widely deployed this extension is.
I’d like to hear from other developers to learn how they have solved this problem.
Thanks very much,
Now, I’m stabbing in the dark here, but what if you call SwapBuffers twice?
- Render scene
- swapbuffers to present the scene from the backbuffer.
- swapbuffers twice without any glClears
Won’t this just block copy the same image again?
If you choose PFD_SWAP_COPY, that may (or may not) give you a back buffer that’ll allow you to blit again by just calling swapbuffers again.
The problem is “may not”. If the obscuring window is another OpenGL window, and the OpenGL driver uses a unified back buffer, then clearly your back buffer will get blown away by the obscurer. That’s why the OpenGL spec does not guarantee anything about back buffers behind overlapping windows.
The things I can think of include drawing to a pbuffer and doing CopyTexSubImage(), or perhaps using the KTX_buffer_region extension.
Thanks for the replies! The PFD_SWAP_COPY option works on my hardware, so I’m going to use that and fall back to re-drawing the scene if it isn’t available.
as well as (the undocumented) ktxbuffer_weegion there is wgl_buffer_region (onj windows) which will alow u to save the color + depth information to a ofscreen buffer for fast redraw again.
“The PFD_SWAP_COPY option works on my hardware, so I’m going to use that and fall back to re-drawing the scene if it isn’t available.”
PFD_SWAP_COPY formats will probably be available on all hardware and that has absolutely nothing to do with the way drawing of unexposed window areas is handled.
Please don’t rely on the behaviour of your single test sytem.
You must handle the WM_PAINT event properly by redrawing stuff you haven’t seen before because you don’t know how the OpenGL implementation underneath handles clipping.
Use a pbuffer if you want to have a reliable unclipped backing storage.