This sample demonstrates how instancing can be used to efficiently tessellate objects in real-time.


APIs Used

  • glDrawElementsInstanced (or glDrawElementsInstancedARB, or glDrawElementsInstancedNV)
  • glVertexAttribDivisor (or glVertexAttribDivisorARB, or glVertexAttribDivisorNV)
  • GL_ARB_instanced_arrays [optional]
  • GL_NV_draw_instanced [optional]

Shared User Interface

The Graphics samples all share a common app framework and certain user interface elements, centered around the "Tweakbar" panel on the left side of the screen which lets you interactively control certain variables in each sample.

To show and hide the Tweakbar, simply click or touch the triangular button positioned in the top-left of the view.

Technical Details

This sample demonstrates how instancing can be used to efficiently tessellate objects in real-time.

The basic idea behind instanced tessellation through instancing is this:

  1. Create a vertex buffer object that contains a barycentric tessellation of a generic triangle.

  2. Use instancing to draw an instance of this generic tessellation for every triangle of the object to be tessellated. For every instance the instance data will be the three 3D vertices and other vertex attributes of one of the current object-triangle be tessellated.

  3. Inside a vertex program use the per instance data to evaluate whatever function using the additional per vertex barycentric coordinates.

Instancing Modes

There are two different modes of instancing demonstrated:

  1. Software Instancing

    One draw call is made for each triangle of the object. The per-instance data is passed as uniforms.

  2. Hardware Instancing

    One draw call is made to tessellate the whole object. Per-instance data comes in as vertex attributes using glDrawElementsInstanced(), glEnableVertexAttribArray(), glVertexAttribPointer(), and glVertexAttribDivisor().

    If the standard functions are not available glVertexAttribDivisorARB/NV or glDrawElementsInstancedARB/NV are used.

Future Work

Two potential areas of future work/demonstration of this approach include:

  • Dynamic tessellation based on size/LOD (for improved performance with small visuals, and improved quality with larger visuals, automatically)
  • Use of displacement texture map for added details in the tessellated geometry.

See Also