The WebGLRenderingContext.pixelStorei()
method of the WebGL API specifies the pixel storage modes.
Syntax
void gl.pixelStorei(pname, param);
Parameters
- pname
- A
Glenum
specifying which parameter to set. See below for possible values. - param
- A
GLint
specifying a value to set thepname
parameter to. See below for possible values.
Return value
None.
Pixel storage parameters
Parameter name (for pname )
|
Description | Type | Default value | Allowed values (for param )
|
Specified in |
---|---|---|---|---|---|
gl.PACK_ALIGNMENT
|
Packing of pixel data into memory | GLint
|
4 | 1, 2, 4, 8 | OpenGL ES 2.0 |
gl.UNPACK_ALIGNMENT
|
Unpacking of pixel data from memory. | GLint
|
4 | 1, 2, 4, 8 | OpenGL ES 2.0 |
gl.UNPACK_FLIP_Y_WEBGL
|
Flips the source data along its vertical axis if true. | GLboolean
|
false | true, false | WebGL |
gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL
|
Multiplies the alpha channel into the other color channels | GLboolean
|
false | true, false | WebGL |
gl.UNPACK_COLORSPACE_CONVERSION_WEBGL
|
Default color space conversion or no color space conversion. | GLenum
|
gl.BROWSER_DEFAULT_WEBGL
|
gl.BROWSER_DEFAULT_WEBGL , gl.NONE
|
WebGL |
When using a WebGL 2 context, the following values are available additionally:
Constant | Description | Type | Default value | Allowed values (for param )
|
Specified in |
---|---|---|---|---|---|
gl.PACK_ROW_LENGTH
|
Number of pixels in a row. | GLint
|
0 | 0 to Infinity
|
OpenGL ES 3.0 |
gl.PACK_SKIP_PIXELS
|
Number of pixel locations skipped before the first pixel is written into memory. | GLint
|
0 | 0 to Infinity
|
OpenGL ES 3.0 |
gl.PACK_SKIP_ROWS
|
Number of rows of pixel locations skipped before the first pixel is written into memory | GLint
|
0 | 0 to Infinity
|
OpenGL ES 3.0 |
gl.UNPACK_ROW_LENGTH
|
Number of pixels in a row. | GLint
|
0 | 0 to Infinity
|
OpenGL ES 3.0 |
gl.UNPACK_IMAGE_HEIGHT
|
Image height used for reading pixel data from memory | GLint
|
0 | 0 to Infinity
|
OpenGL ES 3.0 |
gl.UNPACK_SKIP_PIXELS
|
Number of pixel images skipped before the first pixel is read from memory | GLint
|
0 | 0 to Infinity
|
OpenGL ES 3.0 |
gl.UNPACK_SKIP_ROWS
|
Number of rows of pixel locations skipped before the first pixel is read from memory | GLint
|
0 | 0 to Infinity
|
OpenGL ES 3.0 |
gl.UNPACK_SKIP_IMAGES
|
Number of pixel images skipped before the first pixel is read from memory | GLint
|
0 | 0 to Infinity
|
OpenGL ES 3.0 |
Examples
Setting the pixel storage mode affects the WebGLRenderingContext.readPixels()
operations, as well as unpacking of textures with the WebGLRenderingContext.texImage2D()
and WebGLRenderingContext.texSubImage2D()
methods.
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.pixelStorei(gl.PACK_ALIGNMENT, 4);
To check the values for packing and unpacking of pixel data, you can query the same pixel storage parameters with WebGLRenderingContext.getParameter()
.
gl.getParameter(gl.PACK_ALIGNMENT);
gl.getParameter(gl.UNPACK_ALIGNMENT);
Specifications
Specification | Status | Comment |
WebGL 1.0The definition of 'pixelStorei' in that specification. | Recommendation | Initial definition for WebGL. |
WebGL 1.0The definition of 'Pixel Storage Parameters' in that specification. | Recommendation | Additional pixel storage parameters that aren't specified in OpenGL. |
OpenGL ES 2.0The definition of 'glPixelStorei' in that specification. | Standard | Man page of the OpenGL ES 2.0 API. |
WebGL 2.0The definition of 'pixelStorei' in that specification. | Editor's Draft | Updated definition for WebGL 2. |
OpenGL ES 3.0The definition of 'glPixelStorei' in that specification. | Standard | Man page of the OpenGL ES 3.0 API. |
Browser compatibility
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
pixelStorei
|
Chrome
Full support 9 |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 11 |
Opera
Full support 12 |
Safari
Full support 5.1 |
WebView Android
Full support Yes |
Chrome Android
Full support 25 |
Firefox Android
Full support Yes |
Opera Android
Full support 12 |
Safari iOS
Full support 8 |
Samsung Internet Android
Full support 1.5 |
WebGL2
|
Chrome
Full support 56 |
Edge
Full support 79 |
Firefox
Full support 51 |
IE
No support No |
Opera
Full support 43 |
Safari
No support No |
WebView Android
Full support 58 |
Chrome Android
Full support 58 |
Firefox Android
Full support 51 |
Opera Android
Full support 43 |
Safari iOS
No support No |
Samsung Internet Android
Full support 7.0 |
Legend
- Full support
- Full support
- No support
- No support
See also
WebGLRenderingContext.readPixels()
WebGLRenderingContext.texImage2D()
WebGLRenderingContext.texSubImage2D()
WebGLRenderingContext.pixelStorei() by Mozilla Contributors is licensed under CC-BY-SA 2.5.