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
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
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.
2) 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.
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.So reading 4 components instead of 3 it is faster simply because it matches the framebuffer pixel format ?
dletozeun,
Here is a sample with actual values:
I read a 24bit bitmap with the following dimensions:
Code :6x8 pixels
using:
The Windows bitmap has a row length of 18 bytes and a stride of 20 bytes with a total of 20*8 = 160 bytes.Code :glReadPixels(0, 0, 6, 8, GL_RGB, GL_UNSIGNED_BYTE, bitmapData);
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...![]()
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