GPU Instancing

GPU Instancing

The glcore engine allows for a rendering technique called GPU Instancing. This technique allows an object to be drawn multiple times using hardware instancing techniques, meaning all the instances are drawn with a single GL draw call. More specifically, the instances are grouped based on textures, so all instances with the same texture binding are grouped together and drawn with a single call.

Supported Objects

Currently instancing can be performed using either or Each method has different requirements, advantages and limitations.

Instancing with

When using glcore, draws all copies of the target using GPU instancing. Functionally the object works just as it did with GL2 with the exception that arbitrary OB3D attributes in the glparams list (e.g., attr.rad_minor) are currently not supported. For this functionality you will need to revert to the gl2 engine.


  • The GPU instancing technique requires that the instance parameter values be sent to the shader as attributes, and a special shader must be generated to handle them. It is possible to bind a custom shader with, however it must conform to a specific format.
  • To achieve maximal performance, back-face culling (@cull_face 1) and triangular grid drawing (@gridmode 1) are recommended for all targeted objects (i.e., or When these settings are not used, the extra load on the GPU may result in lower frame rates than experienced in gl2, particularly on older hardware.

Instancing with

The object can also be used for instancing. This allows you to draw many copies of the gl.mesh without using a gl.multiple, thereby giving more control over which vertex-buffers are instance attributes (the vertex attributes that have unique values for each instance). This is made possible by the addition of 4 new vertex attribute buffers that allow you to manipulate the vertex buffer via shaders and requires using the object. The vertex buffers are then accessed via a custom shader that is bound to

Setting vertex_attr buffers in

You can send up to 4 buffers to and access them as inputs in your vertex shader using The @instanced attribute must be enabled (set to 1) and the @type attribute should be set to vertex_attr. To bind multiple vertex attribute buffers, you must specify the buffer index in the form @type vertex_attr0..3. e.g.: @type vertex_attr0 @instanced 1, @type vertex_attr1 @instanced 1, etc.

Note that the index determines the order in which the buffers are applied and can be critical for certain types of operations (like determining current position before applying velocity change). When using a single input, no index is necessary and type can simply be set as `@type vertex_attr`.

Accessing vertex_attr buffers in shaders

To access the buffers in the shader, create a param and specify state as VERTEX_ATTR0..3, e.g.:

<param name="flock_position" type="vec3" state="VERTEX_ATTR0" />
      <param name="flock_velocity" type="vec3" state="VERTEX_ATTR1" />

and in the body of the vertex shader:

in vec3 flock_position;
      in vec3 flock_velocity;

See Also

Name Description
Working with OpenGL Working with OpenGL Generate GL geometry from matrices Create multiple object instances