View Full Version : Stencil bitplanes/glReadPixels() - pixel per byte or pixel per bit ?

Jon Mc Jon
10-05-2006, 07:43 PM

If I read an area of the stencil buffer back using glReadPixels(), and specify that I only wish to read back a single bitplane (and specify the right packing info), are the bits that come back packed into bytes:

* 1 bit per pixel, ie. 8 pixels to a byte


* 1 bit per byte, ie. 1 pixel to a byte



10-06-2006, 04:01 AM
You specify the user side layout of the read back data by using the glReadPixels "type" parameter.
With format GL_STENCIL_INDEX and type GL_UNSIGNED_BYTE you would read the stencil data into 8 bits per pixel. Most OpenGL implementations offer 8 stencil bits per pixel, which matches nicely.
With GL_BITMAP you would get one bit per pixel tightly packed into bytes.

The masking you want doesn't work for glReadPixels, the manual says the readback value is masked with the index mask matching the output size, 255 for unsigned byte, 1 for bitmaps.
Means only if your stencil values are only 0 or 1 you can pack them into 8 bits per byte using GL_BITMAP. (Not tried myself.)
A higher bit can not be extracted during glReadPixels this way, read GL_UNSIGNED_BYTE and do your own masking.

Jon Mc Jon
10-09-2006, 04:06 PM
Thanks Relic!

So glReadPixels() can take GL_BITMAP as a param ?
I'll investigate that.


Jon Mc Jon
10-09-2006, 07:24 PM
Yippee, on paper that seems to do what I want.
Can't believe I missed that in the Spec.
Thanks Relic.