W3cubDocs

/DOM

WebGL2RenderingContext

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The WebGL2RenderingContext interface provides the OpenGL ES 3.0 rendering context for the drawing surface of an HTML <canvas> element.

To get an object of this interface, call getContext() on a <canvas> element, supplying "webgl2" as the argument:

var canvas = document.getElementById('myCanvas');
var gl = canvas.getContext('webgl2');

WebGL 2 is an extension to WebGL 1. The WebGL2RenderingContext interface implements all members of the WebGLRenderingContext interface. Some methods of the WebGL 1 context can accept additional values when used in a WebGL 2 context. You will find this info noted on the WebGL 1 reference pages.

The WebGL tutorial has more information, examples, and resources on how to get started with WebGL.

Constants

See the WebGL constants page.

State information

WebGL2RenderingContext.getIndexedParameter()
Returns the indexed value for the given target.

Buffers

WebGL2RenderingContext.bufferData()
Initializes and creates the buffer object's data store.
WebGL2RenderingContext.bufferSubData()
Updates a subset of a buffer object's data store.
WebGL2RenderingContext.copyBufferSubData()
Copies part of the data of a buffer to another buffer.
WebGL2RenderingContext.getBufferSubData()
Reads data from a buffer and writes them to an ArrayBuffer or SharedArrayBuffer.

Framebuffers

WebGL2RenderingContext.blitFramebuffer()
Transfers a block of pixels from the read framebuffer to the draw framebuffer.
WebGL2RenderingContext.framebufferTextureLayer()
Attaches a single layer of a texture to a framebuffer.
WebGL2RenderingContext.invalidateFramebuffer()
Invalidates the contents of attachments in a framebuffer.
WebGL2RenderingContext.invalidateSubFramebuffer()
Invalidates portions of the contents of attachments in a framebuffer
WebGL2RenderingContext.readBuffer()
Selects a color buffer as the source for pixels.

Renderbuffers

WebGL2RenderingContext.getInternalformatParameter()
Returns information about implementation-dependent support for internal formats.
WebGL2RenderingContext.renderbufferStorageMultisample()
Creates and initializes a renderbuffer object's data store and allows specifying the number of samples to be used.

Textures

WebGL2RenderingContext.texStorage2D()
Specifies all levels of two-dimensional texture storage.
WebGL2RenderingContext.texStorage3D()
Specifies all levels of a three-dimensional texture or two-dimensional array texture.
WebGL2RenderingContext.texImage3D()
Specifies a three-dimensional texture image.
WebGL2RenderingContext.texSubImage3D()
Specifies a sub-rectangle of the current 3D texture.
WebGL2RenderingContext.copyTexSubImage3D()
Copies pixels from the current WebGLFramebuffer into an existing 3D texture sub-image.
WebGL2RenderingContext.compressedTexImage3D()
Specifies a three-dimensional texture image in a compressed format.
WebGL2RenderingContext.compressedTexSubImage3D()
Specifies a three-dimensional sub-rectangle for a texture image in a compressed format.

Programs and shaders

WebGL2RenderingContext.getFragDataLocation()
Returns the binding of color numbers to user-defined varying out variables.

Uniforms and attributes

WebGL2RenderingContext.uniform[1234][uif][v]()
Methods specifying values of uniform variables.
WebGL2RenderingContext.uniformMatrix[234]x[234]fv()
Methods specifying matrix values for uniform variables.
WebGL2RenderingContext.vertexAttribI4[u]i[v]()
Methods specifying integer values for generic vertex attributes.
WebGL2RenderingContext.vertexAttribIPointer()
Specifies integer data formats and locations of vertex attributes in a vertex attributes array.

Drawing buffers

