Results 1 to 9 of 9

Thread: glReadPixels very slow on 6600gt

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2008
    Posts
    6

    glReadPixels very slow on 6600gt

    I tested the same code below on nvidia 6600gt and nvidia 8600gt.
    The first took 400 ms and the second 6 ms for an 256x256 image.
    Is this normal?

    Code :
    ...
    int* ids = new int[m_aantalPixels];
    glReadBuffer(GL_COLOR_ATTACHMENT1_EXT);
    glTime.restart();
    glReadPixels(0,0,m_width,m_height,GL_RGBA,GL_UNSIGNED_BYTE,ids);
    cerr << "Elapsed time: " << glTime.elapsed() << "\n";
    glReadBuffer(GL_BACK);
    ...

    thx

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Apr 2004
    Posts
    990

    Re: glReadPixels very slow on 6600gt

    Are you sure your timer code is accurate and takes the asynchronous nature of the OpenGL API into account?
    If you want some more reliable timer results, I suggest you use:

    Code :
    ...
    int* ids = new int[m_aantalPixels];
    glReadBuffer(GL_COLOR_ATTACHMENT1_EXT);
    glFinish();
    glTime.restart();
    for (int i=0;i<1000;++i)
        glReadPixels(0,0,m_width,m_height,GL_RGBA,GL_UNSIGNED_BYTE,ids);
    glFinish();
    cerr << "Readback time: " << glTime.elapsed()/1000.0 << "\n";
    glReadBuffer(GL_BACK);
    ...

  3. #3
    Senior Member Frequent Contributor
    Join Date
    Apr 2004
    Posts
    990

    Re: glReadPixels very slow on 6600gt

    One other thing. I noticed you used glReadBuffer(GL_COLOR_ATTACHMENT1_EXT) and glReadBuffer(GL_BACK)
    without switching from your application created FBO to you window system provided framebuffer.

    I'm not 100%, but I think you can only use GL_COLOR_ATTACHMENTi_EXT for application created FBOs and GL_FRONT,GL_BACK,... for your window system provided framebuffer.

    Do you get any GL errors?

  4. #4
    Junior Member Newbie
    Join Date
    Jun 2008
    Posts
    6

    Re: glReadPixels very slow on 6600gt

    Are you sure your timer code takes the asynchronous nature of the OpenGL API into account?
    I'm just using QTime (Qt) as timer, so probably not?
    But my program goes very slow thanks to only these lines of code. When i remove them, it runs fast.

    I tried your suggestion code to get an average time and it gave me: Readback time: 180.191 ms.

    The code below gives no error in the first two checkErrors.
    The last checkError gives: Error: invalid enumerant.

    Code :
    glReadBuffer(GL_COLOR_ATTACHMENT1_EXT);
    checkError();
    glReadPixels(0,0,m_width,m_height,GL_RGBA,GL_UNSIGNED_BYTE,ids);
    glFinish();
    checkError();
    glReadBuffer(GL_BACK);
    checkError();

  5. #5
    Senior Member Frequent Contributor
    Join Date
    Apr 2004
    Posts
    990

    Re: glReadPixels very slow on 6600gt

    That's because GL_BACK is not a valid enumerant for an application created FBO like I said in my previous post.
    Have you tried using GL_BGRA instead of GL_RGBA?

  6. #6
    Junior Member Newbie
    Join Date
    Jun 2008
    Posts
    6

    Re: glReadPixels very slow on 6600gt

    I have tried it now, but it doesn't seem to make a difference.
    I tried these combinations:
    Code :
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_BGRA, GL_UNSIGNED_BYTE, 0);
    glReadPixels(0,0,m_width,m_height,GL_BGRA,GL_UNSIGNED_BYTE,ids);

    Code :
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
    glReadPixels(0,0,m_width,m_height,GL_BGRA,GL_UNSIGNED_INT_8_8_8_8_REV,ids);

  7. #7
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: glReadPixels very slow on 6600gt

    Quote Originally Posted by powermax
    Code :
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_BGRA, GL_UNSIGNED_BYTE, 0);
    glReadPixels(0,0,m_width,m_height,GL_BGRA,GL_UNSIGNED_BYTE,ids);

    Code :
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
    glReadPixels(0,0,m_width,m_height,GL_BGRA,GL_UNSIGNED_INT_8_8_8_8_REV,ids);
    What do you expect that this code do?

    If you want to copy the current read buffer into a texture use glCopyTexSubImage2D instead of glReadPixels

  8. #8
    Junior Member Newbie
    Join Date
    Jun 2008
    Posts
    6

    Re: glReadPixels very slow on 6600gt

    First I render to 2 fbo textures with a shader. One fbo texture is used for reading back values from the gpu to the cpu with glReadPixels. This works on my other gpu in 6 ms and the values i get back are correct. I use them in my program on the cpu. The second fbo texture is used in rendering to the framebuffer.

    The glTexImage2D line is located where the fbo and textures are initialy created. The glReadPixels line is located before fbo->unbind.

  9. #9
    Member Newbie
    Join Date
    Jan 2012
    Posts
    31

    Re: glReadPixels very slow on 6600gt

    Hello,

    there are some tips in the OpenGL FAQ to increase the performance of glReadPixels.

    dj3hut1

Similar Threads

  1. glReadPixels too slow
    By e7fendy in forum OpenGL ES
    Replies: 1
    Last Post: 09-05-2011, 03:01 PM
  2. glReadPixels() too slow
    By Andreas K in forum OpenGL: Advanced Coding
    Replies: 9
    Last Post: 07-30-2010, 02:49 PM
  3. glTexImage2D vs glReadPixels - why so slow?
    By Jay Cornwall in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 12-08-2005, 11:41 PM
  4. GL_POINT_SPRITES_ARB slow w/ 6600gt, fast w/ 9800pro wth?
    By chracatoa in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 06-24-2005, 09:08 AM
  5. glreadpixels too slow
    By imported_Adrian in forum OpenGL: Advanced Coding
    Replies: 13
    Last Post: 11-30-2002, 11:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean