nVidia - glReadPixels returning garbage sometimes

I am having an odd problem, occasionally my glReadPixels() from FBO returns garbage. Sometimes it’s just mangled pixels, sometimes it’s an old image (from rendering before). This happens rarely and seemingly at random. It’s very hard to track down the cause because of that. Also this doesn’t seem to happen on another machine running ATI drivers. I’m tempted to blame it on the driver.

I’m running nVidia 258.49 drivers. Also tried older version of the drivers 197.xx. Same results

My code is basically:


glBindFramebufferEXT(myBuffer);
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
...Do My Rendering...
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
glFinish();    //I initially didn't have this, but why not
unsigned char * pixelBuffer = new unsigned char[readWidth*height*3];
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*) pixelBuffer);
glFinish();    //wait for read to finish
GLenum err = glGetError();   //no problems reported here!

Anyone experience anything similar? I’m out of ideas.
Thanks.

The first things that come to my mind when I read GL_RGB and GL_UNSIGNED_BYTE:

  1. Inefficient!! You would certainly be better off with some RGBA format.
  2. is GL_PACK_ALIGNMENT set to 1 ?! If not, this may explain the garbage.

Last but not least, you don’t need those glFinish() calls there, except maybe for timing purposes.

I set GL_PACK_ALIGNMENT when I initialize and create several textures. I don’t change it, so it should remain at 1. I will double check with glGet().

The problem is that glReadPixels() returns garbage sometimes, and then continues to work, the fails again sometimes, then continues fine.

I just added glCheckFramebufferStatusEXT() and FBO is complete at all times, even when I visually see that the image has failed.

I believe I have found the problem - as far as being able to replicate it on demand.

The images come back as garbage whenever I establish or quit a connection to the machine running the OpenGL using RAdmin. RAdmin installs a “mirror driver” so it does interface to the display adapter in some way, and obviously one of the drivers (nVidia or RAdmin) messes something up.

So I connect via RAdmin, there’s a glitch in glReadPixels, then everything goes back to normal and things work. I disconnect (session expires) and there’s another glitch and everything works again. Accounting for the “random” behavior.

Pure luck that I caught it.
Thanks skynet for your suggestions.

Do you know of any actual (and recent) benchmark results for that?
I have tried recently a few ways of glReadPixels - with rgba vs rgb vs bgra vs bgr and saw virtually no difference in dl rate. That said my benchmark could be flawed, my gfx card special etc etc.

So … does special formating for performance reasons of readback of framebuffer still applies on modern gfx cards?

I think he’s referring to the fact that the draw buffer is GL_RGBA and a read of GL_RGB will require a conversion rather than a straight copy.

In the end I need RGB, so someone is going to be converting it - me or the driver.

Also, IIRC for absolute raw speed use BGRA. Don’t know if that’s still true or not, but used to be recommended.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.