WebGL2RenderingContext.vertexAttribDivisor()
Modifies the rate at which generic vertex attributes advance when rendering multiple instances of primitives with gl.drawArraysInstanced() and gl.drawElementsInstanced().
WebGL2RenderingContext.drawArraysInstanced()
Renders primitives from array data. In addition, it can execute multiple instances of the range of elements.
WebGL2RenderingContext.drawElementsInstanced()
Renders primitives from array data. In addition, it can execute multiple instances of a set of elements.
WebGL2RenderingContext.drawRangeElements()
Renders primitives from array data in a given range.
WebGL2RenderingContext.drawBuffers()
Specifies a list of color buffers to be drawn into.
WebGL2RenderingContext.clearBuffer[fiuv]()
Clears buffers from the currently bound framebuffer.

Query objects

Methods for working with WebGLQuery objects.

WebGL2RenderingContext.createQuery()
Creates a new WebGLQuery object.
WebGL2RenderingContext.deleteQuery()
Deletes a given WebGLQuery object.
WebGL2RenderingContext.isQuery()
Returns true if a given object is a valid WebGLQuery object.
WebGL2RenderingContext.beginQuery()
Begins an asynchronous query.
WebGL2RenderingContext.endQuery()
Marks the end of an asynchronous query.
WebGL2RenderingContext.getQuery()
Returns a WebGLQuery object for a given target.
WebGL2RenderingContext.getQueryParameter()
Returns information about a query.

Sampler objects

WebGL2RenderingContext.createSampler()
Creates a new WebGLSampler object.
WebGL2RenderingContext.deleteSampler()
Deletes a given WebGLSampler object.
WebGL2RenderingContext.bindSampler()
Binds a given WebGLSampler to a texture unit.
WebGL2RenderingContext.isSampler()
Returns true if a given object is a valid WebGLSampler object.
WebGL2RenderingContext.samplerParameter[if]()
Sets sampler parameters.
WebGL2RenderingContext.getSamplerParameter()
Returns sampler parameter information.

Sync objects

WebGL2RenderingContext.fenceSync()
Creates a new WebGLSync object and inserts it into the GL command stream.
WebGL2RenderingContext.isSync()
Returns true if the passed object is a valid WebGLSync object.
WebGL2RenderingContext.deleteSync()
Deletes a given WebGLSync object.
WebGL2RenderingContext.clientWaitSync()

Blocks and waits for a WebGLSync object to become signaled or a given timeout to be passed.

WebGL2RenderingContext.waitSync()
Returns immediately, but waits on the GL server until the given WebGLSync object is signaled.
WebGL2RenderingContext.getSyncParameter()
Returns parameter information of a WebGLSync object.

Transform feedback

WebGL2RenderingContext.createTransformFeedback()
Creates and initializes WebGLTransformFeedback objects.
WebGL2RenderingContext.deleteTransformFeedback()
Deletes a given WebGLTransformFeedback object.
WebGL2RenderingContext.isTransformFeedback()
Returns true if the passed object is a valid WebGLTransformFeedback object.
WebGL2RenderingContext.bindTransformFeedback()
Binds a passed WebGLTransformFeedback object to the current GL state.
WebGL2RenderingContext.beginTransformFeedback()
Starts a transform feedback operation.
WebGL2RenderingContext.endTransformFeedback()
Ends a transform feedback operation.
WebGL2RenderingContext.transformFeedbackVaryings()
Specifies values to record in WebGLTransformFeedback buffers.
WebGL2RenderingContext.getTransformFeedbackVarying()
Returns information about varying variables from WebGLTransformFeedback buffers.
WebGL2RenderingContext.pauseTransformFeedback()
Pauses a transform feedback operation.
WebGL2RenderingContext.resumeTransformFeedback()
Resumes a transform feedback operation.

Uniform buffer objects

WebGL2RenderingContext.bindBufferBase()
Binds a given WebGLBuffer to a given binding point (target) at a given index.
WebGL2RenderingContext.bindBufferRange()
Binds a range of a given WebGLBuffer to a given binding point (target) at a given index.
WebGL2RenderingContext.getUniformIndices()

Retrieves the indices of a number of uniforms within a WebGLProgram.

WebGL2RenderingContext.getActiveUniforms()
Retrieves information about active uniforms within a WebGLProgram.
WebGL2RenderingContext.getUniformBlockIndex()
Retrieves the index of a uniform block within a WebGLProgram.
WebGL2RenderingContext.getActiveUniformBlockParameter()
Retrieves information about an active uniform block within a WebGLProgram.
WebGL2RenderingContext.getActiveUniformBlockName()
Retrieves the name of the active uniform block at a given index within a WebGLProgram.
WebGL2RenderingContext.uniformBlockBinding()
Assigns binding points for active uniform blocks.

Vertex array objects

Methods for working with WebGLVertexArrayObject (VAO) objects.

WebGL2RenderingContext.createVertexArray()
Creates a new WebGLVertexArrayObject.
WebGL2RenderingContext.deleteVertexArray()
Deletes a given WebGLVertexArrayObject.
WebGL2RenderingContext.isVertexArray()
Returns true if a given object is a valid WebGLVertexArrayObject.
WebGL2RenderingContext.bindVertexArray()
Binds a given WebGLVertexArrayObject to the buffer.

Specifications

Specification Status Comment
WebGL 2.0
The definition of 'WebGL2RenderingContext' in that specification.
Editor's Draft Initial definition.

Browser compatibility

Feature Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 56 No 51 No 43 No
beginQuery 56 No 51 No 43 No
beginTransformFeedback 56 No 51 No 43 No
bindBufferBase 56 No 51 No 43 No
bindBufferRange 56 No 51 No 43 No
bindSampler 56 No 51 No 43 No
bindTransformFeedback 56 No 51 No 43 No
bindVertexArray 56 No 51 No 43 No
blitFramebuffer 56 No 51 No 43 No
bufferSubData Yes No 51 No Yes No
clearBufferfi 56 No 51 No 43 No
clearBufferfv 56 No 51 No 43 No
clearBufferiv 56 No 51 No 43 No
clearBufferuiv 56 No 51 No 43 No
clientWaitSync 56 No 51 No 43 No
compressedTexImage3D 56 No 51 No 43 No
compressedTexSubImage3D 56 No 51 No 43 No
copyBufferSubData 56 No 51 No 43 No
copyTexSubImage3D 56 No 51 No 43 No
createQuery 56 No 51 No 43 No
createSampler 56 No 51 No 43 No
createTransformFeedback 56 No 51 No 43 No
createVertexArray 56 No 51 No 43 No
deleteQuery 56 No 51 No 43 No
deleteSampler 56 No 51 No 43 No
deleteSync 56 No 51 No 43 No
deleteTransformFeedback 56 No 51 No 43 No
deleteVertexArray 56 No 51 No 43 No
drawArraysInstanced 56 No 51 No 43 No
drawBuffers 56 No 51 No 43 No
drawElementsInstanced 56 No 51 No 43 No
drawRangeElements 56 No 51 No 43 No
endQuery 56 No 51 No 43 No
endTransformFeedback 56 No 51 No 43 No
fenceSync 56 No 51 No 43 No
framebufferTextureLayer 56 No 51 No 43 No
getActiveUniformBlockName 56 No 51 No 43 No
getActiveUniformBlockParameter 56 No 51 No 43 No
getActiveUniforms 56 No 51 No 43 No
getBufferSubData 56 No 51 No Yes No
getFragDataLocation 56 No 51 No 43 No
getInternalformatParameter 56 No 51 No 43 No
getQuery 56 No 51 No 43 No
getQueryParameter 56 No 51 No 43 No
getSamplerParameter 56 No 51 No 43 No
getSyncParameter 56 No 51 No 43 No
getTransformFeedbackVarying 56 No 51 No 43 No
getUniformBlockIndex 56 No 51 No 43 No
getUniformIndices 56 No 51 No 43 No
getIndexedParameter 56 No 51 No 43 No
invalidateFramebuffer 56 No 51 No 43 No
invalidateSubFramebuffer 56 No 51 No 43 No
isQuery 56 No 51 No 43 No
isSampler 56 No 51 No 43 No
isSync 56 No 51 No 43 No
isTransformFeedback 56 No 51 No 43 No
isVertexArray 56 No 51 No 43 No
pauseTransformFeedback 56 No 51 No 43 No
readBuffer 56 No 51 No 43 No
renderbufferStorageMultisample 56 No 51 No 43 No
resumeTransformFeedback 56 No 51 No 43 No
samplerParameteri 56 No 51 No 43 No
samplerParameterf 56 No 51 No 43 No
texImage3D 56 No 51 No 43 No
texStorage2D 56 No 51 No 43 No
texStorage3D 56 No 51 No 43 No
texSubImage3D 56 No 51 No 43 No
transformFeedbackVaryings 56 No 51 No 43 No
uniform1uiv 56 No 51 No 43 No
uniform1ui 56 No 51 No 43 No
uniform1i 56 No 51 No 43 No
uniform1f 56 No 51 No 43 No
uniform2uiv 56 No 51 No 43 No
uniform2ui 56 No 51 No 43 No
uniform2i 56 No 51 No 43 No
uniform2f 56 No 51 No 43 No
uniform3uiv 56 No 51 No 43 No
uniform3ui 56 No 51 No 43 No
uniform3i 56 No 51 No 43 No
uniform3f 56 No 51 No 43 No
uniform4uiv 56 No 51 No 43 No
uniform4ui 56 No 51 No 43 No
uniform4i 56 No 51 No 43 No
uniform4f 56 No 51 No 43 No
uniformBlockBinding 56 No 51 No 43 No
uniformMatrix2fv 56 No 51 No 43 No
uniformMatrix2x3fv 56 No 51 No 43 No
uniformMatrix2x4fv 56 No 51 No 43 No
uniformMatrix3fv 56 No 51 No 43 No
uniformMatrix3x2fv 56 No 51 No 43 No
uniformMatrix3x4fv 56 No 51 No 43 No
uniformMatrix4fv 56 No 51 No 43 No
uniformMatrix4x2fv 56 No 51 No 43 No
uniformMatrix4x3fv 56 No 51 No 43 No
vertexAttribDivisor 56 No 51 No 43 No
vertexAttribI4i 56 No 51 No 43 No
vertexAttribI4iv 56 No 51 No 43 No
vertexAttribI4ui 56 No 51 No 43 No
vertexAttribI4uiv 56 No 51 No 43 No
vertexAttribIPointer 56 No 51 No 43 No
waitSync 56 No 51 No 43 No
Feature Android webview Chrome for Android Edge mobile Firefox for Android IE mobile Opera Android iOS Safari
Basic support 58 58 No 51 No 43 No
beginQuery 58 58 No 51 No 43 No
beginTransformFeedback 58 58 No 51 No 43 No
bindBufferBase 58 58 No 51 No 43 No
bindBufferRange 58 58 No 51 No 43 No
bindSampler 58 58 No 51 No 43 No
bindTransformFeedback 58 58 No 51 No 43 No
bindVertexArray 58 58 No 51 No 43 No
blitFramebuffer 58 58 No 51 No 43 No
bufferSubData Yes Yes No 51 No Yes No
clearBufferfi 58 58 No 51 No 43 No
clearBufferfv 58 58 No 51 No 43 No
clearBufferiv 58 58 No 51 No 43 No
clearBufferuiv 58 58 No 51 No 43 No
clientWaitSync 58 58 No 51 No 43 No
compressedTexImage3D 58 58 No 51 No 43 No
compressedTexSubImage3D 58 58 No 51 No 43 No
copyBufferSubData 58 58 No 51 No 43 No
copyTexSubImage3D 58 58 No 51 No 43 No
createQuery 58 58 No 51 No 43 No
createSampler 58 58 No 51 No 43 No
createTransformFeedback 58 58 No 51 No 43 No
createVertexArray 58 58 No 51 No 43 No
deleteQuery 58 58 No 51 No 43 No
deleteSampler 58 58 No 51 No 43 No
deleteSync 58 58 No 51 No 43 No
deleteTransformFeedback 58 58 No 51 No 43 No
deleteVertexArray 58 58 No 51 No 43 No
drawArraysInstanced 58 58 No 51 No 43 No
drawBuffers 58 58 No 51 No 43 No
drawElementsInstanced 58 58 No 51 No 43 No
drawRangeElements 58 58 No 51 No 43 No
endQuery 58 58 No 51 No 43 No
endTransformFeedback 58 58 No 51 No 43 No
fenceSync 58 58 No 51 No 43 No
framebufferTextureLayer 58 58 No 51 No 43 No
getActiveUniformBlockName 58 58 No 51 No 43 No
getActiveUniformBlockParameter 58 58 No 51 No 43 No
getActiveUniforms 58 58 No 51 No 43 No
getBufferSubData 58 58 No 51 No Yes No
getFragDataLocation 58 58 No 51 No 43 No
getInternalformatParameter 58 58 No 51 No 43 No
getQuery 58 58 No 51 No 43 No
getQueryParameter 58 58 No 51 No 43 No
getSamplerParameter 58 58 No 51 No 43 No
getSyncParameter 58 58 No 51 No 43 No
getTransformFeedbackVarying 58 58 No 51 No 43 No
getUniformBlockIndex 58 58 No 51 No 43 No
getUniformIndices 58 58 No 51 No 43 No
getIndexedParameter 58 58 No 51 No 43 No
invalidateFramebuffer 58 58 No 51 No 43 No
invalidateSubFramebuffer 58 58 No 51 No 43 No
isQuery 58 58 No 51 No 43 No
isSampler 58 58 No 51 No 43 No
isSync 58 58 No 51 No 43 No
isTransformFeedback 58 58 No 51 No 43 No
isVertexArray 58 58 No 51 No 43 No
pauseTransformFeedback 58 58 No 51 No 43 No
readBuffer 58 58 No 51 No 43 No
renderbufferStorageMultisample 58 58 No 51 No 43 No
resumeTransformFeedback 58 58 No 51 No 43 No
samplerParameteri 58 58 No 51 No 43 No
samplerParameterf 58 58 No 51 No 43 No
texImage3D 58 58 No 51 No 43 No
texStorage2D 58 58 No 51 No 43 No
texStorage3D 58 58 No 51 No 43 No
texSubImage3D 58 58 No 51 No 43 No
transformFeedbackVaryings 58 58 No 51 No 43 No
uniform1uiv 58 58 No 51 No 43 No
uniform1ui 58 58 No 51 No 43 No
uniform1i 58 58 No 51 No 43 No
uniform1f 58 58 No 51 No 43 No
uniform2uiv 58 58 No 51 No 43 No
uniform2ui 58 58 No 51 No 43 No
uniform2i 58 58 No 51 No 43 No
uniform2f 58 58 No 51 No 43 No
uniform3uiv 58 58 No 51 No 43 No
uniform3ui 58 58 No 51 No 43 No
uniform3i 58 58 No 51 No 43 No
uniform3f 58 58 No 51 No 43 No
uniform4uiv 58 58 No 51 No 43 No
uniform4ui 58 58 No 51 No 43 No
uniform4i 58 58 No 51 No 43 No
uniform4f 58 58 No 51 No 43 No
uniformBlockBinding 58 58 No 51 No 43 No
uniformMatrix2fv 58 58 No 51 No 43 No
uniformMatrix2x3fv 58 58 No 51 No 43 No
uniformMatrix2x4fv 58 58 No 51 No 43 No
uniformMatrix3fv 58 58 No 51 No 43 No
uniformMatrix3x2fv 58 58 No 51 No 43 No
uniformMatrix3x4fv 58 58 No 51 No 43 No
uniformMatrix4fv 58 58 No 51 No 43 No
uniformMatrix4x2fv 58 58 No 51 No 43 No
uniformMatrix4x3fv 58 58 No 51 No 43 No
vertexAttribDivisor 58 58 No 51 No 43 No
vertexAttribI4i 58 58 No 51 No 43 No
vertexAttribI4iv 58 58 No 51 No 43 No
vertexAttribI4ui 58 58 No 51 No 43 No
vertexAttribI4uiv 58 58 No 51 No 43 No
vertexAttribIPointer 58 58 No 51 No 43 No
waitSync 58 58 No 51 No 43 No

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext