/
index.md
72 lines (48 loc) · 1.63 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
---
title: WebGLRenderingContext.scissor()
slug: Web/API/WebGLRenderingContext/scissor
---
{{APIRef("WebGL")}}
**`WebGLRenderingContext.scissor()`** 方法指定了一个裁剪区域,用来将绘图区域限制在其限定的盒形区域内。
## 语法
```plain
void gl.scissor(x, y, width, height);
```
### 参数
- `x`
- : {{domxref("GLint")}} ,指定盒形裁剪区域左下角所在的横坐标,默认为 0。
- `y`
- : {{domxref("GLint")}} 指定盒形裁剪区域左下角的纵坐标,默认为 0。
- width
- : {{domxref("Glsizei")}},用来确定盒型裁剪区域宽度的非负数,默认为 canvas 的宽度。
- height
- : {{domxref("Glsizei")}} ,用以指定盒形裁剪区域高度的非负数,默认为 canvas 的高度。
### 返回值
无。
### 抛错
宽或高为负值时,抛出 `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` 常量来获取裁剪区域的维度信息,返回值是一个 {{jsxref("Int32Array")}} 对象。
```js
gl.scissor(0, 0, 200, 200);
gl.getParameter(gl.SCISSOR_BOX);
// Int32Array[0, 0, 200, 200]
```
## 规范
{{Specifications}}
## 浏览器兼容性
{{Compat}}
## 参见
- {{domxref("WebGLRenderingContext.viewport()")}}
- {{domxref("WebGLRenderingContext.enable()")}}
- {{domxref("WebGLRenderingContext.disable()")}}