This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Note: This feature is available in Web Workers.
The WebGLRenderingContext.colorMask() method of the WebGL API sets which color components to enable or to disable when drawing or rendering to a WebGLFramebuffer.
colorMask(red, green, blue, alpha)
redA GLboolean specifying whether or not the red color component can be written into the frame buffer. Default value: true.
greenA GLboolean specifying whether or not the green color component can be written into the frame buffer. Default value: true.
blueA GLboolean specifying whether or not the blue color component can be written into the frame buffer. Default value: true.
alphaA GLboolean specifying whether or not the alpha (transparency) component can be written into the frame buffer. Default value: true.
None (undefined).
gl.colorMask(true, true, true, false);
To get the current color mask, query the COLOR_WRITEMASK constant which returns an Array.
gl.getParameter(gl.COLOR_WRITEMASK); // [true, true, true, false]
| Specification |
|---|
| WebGL Specification> # 5.14.3> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
colorMask |
9 | 12 | 4 | 12 | 5.1 | 25 | 4 | 12 | 8 | 1.5 | 4.4.3 | 8 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/colorMask