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

http://opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/readpixels.html

  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.

  1. RGBA8 is faster because it has nice 32bit alignment.

ZbuffeR,

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

Thanks,

Alberto

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

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.

dletozeun,

Here is a sample with actual values:

I read a 24bit bitmap with the following dimensions:

6x8 pixels

using:

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

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… :slight_smile:

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

You are right, I was mistaken, I though it the default value was 2! :slight_smile: So you should not have to set row alignment in this case. I don’t have more ideas. But If I was working on this, I would set alignment myself and not let OpenGL put default one, it is safer! :slight_smile: Who knows, it could change and good luck then to find the bug…

Yeah it looks like a driver bug, I don’t understand myself why it is not working on only one damn machine!

Ok, I will convince the customer of a display driver bug…

Thanks,

Alberto