2010-2014
Khronos Group
glDrawElementsInstanced
3G

# glDrawElementsInstanced

draw multiple instances of a set of elements

## C Specification

                    void glDrawElementsInstanced
                    GLenum mode
                    GLsizei count
                    GLenum type
                    const void * indices
                    GLsizei primcount

## Parameters

`mode`

  Specifies what kind of primitives to render. Symbolic constants `GL_POINTS`, `GL_LINE_STRIP`, `GL_LINE_LOOP`, `GL_LINES`, `GL_TRIANGLE_STRIP`, `GL_TRIANGLE_FAN` and `GL_TRIANGLES` are accepted.

`count`

  Specifies the number of elements to be rendered.

`type`

  Specifies the type of the values in `indices`. Must be one of `GL_UNSIGNED_BYTE`, `GL_UNSIGNED_SHORT`, or `GL_UNSIGNED_INT`.

`indices`

  Specifies a pointer to the location where the indices are stored.

`primcount`

  Specifies the number of instances of the specified range of indices to be rendered.

## Description

`glDrawElementsInstanced` behaves identically to glDrawElements except that `primcount` instances of the set of elements are executed. Those attributes that have divisor N where N is other than zero (as specified by glVertexAttribDivisor) advance once every N instances. Thus, the element transferred from instanced vertex attributes is given by: instance divisor

The value of `instance` may be read by a vertex shader as `gl_InstanceID`.

To enable and disable a generic vertex attribute array, call glEnableVertexAttribArray and glDisableVertexAttribArray.

If an array corresponding to a generic attribute required by a vertex shader is not enabled, then the corresponding element is taken from the current generic attribute state.

## Errors

`GL_INVALID_ENUM` is generated if `mode` is not one of `GL_POINTS`, `GL_LINE_STRIP`, `GL_LINE_LOOP`, `GL_LINES`, `GL_TRIANGLE_STRIP`, `GL_TRIANGLE_FAN`, or `GL_TRIANGLES`.

`GL_INVALID_VALUE` is generated if `count` or `primcount` are negative.

`GL_INVALID_OPERATION` is generated if a non-zero buffer object name is bound to an enabled array and the buffer object's data store is currently mapped.

`GL_INVALID_FRAMEBUFFER_OPERATION` is generated if the currently bound framebuffer is not framebuffer complete (i.e. the return value from glCheckFramebufferStatus is not `GL_FRAMEBUFFER_COMPLETE`).

`GL_INVALID_OPERATION` is generated if transform feedback is active and not paused.

## API Version Support

glDrawElementsInstanced

## See Also

glCheckFramebufferStatus, glDisableVertexAttribArray, glDrawElements, glDrawArrays, glDrawArraysInstanced, glDrawRangeElements, glEnableVertexAttribArray, glVertexAttribDivisor

## Copyright

Copyright 2010-2014 Khronos Group. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999. http://opencontent.org/openpub/.