A common use case in OpenGL is to be able to draw a group of similar objects that share vertex data, primitive count and type, multiple times. The ARB_instanced_arrays extension provides a means of accelerating such use cases while minimizing the number of draw calls and the amount of duplicate data. This extension introduces an array "divisor" for generic vertex array attributes, which when non-zero specifies that the attribute is "instanced". An instanced attribute does not advance per-vertex as usual, but rather after every <divisor> instances are rendered.
This sample demonstrates how to use instancing. By specifying transform data in instanced attributes, one can, in concert with the instancing draw call, draw multiple instances of an object with one draw call.
Press 'space' to toggle the animation.
OS X v10.8 or later, Xcode 4.6 or later
OS X v10.8 or later
The renderer class creates and draws the OpenGL shaders. This is where we set up instancing and draw the set of gears with one single instancing draw call.
The OpenGL view. It delegates to the renderer class for drawing.
The application delegate.
This file contains the vertex data of a triangle toothed gear model.
The vertex shader, which uses instanced attributes, for drawing the gears.
The fragment shader for drawing the gears.
Copyright (C) 2010~2013 Apple Inc. All rights reserved.