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
73
74
75
76
77
78
79
80
81
82
|
---
title: Using WebGL extensions
slug: Web/API/WebGL_API/Using_Extensions
tags:
- WebGL extensions
translation_of: Web/API/WebGL_API/Using_Extensions
---
<div>{{WebGLSidebar}}</div>
<p>WebGL,像它的姐妹API (OpenGL and OpenGL ES),支持使用扩展(extensions)。一份完整的扩展列表可在 <a class="external" href="http://www.khronos.org/registry/webgl/extensions/">khronos webgl extension registry</a>。</p>
<div class="note"><strong>Note:</strong> 不像别的 GL APIs, 在webGL中 , 扩展只有在明确需要的情况下才会加载。</div>
<h2 id="规范扩展名,供应商前缀和首选项">规范扩展名,供应商前缀和首选项</h2>
<p>扩展(extensions)在未被官方正式制定为标准前,某些浏览器厂商可能会支持WebGL扩展 (but only when they are in draft stage)。这样的话,扩展的名字应该加上相应的厂商前缀 (<code>MOZ_</code>, <code>WEBKIT_</code>, etc.),否则这个扩展只能在浏览器切换了偏好设置的前提下生效。</p>
<p>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:</p>
<pre class="brush:js">var ext = (
gl.getExtension('OES_vertex_array_object') ||
gl.getExtension('MOZ_OES_vertex_array_object') ||
gl.getExtension('WEBKIT_OES_vertex_array_object')
);
</pre>
<p>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.</p>
<p>The feature flags are:</p>
<ul>
<li><code>webgl.enable-draft-extensions</code> in Firefox</li>
<li><code>chrome://flags/#enable-webgl-draft-extensions</code> in Chromium based browsers (Chrome, Opera).</li>
</ul>
<h2 id="命名约定">命名约定</h2>
<p>WebGL extensions are prefixed with "ANGLE", "OES", "EXT" or "WEBGL". These prefixes reflect origin and intent:</p>
<ul>
<li>ANGLE_: Extensions that are written by the <a href="https://en.wikipedia.org/wiki/ANGLE_%28software%29">ANGLE library</a> authors.</li>
<li>OES_: Extensions that mirror functionality from OpenGL ES or OpenGL API extensions approved by the respective architecture review boards.</li>
<li>EXT_: Extensions that mirror other OpenGL ES or OpenGL API extensions.</li>
<li>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.</li>
</ul>
<h2 id="查询可用的扩展程序">查询可用的扩展程序</h2>
<p>The WebGL context supports querying what extensions are available.</p>
<pre class="brush:js">var available_extensions = gl.getSupportedExtensions();</pre>
<p>The {{domxref("WebGLRenderingContext.getSupportedExtensions()")}} method returns an array of strings, one for each supported extension.</p>
<h2 id="扩展列表">扩展列表</h2>
<p>The current extensions are:</p>
<p>{{page("en-US/docs/Web/API/WebGL_API", "Extensions")}}</p>
<h2 id="启用一个扩展">启用一个扩展</h2>
<p>Before an extension can be used it has to be enabled using {{domxref("WebGLRenderingContext.getExtension()")}}. For example:</p>
<pre class="brush:js">var float_texture_ext = gl.getExtension('OES_texture_float');</pre>
<p>The return value is <code>null</code> if the extension is not supported, or an extension object otherwise.</p>
<h2 id="扩展对象">扩展对象</h2>
<p>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 <code>gl.getExtension()</code>.</p>
<h2 id="也可以看看">也可以看看</h2>
<ul>
<li>{{domxref("WebGLRenderingContext.getSupportedExtensions()")}}</li>
<li>{{domxref("WebGLRenderingContext.getExtension()")}}</li>
<li><a class="external external-icon" href="http://webglreport.com">webglreport.com</a></li>
<li><a href="http://webglstats.com">webglstats.com</a></li>
</ul>
|