Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: glReadPixel and glPixelStore

  1. #1
    Advanced Member Frequent Contributor
    Join Date
    Dec 2005
    Location
    Italy
    Posts
    656

    glReadPixel and glPixelStore

    Hi All,

    Two questions:

    1) If I read pixels using GL_RGB do I need to use the glPixelStore ?

    2) If I have a 8-8-8-8 (RGBA) pixel format is it true that reading GL_RGBA is faster because pixels need not to be converted to GL_RGB ?

    Thanks,

    Alberto

  2. #2
    Advanced Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

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

    Re: glReadPixel and glPixelStore

    1) Do you refer to GL_PACK_ALIGNMENT/GL_UNPACK_ALIGNMENT? If you do, pixel format is not related to that, this is just to tell Opengl how pixel data rows are aligned in memory, when reading them or writing them with glReadPixels,glDrawPixels, glTexImage2D and friends.

    2) Don't know.

  4. #4
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: glReadPixel and glPixelStore

    2) RGBA8 is faster because it has nice 32bit alignment.

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Dec 2005
    Location
    Italy
    Posts
    656

    Re: glReadPixel and glPixelStore

    ZbuffeR,

    So reading 4 components instead of 3 it is faster simply because it matches the framebuffer pixel format ?

    Thanks,

    Alberto

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Dec 2005
    Location
    Italy
    Posts
    656

    Re: glReadPixel and glPixelStore

    dletozeun,


    We have only one customers complaining about incorrect result in the glReadPixel() on a quite old ATI MOBILITY RADEON Xpress 200 Series.

    I was wondering if we can help him using glPixelStore() with some parameter.

    Generally reading RGB (8-8-8) with a glReadPixel() call needs some GL_PACK_ALIGNMENT settings or not?

    It is possible that an ATI driver fails on this task?


    Thanks,

    Alberto

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

    Re: glReadPixel and glPixelStore

    Ok I understand. Pack alignment, just tells opengl how it has to align each data row. If set 1, the next row to write will start immediately at the next byte. With an alignment value of 2, the next row will start at a even byte index, and so on.

    So, IMO, it depends on what picture format you use to write data. For example, I am used to write screenshots in png format, and I use a packing alignment of 1 (byte alignment). Note that default one is 2.

    So reading 4 components instead of 3 it is faster simply because it matches the framebuffer pixel format ?
    I would say that if reading 4 components is faster that reading 3 ones in the framebuffer, Opengl would always read 4 components even when writing only 3 ones. I think that Zbuffer meant that data writing would be faster with a RGBA pixel format due to the 32 bits alignment.

  8. #8
    Advanced Member Frequent Contributor
    Join Date
    Dec 2005
    Location
    Italy
    Posts
    656

    Re: glReadPixel and glPixelStore

    dletozeun,


    Here is a sample with actual values:

    I read a 24bit bitmap with the following dimensions:

    Code :
    6x8 pixels

    using:

    Code :
    glReadPixels(0, 0, 6, 8, GL_RGB, GL_UNSIGNED_BYTE, bitmapData);
    The Windows bitmap has a row length of 18 bytes and a stride of 20 bytes with a total of 20*8 = 160 bytes.

    Should I set some PACK_ALIGNMENT here? How many bytes is the glReadPixel actually reading?

    The strange thing that works perfectly on hundreds of PC and only one customer is complaining.


    Thanks again,

    Alberto

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

    Re: glReadPixel and glPixelStore

    If the stride is 20, I think that a word alignment is fine:

    glPixelStorei(GL_PACK_ALIGNMENT, 4);

    each row will start to a word multiple which is the 20th byte after the 18 bytes.

    Maybe the hundreds of PC are all the same except the last one...

  10. #10
    Advanced Member Frequent Contributor
    Join Date
    Dec 2005
    Location
    Italy
    Posts
    656

    Re: glReadPixel and glPixelStore

    dletozeun,

    Should I specify glPixelStorei(GL_PACK_ALIGNMENT, 4) even if it is the default value? Usually we don't do it.

    I will ask the customer to upgrade his driver to the latest version, I always more convinced that it is a driver bug.

    Thanks,

    Alberto

Posting Permissions

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