GLREADPIXELS(3G)
π GLREADPIXELS(3G) π
okay so bestie, welcome to the GLREADPIXELS(3G) manual page β we're reading pixels out of the frame buffer and honestly it's giving main character energy β¨
π NAME π
glReadPixels, glReadnPixels β read a block of pixels from the frame buffer π«Ά
π C SPECIFICATION π
okay so here's the exact function drip, no cap:
void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
GLenum format, GLenum type, GLvoid * data);
void glReadnPixels(GLint x, GLint y, GLsizei width, GLsizei height,
GLenum format, GLenum type, GLsizei bufSize,
void *data);
πΈ PARAMETERS πΈ
x,yβ these specify the window coordinates of the first pixel that is read from the frame buffer. This location is the lower left corner of a rectangular block of pixels. π¦width,heightβ these specify the dimensions of the pixel rectangle.widthandheightof one correspond to a single pixel. literally one pixel, bestie πformatβ specifies the format of the pixel data. The following symbolic values are accepted:GL_STENCIL_INDEX,GL_DEPTH_COMPONENT,GL_DEPTH_STENCIL,GL_RED,GL_GREEN,GL_BLUE,GL_RGB,GL_BGR,GL_RGBA, andGL_BGRA. πtypeβ specifies the data type of the pixel data. Must be one ofGL_UNSIGNED_BYTE,GL_BYTE,GL_UNSIGNED_SHORT,GL_SHORT,GL_UNSIGNED_INT,GL_INT,GL_HALF_FLOAT,GL_FLOAT,GL_UNSIGNED_BYTE_3_3_2,GL_UNSIGNED_BYTE_2_3_3_REV,GL_UNSIGNED_SHORT_5_6_5,GL_UNSIGNED_SHORT_5_6_5_REV,GL_UNSIGNED_SHORT_4_4_4_4,GL_UNSIGNED_SHORT_4_4_4_4_REV,GL_UNSIGNED_SHORT_5_5_5_1,GL_UNSIGNED_SHORT_1_5_5_5_REV,GL_UNSIGNED_INT_8_8_8_8,GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,GL_UNSIGNED_INT_2_10_10_10_REV,GL_UNSIGNED_INT_24_8,GL_UNSIGNED_INT_10F_11F_11F_REV,GL_UNSIGNED_INT_5_9_9_9_REV, orGL_FLOAT_32_UNSIGNED_INT_24_8_REV. π₯bufSizeβ specifies the size of the buffer data forglReadnPixelsfunction. πdataβ returns the pixel data. periodt π
β¨ DESCRIPTION β¨
glReadPixels and glReadnPixels return pixel data from the frame buffer, starting with the pixel whose lower left corner is at location (x, y), into client memory starting at location data. π«Ά
Several parameters control the processing of the pixel data before it is placed into client memory. These parameters are set with glPixelStore(). This reference page describes the effects on glReadPixels and glReadnPixels of most, but not all of the parameters specified by these three commands. π
If a non-zero named buffer object is bound to the GL_PIXEL_PACK_BUFFER target (see glBindBuffer()) while a block of pixels is requested, data is treated as a byte offset into the buffer object's data store rather than a pointer to client memory. no cap, that's the vibe π
glReadPixels and glReadnPixels return values from each pixel with lower left corner at x + i, y + j for 0 <= i < width and 0 <= j < height. This pixel is said to be the ith pixel in the jth row. Pixels are returned in row order from the lowest to the highest row, left to right in each row. πΈ
format specifies the format for the returned pixel values; accepted values are:
π GL_STENCIL_INDEX π
Stencil values are read from the stencil buffer.
π GL_DEPTH_COMPONENT π
Depth values are read from the depth buffer. Each component is converted to floating point such that the minimum depth value maps to 0 and the maximum value maps to 1. Each component is clamped to the range 0 to 1.
π GL_DEPTH_STENCIL π
Values are taken from both the depth and stencil buffers. The type parameter must be GL_UNSIGNED_INT_24_8 or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
π GL_RED, GL_GREEN, GL_BLUE, GL_RGB, GL_BGR, GL_RGBA, GL_BGRA π
Color values are taken from the color buffer.
Finally, the indices or components are converted to the proper format, as specified by type. If format is GL_STENCIL_INDEX and type is not GL_FLOAT, each index is masked with the mask value given in the following table. If type is GL_FLOAT, then each integer index is converted to single-precision floating-point format. π§
If format is GL_RED, GL_GREEN, GL_BLUE, GL_RGB, GL_BGR, GL_RGBA, or GL_BGRA and type is not GL_FLOAT, each component is multiplied by the multiplier shown in the following table. If type is GL_FLOAT, then each component is passed as is (or converted to the client's single-precision floating-point format if it is different from the one used by the GL). π
Okay so this next bit is literally just a glow-up chart, bestie β it tells you, for every type you're allowed to hand over, what the index mask is and how the component values get converted. Read it like a little lookbook: left column is the type, middle is the mask, right is the conversion. π
GL_UNSIGNED_BYTEβ index mask2^8 - 1, component conversion(2^8 - 1)cGL_BYTEβ index mask2^7 - 1, component conversion[(2^8 - 1)c - 1] / 2GL_UNSIGNED_SHORTβ index mask2^16 - 1, component conversion(2^16 - 1)cGL_SHORTβ index mask2^15 - 1, component conversion[(2^16 - 1)c - 1] / 2GL_UNSIGNED_INTβ index mask2^32 - 1, component conversion(2^32 - 1)cGL_INTβ index mask2^31 - 1, component conversion[(2^32 - 1)c - 1] / 2
And yes, that lil c in every conversion is just the component value doing its main character thing β it's not a mystery variable, it's the value, no cap. π«Ά
So like, signed types get that - 1 Γ· 2 treatment so they land in the right spot, and unsigned types get the clean straight-up multiply. Notice how the mask for the signed version is one bit smaller (2^7 - 1 vs 2^8 - 1, 2^15 - 1 vs 2^16 - 1, 2^31 - 1 vs 2^32 - 1) but the conversion still uses the unsigned-style 2^8, 2^16, 2^32 scale. That's not a typo, that's just the vibe of the table β literally copy it exactly. β¨
Read the rows, don't vibe-guess the numbers. Half of y'all are gonna squint at 2^31 - 1 and quietly type 2^32 - 1 and then wonder why your pixels are cursed. π Not on my watch.
those stray little c, -, 1 bits at the very top are just the tail end of the cell that got chopped in half by the page break β they're the last crumbs of a 2^N - 1 and a c, nothing new, okurrr π«Ά
and then the table picks right back up. the terminal squished it into vertical confetti (classic), so here's how to read each line: type first, then the middle column, then the right-hand column, left to right, exactly as printed. middle column is either none or 2^N - 1. right-hand column is either just c, or 2^N - 1 with a c chillin' underneath it β¨
GL_HALF_FLOATβnoneΒ·cGL_FLOATβnoneΒ·cGL_UNSIGNED_BYTE_3_3_2β2^N - 1Β·2^N - 1andcGL_UNSIGNED_BYTE_2_3_3_REVβ2^N - 1Β·2^N - 1andcGL_UNSIGNED_SHORT_5_6_5β2^N - 1Β·2^N - 1andcGL_UNSIGNED_SHORT_5_6_5_REVβ2^N - 1Β·2^N - 1andcGL_UNSIGNED_SHORT_4_4_4_4β2^N - 1Β·2^N - 1andcGL_UNSIGNED_SHORT_4_4_4_4_REVβ2^N - 1Β·2^N - 1andc
so the two float-y icon types are out here living their truth with none in the middle column, and every packed type is giving 2^N - 1 realness in both columns, with that little c tagging along on the right π
the list keeps going btw, we're not done, stay with me π₯
β¦okay so the table is like not done yet, bestie π it just keeps going, same vibe every row. Here's the rest of it, and every one of these types comes with size 2, and the two right-hand cells both stack up as 2 / N / - / 1 (the N floating up above the -1), with that last cell wearing a little c tag π
GL_UNSIGNED_SHORT_5_5_5_1β size2; the two component cells both read2/N/-/1, and the last one is taggedcπGL_UNSIGNED_SHORT_1_5_5_5_REVβ size2; same deal, both component cells read2/N/-/1, last cell taggedcβ¨GL_UNSIGNED_INT_8_8_8_8β size2; again2/N/-/1in both cells,con the end πΈGL_UNSIGNED_INT_8_8_8_8_REVβ size2;2/N/-/1twice over, and yep,cπ¦GL_UNSIGNED_INT_10_10_10_2β size2;2/N/-/1,2/N/-/1, plus that littlecπGL_UNSIGNED_INT_2_10_10_10_REVβ size2; both cells2/N/-/1,ctagging along πGL_UNSIGNED_INT_24_8β size2; same pattern one more time β2/N/-/1in both component cells,con the right π
So if you clocked the pattern: every single one of these rows is rocking the exact same structure, no cap π
Rather than making you eyeball that ASCII soup, here's the same seven rows written out the chill way β type, size, and the two stacked cells, with the c marker noted:
GL_UNSIGNED_SHORT_5_5_5_1 2 2 N - 1 2 N - 1 c
GL_UNSIGNED_SHORT_1_5_5_5_REV 2 2 N - 1 2 N - 1 c
GL_UNSIGNED_INT_8_8_8_8 2 2 N - 1 2 N - 1 c
GL_UNSIGNED_INT_8_8_8_8_REV 2 2 N - 1 2 N - 1 c
GL_UNSIGNED_INT_10_10_10_2 2 2 N - 1 2 N - 1 c
GL_UNSIGNED_INT_2_10_10_10_REV 2 2 N - 1 2 N - 1 c
GL_UNSIGNED_INT_24_8 2 2 N - 1 2 N - 1 c
Heads up bestie: those2/N/-/1bits are stacked vertically in the original because it's a typeset table β theNrides up high and the-1sits low, so read them together when you're matching your type against the spec π The letters and numbers themselves are exactly as printed, zero edits, iykyk.
And like β that's the run of the table for this chunk. There's still more page to get through, so don't run off yet, we're not even at the good part π
okay so the table has just these last three rows left, bestie β no cap, weβre almost through the pixel-layout tea:
GL_UNSIGNED_INT_10F_11F_11F_REV/--/SpecialGL_UNSIGNED_INT_5_9_9_9_REV/--/SpecialGL_FLOAT_32_UNSIGNED_INT_24_8_REV/none/c (Depth Only)
Return values get placed in memory like this. If format is GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_RED, GL_GREEN, or GL_BLUE, a single value is returned and the data for the ith pixel in the jth row is placed in location j β’ width + i. GL_RGB and GL_BGR return three values, GL_RGBA and GL_BGRA return four values for each pixel, with all values corresponding to a single pixel occupying contiguous space in data. Storage parameters set by glPixelStore(), such as GL_PACK_LSB_FIRST and GL_PACK_SWAP_BYTES, affect the way that data is written into memory. See glPixelStore() for a description.
glReadnPixels function will only handle the call if bufSize is at least of the size required to store the requested data. Otherwise, it will generate a GL_INVALID_OPERATION error.
π«§ NOTES
- Values for pixels that lie outside the window connected to the current GL context are undefined.
- If an error is generated, no change is made to the contents of
data.
π ERRORS
GL_INVALID_ENUMβ generated ifformatortypeis not an accepted value.GL_INVALID_VALUEβ generated if eitherwidthorheightis negative.GL_INVALID_OPERATIONβ generated ifformatisGL_STENCIL_INDEXand there is no stencil buffer.GL_INVALID_OPERATIONβ generated ifformatisGL_DEPTH_COMPONENTand there is no depth buffer.GL_INVALID_OPERATIONβ generated ifformatisGL_DEPTH_STENCILand there is no depth buffer or if there is no stencil buffer.GL_INVALID_ENUMβ generated ifformatisGL_DEPTH_STENCILandtypeis notGL_UNSIGNED_INT_24_8orGL_FLOAT_32_UNSIGNED_INT_24_8_REV.GL_INVALID_OPERATIONβ generated iftypeis one ofGL_UNSIGNED_BYTE_3_3_2,GL_UNSIGNED_BYTE_2_3_3_REV,GL_UNSIGNED_SHORT_5_6_5, orGL_UNSIGNED_SHORT_5_6_5_REVandformatis notGL_RGB.GL_INVALID_OPERATIONβ generated iftypeis one ofGL_UNSIGNED_SHORT_4_4_4_4,GL_UNSIGNED_SHORT_4_4_4_4_REV,GL_UNSIGNED_SHORT_5_5_5_1,GL_UNSIGNED_SHORT_1_5_5_5_REV,GL_UNSIGNED_INT_8_8_8_8,GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2, orGL_UNSIGNED_INT_2_10_10_10_REVandformatis neitherGL_RGBAnorGL_BGRA.GL_INVALID_OPERATIONβ generated if a non-zero buffer object name is bound to theGL_PIXEL_PACK_BUFFERtarget and the buffer objectβs data store is currently mapped.GL_INVALID_OPERATIONβ generated if a non-zero buffer object name is bound to theGL_PIXEL_PACK_BUFFERtarget and the data would be packed to the buffer object such that the memory writes required would exceed the data store size.GL_INVALID_OPERATIONβ generated if a non-zero buffer object name is bound to theGL_PIXEL_PACK_BUFFERtarget anddatais not evenly divisible into the number of bytes needed to store in memory a datum indicated bytype.GL_INVALID_OPERATIONβ generated ifGL_READ_FRAMEBUFFER_BINDINGis non-zero, the read framebuffer is complete, and the value ofGL_SAMPLE_BUFFERSfor the read framebuffer is greater than zero.GL_INVALID_OPERATIONβ generated byglReadnPixelsif the buffer size required to store the requested data is greater thanbufSize.
π ASSOCIATED GETS
glGet() with argument GL_PIXEL_PACK_BUFFER_BINDING.
π VERSION SUPPORT
The table headers are Function / Feature Name and OpenGL Version, with version columns 2.0, 2.1, 3.0, 3.1, 3.2, 3.3, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5.
glReadPixelsβ2.0:β;2.1:β;3.0:β;3.1:β;3.2:β;3.3:β;4.0:β;4.1:β;4.2:β;4.3:β;4.4:β;4.5:β.glReadnPixelsβ2.0:-;2.1:-;3.0:-;3.1:-;3.2:-;3.3:-;4.0:-;4.1:-;4.2:-;4.3:-;4.4:-;4.5:β.
π SEE ALSO
glPixelStore(), glReadBuffer().
Β©οΈ COPYRIGHT
Copyright Β© 1991-2006 Silicon Graphics, Inc. Copyright Β© 2010-2014 Khronos Group. This document is licensed under the SGI Free Software B License. For details, see http://oss.sgi.com/projects/FreeB/.
Β©οΈ COPYRIGHT
Copyright Β© 1991-2006 Silicon Graphics, Inc. Copyright Β© 2010-2014 Khronos Group
And thatβs the footer, bestie: source/version tag [FIXME: source], date 08/09/2021, page GLREADPIXELS(3G) β iconic. πβ¨
π¦ where this page comes from
- centos-stream 9: gl-manpages 1.1-24.20190306.el9 Β· MIT and Open Publication
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms