WebGLRenderingContext: scissor() 方法
注意:此功能在 Web Workers 中可用。
WebGLRenderingContext.scissor() 方法是 WebGL API 的一部分,用于设置一个剪裁框,将绘制限制在一个指定的矩形区域内。
语法
js
scissor(x, y, width, height)
参数
返回值
无(undefined)。
异常
如果 width 或 height 中的任何一个值为负数,则会抛出 gl.INVALID_VALUE 错误。
示例
当启用剪裁测试时,只有剪裁框内的像素才能被绘图命令修改。
js
// turn on scissor test
gl.enable(gl.SCISSOR_TEST);
// set the scissor rectangle
gl.scissor(x, y, width, height);
// execute drawing commands in the scissor box (e.g. clear)
// turn off scissor test again
gl.disable(gl.SCISSOR_TEST);
要获取当前的剪裁框尺寸,请查询 SCISSOR_BOX 常量,它会返回一个 Int32Array。
js
gl.scissor(0, 0, 200, 200);
gl.getParameter(gl.SCISSOR_BOX);
// Int32Array[0, 0, 200, 200]
规范
| 规范 |
|---|
| WebGL 规范 # 5.14.4 |
浏览器兼容性
加载中…