6
\$\begingroup\$

I'm having trouble understanding the benefit of the newer GL_EXT_draw_instanced over traditional VBO's. Don't both keep geometry cached on the gpu for faster redrawing? VBO's seem much more flexible.

\$\endgroup\$

2 Answers 2

6
\$\begingroup\$

The advantage to instancing is to allow multiple objects to be drawn in a single draw-call, reducing the overhead of calling the API.

Typically as well as the geometry, you would also have a buffer containing multiple transforms, and perhaps other per-object data. This could be used in the shader to vary the appearance of each object by modifying its colour, or using a different texture (generally the texture variations would be achieved by using a texture atlas to pack multiple textures into a single texture).

\$\endgroup\$
1
  • \$\begingroup\$ This makes sense. VBO's allow rendering lots of vertices in one call. Instancing is one level higher in the hierarchy and lets you render lots of VBO's in one call. \$\endgroup\$
    – EricP
    Oct 21, 2010 at 18:11
3
\$\begingroup\$

Instancing should be used in conjunction with VBOs, and is most useful in OpenGL3/4.

The "correct" usage is to have a uniform-array of transform matrices, one for each instance. You then use one instanced draw call to render all the objects that use the same mesh. In your vertex shader, you can then select which transformation matrix to use based on the index ID.

You can do the same for any other number of attributes, but the more attributes you want to change, the fewer instances you can draw at once, due to constraints on the number of uniforms available. If you just want to use a transform matrix, for example, thats 4096/16=256 instances at once on the latest-and-greatest hardware. (assuming no other uniforms in your shaders). If you add colors to that, you're down to 4096/20=204 instances at once.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .