--- title: Using WebGL extensions slug: Web/API/WebGL_API/Using_Extensions tags: - WebGL extensions translation_of: Web/API/WebGL_API/Using_Extensions ---
{{WebGLSidebar}}

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 extensions are prefixed with "ANGLE", "OES", "EXT" or "WEBGL". These prefixes reflect origin and intent:

查询可用的扩展程序

The WebGL context supports querying what extensions are available.

var available_extensions = gl.getSupportedExtensions();

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

扩展列表

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:

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

浏览器兼容性

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 9 {{CompatGeckoDesktop("2.0")}} 11 12 5.1
ANGLE_instanced_arrays {{CompatUnknown}} {{CompatGeckoDesktop("33.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
EXT_blend_minmax {{CompatUnknown}} {{CompatGeckoDesktop("33.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
EXT_color_buffer_half_float {{CompatUnknown}} {{CompatGeckoDesktop("30.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
EXT_disjoint_timer_query {{CompatUnknown}} {{CompatGeckoDesktop("41.0")}} [1] {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
EXT_frag_depth {{CompatUnknown}} {{CompatGeckoDesktop("30.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
EXT_sRGB {{CompatUnknown}} {{CompatGeckoDesktop("28.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
EXT_shader_texture_lod {{CompatUnknown}} {{CompatGeckoDesktop("34.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
EXT_texture_filter_anisotropic {{CompatUnknown}} {{CompatGeckoDesktop("17.0")}} [2] {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
OES_element_index_uint {{CompatUnknown}} {{CompatGeckoDesktop("24.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
OES_standard_derivatives {{CompatUnknown}} {{CompatGeckoDesktop("10.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
OES_texture_float {{CompatUnknown}} {{CompatGeckoDesktop("6.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
OES_texture_float_linear {{CompatUnknown}} {{CompatGeckoDesktop("24.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
OES_texture_half_float {{CompatUnknown}} {{CompatGeckoDesktop("29.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
OES_texture_half_float_linear {{CompatUnknown}} {{CompatGeckoDesktop("30.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
OES_vertex_array_object {{CompatUnknown}} {{CompatGeckoDesktop("25.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBGL_color_buffer_float {{CompatUnknown}} {{CompatGeckoDesktop("30.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBGL_compressed_texture_atc {{CompatUnknown}} {{CompatGeckoDesktop("18.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBGL_compressed_texture_es3 {{CompatUnknown}} {{CompatGeckoDesktop("46.0")}} [1] {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBGL_compressed_texture_etc1 {{CompatUnknown}} {{CompatGeckoDesktop("30.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBGL_compressed_texture_pvrtc {{CompatUnknown}} {{CompatGeckoDesktop("18.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBGL_compressed_texture_s3tc {{CompatUnknown}} {{CompatGeckoDesktop("22.0")}} [2] {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBGL_debug_renderer_info {{CompatUnknown}} {{CompatGeckoDesktop("19.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBGL_debug_shaders {{CompatUnknown}} {{CompatGeckoDesktop("30.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBGL_depth_texture {{CompatUnknown}} {{CompatGeckoDesktop("22.0")}} [2] {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBGL_draw_buffers {{CompatUnknown}} {{CompatGeckoDesktop("28.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBGL_lose_context {{CompatUnknown}} {{CompatGeckoDesktop("22.0")}} [2] {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} 25 {{CompatGeckoMobile("2.0")}} {{CompatVersionUnknown}} 12 8.0
ANGLE_instanced_arrays {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
EXT_blend_minmax {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
EXT_color_buffer_half_float {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
EXT_disjoint_timer_query {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
EXT_frag_depth {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
EXT_sRGB {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
EXT_shader_texture_lod {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
EXT_texture_filter_anisotropic {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
OES_element_index_uint {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
OES_standard_derivatives {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
OES_texture_float {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
OES_texture_float_linear {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
OES_texture_half_float {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
OES_texture_half_float_linear {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
OES_vertex_array_object {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBGL_color_buffer_float {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBGL_compressed_texture_atc {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBGL_compressed_texture_etc1 {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBGL_compressed_texture_s3tc {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBGL_compressed_texture_pvrtc {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBGL_compressed_texture_s3tc {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBGL_debug_renderer_info {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBGL_debug_shaders {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBGL_depth_texture {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBGL_draw_buffers {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
WEBGL_lose_context {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

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

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

也可以看看