Best way to readback float pixels?

Member
Posts: 469
Joined: 2002.10
Post: #1
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.

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Quote this message in a reply
Member
Posts: 72
Joined: 2006.10
Post: #2
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.

- Sohta
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
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.
Quote this message in a reply
Member
Posts: 469
Joined: 2002.10
Post: #4
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.

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Quote this message in a reply
Member
Posts: 469
Joined: 2002.10
Post: #5
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);

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
glMapBufferARB... as much time later as possible.
Quote this message in a reply
Member
Posts: 469
Joined: 2002.10
Post: #7
how do I check if it's done?

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #8
You don't; glMapBufferARB will block if it's not.
Quote this message in a reply
Member
Posts: 469
Joined: 2002.10
Post: #9
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.

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  float FBO on iPhone (invalid operation error) Fenris 11 6,977 Jan 17, 2013 05:40 AM
Last Post: Fenris
  convert NSArray in float[] bonanza 6 6,300 Jun 25, 2007 10:33 AM
Last Post: TomorrowPlusX
  Getting to an NSWindow's pixels ThemsAllTook 4 5,267 Jun 5, 2007 08:05 PM
Last Post: sammyjojo
  SDL Parachute Deployed when accessing surface->pixels BobbyWatson 8 5,504 Jan 23, 2005 06:30 PM
Last Post: MattDiamond
  can display float numbers but not integers WhatMeWorry 5 4,805 Jan 3, 2005 10:27 AM
Last Post: ThemsAllTook