It was my intention to write a full article on this new sample, but who am I kidding – I barely have enough time to write this simple little blog post. So, instead of just sitting on the sample and deluding myself that I will someday have enough free-time to write something substantial concerning it – I will just toss it out the door with a brief announcement of, “Come and get it!”
Recently, I was struggling with an OpenGL feature that required me to research faster ways of reading pixel data back to the CPU from the GPU where I could perform some post processing on it. Typically, you should try very hard to keep your post processing on the GPU instead trying to read it back across the bus, but in this case I wanted to fetch the pixel data back so I could load it into a WPF app and I had no choice. It must come back and as fast as possible.
After much research, I settled on a solution that does an off-screen rendering to a FBO (frame buffer object) and then uses two alternating PBOs (pixel buffer objects) to perform an asynchronous read-back to system memory via DMA transfers. The beauty of this approach is that it disables the blocking behavior which is typically associated with calling glReadPixels, and this is always the prime culprit when it comes to bad read-back performance for pixel data that is being shuttled back across the bus. If you’re researching something similar, I hope this research sample proves useful.
The sample targets the regular desktop version of OpenGL and was coded and tested in Visual Studio 2005 and 2008 on both Windows Xp and Windows 7.