web api interface
WebGL2RenderingContext
Available in workers
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:
const canvas = document.getElementById("myCanvas");
const gl = canvas.getContext("webgl2");
[!NOTE] WebGL 2 is an extension to WebGL 1. The
WebGL2RenderingContextinterface implements all members of theWebGLRenderingContextinterface. 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
getIndexedParameter()- : Returns the indexed value for the given
target.
- : Returns the indexed value for the given
Buffers
bufferData()- : Initializes and creates the buffer object’s data store.
bufferSubData()- : Updates a subset of a buffer object’s data store.
copyBufferSubData()- : Copies part of the data of a buffer to another buffer.
getBufferSubData()- : Reads data from a buffer and writes them to an
ArrayBufferorSharedArrayBuffer.
- : Reads data from a buffer and writes them to an
Framebuffers
blitFramebuffer()- : Transfers a block of pixels from the read framebuffer to the draw framebuffer.
framebufferTextureLayer()- : Attaches a single layer of a texture to a framebuffer.
invalidateFramebuffer()- : Invalidates the contents of attachments in a framebuffer.
invalidateSubFramebuffer()- : Invalidates portions of the contents of attachments in a framebuffer
readBuffer()- : Selects a color buffer as the source for pixels.
Renderbuffers
getInternalformatParameter()- : Returns information about implementation-dependent support for internal formats.
renderbufferStorageMultisample()- : Creates and initializes a renderbuffer object’s data store and allows specifying the number of samples to be used.
Textures
texStorage2D()- : Specifies all levels of two-dimensional texture storage.
texStorage3D()- : Specifies all levels of a three-dimensional texture or two-dimensional array texture.
texImage3D()- : Specifies a three-dimensional texture image.
texSubImage3D()- : Specifies a sub-rectangle of the current 3D texture.
copyTexSubImage3D()- : Copies pixels from the current
WebGLFramebufferinto an existing 3D texture sub-image.
- : Copies pixels from the current
compressedTexImage3D- : Specifies a three-dimensional texture image in a compressed format.
compressedTexSubImage3D()- : Specifies a three-dimensional sub-rectangle for a texture image in a compressed format.
Programs and shaders
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.
vertexAttribIPointer()- : Specifies integer data formats and locations of vertex attributes in a vertex attributes array.
Color spaces
drawingBufferColorSpace- : Specifies the color space of the WebGL drawing buffer.
unpackColorSpace- : Specifies the color space to convert to when importing textures.
Drawing buffers
vertexAttribDivisor()- : Modifies the rate at which generic vertex attributes advance when rendering multiple instances of primitives with
gl.drawArraysInstanced()andgl.drawElementsInstanced().
- : Modifies the rate at which generic vertex attributes advance when rendering multiple instances of primitives with
drawArraysInstanced()- : Renders primitives from array data. In addition, it can execute multiple instances of the range of elements.
drawElementsInstanced()- : Renders primitives from array data. In addition, it can execute multiple instances of a set of elements.
drawRangeElements()- : Renders primitives from array data in a given range.
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.
createQuery()- : Creates a new
WebGLQueryobject.
- : Creates a new
deleteQuery()- : Deletes a given
WebGLQueryobject.
- : Deletes a given
isQuery()- : Returns
trueif a given object is a validWebGLQueryobject.
- : Returns
beginQuery()- : Begins an asynchronous query.
endQuery()- : Marks the end of an asynchronous query.
getQuery()- : Returns a
WebGLQueryobject for a given target.
- : Returns a
getQueryParameter()- : Returns information about a query.
Sampler objects
createSampler()- : Creates a new
WebGLSamplerobject.
- : Creates a new
deleteSampler()- : Deletes a given
WebGLSamplerobject.
- : Deletes a given
bindSampler()- : Binds a given
WebGLSamplerto a texture unit.
- : Binds a given
isSampler()- : Returns
trueif a given object is a validWebGLSamplerobject.
- : Returns
WebGL2RenderingContext.samplerParameter[if]()- : Sets sampler parameters.
getSamplerParameter()- : Returns sampler parameter information.
Sync objects
fenceSync()- : Creates a new
WebGLSyncobject and inserts it into the GL command stream.
- : Creates a new
isSync()- : Returns
trueif the passed object is a validWebGLSyncobject.
- : Returns
deleteSync()- : Deletes a given
WebGLSyncobject.
- : Deletes a given
clientWaitSync()- : Blocks and waits for a
WebGLSyncobject to become signaled or a given timeout to be passed.
- : Blocks and waits for a
waitSync()- : Returns immediately, but waits on the GL server until the given
WebGLSyncobject is signaled.
- : Returns immediately, but waits on the GL server until the given
getSyncParameter()- : Returns parameter information of a
WebGLSyncobject.
- : Returns parameter information of a
Transform feedback
createTransformFeedback()- : Creates and initializes
WebGLTransformFeedbackobjects.
- : Creates and initializes
deleteTransformFeedback()- : Deletes a given
WebGLTransformFeedbackobject.
- : Deletes a given
isTransformFeedback()- : Returns
trueif the passed object is a validWebGLTransformFeedbackobject.
- : Returns
bindTransformFeedback()- : Binds a passed
WebGLTransformFeedbackobject to the current GL state.
- : Binds a passed
beginTransformFeedback()- : Starts a transform feedback operation.
endTransformFeedback()- : Ends a transform feedback operation.
transformFeedbackVaryings()- : Specifies values to record in
WebGLTransformFeedbackbuffers.
- : Specifies values to record in
getTransformFeedbackVarying()- : Returns information about varying variables from
WebGLTransformFeedbackbuffers.
- : Returns information about varying variables from
pauseTransformFeedback()- : Pauses a transform feedback operation.
resumeTransformFeedback()- : Resumes a transform feedback operation.
Uniform buffer objects
bindBufferBase()- : Binds a given
WebGLBufferto a given binding point (target) at a givenindex.
- : Binds a given
bindBufferRange()- : Binds a range of a given
WebGLBufferto a given binding point (target) at a givenindex.
- : Binds a range of a given
getUniformIndices()- : Retrieves the indices of a number of uniforms within a
WebGLProgram.
- : Retrieves the indices of a number of uniforms within a
getActiveUniforms()- : Retrieves information about active uniforms within a
WebGLProgram.
- : Retrieves information about active uniforms within a
getUniformBlockIndex()- : Retrieves the index of a uniform block within a
WebGLProgram.
- : Retrieves the index of a uniform block within a
getActiveUniformBlockParameter()- : Retrieves information about an active uniform block within a
WebGLProgram.
- : Retrieves information about an active uniform block within a
getActiveUniformBlockName()- : Retrieves the name of the active uniform block at a given index within a
WebGLProgram.
- : Retrieves the name of the active uniform block at a given index within a
uniformBlockBinding()- : Assigns binding points for active uniform blocks.
Vertex array objects
Methods for working with WebGLVertexArrayObject (VAO) objects.
createVertexArray()- : Creates a new
WebGLVertexArrayObject.
- : Creates a new
deleteVertexArray()- : Deletes a given
WebGLVertexArrayObject.
- : Deletes a given
isVertexArray()- : Returns
trueif a given object is a validWebGLVertexArrayObject.
- : Returns
bindVertexArray()- : Binds a given
WebGLVertexArrayObjectto the buffer.
- : Binds a given