Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1055102 of WebGL

  • Revision slug: Web/API/WebGL_API
  • Revision title: WebGL
  • Revision id: 1055102
  • Created:
  • Creator: Archil
  • Is current revision? No
  • Comment

Revision Content

{{WebGLSidebar}}

WebGL (Web Graphics Library) is a JavaScript API for rendering 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 {{HTMLElement("canvas")}} elements.

Support for WebGL is present in Firefox 4+, Google Chrome 9+, Opera 12+, Safari 5.1+ and Internet Explorer 11+; however, the user's device must also have hardware that supports these features.

The {{HTMLElement("canvas")}} element is also used by Canvas 2D to do 2D graphics on web pages.

Reference

Standard interfaces

  • {{domxref("WebGLRenderingContext")}}
  • {{domxref("WebGL2RenderingContext")}} {{experimental_inline}}
  • {{domxref("WebGLActiveInfo")}}
  • {{domxref("WebGLBuffer")}}
  • {{domxref("WebGLContextEvent")}}
  • {{domxref("WebGLFramebuffer")}}
  • {{domxref("WebGLProgram")}}
  • {{domxref("WebGLQuery")}} {{experimental_inline}}
  • {{domxref("WebGLRenderbuffer")}}
  • {{domxref("WebGLSampler")}} {{experimental_inline}}
  • {{domxref("WebGLShader")}}
  • {{domxref("WebGLShaderPrecisionFormat")}}
  • {{domxref("WebGLSync")}} {{experimental_inline}}
  • {{domxref("WebGLTexture")}}
  • {{domxref("WebGLTransformFeedback")}} {{experimental_inline}}
  • {{domxref("WebGLUniformLocation")}}
  • {{domxref("WebGLVertexArrayObject")}} {{experimental_inline}}

Extensions

  • {{domxref("ANGLE_instanced_arrays")}}
  • {{domxref("EXT_blend_minmax")}}
  • {{domxref("EXT_color_buffer_half_float")}}
  • {{domxref("EXT_disjoint_timer_query")}}
  • {{domxref("EXT_frag_depth")}}
  • {{domxref("EXT_sRGB")}}
  • {{domxref("EXT_shader_texture_lod")}}
  • {{domxref("EXT_texture_filter_anisotropic")}}
  • {{domxref("OES_element_index_uint")}}
  • {{domxref("OES_standard_derivatives")}}
  • {{domxref("OES_texture_float")}}
  • {{domxref("OES_texture_float_linear")}}
  • {{domxref("OES_texture_half_float")}}
  • {{domxref("OES_texture_half_float_linear")}}
  • {{domxref("OES_vertex_array_object")}}
  • {{domxref("WEBGL_color_buffer_float")}}
  • {{domxref("WEBGL_compressed_texture_atc")}}
  • {{domxref("WEBGL_compressed_texture_es3")}}
  • {{domxref("WEBGL_compressed_texture_etc1")}}
  • {{domxref("WEBGL_compressed_texture_pvrtc")}}
  • {{domxref("WEBGL_compressed_texture_s3tc")}}
  • {{domxref("WEBGL_debug_renderer_info")}}
  • {{domxref("WEBGL_debug_shaders")}}
  • {{domxref("WEBGL_depth_texture")}}
  • {{domxref("WEBGL_draw_buffers")}}
  • {{domxref("WEBGL_lose_context")}}

Events

  • {{Event("webglcontextlost")}}
  • {{Event("webglcontextrestored")}}
  • {{Event("webglcontextcreationerror")}}

Constants and types

Guides and tutorials

  • WebGL tutorial: A beginner's guide to WebGL core concepts. A good place to start if you don't have previous WebGL experience.
  • WebGL best practices: Tips and suggestions to improve your WebGL content.
  • Using extensions: How to use extensions that are available in WebGL.

Advanced tutorials

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

Resources

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

Libraries

  • glMatrix JavaScript Matrix and Vector library for High Performance WebGL apps
  • Sylvester An open source library for manipulating vectors and matrices. Not optimized for WebGL but extremely robust.

Specifications

Specification Status Comment
{{SpecName('WebGL')}} {{Spec2('WebGL')}} Initial definition. Based on OpenGL ES 2.0
{{SpecName('WebGL2')}} {{Spec2('WebGL2')}} Builds on top of WebGL1. Based on OpenGL ES 3.0.
{{SpecName('OpenGL ES 2.0')}} {{Spec2('OpenGL ES 2.0')}}  
{{SpecName('OpenGL ES 3.0')}} {{Spec2('OpenGL ES 3.0')}}  

Browser compatibility

{{CompatibilityTable}}
Feature Firefox (Gecko) Chrome Internet Explorer Opera Safari
Basic support {{CompatGeckoDesktop("2.0")}} 9 11 12[1] 5.1[1]
Feature Firefox Mobile (Gecko) Chrome for Android IE Mobile Opera Mobile Safari Mobile
Basic support 4 25[1] {{CompatNo}} 12[1] 8.1

[1] The implementation of this feature is experimental.

Compatibility notes

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.

Gecko notes

WebGL debugging and 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
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 is false by default.
webgl.disable_extensions
A Boolean property that, when true, disables all WebGL extensions. This is false by default.

See also

Revision Source

<div>{{WebGLSidebar}}</div>

<div class="summary">
<p>WebGL (Web Graphics Library) is a JavaScript API for rendering 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 {{HTMLElement("canvas")}} elements.</p>
</div>

<p>Support for WebGL is present in <a href="/en-US/Firefox" title="Firefox 4 for developers">Firefox</a>&nbsp;4+, <a href="https://www.google.com/chrome/" title="https://www.google.com/chrome/">Google Chrome</a> 9+, <a href="https://www.opera.com/" title="https://www.opera.com/">Opera</a>&nbsp;12+, <a href="https://www.apple.com/safari/" title="https://www.apple.com/fr/safari/">Safari </a>5.1+ and <a href="https://windows.microsoft.com/en-us/internet-explorer/browser-ie" title="https://windows.microsoft.com/en-us/internet-explorer/download-ie">Internet Explorer</a> 11+; however, the user's device must also have hardware that supports these features.</p>

<p>The {{HTMLElement("canvas")}} element is also used by <a href="/en-US/docs/Web/API/Canvas_API">Canvas 2D</a> to do 2D graphics on web pages.</p>

<h2 id="Reference">Reference</h2>

<h3 id="Standard_interfaces">Standard interfaces</h3>

<div class="index">
<ul>
 <li>{{domxref("WebGLRenderingContext")}}</li>
 <li>{{domxref("WebGL2RenderingContext")}} {{experimental_inline}}</li>
 <li>{{domxref("WebGLActiveInfo")}}</li>
 <li>{{domxref("WebGLBuffer")}}</li>
 <li>{{domxref("WebGLContextEvent")}}</li>
 <li>{{domxref("WebGLFramebuffer")}}</li>
 <li>{{domxref("WebGLProgram")}}</li>
 <li>{{domxref("WebGLQuery")}} {{experimental_inline}}</li>
 <li>{{domxref("WebGLRenderbuffer")}}</li>
 <li>{{domxref("WebGLSampler")}} {{experimental_inline}}</li>
 <li>{{domxref("WebGLShader")}}</li>
 <li>{{domxref("WebGLShaderPrecisionFormat")}}</li>
 <li>{{domxref("WebGLSync")}} {{experimental_inline}}</li>
 <li>{{domxref("WebGLTexture")}}</li>
 <li>{{domxref("WebGLTransformFeedback")}} {{experimental_inline}}</li>
 <li>{{domxref("WebGLUniformLocation")}}</li>
 <li>{{domxref("WebGLVertexArrayObject")}} {{experimental_inline}}</li>
</ul>
</div>

<h3 id="Extensions">Extensions</h3>

<div class="index">
<ul>
 <li>{{domxref("ANGLE_instanced_arrays")}}</li>
 <li>{{domxref("EXT_blend_minmax")}}</li>
 <li>{{domxref("EXT_color_buffer_half_float")}}</li>
 <li>{{domxref("EXT_disjoint_timer_query")}}</li>
 <li>{{domxref("EXT_frag_depth")}}</li>
 <li>{{domxref("EXT_sRGB")}}</li>
 <li>{{domxref("EXT_shader_texture_lod")}}</li>
 <li>{{domxref("EXT_texture_filter_anisotropic")}}</li>
 <li>{{domxref("OES_element_index_uint")}}</li>
 <li>{{domxref("OES_standard_derivatives")}}</li>
 <li>{{domxref("OES_texture_float")}}</li>
 <li>{{domxref("OES_texture_float_linear")}}</li>
 <li>{{domxref("OES_texture_half_float")}}</li>
 <li>{{domxref("OES_texture_half_float_linear")}}</li>
 <li>{{domxref("OES_vertex_array_object")}}</li>
 <li>{{domxref("WEBGL_color_buffer_float")}}</li>
 <li>{{domxref("WEBGL_compressed_texture_atc")}}</li>
 <li>{{domxref("WEBGL_compressed_texture_es3")}}</li>
 <li>{{domxref("WEBGL_compressed_texture_etc1")}}</li>
 <li>{{domxref("WEBGL_compressed_texture_pvrtc")}}</li>
 <li>{{domxref("WEBGL_compressed_texture_s3tc")}}</li>
 <li>{{domxref("WEBGL_debug_renderer_info")}}</li>
 <li>{{domxref("WEBGL_debug_shaders")}}</li>
 <li>{{domxref("WEBGL_depth_texture")}}</li>
 <li>{{domxref("WEBGL_draw_buffers")}}</li>
 <li>{{domxref("WEBGL_lose_context")}}</li>
</ul>
</div>

<h3 id="Events">Events</h3>

<ul>
 <li>{{Event("webglcontextlost")}}</li>
 <li>{{Event("webglcontextrestored")}}</li>
 <li>{{Event("webglcontextcreationerror")}}</li>
</ul>

<h3 id="Constants_and_types">Constants and types</h3>

<ul>
 <li><a href="/en-US/docs/Web/API/WebGL_API/Constants">WebGL constants</a></li>
 <li><a href="/en-US/docs/Web/API/WebGL_API/Types">WebGL types</a></li>
</ul>

<h2 id="Guides_and_tutorials">Guides and tutorials</h2>

<ul>
 <li><a href="/en-US/docs/Web/API/WebGL_API/Tutorial">WebGL tutorial</a>: A beginner's guide to WebGL core concepts. A good place to start if you don't have previous WebGL experience.</li>
 <li><a href="/en-US/docs/Web/API/WebGL_API/WebGL_best_practices">WebGL best practices</a>: Tips and suggestions to improve your WebGL content.</li>
 <li><a href="/en-US/docs/Web/API/WebGL_API/Using_Extensions">Using extensions</a>: How to use extensions that are available in WebGL.</li>
</ul>

<h3 id="Advanced_tutorials">Advanced tutorials</h3>

<ul>
 <li><a href="/en-US/docs/Web/API/WebGL_API/WebGL_model_view_projection">WebGL model view projection</a>: A detailed explanation of the three core matrices that are typically used to represent a 3D object view: the model, view and projection matrices.</li>
 <li><a href="/en-US/docs/Web/API/WebGL_API/Matrix_math_for_the_web">Matrix math for the web</a>: A useful guide to how 3D transform matrices work, and can be used on the web — both for WebGL calculations and in CSS3 transforms.</li>
</ul>

<h2 id="Resources">Resources</h2>

