PUBLIC
Contribute via GitHub Feedback

JavaScript WebGLRenderingContext : Object

The WebGLRenderingContext is an object that is used to issue WebGL rendering commands to a canvas. The WebGLRenderingContext is obtained by passing 'webgl' to the HTMLCanvasElement.getContext() method. See WebGLContextAttributes for configuration options you can specify when calling getContext().

For detailed information on the shader language used by WebGL, see the GLSL Specification.

While developing with WebGL, you can use the debug context to easily find errors in your code. The samples below use the debug context to help catch errors but you should remove it in production code. See http://www.khronos.org/webgl/wiki/Debugging for more details.

Instance Properties

canvas : HTMLCanvasElement  

The canvas that owns this WebGL context.

Example:

Run

Results:

 

drawingBufferHeight : Number  

Returns the height of the owner canvas in pixels.

Example:

Run

Results:

 

drawingBufferWidth : Number  

Returns the width of the owner canvas in pixels.

Example:

Run

Results:

 

Instance Methods

activeTexture(unit : Number) : undefined

Set the texture unit subsequent texture operations apply to.

unit
must be one of TEXTURE0, TEXTURE1, to getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS) - 1.
The default value is TEXTURE0. A texture must be bound to the active texture unit using bindTexture().

attachShader(program : WebGLProgram, shader : WebGLShader) : undefined

Attaches shader to program. A program must have both a VERTEX_SHADER and FRAGMENT_SHADER before it can be used. shader can be attached before its souce has been set. See also detachShader().

Example:

Run

Results:

 

bindAttribLocation(program : WebGLProgram, location : Number, attributeName : String) : undefined

Associates a number (location) with an attribute (a shader input such as vertex position) in program. Other webgl functions (such as enableVertexAttribArray() or vertexAttribPointer()) deal with an attribute location number instead of the name used in the program and bindAttribLocation is used to choose the number used for that attribute. Locations are automatically assigned if you do not call bindAttribLocation so this method is only necessary if you wish to assign a specific location for an attribute. Use getAttribLocation() to retrieve the automatically assigned location. bindAttribLocation() must be called before calling linkProgram(program) and location must be an integer in the range 0 to getParameter(gl.MAX_VERTEX_ATTRIBS) - 1.

Example:

Run

Results:

 

bindBuffer(target : Number, buffer : WebGLBuffer) : undefined

Sets the current buffer for target to buffer. target must be either ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER. Use bufferData() to fill the bound buffer with data.

bindFramebuffer(target : Number, framebuffer : WebGLFramebuffer) : undefined

Sets the current framebuffer to framebuffer. target must be FRAMEBUFFER or null. If null, the rendering will go to the canvas. See createFramebuffer() for an example of using bindFramebuffer().

bindRenderbuffer(target : Number, renderbuffer : WebGLRenderbuffer) : undefined

Sets the current renderbuffer to renderbuffer. target must be RENDERBUFFER.

bindTexture(target : Number, texture : WebGLTexture) : undefined

Sets the specified target and texture (created with createTexture) for the bound texture in the active texture unit (set through activeTexture() and bindTexture()). target must be one of TEXTURE_2D or TEXTURE_CUBE_MAP

blendColor(red : Number, green : Number, blue : Number, alpha : Number) : undefined

Specifies the blend color used with blendFunc(). Each component must be in the range 0.0 to 1.0.

blendEquation(mode : Number) : undefined
blendEquationSeparate(modeRGB : Number, modeAlpha : Number) : undefined

Sets how the newly rendered pixel color and alpha (src) is combined with the existing framebuffer color and alpha (dst) before storing in the framebuffer.

modeRGB and modeAlpha
must be one of FUNC_ADD, FUNC_SUBTRACT, or FUNC_REVERSE_SUBTRACT.
If the mode is FUNC_ADD, the destination color will be src + dst. If the mode is FUNC_SUBTRACT, the destination color will be src - dst. If the mode is FUNC_REVERSE_SUBTRACT, the destination color will be dst - src. Both modeRGB and modeAlpha default to FUNC_ADD. Use getParameter(gl.BLEND_EQUATION_RGB) and getParameter(gl.BLEND_EQUATION_ALPHA) to get the current values. See blendFuncSeparate() for how src and dst are computed. Blending must be enabled with enable(BLEND).

blendFunc(srcFactor : Number, dstFactor : Number) : undefined
blendFuncSeparate(srcRGB : Number, dstRGB : Number, srcAlpha : Number, dstAlpha : Number) : undefined

Adjusts the newly rendered pixel color and alpha (src) and existing framebuffer color and alpha in the framebuffer (dst) before being combined using blendEquationSeparate().

srcRGB, dstRGB, srcAlpha, and dstAlpha
must be one of ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR, SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR, CONSTANT_ALPHA, ONE_MINUS_CONSTANT_ALPHA, or SRC_ALPHA_SATURATE
srcRGB and srcAlpha default to ONE. dstRGB and dstAlpha default to NONE.

For traditional alpha blending, use:
gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ZERO).

For premultiplied alpha blending, use:
gl.blendFuncSeparate(gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ZERO).

Use getParameter(gl.BLEND_SRC_RGB), getParameter(gl.BLEND_DST_RGB), getParameter(gl.BLEND_SRC_ALPHA), and getParameter(gl.BLEND_DST_ALPHA) to get the current values.

bufferData 3 variants
bufferData(target : Number, data : ArrayBufferView, usage : Number) : undefined
bufferData(target : Number, data : ArrayBuffer, usage : Number) : undefined
bufferData(target : Number, size : Number, usage : Number) : undefined

Creates the storage for the currently bound buffer.

target
must be one of ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER.
size
the size in bytes of the buffer to allocate.
usage
must be one of STREAM_DRAW, STATIC_DRAW, or DYNAMIC_DRAW.

bufferSubData 2 variants
bufferSubData(target : Number, offset : Number, data : ArrayBufferView) : undefined
bufferSubData(target : Number, offset : Number, data : ArrayBuffer) : undefined
checkFramebufferStatus(target : Number) : Number

Returns one of the following to indicate the current status of the framebuffer: FRAMEBUFFER_COMPLETE, FRAMEBUFFER_INCOMPLETE_ATTACHMENT, FRAMEBUFFER_INCOMPLETE_DIMENSIONS, FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT, or FRAMEBUFFER_UNSUPPORTED. target must be set to gl.FRAMEBUFFER.

clear(mask : Number) : undefined

Clears the buffers specified by mask where mask is the bitwise OR (|) of one or more of the following values: COLOR_BUFFER_BIT, STENCIL_BUFFER_BIT, and DEPTH_BUFFER_BIT.

Example:

Run

Results:

 

clearColor(red : Number, green : Number, blue : Number, alpha : Number) : undefined

Specifies the color to fill the color buffer when clear() is called with the COLOR_BUFFER_BIT. The parameters are clamped to the range 0 to 1.

Example:

Run

Results:

 

clearDepth(depth : Number) : undefined

Specifies the value to fill the depth buffer when clear() is called with the DEPTH_BUFFER_BIT. depth is clamped to the range 0 (near) to 1 (far). Defaults to 1 if not specified.

Example:

Run

Results:

 

clearStencil(s : Number) : undefined

Specifies the value (integer) to fill the depth buffer when clear() is called with the STENCIL_BUFFER_BIT.

Example:

Run

Results:

 

colorMask(red : Boolean, green : Boolean, blue : Boolean, alpha : Boolean) : undefined

Turns on or off writing to the specified channels of the frame buffer. Defaults to true for all channels. Use getParameter(gl.COLOR_WRITEMASK) to get the current value.

compileShader(shader : WebGLShader) : undefined

Compiles the specified shader. Must be called after setting the source with shaderSource(). If the shader had errors during compilation, gl.getShaderParameter(shader, gl.COMPILE_STATUS) will return false and you can use getShaderInfoLog() to get details about the error.

copyTexImage2D(target : Number, level : Number, internalformat : Number, x : Number, y : Number, width : Number, height : Number, border : Number) : undefined

Copies pixels from the framebuffer to the bound texture in the active texture unit (set through activeTexture() and bindTexture()).

target
must be one of TEXTURE_2D, TEXTURE_CUBE_MAP_POSITIVE_X, TEXTURE_CUBE_MAP_NEGATIVE_X, TEXTURE_CUBE_MAP_POSITIVE_Y, TEXTURE_CUBE_MAP_NEGATIVE_Y, TEXTURE_CUBE_MAP_POSITIVE_Z, or TEXTURE_CUBE_MAP_NEGATIVE_Z.
level
specifies the mipmap level to copy into.
internalformat
ALPHA, LUMINANCE, LUMINANCE_ALPHA, RGB, or RGBA.
x, y, width, height
the rectangle in framebuffer to copy.
border
must be 0.

copyTexSubImage2D(target : Number, level : Number, textureX : Number, textureY : Number, framebufferX : Number, framebufferY : Number, width : Number, height : Number) : undefined

Copies pixels from the framebuffer to a subregion of the bound texture in the active texture unit (set through activeTexture() and bindTexture()).

target
must be one of TEXTURE_2D, TEXTURE_CUBE_MAP_POSITIVE_X, TEXTURE_CUBE_MAP_NEGATIVE_X, TEXTURE_CUBE_MAP_POSITIVE_Y, TEXTURE_CUBE_MAP_NEGATIVE_Y, TEXTURE_CUBE_MAP_POSITIVE_Z, or TEXTURE_CUBE_MAP_NEGATIVE_Z.
level
specifies the mipmap level to copy into.
textureX, textureY
the position in the texture to store the copied pixels.
framebufferX, framebufferY
the position in the framebuffer to read the pixels to copy.
width, height
the size of the region to copy.

createBuffer() : WebGLBuffer

Creates a buffer. A buffer is memory used to store data passed to the shader program through attributes. See also bindBuffer(), bufferData(), bufferSubData(), deleteBuffer(), isBuffer(), vertexAttribPointer() and enableVertexAttribArray().

Example:

Run

Results:

 

createFramebuffer() : WebGLFramebuffer

Creates a framebuffer that can be used for offscreen rendering. The actual content of the surface is stored in a either a WebGLRenderbuffer or WebGLTexture. See also bindFramebuffer(), checkFramebufferStatus(), deleteFramebuffer(), framebufferRenderbuffer(), framebufferTexture2D(), getFramebufferAttachmentParameter(), and isFramebuffer().

Example:

Run

Results:

 

createProgram() : WebGLProgram

Creates a shader program. A shader program consists of a vertex shader and fragment shader. Use attachShader() to associate shaders with the program and linkProgram() to finalize the program. After linking, use useProgram() to select the program to use.

createRenderbuffer() : WebGLRenderbuffer

Creates a renderbuffer. A renderbuffer is an offscreen section of memory used to store the result of rendering, such as the color buffer, depth buffer, or stencil buffer. See also framebufferRenderbuffer(), renderbufferStorage().

Example:

Run

Results:

 

createShader(type : Number) : WebGLShader

Creates a vertex or fragment shader. type must be either VERTEX_SHADER or FRAGMENT_SHADER. Shaders must be compiled using compileShader() and then attached to a WebGLProgram using attachShader() before they can be used.

createTexture() : WebGLTexture

Creates a texture. Use activeTexture() to select a texture unit and then bindTexture() to bind a texture to that unit. See also copyTexImage2D(), copyTexSubImage2D(), deleteTexture(), framebufferTexture2D(), getTexParameter(), isTexture(), texImage2D(), texParameterf(), texParameteri(), and texSubImage2D().

Example:

Run

Results:

 

cullFace(mode : Number) : undefined

Sets which side of the triangle is culled (not drawn). mode must be one of BACK, FRONT, or FRONT_AND_BACK. Defaults to BACK. To turn on culling, you must call enable(CULL_FACE). To select which face is the front or back, use frontFace().

deleteBuffer(buffer : WebGLBuffer) : undefined

Deletes the specified buffer.

deleteFramebuffer(framebuffer : WebGLFramebuffer) : undefined

Deletes the specified framebuffer.

deleteProgram(program : WebGLProgram) : undefined

Deletes the specified program.

deleteRenderbuffer(renderbuffer : WebGLRenderbuffer) : undefined

Deletes the specified renderprogram.

deleteShader(shader : WebGLShader) : undefined

Deletes the specified shader.

deleteTexture(texture : WebGLTexture) : undefined

Deletes the specified texture.

depthFunc(func : Number) : undefined

Specifies what function used to compare the rendered depth with the existing depth in the framebuffer to determine if the pixel will be written to the framebuffer. func must be one of NEVER, LESS, EQUAL, LEQUAL, GREATER, NOTEQUAL, GEQUAL, or ALWAYS. Defaults to LESS. Depth test will only be used if enabled with enable(DEPTH_TEST).

depthMask(write : Boolean) : undefined

Turns on or off writing to the depth buffer. Defaults to true. Use getParameter(gl.DEPTH_WRITEMASK) to get the current value. Depth test will only be used if enabled with enable(DEPTH_TEST).

depthRange(zNear : Number, zFar : Number) : undefined

Sets how z values returned from the vertex shader are mapped to values to store in the depth buffer. This mapping is necessary because the vertex shader output z values will be clipped to the range -1 to 1 but the depth buffer stores depth values in the range 0 to 1.

zNear
specifies what the vertex shader's -1 maps to in the depth buffer.
zFar
specifies what the vertex shader's 1 maps to in the depth buffer.
By default, zNear is 0 and zFar is 1.

detachShader(program : WebGLProgram, shader : WebGLShader) : undefined

Detaches shader from program. shader must have been attached to program using attachShader().

disable(capability : Number) : undefined

Turns off a capability. See enable() for a list of capabilities.

disableVertexAttribArray(index : Number) : undefined
drawArrays(mode : Number, vertexOffset : Number, vertexCount : Number) : undefined

Draws primitives using the vertex buffer data (stored in the ARRAY_BUFFER buffer).

mode
must be one of POINTS, LINE_STRIP, LINE_LOOP, LINES, TRIANGLE_STRIP, TRIANGLE_FAN, or TRIANGLES.
vertexOffset
specifies the index of the first vertex to draw.
vertexCount
specifies the number of vertices to draw.
You must call enableVertexAttribArray() for each attribute in the vertex shader that uses the vertex data. See also drawElements().

Example:

Run

Results:

 

drawElements(mode : Number, indicesCount : Number, indicesNumberType : Number, indicesOffset : Number) : undefined

Draws primitives using the vertex buffer data (stored in the ARRAY_BUFFER buffer) and the index buffer data (stored in the ELEMENT_ARRAY_BUFFER buffer).

mode
must be one of POINTS, LINE_STRIP, LINE_LOOP, LINES, TRIANGLE_STRIP, TRIANGLE_FAN, or TRIANGLES.
indicesCount
specifies the number of number of indices to use.
indicesNumberType
must be one of UNSIGNED_BYTE or UNSIGNED_SHORT.
indicesOffset
specifies the index into the indices array of the first element to draw.
You must call enableVertexAttribArray() for each attribute in the vertex shader that uses the vertex data. See also drawArrays().

Example:

Run

Results:

 

enable(capability : Number) : undefined

Turns on a capability. capability must be one of the following:

BLEND
if enabled, will combine the color generated by the fragment shader with the existing color in the framebuffer using the method specified by blendFunc(). Most commonly used to enable alpha blending. Defaults to disabled.
CULL_FACE
if enabled, will cull (not draw) triangles based on which face is visible. See cullFace() and frontFace() to configure culling. Defaults to disabled.
DEPTH_TEST
if enabled, fragments will only be written to the framebuffer if they pass the depth function (set with gl.depthFunc()). See also depthMask(), and depthRange(). Most commonly used to draw closer objects on top of further away objects. Defaults to disabled.
DITHER
if enabled, the colors will be dithered when written to the color buffer. Defaults to enabled.
POLYGON_OFFSET_FILL
if enabled, the offset specified by polygonOffset will be added to the depth for the fragment when writing to the depth buffer. Most commonly used to draw decals on top of already drawn surfaces. Defaults to disabled.
SAMPLE_COVERAGE
Defaults to disabled.
SAMPLE_ALPHA_TO_COVERAGE
Defaults to disabled.
SCISSOR_TEST
if enabled, fragments outside the scissor rectangle (set with scissor() will not be drawn. Defaults to disabled.
STENCIL_TEST
if enabled, perform a stencil test on each fragment and update the stencil buffer. See also stencilFunc and stencilOp. Defaults to disabled.
Use disable() to turn off the capability.

enableVertexAttribArray(attributeLocation : Number) : undefined

Turns on passing data to the vertex shader from the vertex buffer for the specified attribute. Use getAttribLocation() to retrieve the location of an attribute by name.

finish() : undefined
flush() : undefined
framebufferRenderbuffer(target : Number, attachment : Number, renderbuffertarget : Number, renderbuffer : WebGLRenderbuffer) : undefined

Specifies the renderbuffer to use as destination of rendering for the current framebuffer (set with the most recent bindFramebuffer() call).

target
must be FRAMEBUFFER.
attachment
determines what is rendered into renderbuffer. Pass COLOR_ATTACHMENT0 for color data, DEPTH_ATTACHMENT for depth data, or STENCIL_ATTACHMENT for stencil data.
renderbuffertarget
must be RENDERBUFFER.
renderbuffer
the buffer to store the rendered output.

Example:

Run

Results:

 

framebufferTexture2D(target : Number, attachment : Number, textarget : Number, texture : WebGLTexture, level : Number) : undefined

Specifies the texture to use as destination of rendering for the current framebuffer (set with the most recent bindFramebuffer() call).

target
must be FRAMEBUFFER.
attachment
determines what is rendered into renderbuffer. Pass COLOR_ATTACHMENT0 for color data, DEPTH_ATTACHMENT for depth data, or STENCIL_ATTACHMENT for stencil data.
target
must be one of TEXTURE_2D, TEXTURE_CUBE_MAP_POSITIVE_X, TEXTURE_CUBE_MAP_NEGATIVE_X, TEXTURE_CUBE_MAP_POSITIVE_Y, TEXTURE_CUBE_MAP_NEGATIVE_Y, TEXTURE_CUBE_MAP_POSITIVE_Z, or TEXTURE_CUBE_MAP_NEGATIVE_Z.
texture
the texture to store the rendered output.
level
must be 0.

frontFace(mode : Number) : undefined

Determines which side of triangles is the front face. mode must be one of CW or CCW. To turn on culling, you must call enable(CULL_FACE). To select which face is culled, use cullFace().

generateMipmap(target : Number) : undefined

Generate the mipmap for the bound texture in the active texture unit (set through activeTexture() and bindTexture()). A mipmap is a set of textures that are 1/2, 1/4, 1/8, etc of the original image. The mipmap allows higher quality rendering when drawing the texture at smaller sizes. target must be one of TEXTURE_2D or TEXTURE_CUBE_MAP. Note, you can only generate mipmaps for textures where the width and height are both powers of 2 (such as 128, 256, 512, etc).

getActiveAttrib(program : WebGLProgram, index : Number) : WebGLActiveInfo

Returns information about an attribute in program. program must be linked before calling getActiveAttrib(). index must be between 0 and gl.getProgramParameter(program, ACTIVE_ATTRIBUTES) - 1.

Example:

Run

Results:

 

getActiveUniform(program : WebGLProgram, index : Number) : WebGLActiveInfo

Returns information about a uniform in program. program must be linked before calling getActiveUniform(). index must be between 0 and gl.getProgramParameter(program, ACTIVE_UNIFORMS) - 1.

Example:

Run

Results:

 

getAttachedShaders(program : WebGLProgram) : Array<WebGLShader>
getAttribLocation(program : WebGLProgram, name : String) : Number
getBufferParameter(target : Number, parameter : Number) : Object

target
must be one of ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER.
parameter
must be one of BUFFER_SIZE or BUFFER_USAGE.

getContextAttributes() : WebGLContextAttributes

Returns the attributes used to construct this context. To modify these attributes, pass in the desired attributes to the first call to HTMLCanvasElement.getContext('webgl', attributes).

Example:

Run

Results:

 

getError() : Number

Returns the first error hit since the last time getError() was called. The returned value will be one of NO_ERROR, INVALID_ENUM, INVALID_VALUE, INVALID_OPERATION, INVALID_FRAMEBUFFER_OPERATION, or OUT_OF_MEMORY.

getExtension(name : String) : Object

Enables the specified extension and returns an object that contains any constants or functions provided by the extension. Call getSupportedExtensions() to get an array of valid extension names. If name is not in the Array returned by getSupportedExtensions(), getExtension() will return null.

Example:

Run

Results:

 

getFramebufferAttachmentParameter(target : Number, attachment : Number, parameter : Number) : Object

target
must be FRAMEBUFFER.
attachment
the render target to query. Must be one of COLOR_ATTACHMENT0 for color data, DEPTH_ATTACHMENT for depth data, or STENCIL_ATTACHMENT for stencil data.
parameter
the parameter to query. Must be one of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL, or FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE.

getParameter(parameter : Number) : Object

parameter must be one of ACTIVE_TEXTURE, ALIASED_LINE_WIDTH_RANGE, ALIASED_POINT_SIZE_RANGE, ALPHA_BITS, ARRAY_BUFFER_BINDING, BLEND, BLEND_DST_ALPHA, BLEND_DST_RGB, BLEND_EQUATION_ALPHA, BLEND_EQUATION_RGB, BLEND_SRC_ALPHA, BLEND_SRC_RGB, BLUE_BITS, COLOR_CLEAR_VALUE, COLOR_WRITEMASK, COMPRESSED_TEXTURE_FORMATS, CULL_FACE, CULL_FACE_MODE, CURRENT_PROGRAM, DEPTH_BITS, DEPTH_CLEAR_VALUE, DEPTH_FUNC, DEPTH_RANGE, DEPTH_TEST, DEPTH_WRITEMASK, DITHER, ELEMENT_ARRAY_BUFFER_BINDING, FRAMEBUFFER_BINDING, FRONT_FACE, GENERATE_MIPMAP_HINT, GREEN_BITS, LINE_WIDTH, MAX_COMBINED_TEXTURE_IMAGE_UNITS, MAX_CUBE_MAP_TEXTURE_SIZE, MAX_FRAGMENT_UNIFORM_VECTORS, MAX_RENDERBUFFER_SIZE, MAX_TEXTURE_IMAGE_UNITS, MAX_TEXTURE_SIZE, MAX_VARYING_VECTORS, MAX_VERTEX_ATTRIBS, MAX_VERTEX_TEXTURE_IMAGE_UNITS, MAX_VERTEX_UNIFORM_VECTORS, MAX_VIEWPORT_DIMS, NUM_COMPRESSED_TEXTURE_FORMATS, PACK_ALIGNMENT, POLYGON_OFFSET_FACTOR, POLYGON_OFFSET_FILL, POLYGON_OFFSET_UNITS, RED_BITS, RENDERBUFFER_BINDING, RENDERER, SAMPLE_ALPHA_TO_COVERAGE, SAMPLE_BUFFERS, SAMPLE_COVERAGE, SAMPLE_COVERAGE_INVERT, SAMPLE_COVERAGE_VALUE, SAMPLES, SCISSOR_BOX, SCISSOR_TEST, SHADING_LANGUAGE_VERSION, STENCIL_BACK_FAIL, STENCIL_BACK_FUNC, STENCIL_BACK_PASS_DEPTH_FAIL, STENCIL_BACK_PASS_DEPTH_PASS, STENCIL_BACK_REF, STENCIL_BACK_VALUE_MASK, STENCIL_BACK_WRITEMASK, STENCIL_BITS, STENCIL_CLEAR_VALUE, STENCIL_FAIL, STENCIL_FUNC, STENCIL_PASS_DEPTH_FAIL, STENCIL_PASS_DEPTH_PASS, STENCIL_REF, STENCIL_TEST, STENCIL_VALUE_MASK, STENCIL_WRITEMASK, SUBPIXEL_BITS, TEXTURE_BINDING_2D, TEXTURE_BINDING_CUBE_MAP, UNPACK_ALIGNMENT, VIEWPORT, VENDOR, or VERSION.

Example:

Run

Results:

 

getProgramInfoLog(program : WebGLProgram) : String
getProgramParameter(program : WebGLProgram, parameter : Number) : Object
getShaderInfoLog(shader : WebGLShader) : String
getShaderParameter(shader : WebGLShader, parameter : Number) : Object

parameter must be one of SHADER_TYPE, DELETE_STATUS, or COMPILE_STATUS.

getShaderPrecisionFormat(shadertype : Number, precisiontype : Number) : WebGLShaderPrecisionFormat

Returns information about the numerical precision limits of shader data types. target must be one of FRAGMENT_SHADER or VERTEX_SHADER. precisiontype must be one of LOW_FLOAT, MEDIUM_FLOAT, HIGH_FLOAT, LOW_INT, MEDIUM_INT, or HIGH_INT.

Example:

Run

Results:

 

getShaderSource(shader : WebGLShader) : String
getSupportedExtensions() : Array<String>

Returns an Array of Strings that indicate which extensions this canvas supports. See getExtension().

Example:

Run

Results:

 

getTexParameter(target : Number, parameter : Number) : Object

Returns the value of the specified parameter for the the bound texture in the active texture unit (set through activeTexture() and bindTexture()). Use texParameterf() and texParameteri() to set texture parameters.

target
must be one of TEXTURE_2D or TEXTURE_CUBE_MAP.
parameter
must be one of TEXTURE_MAG_FILTER, TEXTURE_MIN_FILTER, TEXTURE_WRAP_S, or TEXTURE_WRAP_T.

getUniform(program : WebGLProgram, location : WebGLUniformLocation) : Object

Retrieves the value stored in location by a uniform*() call.

Example:

Run

Results:

 

getUniformLocation(program : WebGLProgram, name : String) : WebGLUniformLocation
getVertexAttribOffset(index : Number, parameter : Number) : Number

parameter must be VERTEX_ATTRIB_ARRAY_POINTER.

hint(target : Number, mode : Number) : undefined

target
must be GENERATE_MIPMAP_HINT.
mode
must be one of FASTEST, NICEST, or DONT_CARE.

isBuffer(buffer : WebGLBuffer) : Boolean

Returns true if buffer is a valid, bound buffer.

Example:

Run

Results:

 

isContextLost() : Boolean

isEnabled(capability : Number) : Boolean

Returns true if specified capability is enabled. See enable() for a list of capabilities.

isFramebuffer(framebuffer : WebGLFramebuffer) : Boolean

Returns true if framebuffer is a valid, bound framebuffer.

Example:

Run

Results:

 

isProgram(program : WebGLProgram) : Boolean

Returns true if program is a valid program.

Example:

Run

Results:

 

isRenderbuffer(renderbuffer : WebGLRenderbuffer) : Boolean

Returns true if renderbuffer is a valid, bound renderbuffer.

Example:

Run

Results:

 

isShader(shader : WebGLShader) : Boolean

Returns true if shader is a valid shader.

Example:

Run

Results:

 

isTexture(texture : WebGLTexture) : Boolean

Returns true if texture is a valid, bound texture.

Example:

Run

Results:

 

lineWidth(width : Number) : undefined
linkProgram(program : WebGLProgram) : undefined
makeXRCompatible() : Promise<undefined>

See also xrCompatible().

pixelStorei(parameter : Number, value : Number) : undefined

Sets options that affect readPixels, texImage2D, texSubImage2D.

parameter Valid Values Initial Value
PACK_ALIGNMENT 1, 2, 4, or 8 4
UNPACK_ALIGNMENT 1, 2, 4, or 8 4
UNPACK_FLIP_Y_WEBGL true or false false
UNPACK_PREMULTIPLY_ALPHA_WEBGL true or false false
UNPACK_COLORSPACE_CONVERSION_WEBGL BROWSER_DEFAULT_WEBGL or NONE BROWSER_DEFAULT_WEBGL

polygonOffset(factor : Number, units : Number) : undefined
readPixels(x : Number, y : Number, width : Number, height : Number, format : Number, type : Number, data : ArrayBufferView) : undefined

Reads pixels from the framebuffer and copies them to data.

x, y, width, height
the region of the framebuffer to read.
format
must be one of ALPHA, RGB, or RGBA.
type
must be one of UNSIGNED_BYTE, UNSIGNED_SHORT_5_6_5, UNSIGNED_SHORT_4_4_4_4, or UNSIGNED_SHORT_5_5_5_1.
data
stores the read pixels
The read data is affected by the pixelStorei() options.

renderbufferStorage(target : Number, internalformat : Number, width : Number, height : Number) : undefined

Creates and initializes the backing storage for a renderbuffer.

target
must be RENDERBUFFER.
internalformat
must be one of RGBA4, RGB565, RGB5_A1, DEPTH_COMPONENT16, or STENCIL_INDEX8.
width, height
the size of the renderbuffer.
See also createRenderbuffer().

sampleCoverage(value : Number, invert : Boolean) : undefined
scissor(x : Number, y : Number, width : Number, height : Number) : undefined
shaderSource(shader : WebGLShader, source : String) : undefined
stencilFunc(function : Number, reference : Number, mask : Number) : undefined

Same as stencilFuncSeparate() with face set to FRONT_AND_BACK.

stencilFuncSeparate(face : Number, func : Number, ref : Number, mask : Number) : undefined

Sets the stencil function. To use stencil tests, you must set the WebGLContextAttributes.stencil parameter to true when calling getContext('webgl', contextAttributes) and enable with enable(STENCIL_TEST).

face
must be one of FRONT, BACK, or FRONT_AND_BACK
function
must be one of NEVER, LESS, LEQUAL, GREATER, GEQUAL, EQUAL, NOTEQUAL, or ALWAYS. Defaults to ALWAYS.
reference
The value to compare with the value in the stencil buffer. It is also the value that be written to the stencil buffer if stencilOp is set to REPLACE.
mask
A value bitwise ANDed with reference and the value in the stencil buffer before performing the stencil function.

stencilMask(mask : Number) : undefined
stencilMaskSeparate(face : Number, mask : Number) : undefined
stencilOp(fail : Number, zfail : Number, zpass : Number) : undefined
stencilOpSeparate(face : Number, fail : Number, zfail : Number, zpass : Number) : undefined
texImage2D 5 variants
texImage2D(target : Number, level : Number, internalformat : Number, format : Number, type : Number, canvas : HTMLCanvasElement) : undefined
texImage2D(target : Number, level : Number, internalformat : Number, format : Number, type : Number, data : ImageData) : undefined

Specifies the data for the bound texture in the active texture unit (set through activeTexture() and bindTexture()).

target
must be one of TEXTURE_2D, TEXTURE_CUBE_MAP_POSITIVE_X, TEXTURE_CUBE_MAP_NEGATIVE_X, TEXTURE_CUBE_MAP_POSITIVE_Y, TEXTURE_CUBE_MAP_NEGATIVE_Y, TEXTURE_CUBE_MAP_POSITIVE_Z, or TEXTURE_CUBE_MAP_NEGATIVE_Z.
level
is the mipmap level (0 is base level).
internalformat
must be one of ALPHA, LUMINANCE, LUMINANCE_ALPHA, RGB, or RGBA.
format
must match internalformat.
type
must be one of UNSIGNED_BYTE, UNSIGNED_SHORT_5_6_5, UNSIGNED_SHORT_4_4_4_4, or UNSIGNED_5_5_5_1;
data
is the data to load into the texture.
The loaded data is affected by the pixelStorei() options. You can also use copyTexSubImage2D or texSubImage2D to initialize the texture.

Example:

Run

Results:

 

texImage2D(target : Number, level : Number, internalformat : Number, format : Number, type : Number, image : HTMLImageElement) : undefined

Example:

Run

Results:

 

texImage2D(target : Number, level : Number, internalformat : Number, format : Number, type : Number, video : HTMLVideoElement) : undefined
texImage2D(target : Number, level : Number, internalformat : Number, width : Number, height : Number, border : Number, format : Number, type : Number, data : ArrayBufferView) : undefined

Specifies the size and data of the bound texture in the active texture unit (set through activeTexture() and bindTexture()).

target
must be one of TEXTURE_2D, TEXTURE_CUBE_MAP_POSITIVE_X, TEXTURE_CUBE_MAP_NEGATIVE_X, TEXTURE_CUBE_MAP_POSITIVE_Y, TEXTURE_CUBE_MAP_NEGATIVE_Y, TEXTURE_CUBE_MAP_POSITIVE_Z, or TEXTURE_CUBE_MAP_NEGATIVE_Z.
level
is the mipmap level (0 is base level).
internalformat
must be one of ALPHA, LUMINANCE, LUMINANCE_ALPHA, RGB, or RGBA.
width and height
are the size of the texture.
border
must be 0.
format
must match internalformat.
type
must be one of UNSIGNED_BYTE, UNSIGNED_SHORT_5_6_5, UNSIGNED_SHORT_4_4_4_4, or UNSIGNED_5_5_5_1;
data
is the data to load into the texture. May be null to allocate the texture without data.
The loaded data is affected by the pixelStorei() options. You can also use copyTexSubImage2D or texSubImage2D to initialize the texture.

Example:

Run

Results:

 

texParameterf(target : Number, parameter : Number, value : Number) : undefined
texParameteri(target : Number, parameter : Number, value : Number) : undefined

Sets the value of the specified parameter for the bound texture in the active texture unit (set through activeTexture() and bindTexture()). Use getTexParameter() to get texture parameters.

parameter Valid Values Initial Value
TEXTURE_MIN_FILTER NEAREST, LINEAR, NEAREST_MIPMAP_NEAREST, LINEAR_MIPMAP_NEAREST, NEAREST_MIPMAP_LINEAR, or LINEAR_MIPMAP_LINEAR NEAREST_MIPMAP_LINEAR
TEXTURE_MAG_FILTER NEAREST or LINEAR LINEAR
TEXTURE_WRAP_S CLAMP_TO_EDGE, MIRRORED_REPEAT, or REPEAT REPEAT
TEXTURE_WRAP_T CLAMP_TO_EDGE, MIRRORED_REPEAT, or REPEAT REPEAT

texSubImage2D 5 variants
texSubImage2D(target : Number, level : Number, xoffset : Number, yoffset : Number, format : Number, type : Number, canvas : HTMLCanvasElement) : undefined
texSubImage2D(target : Number, level : Number, xoffset : Number, yoffset : Number, format : Number, type : Number, image : HTMLImageElement) : undefined
texSubImage2D(target : Number, level : Number, xoffset : Number, yoffset : Number, format : Number, type : Number, pixels : ImageData) : undefined
texSubImage2D(target : Number, level : Number, xoffset : Number, yoffset : Number, format : Number, type : Number, video : HTMLVideoElement) : undefined
texSubImage2D(target : Number, level : Number, xoffset : Number, yoffset : Number, width : Number, height : Number, format : Number, type : Number, pixels : ArrayBufferView) : undefined

The loaded data is affected by the pixelStorei() options.

uniform1f(uniformLocation : WebGLUniformLocation, x : Number) : undefined
uniform1fv 2 variants
uniform1fv(uniformLocation : WebGLUniformLocation, v : Array) : undefined
uniform1fv(uniformLocation : WebGLUniformLocation, v : Float32Array) : undefined
uniform1i(uniformLocation : WebGLUniformLocation, x : Number) : undefined
uniform1iv 2 variants
uniform1iv(uniformLocation : WebGLUniformLocation, v : Int32Array) : undefined
uniform1iv(uniformLocation : WebGLUniformLocation, v : Array) : undefined
uniform2f(uniformLocation : WebGLUniformLocation, x : Number, y : Number) : undefined
uniform2fv 2 variants
uniform2fv(uniformLocation : WebGLUniformLocation, v : Array) : undefined
uniform2fv(uniformLocation : WebGLUniformLocation, v : Float32Array) : undefined
uniform2i(uniformLocation : WebGLUniformLocation, x : Number, y : Number) : undefined
uniform2iv 2 variants
uniform2iv(uniformLocation : WebGLUniformLocation, v : Int32Array) : undefined
uniform2iv(uniformLocation : WebGLUniformLocation, v : Array) : undefined
uniform3f(uniformLocation : WebGLUniformLocation, x : Number, y : Number, z : Number) : undefined
uniform3fv 2 variants
uniform3fv(uniformLocation : WebGLUniformLocation, v : Array) : undefined
uniform3fv(uniformLocation : WebGLUniformLocation, v : Float32Array) : undefined
uniform3i(uniformLocation : WebGLUniformLocation, x : Number, y : Number, z : Number) : undefined
uniform3iv 2 variants
uniform3iv(uniformLocation : WebGLUniformLocation, v : Int32Array) : undefined
uniform3iv(uniformLocation : WebGLUniformLocation, v : Array) : undefined
uniform4f(uniforLocation : WebGLUniformLocation, x : Number, y : Number, z : Number, w : Number) : undefined