View Full Version : Reading fragment shader output

Maciek R.
10-25-2010, 01:46 PM
I'm sending data to shader program, doing some filtering, and then the shader out variable (vec4) contains the desired output of algorithm.
This output is needed by the rest of application, so I would like to have it accessible through normal (accessible by CPU) pointer.
Is there any way to read (map into CPU memory) such variable from fragment shader?

Alfonse Reinheart
10-25-2010, 03:26 PM
Short answer: use OpenCL.

Long answer:

There is no way to directly access the GPU memory that fragment shaders write to. You could use a vertex shader instead of a fragment shader; you can use transform feedback to store the output of a vertex shader directly into a buffer object. Buffer objects can be mapped and read by the CPU "directly" (there's no guarantee of immediate access to the data).

OpenCL is really what you want if you're using the GPU to compute arbitrary data instead of drawing stuff.

10-25-2010, 08:51 PM
Other way could be to render to a texture and then read or copy the content of the texture into a new buffer. I guess this can be done with FBOs

Maciek R.
10-26-2010, 12:22 AM
Thanks for answers - I have to look into FBOs.
As for OpenCL - I wish I could. But the graphic chip producer made a nasty surprise - first they enabled support for my card (mobile chip - I cannont replace it), and then they dropped it.