Sign in to follow this  
CatmanFS

OpenGL Pixel buffer

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites


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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this