Pixel buffer

Started by
5 comments, last by MJP 10 years, 3 months ago
I'm working with openGL, and I want to know which is the best method of directly accessing information in the frambuffer. I want to be able to read the pixels being displayed onscreen and place them into an array, perform operations, and put them back into the current frame.

What is the best method, meaning fastest or most flexible or is there a tradeoff? If you could give me a few ideas or point me in the right direction I would be much appreciative.
Airlight is looking for game developers
Advertisement
Also, if anyone has any pointers about what operations can be performed the fastest, and any additional information about per-pixel operations would be nice.

I'm really just concerned about direct control over gamma, brightness, contrast, that sort of thing. Would also be nice to hear about any useful ideas for maybe having a histogram or something that could help correct over or underexposure for post processed images.

I'm sure there's a whole list of websites or pages somewhere that has info on this, but I would like to hear some recomendations, maybe a specific site that focuses on post processing operations.
Airlight is looking for game developers


I'm really just concerned about direct control over gamma, brightness, contrast, that sort of thing.
You would be much better off doing these operations using a pixel shader on the GPU. If you use the CPU, it will absolutely ruin performance.

To do this, you'd use FBO's which let you render directly to a texture. You can render a quad to a new texture, which uses a pixel shader that reads the old texture and modifies it in some way.

Reading back data on the CPU is fundamentally at odds with the way that GPU's and drivers work. The driver wants to buffer commands well ahead of when the GPU executes them, and then the GPU works on rendering while the CPU is submitting commands for the next frame or the frame after. This ensures that the CPU and GPU are working in parallel, so that you're utilizing both at the same time. Whenever you read back data from the GPU, you effectively insert a sync point where the CPU has to flush all pending commands, and sit around idle while it waits for the GPU to finish rendering. This then causes the GPU to stall while it waits for the CPU to issue more commands.

I agree with Hodgman: the kinds of operations you've mentioned would be many times more efficient if performed in a fragment shader on the GPU. It will avoid stalls, plus it's extremely likely that the GPU can do the work much faster than a CPU could.

So just keep all he graphics operations on the gpu, got it. Is there a good, cross-platform, well documented method that most people use? Are there tutorials or examples of this somewhere?
Airlight is looking for game developers

As MJP said, a good, cross-platform, well documented method people use is a fragment shader. If you're using OpenGL, just google around for GLSL tutorials. For DX, you'd want HLSL tutorials.

I would do some searching for "post-processing", which is a common term used for performing full-screen operations using fragment shaders. This is one tutorial I found very quickly through Google, although I can't verify that's it's correct or up-to-date since I'm not very familiar with OpenGL specifics.

This topic is closed to new replies.

Advertisement