glReadPixels(3G)

glReadPixels - read a block of pixels from the frame buffer

As shipped in IRIX 6.5.30. Last changed in IRIX 6.5.15.

NAME
     glReadPixels - read a block of pixels from the frame buffer


C SPECIFICATION
     void glReadPixels( GLint x,
                        GLint y,
                        GLsizei width,
                        GLsizei height,
                        GLenum format,
                        GLenum type,
                        GLvoid *pixels )


PARAMETERS
     x, y 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
          Specify the dimensions of the pixel rectangle.  width and height of
          one correspond to a single pixel.

     format
          Specifies the format of the pixel data.  The following symbolic
          values are accepted:  GL_COLOR_INDEX, GL_STENCIL_INDEX,
          GL_DEPTH_COMPONENT, GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA, GL_RGB,
          GL_BGR, GL_RGBA, GL_BGRA, GL_ABGR_EXT, GL_LUMINANCE, and
          GL_LUMINANCE_ALPHA.

     type Specifies the data type of the pixel data.  Must be one of
          GL_UNSIGNED_BYTE, GL_BYTE, GL_BITMAP, GL_UNSIGNED_SHORT, GL_SHORT,
          GL_UNSIGNED_INT, GL_INT, 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, or
          GL_UNSIGNED_INT_2_10_10_10_REV.

     pixels
          Returns the pixel data.

