iDevGames Forums
Best way to readback float pixels? - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Best way to readback float pixels? (/thread-2750.html)



Best way to readback float pixels? - kelvin - Feb 27, 2008 04:43 PM

So, what I'm doing right now is creating a texture backed FBO/renderbuffer, rendering, then reading back with glGetTexImage().

My problem is that my component values are being clipped to [0.0f,1.0f]. I'm using a float_pixel texture. Is there anyway I can get values outside of [0.0f,1.0f] back?

***Edit: Cripes. So I messed up. My values were being clipped because I was using glColor to draw. Once I stick my floats in a texture, I get the right output.

Anyhow, I'm still interested in hearing what the best way to do the readback is.


Best way to readback float pixels? - sohta - Feb 27, 2008 06:55 PM

The only real good way of doing this is to figure out a way of not having to do it... The performance hit you get is MASSIVE. It's way lighter to monopolize a texture unit for a one pixel texture, and use a texture sampler in your shader, than reading the single pixel over the bus and pushing it back as a uniform.

If it's that bad for a single pixel, you can imagine the rest.

On the other hand, if you really have to. You don't have to make the FBO a texture target. You can create a regular FBO and use glReadPixels instead. This way, you won't be locking up a texture unit.


Best way to readback float pixels? - OneSadCookie - Feb 27, 2008 07:06 PM

You can use pixel buffer objects (ARB_pixel_buffer_object) to get asynchronous pixel readback, if you can cope with the latency required you shouldn't see a major performance hit I think. Examples in the PBO spec.


Best way to readback float pixels? - kelvin - Feb 27, 2008 07:27 PM

Just to clarify, the rendering I'm doing isn't for anything visible. This is all offscreen and not used for graphics. The reason I want to do the readback is because I want to sample (potentially) thousands of points in the frame for calculation of a vector field. The floats I get out of the readback need to update the state of my application, not just the graphics.

So yeah, I want pretty much all the data in the frame. And no, I'm not bound by synchronizing with the graphics.


Best way to readback float pixels? - kelvin - Feb 27, 2008 07:31 PM

OneSadCookie Wrote:You can use pixel buffer objects (ARB_pixel_buffer_object) to get asynchronous pixel readback, if you can cope with the latency required you shouldn't see a major performance hit I think. Examples in the PBO spec.

I looked at the PBO route, but I wasn't clear on how to get the pixels out of GL and back into my application layer. I can do this to get the pixels into a PBO float array, but then what?
Code:
glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, pbo);    
glReadPixels(0, 0, m_width, m_height, GL_RGBA, GL_FLOAT, NULL);



Best way to readback float pixels? - OneSadCookie - Feb 27, 2008 07:44 PM

glMapBufferARB... as much time later as possible.


Best way to readback float pixels? - kelvin - Feb 27, 2008 07:48 PM

how do I check if it's done?


Best way to readback float pixels? - OneSadCookie - Feb 27, 2008 08:23 PM

You don't; glMapBufferARB will block if it's not.


Best way to readback float pixels? - kelvin - Feb 27, 2008 10:23 PM

For a 480x360 frame buffer backed by a float32 rgba texture I get:
glGetTexImage: 40.1FPS max
glMapBufferARB: 76.8FPS max

so far so good I guess.

EDIT:
ew... well, if up the buffer to 512x512 it starts to barf about 2/3rds the way in... if I push it higher it barfs on all the bytes.