1
\$\begingroup\$


I recently worked through this tutorial about instanced rendering. At the end it promises to draw a huge amount of instances of one model without performance drops.
So I tried some simple instanced rendering to see these effects. So I created a VBO containing four times xyz-coordiantes, vertex color and texcoords.

float[] backgroundData = new float[] {
            -1.0f, -1.0f, 0.0f, 1f,1f,1f,1f, 0.0f, 0.0f, 0.0f,
            1.0f, -1.0f, 0.0f, 1f,1f,1f,1f, 1.0f, 0.0f, 0.0f,
            -1.0f, 1.0f, 0.0f, 1f,1f,1f,1f, 0.0f, 1.0f, 0.0f,
            1.0f, 1.0f, 0.0f, 1f,1f,1f,1f, 1.0f, 1.0f, 0.0f
    };

I also created a VAO and EBO containing the glVertexAttribPointers and indices int[] indices = new int[]{0,1,2,1,2,3};.

Now I draw everything with glDrawElementsInstanced(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0, 10_000). But the Framerate drops as much as if I had the indices 10.000 times in my EBO. Why is the outcome so different? Did I do something wrong?

\$\endgroup\$
3
\$\begingroup\$

Instancing is an improvement relative to multiple draw calls, with state changes between each draw.

Instancing exists to allow you to provide per-instance data to each instance, so that it can iterate over the same vertices with new data. This allows you to do things like provide offsets or even full transformation matrices to each instance of vertices, all while only issuing one draw.

So that's what you need to compare it to: setting up the data for an instance, then drawing it, then setting up the data for the next instance. It's meaningless to test the performance between rendering 10,000 individual instances and 10,000 copies of the same object using the same rendering state.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.