WebGL (Web Graphics Library) is a JavaScript API for rendering high-performance interactive 3D and 2D graphics within any compatible web browser without the use of plug-ins. WebGL does so by introducing an API that closely conforms to OpenGL ES 2.0 that can be used in HTML5
<canvas>
元素。
This conformance makes it possible for the API to take advantage of hardware graphics acceleration provided by the user's device.
Support for WebGL is present in Firefox 4+, Google Chrome 9+, Opera 12+, Safari 5.1+, Internet Explorer 11+, and Microsoft Edge build 10240+; however, the user's device must also have hardware that supports these features.
WebGL 2
API introduces support for much of the OpenGL ES 3.0 feature set; it's provided through the
WebGL2RenderingContext
接口。
<canvas>
element is also used by the
画布 API
to do 2D graphics on web pages.
WebGLRenderingContext
WebGL2RenderingContext
WebGLActiveInfo
WebGLBuffer
WebGLContextEvent
WebGLFramebuffer
WebGLProgram
WebGLQuery
WebGLRenderbuffer
WebGLSampler
WebGLShader
WebGLShaderPrecisionFormat
WebGLSync
WebGLTexture
WebGLTransformFeedback
WebGLUniformLocation
WebGLVertexArrayObject
ANGLE_instanced_arrays
EXT_blend_minmax
EXT_color_buffer_float
EXT_color_buffer_half_float
EXT_disjoint_timer_query
EXT_float_blend
EXT_frag_depth
EXT_sRGB
EXT_shader_texture_lod
EXT_texture_compression_bptc
EXT_texture_compression_rgtc
EXT_texture_filter_anisotropic
KHR_parallel_shader_compile
OES_element_index_uint
OES_fbo_render_mipmap
OES_standard_derivatives
OES_texture_float
OES_texture_float_linear
OES_texture_half_float
OES_texture_half_float_linear
OES_vertex_array_object
OVR_multiview2
WEBGL_color_buffer_float
WEBGL_compressed_texture_astc
WEBGL_compressed_texture_atc
WEBGL_compressed_texture_etc
WEBGL_compressed_texture_etc1
WEBGL_compressed_texture_pvrtc
WEBGL_compressed_texture_s3tc
WEBGL_compressed_texture_s3tc_srgb
WEBGL_debug_renderer_info
WEBGL_debug_shaders
WEBGL_depth_texture
WEBGL_draw_buffers
WEBGL_lose_context
WebGL 2 is a major update to WebGL which is provided through the
WebGL2RenderingContext
interface. It is based on OpenGL ES 3.0 and new features include:
See also the blog post "WebGL 2 lands in Firefox" and webglsamples.org/WebGL2Samples for a few demos.
Below, you'll find an assortment of guides to help you learn WebGL concepts and tutorials that offer step-by-step lessons and examples.
A guide to variables, buffers, and other types of data used when writing WebGL code.
Tips and suggestions to help you improve the quality, performance, and reliability of your WebGL content.
A guide to using WebGL extensions.
A beginner's guide to WebGL core concepts. A good place to start if you don't have previous WebGL experience.
This example demonstrates the simple animation of a one-color shape. Topics examined are adapting to aspect ratio differences, a function to build shader programs from sets of multiple shaders, and the basics of drawing in WebGL.
A series of live samples with short explanations that showcase WebGL concepts and capabilities. The examples are sorted according to topic and level of difficulty, covering the WebGL rendering context, shader programming, textures, geometry, user interaction, and more.
A detailed explanation of the three core matrices that are typically used to represent a 3D object view: the model, view and projection matrices.
A useful guide to how 3D transform matrices work, and can be used on the web — both for WebGL calculations and in CSS3 transforms.
| 规范 | 状态 | 注释 |
|---|---|---|
| OpenGL ES 3.0 | 标准 | |
| OpenGL ES 2.0 | 标准 | |
| WebGL 2.0 | 编者草案 | Builds on top of WebGL 1. Based on OpenGL ES 3.0. |
| WebGL 1.0 | 推荐 | Initial definition. Based on OpenGL ES 2.0 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
WebGLRenderingContext
|
Chrome 9 |
Edge
12
注意事项
|
Firefox 4 |
IE
11
注意事项
|
Opera 12 | Safari 5.1 | WebView Android Yes | Chrome Android 25 | Firefox Android Yes | Opera Android 12 | Safari iOS 8 | Samsung Internet Android 1.5 |
完整支持
见实现注意事项。
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
WebGL2RenderingContext
|
Chrome 56 | Edge 79 | Firefox 51 | IE 不支持 No | Opera 43 | Safari 不支持 No | WebView Android 58 | Chrome Android 58 | Firefox Android 51 | Opera Android 43 | Safari iOS 不支持 No | Samsung Internet Android 7.0 |
完整支持
不支持
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
webgl2
.
Starting with Gecko 10.0 (Firefox 10.0 / Thunderbird 10.0 / SeaMonkey 2.7), 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
在默认情况下。
webgl.disable_extensions
true
, disables all WebGL extensions. This is
false
在默认情况下。