Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: nVidia - glReadPixels returning garbage sometimes.

  1. #1
    Intern Contributor
    Join Date
    Jul 2004
    Location
    Toronto
    Posts
    97

    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:
    Code :
    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.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2003
    Posts
    665

    Re: nVidia - glReadPixels returning garbage sometimes.

    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.

  3. #3
    Intern Contributor
    Join Date
    Jul 2004
    Location
    Toronto
    Posts
    97

    Re: nVidia - glReadPixels returning garbage sometimes.

    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.

  4. #4
    Intern Contributor
    Join Date
    Jul 2004
    Location
    Toronto
    Posts
    97

    Re: nVidia - glReadPixels returning garbage sometimes.

    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.

  5. #5
    Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    268

    Re: nVidia - glReadPixels returning garbage sometimes.

    Quote Originally Posted by skynet
    1) Inefficient!! You would certainly be better off with some RGBA format.
    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?

  6. #6
    Intern Contributor
    Join Date
    Jul 2004
    Location
    Toronto
    Posts
    97

    Re: nVidia - glReadPixels returning garbage sometimes.

    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.

  7. #7
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,213

    Re: nVidia - glReadPixels returning garbage sometimes.

    Quote Originally Posted by Budric
    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.
    Also, IIRC for absolute raw speed use BGRA. Don't know if that's still true or not, but used to be recommended.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •