WebGLRenderingContext: drawElements() method

Note: This feature is available in Web Workers.

The WebGLRenderingContext.drawElements() method of the WebGL API renders primitives from array data.

Syntax

js
drawElements(mode, count, type, offset)

Parameters

mode

A GLenum specifying the type primitive to render. Possible values are:

count

A GLsizei specifying the number of elements of the bound element array buffer to be rendered. For example, to draw a wireframe triangle with gl.LINES the count should be 2 endpoints per line × 3 lines = 6 elements. However to draw the same wireframe triangle with gl.LINE_STRIP the element array buffer does not repeat the indices for the end of the first line/start of the second line, and end of the second line/start of the third line, so count will be four. To draw the same triangle with gl.LINE_LOOP the element array buffer does not repeat the first/last vertex either so count will be three.

type

A GLenum specifying the type of the values in the element array buffer. Possible values are:

When using the OES_element_index_uint extension:

offset

A GLintptr specifying a byte offset in the element array buffer. Must be a valid multiple of the size of the given type.

Return value

None (undefined).

Exceptions

Examples

js
gl.drawElements(gl.POINTS, 8, gl.UNSIGNED_BYTE, 0);

Specifications

See also