Using WebGL extensions - Web API 接口参考 编辑

WebGL,像它的姐妹API (OpenGL and OpenGL ES),支持使用扩展(extensions)。一份完整的扩展列表可在 khronos webgl extension registry

Note: 不像别的 GL APIs, 在webGL中 , 扩展只有在明确需要的情况下才会加载。

规范扩展名,供应商前缀和首选项

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

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:

var 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.

The feature flags are:

  • webgl.enable-draft-extensions in Firefox
  • chrome://flags/#enable-webgl-draft-extensions in Chromium based browsers (Chrome, Opera).

命名约定

WebGL extensions are prefixed with "ANGLE", "OES", "EXT" or "WEBGL". These prefixes reflect origin and intent:

  • ANGLE_: Extensions that are written by the ANGLE library 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.

查询可用的扩展程序

The WebGL context supports querying what extensions are available.

var available_extensions = gl.getSupportedExtensions();

The WebGLRenderingContext.getSupportedExtensions() method returns an array of strings, one for each supported extension.

扩展列表

The current extensions are:

启用一个扩展

Before an extension can be used it has to be enabled using WebGLRenderingContext.getExtension(). For example:

var float_texture_ext = gl.getExtension('OES_texture_float');

The return value is null if the extension is not supported, or an extension object otherwise.

扩展对象

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().

浏览器兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support94.0 (2.0)11125.1
ANGLE_instanced_arrays?33.0 (33.0)???
EXT_blend_minmax?33.0 (33.0)???
EXT_color_buffer_half_float?30.0 (30.0)???
EXT_disjoint_timer_query?41.0 (41.0) [1]???
EXT_frag_depth?30.0 (30.0)???
EXT_sRGB?28.0 (28.0)???
EXT_shader_texture_lod?34.0 (34.0)???
EXT_texture_filter_anisotropic?17.0 (17.0) [2]???
OES_element_index_uint?24.0 (24.0)???
OES_standard_derivatives?10.0 (10.0)???
OES_texture_float?6.0 (6.0)???
OES_texture_float_linear?24.0 (24.0)???
OES_texture_half_float?29.0 (29.0)???
OES_texture_half_float_linear?30.0 (30.0)???
OES_vertex_array_object?25.0 (25.0)???
WEBGL_color_buffer_float?30.0 (30.0)???
WEBGL_compressed_texture_atc?18.0 (18.0)???
WEBGL_compressed_texture_es3?46.0 (46.0) [1]???
WEBGL_compressed_texture_etc1?30.0 (30.0)???
WEBGL_compressed_texture_pvrtc?18.0 (18.0)???
WEBGL_compressed_texture_s3tc?22.0 (22.0) [2]???
WEBGL_debug_renderer_info?19.0 (19.0)???
WEBGL_debug_shaders?30.0 (30.0)???
WEBGL_depth_texture?22.0 (22.0) [2]???
WEBGL_draw_buffers?28.0 (28.0)???
WEBGL_lose_context?22.0 (22.0) [2]???
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support(Yes)254.0 (2.0)(Yes)128.0
ANGLE_instanced_arrays??????
EXT_blend_minmax??????
EXT_color_buffer_half_float??????
EXT_disjoint_timer_query??????
EXT_frag_depth??????
EXT_sRGB??????
EXT_shader_texture_lod??????
EXT_texture_filter_anisotropic??????
OES_element_index_uint??????
OES_standard_derivatives??????
OES_texture_float??????
OES_texture_float_linear??????
OES_texture_half_float??????
OES_texture_half_float_linear??????
OES_vertex_array_object??????
WEBGL_color_buffer_float??????
WEBGL_compressed_texture_atc??????
WEBGL_compressed_texture_etc1??????
WEBGL_compressed_texture_s3tc??????
WEBGL_compressed_texture_pvrtc??????
WEBGL_compressed_texture_s3tc??????
WEBGL_debug_renderer_info??????
WEBGL_debug_shaders??????
WEBGL_depth_texture??????
WEBGL_draw_buffers??????
WEBGL_lose_context??????

[1] Toggling the webgl.enable-draft-extensions preference in about:config is required.

[2] This extension was prefixed with MOZ_ in prior versions.

也可以看看

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:111 次

字数:18860

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文