Skip to content

Commit

Permalink
zh-cn: Format /web/api using Prettier (part 11)
Browse files Browse the repository at this point in the history
  • Loading branch information
queengooborg committed Jul 28, 2023
1 parent 09c0ef4 commit a38e65b
Show file tree
Hide file tree
Showing 100 changed files with 1,058 additions and 855 deletions.
279 changes: 158 additions & 121 deletions files/zh-cn/web/api/webgl_api/webgl_model_view_projection/index.md

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions files/zh-cn/web/api/webgl_lose_context/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@ WebGL 扩展可以通过 {{domxref("WebGLRenderingContext.getExtension()")}} 方
使用这个扩展,你可以模拟 [`webglcontextlost`](/zh-CN/docs/Web/API/HTMLCanvasElement/webglcontextlost_event)[`webglcontextrestored`](/zh-CN/docs/Web/API/HTMLCanvasElement/webglcontextrestored_event) 事件:

```js
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');

canvas.addEventListener('webglcontextlost', function(e) {
console.log(e);
}, false);

gl.getExtension('WEBGL_lose_context').loseContext();
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");

canvas.addEventListener(
"webglcontextlost",
function (e) {
console.log(e);
},
false,
);

gl.getExtension("WEBGL_lose_context").loseContext();

// 打印了 "webglcontextlost" 类型的 WebGLContextEvent 事件。
```
Expand Down
20 changes: 12 additions & 8 deletions files/zh-cn/web/api/webgl_lose_context/losecontext/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ gl.getExtension('WEBGL_lose_context').loseContext();
你可以用这个方法模拟 [`webglcontextlost`](/zh-CN/docs/Web/API/HTMLCanvasElement/webglcontextlost_event) 事件:

```js
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');

canvas.addEventListener('webglcontextlost', function(e) {
console.log(e);
}, false);

gl.getExtension('WEBGL_lose_context').loseContext();
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");

canvas.addEventListener(
"webglcontextlost",
function (e) {
console.log(e);
},
false,
);

gl.getExtension("WEBGL_lose_context").loseContext();

// webglcontextlost 事件被触发。
```
Expand Down
20 changes: 12 additions & 8 deletions files/zh-cn/web/api/webgl_lose_context/restorecontext/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ gl.getExtension('WEBGL_lose_context').restoreContext();
你可以用这个方法模拟 [`webglcontextrestored`](/zh-CN/docs/Web/API/HTMLCanvasElement/webglcontextrestored_event) 事件:

```js
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');

canvas.addEventListener('webglcontextrestored', function(e) {
console.log(e);
}, false);

gl.getExtension('WEBGL_lose_context').restoreContext();
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");

canvas.addEventListener(
"webglcontextrestored",
function (e) {
console.log(e);
},
false,
);

gl.getExtension("WEBGL_lose_context").restoreContext();
```

## 规范
Expand Down
4 changes: 2 additions & 2 deletions files/zh-cn/web/api/webglbuffer/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ slug: Web/API/WebGLBuffer
### 创建一个缓冲区

```js
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");
var buffer = gl.createBuffer();
```

