--- title: WebGL slug: Web/API/WebGL_API tags: - WebGL translation_of: Web/API/WebGL_API ---
{{WebGLSidebar}}
WebGL (Web Graphics Library) 是一個透過瀏覽器渲染3D及2D圖像的 JavaScript API ,且不需要安裝任何插件。 WebGL 透過與OpenGL ES 2.0緊密連結的API,將3D圖像帶入HTML5中,並可透過canvas元素呈現於瀏覽器中
Support for WebGL is present in Firefox 4+, Google Chrome 9+, Opera 12+, Safari 5.1+ 以及 Internet Explorer 11+; 然而,使用者的 GPU 也必須支援。
Feature | Firefox (Gecko) | Chrome | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
基本支援 | {{CompatGeckoDesktop("2.0")}} | 9 | 11 | 12 (experiment) | 5.1 (experiment) |
OES_texture_float |
{{CompatGeckoDesktop("6.0")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
OES_standard_derivatives |
{{CompatGeckoDesktop("10.0")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
EXT_texture_filter_anisotropic |
{{CompatGeckoDesktop("13.0")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
WEBGL_compressed_texture_s3tc |
{{CompatGeckoDesktop("15.0")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
drawingBufferWidth and drawingBufferHeight attributes |
{{CompatGeckoDesktop("9.0")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
Feature | Firefox Mobile (Gecko) | Chrome for Android | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | 4 | 25 (experiment) | {{CompatNo}} | 12 (experiment) | {{CompatNo}} |
drawingBufferWidth and drawingBufferHeight attributes |
{{CompatGeckoMobile("9.0")}} | 25 | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
OES_texture_float |
{{CompatGeckoMobile("6.0")}} | 25 | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
OES_standard_derivatives |
{{CompatGeckoMobile("10.0")}} | 25 | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
EXT_texture_filter_anisotropic |
{{CompatGeckoMobile("13.0")}} | 25 | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
OES_element_index_uint |
{{CompatUnknown}} | 25 | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
OES_vertex_array_object |
{{CompatUnknown}} | 25 | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
WEBGL_compressed_texture_s3tc |
{{CompatGeckoMobile("15.0")}} | 25 prefixed with WEBKIT_ |
{{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
WEBKIT_EXT_texture_filter_nisotropic |
{{CompatNo}} | 25 | {{CompatNo}} | {{CompatNo}} | {{CompatUnknown}} |
In addition to the browser, the GPU itself also needs to support the feature. So, for example, S3 Texture Compression (S3TC) is only available on Tegra-based tablets. Most browsers make the WebGL context available through the webgl
context name, but older ones need experimental-webgl
as well. In addition, the upcoming WebGL 2 is fully backwards-compatible and will have the context name experimental-webgl2
in the future for testing.
Starting with Gecko 10.0 {{geckoRelease("10.0")}}, there are two preferences available which let you control the capabilities of WebGL for testing purposes:
webgl.min_capability_mode
true
, enables a minimum capability mode. When in this mode, WebGL is configured to only support the bare minimum feature set and capabilities required by the WebGL specification. This lets you ensure that your WebGL code will work on any device or browser, regardless of their capabilities. This is false
by default.webgl.disable_extensions
true
, disables all WebGL extensions. This is false
by default.Raw WebGL: a talk by Nick Desaulniers:
{{EmbedYouTube("H4c8t6myAWU")}}