Accessing an entire column or row of a frame.

Is there a way to access all the elements of a particular column (and row) of a frame (sized MxN) in the fragment shader? My application requires processing a column (say adding all pixels of a column).

 

I prefer not to use glReadPixels() as it degrades the performance considerably.

 

Thanks.

You can render to a texture, then sample from that texture using texture2D in the fragment shader. Note that - depending on what operation you want - splitting the process into multiple steps may be more efficient.Xmas2011-01-25 10:48:01

Did you mean rendering the whole frame (of size MxN,  with M=640 and N=480)? Can you please elaborate more on that?


Now each fragment operation should be about adding/processing the 480 pixel elements in each column.
OpenGLES wrote:
Did you mean rendering the whole frame (of size MxN,  with M=640 and N=480)? Can you please elaborate more on that?

Yes, you would render the whole scene to a texture (used as a colour attachment to a framebuffer object) so it can later be accessed in a fragment shader.



There is example code in our SDK which demonstrates rendering to a texture.



Quote:
Now each fragment operation should be about adding/processing the 480 pixel elements in each column.

It may be more efficient to reduce the texture in multiple steps, e.g. adding groups of eight elements from each column at a time. That way you'd reduce the frame from 640x480 to 640x60 to 640x8.

What's best depends on the exact operation you want to perform (including the precision requirements).