The WebGLRenderingContext.pixelStorei()
method of the WebGL API specifies the pixel storage modes.
The WebGLRenderingContext.pixelStorei()
method of the WebGL API specifies the pixel storage modes.
js
pixelStorei(pname, param)
None (undefined
).
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 |
Setting the pixel storage mode affects the WebGLRenderingContext.readPixels()
operations, as well as unpacking of textures with the WebGLRenderingContext.texImage2D()
and WebGLRenderingContext.texSubImage2D()
methods.
js
const 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()
.
js
gl.getParameter(gl.PACK_ALIGNMENT); gl.getParameter(gl.UNPACK_ALIGNMENT);
Specification |
---|
WebGL Specification # 5.14.3 |
WebGL Specification # PIXEL_STORAGE_PARAMETERS |
WebGL 2.0 Specification # 3.7.2 |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
pixelStorei |
9 | 12 | 4 | 11 | 12 | 5.1 | 4.4.3 | 25 | 4 | 12 | 8 | 1.5 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/pixelStorei