Expand Down
20 changes: 12 additions & 8 deletions files/zh-cn/web/api/webglcontextevent/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ _此接口本身并没有定义任何方法,而是从它的父接口 {{domxref
使用 {{domxref("WEBGL_lose_context")}} 插件,你可以模拟 {{domxref("HTMLCanvasElement/webglcontextlost_event", "webglcontextlost")}} 和 {{domxref("HTMLCanvasElement/webglcontextrestored_event", "webglcontextrestored")}} 事件:

```js
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');

canvas.addEventListener('webglcontextlost', function(e) {
console.log(e);
}, false);

gl.getExtension('WEBGL_lose_context').loseContext();
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");

canvas.addEventListener(
"webglcontextlost",
function (e) {
console.log(e);
},
false,
);

gl.getExtension("WEBGL_lose_context").loseContext();

// 记录了 "webglcontextlost" 类型的 WebGLContextEvent 事件
```
Expand Down
4 changes: 2 additions & 2 deletions files/zh-cn/web/api/webglframebuffer/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ slug: Web/API/WebGLFramebuffer
### 创建一个帧缓冲

```js
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");
var buffer = gl.createFramebuffer();
```

Expand Down
4 changes: 2 additions & 2 deletions files/zh-cn/web/api/webglprogram/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ gl.attachShader(program, fragmentShader);

gl.linkProgram(program);

if ( !gl.getProgramParameter( program, gl.LINK_STATUS) ) {
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
var info = gl.getProgramInfoLog(program);
throw 'WebGL program 不能编译。\n\n' + info;
throw "WebGL program 不能编译。\n\n" + info;
}
```

Expand Down
4 changes: 2 additions & 2 deletions files/zh-cn/web/api/webglrenderbuffer/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ slug: Web/API/WebGLRenderbuffer
### 创建一个 render buffer 对象

```js
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");
var buffer = gl.createRenderbuffer();
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ gl.attachShader(program, fragmentShader);

gl.linkProgram(program);

if ( !gl.getProgramParameter( program, gl.LINK_STATUS) ) {
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
var info = gl.getProgramInfoLog(program);
throw "Could not compile WebGL program. \n\n" + info;
}
Expand Down
4 changes: 2 additions & 2 deletions files/zh-cn/web/api/webglrenderingcontext/bindbuffer/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ void gl.bindBuffer(target, buffer);
### 将缓冲区绑定到目标

```js
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");
var buffer = gl.createBuffer();

gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ None.
### 绑定帧缓冲区

```js
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");
var framebuffer = gl.createFramebuffer();

gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ None.
### 绑定一个渲染缓冲区

```js
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");
var renderbuffer = gl.createRenderbuffer();

gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ void gl.bindTexture(target, texture);
### 绑定纹理

```js
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");
var texture = gl.createTexture();

gl.bindTexture(gl.TEXTURE_2D, texture);
Expand Down
4 changes: 2 additions & 2 deletions files/zh-cn/web/api/webglrenderingcontext/bufferdata/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ None.
### 使用 `bufferData`

```js
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");
var buffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
gl.bufferData(gl.ARRAY_BUFFER, 1024, gl.STATIC_DRAW);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,22 @@ None.
## Examples

```js
var ext = (
gl.getExtension('WEBGL_compressed_texture_s3tc') ||
gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') ||
gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc')
);
var ext =
gl.getExtension("WEBGL_compressed_texture_s3tc") ||
gl.getExtension("MOZ_WEBGL_compressed_texture_s3tc") ||
gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");

var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.compressedTexImage2D(gl.TEXTURE_2D, 0, ext.COMPRESSED_RGBA_S3TC_DXT5_EXT, 512, 512, 0, textureData);
gl.compressedTexImage2D(
gl.TEXTURE_2D,
0,
ext.COMPRESSED_RGBA_S3TC_DXT5_EXT,
512,
512,
0,
textureData,
);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ WebGLBuffer gl.createBuffer();
### 创建一个缓冲区

```js
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");
var buffer = gl.createBuffer();
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ None.
### 创建一个帧缓冲区

```js
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");
var framebuffer = gl.createFramebuffer();
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ gl.attachShader(program, fragmentShader);

gl.linkProgram(program);

if ( !gl.getProgramParameter( program, gl.LINK_STATUS) ) {
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
var info = gl.getProgramInfoLog(program);
throw "Could not compile WebGL program. \n\n" + info;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ None.
### 创建一个渲染缓冲区

```js
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");
var renderBuffer = gl.createRenderBuffer();
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ WebGLTexture gl.createTexture();
### 创建一个纹理

```js
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");
var texture = gl.createTexture();
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ None.
### 删除一个 buffer

```js
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");
var buffer = gl.createBuffer();

// ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ None.
### 删除一个帧缓冲区

```js
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");
var framebuffer = gl.createFramebuffer();

// ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ None.
### 删除一个程序

```js
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");
var program = gl.createProgram();

// ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ None.
### 删除一个渲染缓冲区

```js
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");
var renderbuffer = gl.createRenderbuffer();

// ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ void gl.deleteTexture(texture);
### Deleting a texture

```js
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");
var texture = gl.createTexture();

// ...
Expand Down
20 changes: 10 additions & 10 deletions files/zh-cn/web/api/webglrenderingcontext/disable/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ void gl.disable(cap);

- : A {{domxref("GLenum")}} specifying which WebGL capability to disable. Possible values:

| Constant | Description |
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `gl.BLEND` | Deactivates blending of the computed fragment color values. See {{domxref("WebGLRenderingContext.blendFunc()")}}. |
| `gl.CULL_FACE` | Deactivates culling of polygons. See {{domxref("WebGLRenderingContext.cullFace()")}}. |
| `gl.DEPTH_TEST` | Deactivates depth comparisons and updates to the depth buffer. See {{domxref("WebGLRenderingContext.depthFunc()")}}. |
| `gl.DITHER` | Deactivates dithering of color components before they get written to the color buffer. |
| `gl.POLYGON_OFFSET_FILL` | Deactivates adding an offset to depth values of polygon's fragments. See {{domxref("WebGLRenderingContext.polygonOffset()")}}. |
| `gl.SAMPLE_ALPHA_TO_COVERAGE` | Deactivates the computation of a temporary coverage value determined by the alpha value. |
| `gl.SAMPLE_COVERAGE` | Deactivates ANDing the fragment's coverage with the temporary coverage value. See {{domxref("WebGLRenderingContext.sampleCoverage()")}}. |
| Constant | Description |
| ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| `gl.BLEND` | Deactivates blending of the computed fragment color values. See {{domxref("WebGLRenderingContext.blendFunc()")}}. |
| `gl.CULL_FACE` | Deactivates culling of polygons. See {{domxref("WebGLRenderingContext.cullFace()")}}. |
| `gl.DEPTH_TEST` | Deactivates depth comparisons and updates to the depth buffer. See {{domxref("WebGLRenderingContext.depthFunc()")}}. |
| `gl.DITHER` | Deactivates dithering of color components before they get written to the color buffer. |
| `gl.POLYGON_OFFSET_FILL` | Deactivates adding an offset to depth values of polygon's fragments. See {{domxref("WebGLRenderingContext.polygonOffset()")}}. |
| `gl.SAMPLE_ALPHA_TO_COVERAGE` | Deactivates the computation of a temporary coverage value determined by the alpha value. |
| `gl.SAMPLE_COVERAGE` | Deactivates ANDing the fragment's coverage with the temporary coverage value. See {{domxref("WebGLRenderingContext.sampleCoverage()")}}. |
| `gl.SCISSOR_TEST` | Deactivates the scissor test that discards fragments that are outside of the scissor rectangle. See {{domxref("WebGLRenderingContext.scissor()")}}. |
| `gl.STENCIL_TEST` | Deactivates stencil testing and updates to the stencil buffer. See {{domxref("WebGLRenderingContext.stencilFunc()")}}. |
| `gl.STENCIL_TEST` | Deactivates stencil testing and updates to the stencil buffer. See {{domxref("WebGLRenderingContext.stencilFunc()")}}. |

When using a {{domxref("WebGL2RenderingContext", "WebGL 2 context", "", 1)}}, the following values are available additionally:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ gl.drawingBufferWidth;
你可以通过下面几行代码来获取绘图缓冲区的宽度:

```js
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");
gl.drawingBufferWidth; // 300
```

Expand Down
Loading

0 comments on commit a38e65b

Please sign in to comment.