DESCRIPTION
     glReadPixels returns 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 pixels.  Several parameters control the processing
     of the pixel data before it is placed into client memory.  These
     parameters are set with three commands:  glPixelStore, glPixelTransfer,
     and glPixelMap.  This reference page describes the effects on
     glReadPixels of most, but not all of the parameters specified by these
     three commands.
     When the GL_ARB_imaging extension is supported, the pixel data may be
     processed by additional operations including color table lookup, color
     matrix tranformations, convolutions, histograms and minimum and maximun
     pixel value computations.

     glReadPixels returns 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_COLOR_INDEX
               Color indices are read from the color buffer selected by
               glReadBuffer.  Each index is converted to fixed point, shifted
               left or right depending on the value and sign of
               GL_INDEX_SHIFT, and added to GL_INDEX_OFFSET. If GL_MAP_COLOR
               is GL_TRUE, indices are replaced by their mappings in the table
               GL_PIXEL_MAP_I_TO_I.

     GL_STENCIL_INDEX
               Stencil values are read from the stencil buffer.  Each index is
               converted to fixed point, shifted left or right depending on
               the value and sign of GL_INDEX_SHIFT, and added to
               GL_INDEX_OFFSET. If GL_MAP_STENCIL is GL_TRUE, indices are
               replaced by their mappings in the table GL_PIXEL_MAP_S_TO_S.

     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
               then multiplied by GL_DEPTH_SCALE, added to GL_DEPTH_BIAS, and
               finally clamped to the range [0,1].

     GL_RED

     GL_GREEN

     GL_BLUE

     GL_ALPHA

     GL_RGB

     GL_BGR

     GL_RGBA

     GL_BGRA

     GL_ABGR_EXT

     GL_LUMINANCE

     GL_LUMINANCE_ALPHA
               Processing differs depending on whether color buffers store
               color indices or RGBA color components.  If color indices are
               stored, they are read from the color buffer selected by
               glReadBuffer.  Each index is converted to fixed point, shifted
               left or right depending on the value and sign of
               GL_INDEX_SHIFT, and added to GL_INDEX_OFFSET. Indices are then
               replaced by the red, green, blue, and alpha values obtained by
               indexing the tables GL_PIXEL_MAP_I_TO_R, GL_PIXEL_MAP_I_TO_G,
               GL_PIXEL_MAP_I_TO_B, and GL_PIXEL_MAP_I_TO_A.  Each table must
                           n
               be of size 2 , but n may be different for different tables.
               Before an index is used to look up a value in a table of size
                n                             n
               2 , it must be masked against 2 -1.

               If RGBA color components are stored in the color buffers, they
               are read from the color buffer selected by glReadBuffer.  Each
               color component is converted to floating point such that zero
               intensity maps to 0.0 and full intensity maps to 1.0.  Each
               component is then multiplied by GL_c_SCALE and added to
               GL_c_BIAS, where c is RED, GREEN, BLUE, or ALPHA. Finally, if
               GL_MAP_COLOR is GL_TRUE, each component is clamped to the range
               [0, 1], scaled to the size of its corresponding table, and is
               then replaced by its mapping in the table GL_PIXEL_MAP_c_TO_c,
               where c is R, G, B, or A.

               Unneeded data is then discarded.  For example, GL_RED discards
               the green, blue, and alpha components, while GL_RGB discards
               only the alpha component.  GL_LUMINANCE computes a single-
               component value as the sum of the red, green, and blue
               components, and GL_LUMINANCE_ALPHA does the same, while keeping
               alpha as a second value.  The final values are clamped to the
               range [0, 1].

     The shift, scale, bias, and lookup factors just described are all
     specified by
     glPixelTransfer.  The lookup table contents themselves are specified by
     glPixelMap.

     Finally, the indices or components are converted to the proper format, as
     specified by type.  If format is GL_COLOR_INDEX or 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_ALPHA, GL_RGB, GL_BGR,
     GL_RGBA, GL_BGRA, GL_ABGR_EXT, GL_LUMINANCE, or GL_LUMINANCE_ALPHA 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).

               _____________________________________________________
               type                index mask   component conversion
               _____________________________________________________

               GL_UNSIGNED_BYTE      2^8-1            (2^8-1)c
               GL_BYTE               2^7-1         [(2^8-1)c-1]/2
               GL_BITMAP               1                 1
               GL_UNSIGNED_SHORT     2^16-1          (2^16-1)c
               GL_SHORT              2^15-1       [(2^16-1)c-1]/2
               GL_UNSIGNED_INT       2^32-1          (2^32-1)c
               GL_INT                2^31-1       [(2^32-1)c-1]/2
               GL_FLOAT               none               c
               _____________________________________________________

     Return values are placed in memory as follows.  If format is
     GL_COLOR_INDEX, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_RED, GL_GREEN,
     GL_BLUE, GL_ALPHA, or GL_LUMINANCE, 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, GL_BGRA
     and GL_ABGR_EXT return four values, and GL_LUMINANCE_ALPHA returns two
     values for each pixel, with all values corresponding to a single pixel
     occupying contiguous space in pixels.  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.

     Normally glReadPixels is synchronous: OpenGL executes a glReadPixels
     command in the order it is issued in the OpenGL command stream.  Calling
     glEnable with parameter GL_ASYNC_READ_PIXELS_SGIX causes subsequent
     glReadPixels commands to be asynchronous as defined by the SGIX_async
     extension.  An implementation of the asynchronous glReadPixels command
     may be non-blocking:  It may return control to the program immediately
     rather than waiting for the command's results to be written into the
     destination rectangle in host memory.  The glReadPixels command samples
     the OpenGL state vector at the time it is issued, but it may be executed
     at some undefined point in the future.  In particular, if subsequent
     commands change the contents of the source rectangle in the framebuffer,
     then the result of the glReadPixels is undefined.

     Calling glDisable with parameter GL_ASYNC_READ_PIXELS_SGIX restores the
     default synchronous behavior for subsequent glReadPixels commands.  It
     does not affect any pending asynchronous glReadPixels commands, or wait
     for their completion.

     When an asynchronous glReadPixels command is issued, it is associated
     with the current value of GL_ASYNC_MARKER_SGIX as defined by the
     SGIX_async extension.  A program can determine if an asynchronous
     glReadPixels command has completed by using the glFinishAsyncSGIX or
     glPollAsyncSGIX commands.

     There is a maximum number of asynchronous glReadPixels commands that can
     be outstanding at any one time, defined by the implementation.  This
     value can be queried with glGetIntegerv with argument
     GL_MAX_ASYNC_READ_PIXELS_SGIX.

     When GL_INTERLACE_READ_INGR is enabled, every other row of the source
     pixel rectangle is read.  The height of the pixel rectangle is equivalent
     to 2xheight.  Only rows (y+0,y+2,...) are read and affected by the pixel
     transfer and store operations.

NOTES
     Values for pixels that lie outside the window connected to the current GL
     context are undefined.

     GL_ABGR_EXT is valid only if the EXT_abgr extension is supported.

     If an error is generated, no change is made to the contents of pixels.

