PDA

View Full Version : glReadPixel and glPixelStore



devdept
11-21-2008, 05:47 AM
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

_NK47
11-21-2008, 09:05 AM
http://opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/readpixels.html

dletozeun
11-21-2008, 11:34 AM
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.

ZbuffeR
11-21-2008, 12:21 PM
2) RGBA8 is faster because it has nice 32bit alignment.

devdept
11-21-2008, 03:26 PM
ZbuffeR,

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

Thanks,

Alberto

devdept
11-21-2008, 03:30 PM
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

dletozeun
11-22-2008, 08:28 AM
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.

devdept
11-23-2008, 07:44 AM
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

dletozeun
11-23-2008, 09:28 AM
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... :)

devdept
11-24-2008, 01:49 AM
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

dletozeun
11-24-2008, 03:14 PM
You are right, I was mistaken, I though it the default value was 2! :) 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! :) 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!

devdept
11-25-2008, 01:49 AM
Ok, I will convince the customer of a display driver bug...

Thanks,

Alberto