Esta tradução está incompleta. Por favor, ajude a traduzir este artigo do Inglês.
WebGL (Biblioteca de Gráficos da Web) é uma API de JavaScript para a renderização de gráficos 2D e 3D interativos dentro de qualquer navegador da Web compatível sem a utilização de plug-ins. WebGL fazi isso, ao introduzir uma API que está em conformidade com o OpenGL ES 2.0 que pode ser utilizado em elementos <canvas> de HTML5.
O suporte para WebGL está presente no Firefox 4+, Google Chrome 9+, Opera 12+, Safari 5.1+ and Internet Explorer 11+, e Microsoft Edge build 10240+; contudo, o dispositivo do utilizador também deve ter hardware que suporte estas funcionalidades.
O elemento <canvas> também é utilizado por Canvas 2D para gráficos 2D nas páginas da Web.
Referência
Interfaces padrão
Extensões
ANGLE_instanced_arraysEXT_blend_minmaxEXT_color_buffer_floatEXT_color_buffer_half_floatEXT_disjoint_timer_queryEXT_frag_depthEXT_sRGBEXT_shader_texture_lodEXT_texture_filter_anisotropicOES_element_index_uintOES_standard_derivativesOES_texture_floatOES_texture_float_linearOES_texture_half_floatOES_texture_half_float_linearOES_vertex_array_objectWEBGL_color_buffer_floatWEBGL_compressed_texture_astcWEBGL_compressed_texture_atcWEBGL_compressed_texture_etcWEBGL_compressed_texture_etc1WEBGL_compressed_texture_pvrtcWEBGL_compressed_texture_s3tcWEBGL_compressed_texture_s3tc_srgbWEBGL_debug_renderer_infoWEBGL_debug_shadersWEBGL_depth_textureWEBGL_draw_buffersWEBGL_lose_context
Eventos
Constantes e tipos
WebGL 2
WebGL 2 é uma atualização muito importante para WebGL que é fornecida através da inteface de WebGL2RenderingContext. Esta tem como base o OpenGL ES 3.0 e novas funcionalidades includas:
- 3D textures,
- Sampler objects,
- Uniform Buffer objects,
- Sync objects,
- Query objects,
- Transform Feedback objects,
- Promoted extensions that are now core to WebGL 2: Vertex Array objects, instancing, multiple render targets, fragment depth.
See also the blog post "WebGL 2 lands in Firefox" and webglsamples.org/WebGL2Samples for a few demos.
Guias e tutoriais
Below, you'll find an assortment of guides to help you learn WebGL concepts and tutorials that offer step-by-step lessons and examples.
Guias
- Dados em WebGL
- A guide to variables, buffers, and other types of data used when writing WebGL code.
- WebGL best practices
- Tips and suggestions to help you improve the quality, performance, and reliability of your WebGL content.
- Using extensions
- A guide to using WebGL extensions.
Tutoriais
- WebGL tutorial
- A beginner's guide to WebGL core concepts. A good place to start if you don't have previous WebGL experience.
Exemplos
- A basic 2D WebGL animation example
- 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.
- WebGL by example
- 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.
Tutoriais avançados
- WebGL model view projection
- A detailed explanation of the three core matrices that are typically used to represent a 3D object view: the model, view and projection matrices.
- Matrix math for the web
- A useful guide to how 3D transform matrices work, and can be used on the web — both for WebGL calculations and in CSS3 transforms.
Recursos
- Raw WebGL: An introduction to WebGL A talk by Nick Desaulniers that introduces the basics of WebGL. This is a great place to start if you've never done low-level graphics programming.
- Khronos WebGL site The main web site for WebGL at the Khronos Group.
- Learning WebGL A site with tutorials on how to use WebGL.
- WebGL Fundamentals A basic tutorial with fundamentals of WebGL.
- WebGL playground An online tool for creating and sharing WebGL projects. Good for quick prototyping and experimenting.
- WebGL Academy An HTML/JavaScript editor with tutorials to learn basics of webgl programming.
- WebGL Stats A site with statistics about WebGL capabilities in browsers on different platforms.
Bibliotecas
- glMatrix is a JavaScript matrix and vector library for high-performance WebGL apps.
- PhiloGL is a WebGL framework for data visualization, creative coding, and game development.
- Pixi.js is a fast, open-source 2D WebGL renderer.
- PlayCanvas is an open-source game engine.
- Sylvester is an open-source library for manipulating vectors and matrices. Not optimized for WebGL but extremely robust.
- three.js is an open-source, fully featured 3D WebGL library.
Especificações
| Especificação | Estado | Comentário |
|---|---|---|
| WebGL 1.0 | Recommendation | Initial definition. Based on OpenGL ES 2.0 |
| WebGL 2.0 | Editor's Draft | Builds on top of WebGL 1. Based on OpenGL ES 3.0. |
| OpenGL ES 2.0 | Standard | |
| OpenGL ES 3.0 | Standard |
Compatibilidade de navegador
WebGL 1
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
WebGLRenderingContext | Chrome Full support 9 | Edge
Full support
12
| Firefox Full support 4 | IE
Full support
11
| Opera Full support 12 | Safari Full support 5.1 | WebView Android Full support Yes | Chrome Android Full support 25 | Firefox Android Full support Yes | Opera Android Full support 12 | Safari iOS Full support 8.1 | Samsung Internet Android Full support Yes |
Legend
- Full support
- Full support
- See implementation notes.
- See implementation notes.
WebGL 2
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
WebGL2RenderingContext | Chrome Full support 56 | Edge No support No | Firefox Full support 51 | IE No support No | Opera Full support 43 | Safari No support No | WebView Android Full support 58 | Chrome Android Full support 58 | Firefox Android Full support 51 | Opera Android Full support 43 | Safari iOS No support No | Samsung Internet Android Full support 7.0 |
Legend
- Full support
- Full support
- No support
- No support
Notas de compatibilidade
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.
Notas do Gecko
Depuração e teste de WebGL
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- A Boolean property that, when
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 isfalseby default. webgl.disable_extensions- A Boolean property that, when
true, disables all WebGL extensions. This isfalseby default.

