reading floats from pixel buffer objects


I want to read out float values from a pixel buffer object, but unfortunately it doesn’t work. First I initialize the pbo like this:

glGenBuffers(1, &pixelBuffer_);
glBindBuffer(GL_PIXEL_PACK_BUFFER_EXT, pixelBuffer_);
glBufferData(GL_PIXEL_PACK_BUFFER_EXT, number*4*sizeof(float), NULL, GL_DYNAMIC_COPY_ARB);

And after rendering I want to read it out:

glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, pixelBuffer_);
glReadPixels(0,0,res,res,GL_RGBA,GL_FLOAT, NULL);
void* pboMemory = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB);

When I watch the pboMemory, it only contains zero values. But if I change GL_FLOAT to GL_UNSIGNED_BYTE in the ReadPixels call, it works. But I need floats. Am I doing something wrong, or doesn’t pbo work with floats?
thanks for answers!

I think you’re looking for a renderbuffer, not a pixelbuffer-object (I guess someone ought to appologize for the horrible naming). Take a look at the framebuffer-object specification:

@Mikkel Gjoel:
You are wrong… This is PIXEL_BUFFER_OBJECT_EXT related question not FRAME_BUFFER_OBJECTS_EXT.

This should work. Can you tell us your hw specification? OS, graphics card and driver.
btw… did you check for gl errors?


Yes, I am really talking about PIXEL_BUFFER_OBJECT_ARB ( )
I use the following system:
NVIDIA GeForce6200
ForceWare Release 80, Version: 84.21, Release Date: March 17, 2006
WinXP Prof.

If I try to read floats, the glReadPixels call produces the gl-error “invalid operation”. With unsigned bytes it doesn’t.

I need the pbo, because I compute vertices of shadow volume faces in a fragment shader and in the next render pass I want to use the output of the fragment shader as input for a vertex shader. I already have a working version where I read the fragment shader output into the main memory, but this is slow and with the pbo I want to keep the data in the memory of the graphics card. This should be much faster.

I have working demo… readback to PBO and using this data as VBO… Im using
glReadPixels(0,0,TEXX, TEXY, GL_BGRA, GL_FLOAT, BUFFER_OFFSET(0)) call to readback data from offscreen PBUFFER.

Tested on 7600GT, 6800GT, 6800U.

I found my mistake, in the glBufferData call I did not allocate enough memory for floats. Stupid,stupid :wink:
Now it works. Thanks a lot for the hint looking for gl errors!!