ERRORS
     GL_INVALID_ENUM is generated if format or type is not an accepted value.

     GL_INVALID_ENUM is generated if type is GL_BITMAP and format is not
     GL_COLOR_INDEX or GL_STENCIL_INDEX.

     GL_INVALID_VALUE is generated if either width or height is negative.

     GL_INVALID_OPERATION is generated if format is GL_COLOR_INDEX and the
     color buffers store RGBA color components.

     GL_INVALID_OPERATION is generated if format is GL_STENCIL_INDEX and there
     is no stencil buffer.

     GL_INVALID_OPERATION is generated if format is GL_DEPTH_COMPONENT and
     there is no depth buffer.

     GL_INVALID_OPERATION is generated if glReadPixels is executed between the
     execution of glBegin and the corresponding execution of glEnd.

     GL_INVALID_OPERATION is generated if type is one of
     GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
     GL_UNSIGNED_SHORT_5_6_5, or GL_UNSIGNED_SHORT_5_6_5_REV and format is not
     GL_RGB.

     GL_INVALID_OPERATION is generated if type is one of
     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, or GL_UNSIGNED_INT_2_10_10_10_REV and format
     is not GL_RGBA, GL_BGRA or GL_ABGR_EXT.

     The formats GL_BGR, and GL_BGRA and types 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, and
     GL_UNSIGNED_INT_2_10_10_10_REV are available only if the GL version is
     1.2 or greater.

     GL_INVALID_OPERATION is generated when the SGIX_subsample extension is
     supported, and the pixel storage mode GL_PACK_SUBSAMPLE_RATE_SGIX is not
     GL_PIXEL_SUBSAMPLE_4444_SGIX, and width is not a multiple of 2, or format
     is not a 3 or 4 component format, or type is a packed pixels type.

     GL_INVALID_OPERATION is generated if GL_ASYNC_READ_PIXELS_SGIX is enabled
     and the number of asynchronous glReadPixels commands that have been
     issued but not queried (using glFinishAsyncSGIX or glPollAsyncSGIX)
     exceeds GL_MAX_ASYNC_READ_PIXELS_SGIX.

ASSOCIATED GETS
     glGet with argument GL_INDEX_MODE


MACHINE DEPENDENCIES
     The SGIX_async and SGIX_async_pixel extensions are implemented only on
     Octane2 VPro systems.

     RealityEngine, RealityEngine2, and VTX systems do not support convolving
     images as they are read from the framebuffer.

     The SGIX_ycrcb extension is supported only on O2 systems.  When using
     GL_YCRCB_422_SGIX with glReadPixels on O2 systems, an odd integer value
     for GL_PACK_SKIP_PIXELS will be set to the next highest even integer
     value to preserve color alignment.

     On Octane2 VPro systems the format GL_DEPTH_COMPONENT24_SGIX can be used
     to transfer depth pixel values to and from the depth buffer in their
     internal eye-space range.  There are performance advantages over
     transfers that convert to screen-space values, particularly for
     GL_UNSIGNED_INT type pixels.

     On RealityEngine, RealityEngine2, and VTX systems, histogramming and
     minmax never sink pixel data that is being read from the framebuffer.

     The INGR_interlace_read extension is supported only on Octane2 VPro
     systems, and on O2 systems.

     The EXT_packed_pixels extension is not supported on RealityEngine,
     RealityEngine2, and VTX systems.

     The following problems are known to exist on RealityEngine,
     RealityEngine2, and VTX systems:

          1.  It is not possible to read the depth or stencil buffers of
              multisample-capable Visuals.

          2.  Reading the depth-buffer is much slower than reading a color-
              buffer.

          3.  Reading RGBA format data from a color-index window does not work
              correctly.

     The SGIX_subsample and SGIX_resample extensions are supported only on
     Octane2 VPro systems.  Applying the GL_PIXEL_SUBSAMPLE_2424_SGIX
     subsample rate is accelerated for direct immmediate mode transfers when
     the format is GL_RGB or GL_RGBA, and the type is GL_UNSIGNED_BYTE or
     GL_UNSIGNED_SHORT.


SEE ALSO
     glCopyPixels, glDrawPixels, glPixelMap, glPixelStore, glPixelTransfer,
     glReadBuffer, glAsyncMarkerSGIX, glDeleteAsyncMarkersSGIX,
     glFinishAsyncSGIX, glGenAsyncMarkersSGIX, glIsAsyncMarkerSGIX,
     glPollAsyncSGIX