Skip to content

Commit

Permalink
sync with english version for using extensions (#10816)
Browse files Browse the repository at this point in the history
  • Loading branch information
yin1999 authored Dec 29, 2022
1 parent 292e514 commit 25942d0
Showing 1 changed file with 69 additions and 34 deletions.
103 changes: 69 additions & 34 deletions files/zh-cn/web/api/webgl_api/using_extensions/index.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,111 @@
---
title: Using WebGL extensions
title: 使用 WebGL 扩展
slug: Web/API/WebGL_API/Using_Extensions
---

{{DefaultAPISidebar("WebGL")}}

WebGL,像它的姐妹 API (OpenGL and OpenGL ES),支持使用扩展(extensions)。一份完整的扩展列表可在 [khronos webgl extension registry](http://www.khronos.org/registry/webgl/extensions/)
WebGL,像它的姐妹 APIOpenGL OpenGL ES,支持使用扩展(extension)。可在 [khronos webgl extension registry](https://www.khronos.org/registry/webgl/extensions/) 查看完整的扩展列表

> **备注:** 不像别的 GL APIs,在 webGL 中 , 扩展只有在明确需要的情况下才会加载。
> **备注:** 不像别的 GL API,在 WebGL 中,扩展只有在明确需要的情况下才会加载。
## 规范扩展名供应商前缀和首选项
## 规范扩展名供应商前缀和首选项

扩展(extensions)在未被官方正式制定为标准前,某些浏览器厂商可能会支持 WebGL 扩展 (but only when they are in draft stage)。这样的话,扩展的名字应该加上相应的厂商前缀 (`MOZ_`, `WEBKIT_`, etc.),否则这个扩展只能在浏览器切换了偏好设置的前提下生效。
扩展(extension)在未被官方正式制定为标准前(但仅当它们处于草案阶段时),某些浏览器厂商可能会支持 WebGL 扩展。这样的话,扩展的名字应该加上相应的厂商前缀`MOZ_``WEBKIT_` 等),否则这个扩展只能在浏览器切换了偏好设置的前提下生效。

If you wish to work with the bleeding edge of extensions, and want to keep working on upon ratification (assuming, of course, that the extension doesn't change in incompatible ways), that you query the canonical extension name as well as the vendor extension name. For instance:
如果你希望使用最前沿的扩展,并希望在规范被批准后可以继续使用(当然,假设扩展不会以不兼容的方式更改),你可以查询规范扩展名称以及供应商扩展名称。例如:

```js
var ext = (
gl.getExtension('OES_vertex_array_object') ||
gl.getExtension('MOZ_OES_vertex_array_object') ||
gl.getExtension('WEBKIT_OES_vertex_array_object')
);
const ext =
gl.getExtension("OES_vertex_array_object") ||
gl.getExtension("MOZ_OES_vertex_array_object") ||
gl.getExtension("WEBKIT_OES_vertex_array_object");
```

Note that, vendor prefix have been discouraged more and more and thus most browser implement experimental extensions behind a feature flag rather than vendor prefix.
请注意,不鼓励使用供应商前缀,因此大多数浏览器使用功能标志(feature flag)而不是供应商前缀后面实施实验性扩展。

The feature flags are:
功能标志有:

- `webgl.enable-draft-extensions` in Firefox
- `chrome://flags/#enable-webgl-draft-extensions` in Chromium based browsers (Chrome, Opera).
- Firefox:`webgl.enable-draft-extensions`
- 基于 Chromium 的浏览器(Chrome、Opera):`chrome://flags/#enable-webgl-draft-extensions`

## 命名约定

WebGL extensions are prefixed with "ANGLE", "OES", "EXT" or "WEBGL". These prefixes reflect origin and intent:
WebGL 扩展以“ANGLE”、“OES”、“EXT”、“WEBGL”为前缀。这些前缀反映了来源和意图:

- `ANGLE_`: Extensions that are written by the [ANGLE library](https://en.wikipedia.org/wiki/ANGLE_%28software%29) authors.
- `OES_`: Extensions that mirror functionality from OpenGL ES or OpenGL API extensions approved by the respective architecture review boards.
- `EXT_`: Extensions that mirror other OpenGL ES or OpenGL API extensions.
- `WEBGL_`: Extensions that are WebGL-specific and intended to be compatible with multiple web browsers. It should also be used for extensions which originated with the OpenGL ES or OpenGL APIs, but whose behavior has been significantly altered.
- `ANGLE_`:由 [ANGLE library](https://en.wikipedia.org/wiki/ANGLE_%28software%29) 的作者编写的扩展。
- `OES_``KHR_`:由各自的架构审查委员会(Khronos)批准的对 OpenGL ES(OES)或 OpenGL API 扩展的功能的镜像。
- `OVR_`:针对虚拟现实进行优化的扩展。
- `EXT_`:从其它 OpenGL ES 或 OpenGL API 扩展镜像的扩展。
- `WEBGL_`:特定于 WebGL 的扩展,旨在与多种 Web 浏览器兼容。它也应该用于源自 OpenGL ES 或 OpenGL API 的扩展,但其行为已被显著改变。

## 查询可用的扩展程序

The WebGL context supports querying what extensions are available.
WebGL 上下文支持查询可用的扩展。

```js
var available_extensions = gl.getSupportedExtensions();
const available_extensions = gl.getSupportedExtensions();
```

The {{domxref("WebGLRenderingContext.getSupportedExtensions()")}} method returns an array of strings, one for each supported extension.
{{domxref("WebGLRenderingContext.getSupportedExtensions()")}} 方法返回一个字符串数组,每个字符串对应一个支持的扩展。

## 扩展列表

The current extensions are:

{{page("en-US/docs/Web/API/WebGL_API", "Extensions")}}

## 启用一个扩展

Before an extension can be used it has to be enabled using {{domxref("WebGLRenderingContext.getExtension()")}}. For example:
当前的扩展有:

- {{domxref("ANGLE_instanced_arrays")}}
- {{domxref("EXT_blend_minmax")}}
- {{domxref("EXT_color_buffer_float")}}
- {{domxref("EXT_color_buffer_half_float")}}
- {{domxref("EXT_disjoint_timer_query")}}
- {{domxref("EXT_float_blend")}} {{experimental_inline}}
- {{domxref("EXT_frag_depth")}}
- {{domxref("EXT_shader_texture_lod")}}
- {{domxref("EXT_sRGB")}}
- {{domxref("EXT_texture_compression_bptc")}}
- {{domxref("EXT_texture_compression_rgtc")}}
- {{domxref("EXT_texture_filter_anisotropic")}}
- {{domxref("EXT_texture_norm16")}}
- {{domxref("KHR_parallel_shader_compile")}}
- {{domxref("OES_element_index_uint")}}
- {{domxref("OES_fbo_render_mipmap")}}
- {{domxref("OES_standard_derivatives")}}
- {{domxref("OES_texture_float")}}
- {{domxref("OES_texture_float_linear")}}
- {{domxref("OES_texture_half_float")}}
- {{domxref("OES_texture_half_float_linear")}}
- {{domxref("OES_vertex_array_object")}}
- {{domxref("OVR_multiview2")}}
- {{domxref("WEBGL_color_buffer_float")}}
- {{domxref("WEBGL_compressed_texture_astc")}}
- {{domxref("WEBGL_compressed_texture_etc")}}
- {{domxref("WEBGL_compressed_texture_etc1")}}
- {{domxref("WEBGL_compressed_texture_pvrtc")}}
- {{domxref("WEBGL_compressed_texture_s3tc")}}
- {{domxref("WEBGL_compressed_texture_s3tc_srgb")}}
- {{domxref("WEBGL_debug_renderer_info")}}
- {{domxref("WEBGL_debug_shaders")}}
- {{domxref("WEBGL_depth_texture")}}
- {{domxref("WEBGL_draw_buffers")}}
- {{domxref("WEBGL_lose_context")}}
- {{domxref("WEBGL_multi_draw")}}

## 启用扩展

在一个扩展可用之前,必须使用 {{domxref("WebGLRenderingContext.getExtension()")}} 来启用它。例如:

```js
var float_texture_ext = gl.getExtension('OES_texture_float');
const float_texture_ext = gl.getExtension("OES_texture_float");
```

The return value is `null` if the extension is not supported, or an extension object otherwise.
如果不支持扩展,则返回值为 `null`,否则为扩展对象。

## 扩展对象

If an extension defines specific symbols or functions that are not available in the core specification of WebGL, they will be available on the extension object returned by the call to `gl.getExtension()`.
如果扩展定义了 WebGL 核心规范中不可用的特定符号或函数,则它们将在调用 `gl.getExtension()` 后返回的扩展对象中可用。

## 参见

- {{domxref("WebGLRenderingContext.getSupportedExtensions()")}}
- {{domxref("WebGLRenderingContext.getExtension()")}}
- [webglreport.com](http://webglreport.com)
- [webglreport.com](https://webglreport.com/)

0 comments on commit 25942d0

Please sign in to comment.