<ul>
 <li><a href="https://www.youtube.com/embed/H4c8t6myAWU/?feature=player_detailpage">Raw WebGL: An introduction to WebGL</a> 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.</li>
 <li><a href="https://www.khronos.org/webgl/" title="https://www.khronos.org/webgl/">Khronos WebGL site</a> The main web site for WebGL at the Khronos Group.</li>
 <li><a href="https://learningwebgl.com/blog/?page_id=1217" title="https://learningwebgl.com/blog/">Learning WebGL</a> A site with tutorials on how to use WebGL.</li>
 <li><a href="https://www.html5rocks.com/en/tutorials/webgl/webgl_fundamentals/" title="https://www.html5rocks.com/en/tutorials/webgl/webgl_fundamentals/">WebGL Fundamentals</a> A basic tutorial with fundamentals of WebGL.</li>
 <li><a href="https://webglplayground.net" title="https://webglplayground.net">WebGL playground</a> An online tool for creating and sharing WebGL projects. Good for quick prototyping and experimenting.</li>
 <li><a href="https://www.webglacademy.com" title="https://www.webglacademy.com">WebGL Academy</a> An HTML/JavaScript editor with tutorials to learn basics of webgl programming.</li>
 <li><a href="https://webglstats.com/">WebGL Stats</a> A site with statistics about WebGL capabilities in browsers on different platforms.</li>
</ul>

<h3 id="Libraries">Libraries</h3>

<ul>
 <li><a class="link-https" href="https://github.com/toji/gl-matrix" title="https://github.com/toji/gl-matrix">glMatrix</a> JavaScript Matrix and Vector library for High Performance WebGL apps</li>
 <li><a href="https://sylvester.jcoglan.com/" title="https://sylvester.jcoglan.com/">Sylvester</a> An open source library for manipulating vectors and matrices. Not optimized for WebGL but extremely robust.</li>
</ul>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('WebGL')}}</td>
   <td>{{Spec2('WebGL')}}</td>
   <td>Initial definition. Based on OpenGL ES 2.0</td>
  </tr>
  <tr>
   <td>{{SpecName('WebGL2')}}</td>
   <td>{{Spec2('WebGL2')}}</td>
   <td>Builds on top of WebGL1. Based on OpenGL ES 3.0.</td>
  </tr>
  <tr>
   <td>{{SpecName('OpenGL ES 2.0')}}</td>
   <td>{{Spec2('OpenGL ES 2.0')}}</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>{{SpecName('OpenGL ES 3.0')}}</td>
   <td>{{Spec2('OpenGL ES 3.0')}}</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<div>{{CompatibilityTable}}</div>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Firefox (Gecko)</th>
   <th>Chrome</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatGeckoDesktop("2.0")}}</td>
   <td>9</td>
   <td>11</td>
   <td>12<sup>[1]</sup></td>
   <td>5.1<sup>[1]</sup></td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>Chrome for Android</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>4</td>
   <td>25<sup>[1]</sup></td>
   <td>{{CompatNo}}</td>
   <td>12<sup>[1]</sup></td>
   <td>8.1</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] The implementation of this feature is experimental.</p>

<h3 id="Compatibility_notes">Compatibility notes</h3>

<p>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 <code>webgl</code> context name, but older ones need <code>experimental-webgl</code> as well. In addition, the upcoming <a href="/en-US/docs/Web/API/WebGL2RenderingContext">WebGL 2</a> is fully backwards-compatible and will have the context name <code>webgl2</code>.</p>

<h3 id="Gecko_notes">Gecko notes</h3>

<h4 id="WebGL_debugging_and_testing">WebGL debugging and testing</h4>

<p>Starting with Gecko 10.0 {{geckoRelease("10.0")}}, there are two preferences available which let you control the capabilities of WebGL for testing purposes:</p>

<dl>
 <dt><code>webgl.min_capability_mode</code></dt>
 <dd>A Boolean property that, when <code>true</code>, 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 <code>false</code> by default.</dd>
 <dt><code>webgl.disable_extensions</code></dt>
 <dd>A Boolean property that, when <code>true</code>, disables all WebGL extensions. This is <code>false</code> by default.</dd>
</dl>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/API/Canvas_API">Canvas</a></li>
 <li><a href="https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/getSupportedExtensions#Browser_compatibility">Compatibility info about WebGL extensions</a></li>
</ul>
Revert to this revision