GlReadPixels: Difference between revisions
(Created page with "'''_glReadPixels:''' read a block of pixels from the frame buffer {{PageSyntax}} SUB _glReadPixels (BYVAL x AS LONG, BYVAL y AS LONG, BYVAL width AS LONG, BYVAL height AS LONG, BYVAL format AS _UNSIGNED LONG, BYVAL type AS _UNSIGNED LONG, pixels AS _OFFSET) void '''_glReadPixels'''(GLint {{Parameter|x}}, GLint {{Parameter|y}}, GLsizei {{Parameter|width}}, GLsizei {{Parameter|height}}, GLenum {{Parameter|format}}, GLenum {{Parameter|type}}, GLvoid * {{Parameter|dat...") |
No edit summary |
||
Line 21: | Line 21: | ||
If a non-zero named buffer object is bound to the {{KW|_GL_PIXEL_PACK_BUFFER}} target (see {{KW|_glBindBuffer}}) while a block of pixels is requested, {{Parameter|data}} is treated as a byte offset into the buffer object's data store rather than a pointer to client memory. | If a non-zero named buffer object is bound to the {{KW|_GL_PIXEL_PACK_BUFFER}} target (see {{KW|_glBindBuffer}}) while a block of pixels is requested, {{Parameter|data}} is treated as a byte offset into the buffer object's data store rather than a pointer to client memory. | ||
'''_glReadPixels''' returns values from each pixel with lower left corner at (''x'' + ''i'', ''y'' + ''j'') for 0 | '''_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 ''i''th pixel in the ''j''th row. Pixels are returned in row order from the lowest to the highest row, left to right in each row. | ||
{{Parameter|format}} specifies the format for the returned pixel values; accepted values are: | {{Parameter|format}} specifies the format for the returned pixel values; accepted values are: | ||
Line 42: | Line 42: | ||
If {{Parameter|format}} is {{KW|_GL_RED}}, {{KW|_GL_GREEN}}, {{KW|_GL_BLUE}}, {{KW|_GL_RGB}}, {{KW|_GL_BGR}}, {{KW|_GL_RGBA}}, or {{KW|_GL_BGRA}} and {{Parameter|type}} is not {{KW|_GL_FLOAT}}, each component is multiplied by the multiplier shown in the following table. If type is {{KW|_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). | If {{Parameter|format}} is {{KW|_GL_RED}}, {{KW|_GL_GREEN}}, {{KW|_GL_BLUE}}, {{KW|_GL_RGB}}, {{KW|_GL_BGR}}, {{KW|_GL_RGBA}}, or {{KW|_GL_BGRA}} and {{Parameter|type}} is not {{KW|_GL_FLOAT}}, each component is multiplied by the multiplier shown in the following table. If type is {{KW|_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). | ||
{| class= | {| class="wikitable" | ||
|+ | |+ | ||
! {{Parameter|type}} | ! {{Parameter|type}} | ||
Line 49: | Line 49: | ||
|+ | |+ | ||
| {{KW|_GL_UNSIGNED_BYTE}} | | {{KW|_GL_UNSIGNED_BYTE}} | ||
| 2 | | 2<sup>8</sup> - 1 | ||
| | | <math>(2^8 - 1)c</math> | ||
|+ | |+ | ||
| {{KW|_GL_BYTE}} | | {{KW|_GL_BYTE}} | ||
| 2 | | 2<sup>7</sup> - 1 | ||
| | | <math>\tfrac{(2^8 - 1)c - 1}{2}</math> | ||
|+ | |+ | ||
| {{KW|_GL_UNSIGNED_SHORT}} | | {{KW|_GL_UNSIGNED_SHORT}} | ||
| 2 | | 2<sup>16</sup> - 1 | ||
| | | <math>(2^{16} - 1)c</math> | ||
|+ | |+ | ||
| {{KW|_GL_SHORT}} | | {{KW|_GL_SHORT}} | ||
| 2 | | 2<sup>15</sup> - 1 | ||
| | | <math>\tfrac{(2^{16} - 1)c - 1}{2}</math> | ||
|+ | |+ | ||
| {{KW|_GL_UNSIGNED_INT}} | | {{KW|_GL_UNSIGNED_INT}} | ||
| 2 | | 2<sup>32</sup> - 1 | ||
| | | <math>(2^{32} - 1)c</math> | ||
|+ | |+ | ||
| {{KW|_GL_INT}} | | {{KW|_GL_INT}} | ||
| 2 | | 2<sup>31</sup> - 1 | ||
| | | <math>\tfrac{(2^{32} - 1)c - 1}{2}</math> | ||
|+ | |+ | ||
| {{KW|_GL_HALF_FLOAT}} | | {{KW|_GL_HALF_FLOAT}} | ||
Line 81: | Line 81: | ||
|+ | |+ | ||
| {{KW|_GL_UNSIGNED_BYTE_3_3_2}} | | {{KW|_GL_UNSIGNED_BYTE_3_3_2}} | ||
| 2 | | 2<sup>N</sup> - 1 | ||
| | | <math>(2^N - 1)c</math> | ||
|+ | |+ | ||
| {{KW|_GL_UNSIGNED_BYTE_2_3_3_REV}} | | {{KW|_GL_UNSIGNED_BYTE_2_3_3_REV}} | ||
| 2 | | 2<sup>N</sup> - 1 | ||
| | | <math>(2^N - 1)c</math> | ||
|+ | |+ | ||
| {{KW|_GL_UNSIGNED_SHORT_5_6_5}} | | {{KW|_GL_UNSIGNED_SHORT_5_6_5}} | ||
| 2 | | 2<sup>N</sup> - 1 | ||
| | | <math>(2^N - 1)c</math> | ||
|+ | |+ | ||
| {{KW|_GL_UNSIGNED_SHORT_5_6_5_REV}} | | {{KW|_GL_UNSIGNED_SHORT_5_6_5_REV}} | ||
| 2 | | 2<sup>N</sup> - 1 | ||
| | | <math>(2^N - 1)c</math> | ||
|+ | |+ | ||
| {{KW|_GL_UNSIGNED_SHORT_4_4_4_4}} | | {{KW|_GL_UNSIGNED_SHORT_4_4_4_4}} | ||
| 2 | | 2<sup>N</sup> - 1 | ||
| | | <math>(2^N - 1)c</math> | ||
|+ | |+ | ||
| {{KW|_GL_UNSIGNED_SHORT_4_4_4_4_REV}} | | {{KW|_GL_UNSIGNED_SHORT_4_4_4_4_REV}} | ||
| 2 | | 2<sup>N</sup> - 1 | ||
| | | <math>(2^N - 1)c</math> | ||
|+ | |+ | ||
| {{KW|_GL_UNSIGNED_SHORT_5_5_5_1}} | | {{KW|_GL_UNSIGNED_SHORT_5_5_5_1}} | ||
| 2 | | 2<sup>N</sup> - 1 | ||
| | | <math>(2^N - 1)c</math> | ||
|+ | |+ | ||
| {{KW|_GL_UNSIGNED_SHORT_1_5_5_5_REV}} | | {{KW|_GL_UNSIGNED_SHORT_1_5_5_5_REV}} | ||
| 2 | | 2<sup>N</sup> - 1 | ||
| | | <math>(2^N - 1)c</math> | ||
|+ | |+ | ||
| {{KW|_GL_UNSIGNED_INT_8_8_8_8}} | | {{KW|_GL_UNSIGNED_INT_8_8_8_8}} | ||
| 2 | | 2<sup>N</sup> - 1 | ||
| | | <math>(2^N - 1)c</math> | ||
|+ | |+ | ||
| {{KW|_GL_UNSIGNED_INT_8_8_8_8_REV}} | | {{KW|_GL_UNSIGNED_INT_8_8_8_8_REV}} | ||
| 2 | | 2<sup>N</sup> - 1 | ||
| | | <math>(2^N - 1)c</math> | ||
|+ | |+ | ||
| {{KW|_GL_UNSIGNED_INT_10_10_10_2}} | | {{KW|_GL_UNSIGNED_INT_10_10_10_2}} | ||
| 2 | | 2<sup>N</sup> - 1 | ||
| | | <math>(2^N - 1)c</math> | ||
|+ | |+ | ||
| {{KW|_GL_UNSIGNED_INT_2_10_10_10_REV}} | | {{KW|_GL_UNSIGNED_INT_2_10_10_10_REV}} | ||
| 2 | | 2<sup>N</sup> - 1 | ||
| | | <math>(2^N - 1)c</math> | ||
|+ | |+ | ||
| {{KW|_GL_UNSIGNED_INT_24_8}} | | {{KW|_GL_UNSIGNED_INT_24_8}} | ||
| 2 | | 2<sup>N</sup> - 1 | ||
| | | <math>(2^N - 1)c</math> | ||
|+ | |+ | ||
| {{KW|_GL_UNSIGNED_INT_10F_11F_11F_REV}} | | {{KW|_GL_UNSIGNED_INT_10F_11F_11F_REV}} |
Revision as of 22:24, 4 May 2022
_glReadPixels: read a block of pixels from the frame buffer
Syntax
SUB _glReadPixels (BYVAL x AS LONG, BYVAL y AS LONG, BYVAL width AS LONG, BYVAL height AS LONG, BYVAL format AS _UNSIGNED LONG, BYVAL type AS _UNSIGNED LONG, pixels AS _OFFSET) void _glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid * data);
- 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.
Template:Glapi pixeltransferupparams
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 data. Several parameters control the processing of the pixel data before it is placed into client memory. These parameters are set with Template:KW. This reference page describes the effects on _glReadPixels of most, but not all of the parameters specified by these three commands.
If a non-zero named buffer object is bound to the Template:KW target (see Template:KW) 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.
_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:
- Template:KW
- 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 Template:KW, and added to Template:KW. If Template:KW is Template:KW, indices are replaced by their mappings in the table Template:KW.
- Template:KW
- 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 Template:KW, added to Template:KW, and finally clamped to the range [0, 1].
- Template:KW
- Values are taken from both the depth and stencil buffers. The type parameter must be Template:KW or Template:KW.
- Template:KW
- Template:KW
- Template:KW
- Template:KW
- Template:KW
- Template:KW
- Template:KW
- Finally, the indices or components are converted to the proper format, as specified by type. If format is Template:KW and type is not Template:KW, each index is masked with the mask value given in the following table. If type is Template:KW, then each integer index is converted to single-precision floating-point format.
If format is Template:KW, Template:KW, Template:KW, Template:KW, Template:KW, Template:KW, or Template:KW and type is not Template:KW, each component is multiplied by the multiplier shown in the following table. If type is Template:KW, 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 |
---|---|---|
Template:KW | 28 - 1 | <math>(2^8 - 1)c</math> |
Template:KW | 27 - 1 | <math>\tfrac{(2^8 - 1)c - 1}{2}</math> |
Template:KW | 216 - 1 | <math>(2^{16} - 1)c</math> |
Template:KW | 215 - 1 | <math>\tfrac{(2^{16} - 1)c - 1}{2}</math> |
Template:KW | 232 - 1 | <math>(2^{32} - 1)c</math> |
Template:KW | 231 - 1 | <math>\tfrac{(2^{32} - 1)c - 1}{2}</math> |
Template:KW | none | c |
Template:KW | none | c |
Template:KW | 2N - 1 | <math>(2^N - 1)c</math> |
Template:KW | 2N - 1 | <math>(2^N - 1)c</math> |
Template:KW | 2N - 1 | <math>(2^N - 1)c</math> |
Template:KW | 2N - 1 | <math>(2^N - 1)c</math> |
Template:KW | 2N - 1 | <math>(2^N - 1)c</math> |
Template:KW | 2N - 1 | <math>(2^N - 1)c</math> |
Template:KW | 2N - 1 | <math>(2^N - 1)c</math> |
Template:KW | 2N - 1 | <math>(2^N - 1)c</math> |
Template:KW | 2N - 1 | <math>(2^N - 1)c</math> |
Template:KW | 2N - 1 | <math>(2^N - 1)c</math> |
Template:KW | 2N - 1 | <math>(2^N - 1)c</math> |
Template:KW | 2N - 1 | <math>(2^N - 1)c</math> |
Template:KW | 2N - 1 | <math>(2^N - 1)c</math> |
Template:KW | -- | Special |
Template:KW | -- | Special |
Template:KW | none | c (Depth Only) |
Return values are placed in memory as follows. If format is Template:KW, Template:KW, Template:KW, Template:KW, or Template:KW, a single value is returned and the data for the ith pixel in the jth row is placed in location j * width + i. Template:KW and Template:KW return three values, Template:KW and Template:KW return four values for each pixel, with all values corresponding to a single pixel occupying contiguous space in data. Storage parameters set by Template:KW, such as Template:KW and Template:KW, affect the way that data is written into memory. See Template:KW for a description.
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.
Template:KW is generated if format or type is not an accepted value.
Template:KW is generated if either width or height is negative.
Template:KW is generated if format is Template:KW and there is no stencil buffer.
Template:KW is generated if format is Template:KW and there is no depth buffer.
Template:KW is generated if format is Template:KW and there is no depth buffer or if there is no stencil buffer.
Template:KW is generated if format is Template:KW and type is not Template:KW or Template:KW.
Template:KW is generated if type is one of Template:KW, Template:KW, Template:KW, or Template:KW and format is not Template:KW.
Template:KW is generated if type is one of Template:KW, Template:KW, Template:KW, Template:KW, Template:KW, Template:KW, Template:KW, or Template:KW and format is neither Template:KW nor Template:KW.
Template:KW is generated if a non-zero buffer object name is bound to the Template:KW target and the buffer object's data store is currently mapped.
Template:KW is generated if a non-zero buffer object name is bound to the Template:KW target and the data would be packed to the buffer object such that the memory writes required would exceed the data store size.
Template:KW is generated if a non-zero buffer object name is bound to the Template:KW target and data is not evenly divisible into the number of bytes needed to store in memory a datum indicated by type.
Template:KW is generated if Template:KW is non-zero, the read framebuffer is complete, and the value of Template:KW for the read framebuffer is greater than zero.
Template:KW with argument Template:KW
Template:KW with argument Template:KW
See also
SUB _GL Template:KW, Template:KW, Template:KW, Template:KW, Template:KW
Pixel Transfer, Pixel Buffer Object
Copyright 1991-2006 Silicon Graphics, Inc. This document is licensed under the SGI Free Software B License. For details, see http://oss.sgi.com/projects/FreeB/.