WebGL API 的 WebGLRenderingContext.clear() 方法使用预设值来清空缓冲。
预设值可以使用 clearColor() 、 clearDepth() 或 clearStencil() 设置。
裁剪、抖动处理和缓冲写入遮罩会影响 clear() 方法。
句法
void gl.clear(mask);
参数
mask- 一个用于指定需要清除的缓冲区的
GLbitfield。可能的值有:gl.COLOR_BUFFER_BITgl.DEPTH_BUFFER_BITgl.STENCIL_BUFFER_BIT
错误抛出
如果mask不是以上列出的值,会抛出 gl.INVALID_ENUM 错误。
返回值
无
示例
clear() 方法可接受复合值,
gl.clear(gl.DEPTH_BUFFER_BIT); gl.clear(gl.DEPTH_BUFFER_BIT | gl.COLOR_BUFFER_BIT);
要获得当前的清除值,传入 COLOR_CLEAR_VALUE,、DEPTH_CLEAR_VALUE或STENCIL_CLEAR_VALUE 常量。
gl.getParameter(gl.COLOR_CLEAR_VALUE); gl.getParameter(gl.DEPTH_CLEAR_VALUE); gl.getParameter(gl.STENCIL_CLEAR_VALUE);
规范
| Specification | Status | Comment |
|---|---|---|
| WebGL 1.0 clear |
Recommendation | Initial definition. |
| OpenGL ES 2.0 glClear |
Standard | Man page of the OpenGL API. |
浏览器兼容
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.
| Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | Servo |
|---|---|---|---|---|---|---|---|
| Basic Support | 9 | 12 | 4.0 | 11 | 12 | 5.1 | No support |
| Feature | Android | Chrome for Android | Edge Mobile | Firefox for Android | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|---|
| Basic Support | (Yes) | 25 | (Yes) | 4.0 | 11 | 12 | 8.1 |