Using GPU instancing to reduce data transfers
By using so-called instanced drawing, the graphics card duplicates the vertex data for the model instances by itself. All we must tell the GPU is the location of the vertex or index buffer data to use, and the number of instances to create.
The normal call telling OpenGL to start drawing looks like this:
void glDrawElements(drawMode, indexCount,
componentType, indices);
For the drawing mode, we are using GL_TRIANGLES
to draw triangles, defined by groups of three vertices. The index count is the number of entries in the index buffer. If some vertices are shared between triangles, the number of index entries may be lower than the overall number of vertices. Depending on the amount of index entries, the component type could be a byte, a short integer with 16 bits, or an integer with 32 bits. As we are using an index buffer to store the index elements, the last parameter is nullptr
.
The call to tell OpenGL to create more than one...