I have been learning OpenGL 2.1 but using shaders, VBOs, IBOs, etc. I have gotten a rendering engine that can load and draw meshes, materials, forward lighting (no shadows yet), SceneNodes, and NodeComponents. There are no optimizations yet (for obvious reasons) such as occlusion culling, only Face culling at the moment.
A mesh (simplified) class looks like this:
struct Mesh
{
GLuint vbo;
GLuint ibo;
GLuint size;
void draw(Program* shaderProgram) const
{
glEnableVertexAttribArray(shaderProgram->attrib("vertPos"));
glEnableVertexAttribArray(shaderProgram->attrib("vertTexCoord"));
...
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexAttribPointer(shaderProgram->attrib("vertPos"), 3, GL_FLOAT, false,
sizeof(Vertex), (const GLvoid*)(0 * sizeof(float)));
...
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glDrawElements(GL_TRIANGLES, size, GL_UNSIGNED_INT, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glDisableVertexAttribArray(shaderProgram->attrib("vertPos"));
...
}
}
When I have been drawing multiple objects with the same mesh (or multiple meshes), I notice a frame drop compared to a single mesh with the same number of triangles.
Stanford Models were used.
(1 Face = Triangle)
| Model | Num Models | Total Faces | With Lighting | Without Lighting |
| - | - | - | ms / frame | ms / frame |
|--------|-------------|-------------|---------------|------------------|
| | 0 (control) | 0 | 0.47 | 0.41 |
| bunny | 1 | 69630 | 1.2 | 0.64 |
| bunny | 14 | 974820 | 12.4 | 3.50 |
| buddha | 1 | 1087474 | 7.87 | 2.89 |
| buddha | 10 | 10874740 | 71.4 | 23.8 |
I does look like that time/frame is ~O(n). However, drawing one vbo with 12% more faces, the frame time is decreased by 37%.
So my questions are:
- Is drawing multiple VBOs actually worse than drawing one big one?
- How would I combine these VBOs and IBOs into one big one if this is true?