Hello All,
iam reading OpenGL Superbible 5th and dealing with VAO/VBO part. I can render my meshes fairly easy and efficiently by them.
What i do not see still, how should i deal with massive number of meshes, lets say 9999.
Please note, that this sample code is for demonstration only:
- Should i have 9999 VAO generated for each mesh, and upload data of a single mesh only then repeat it 9998 times ?
//1 VAO is a single mesh which has 2 VBO
glGenVertexArrays(1, &mesh0_VAO);
glGenBuffers(1, &mesh0_verts);
glGenBuffers(1, &mesh0_indicies);
glBindVertexArray(mesh0_VAO);
// VBO 1
glBindBuffer(GL_ARRAY_BUFFER, mesh0_verts);
glBufferData(GL_ARRAY_BUFFER, ...., GL_STATIC_DRAW);
// VBO 2
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh0_indicies);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, .... GL_STATIC_DRAW);
- Or should i just create only one VAO for all the meshes and have 9999*2 VBO-s for different different meshes.
//1 VAO for all the meshes which has 9999*2 VBO
glGenVertexArrays(1, &allmeshes);
glGenBuffers(1, &mesh0_verts);
glGenBuffers(1, &mesh0_indicies);
glGenBuffers(1, &mesh1_verts);
glGenBuffers(1, &mesh1_indicies);
...
glGenBuffers(1, &mesh9999_verts);
glGenBuffers(1, &mesh9999_indicies);
glBindVertexArray(allmeshes);
// mesh 0 VBO-s
glBindBuffer(GL_ARRAY_BUFFER, mesh0_verts);
glBufferData(GL_ARRAY_BUFFER, ...., GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh0_indicies);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, .... GL_STATIC_DRAW);
// mesh 1 VBO-s
glBindBuffer(GL_ARRAY_BUFFER, mesh1_verts);
glBufferData(GL_ARRAY_BUFFER, ...., GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh1_indicies);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, .... GL_STATIC_DRAW);
...
// mesh 9999 VBO-s
glBindBuffer(GL_ARRAY_BUFFER, mesh9999_verts);
glBufferData(GL_ARRAY_BUFFER, ...., GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh9999_indicies);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, .... GL_STATIC_DRAW);
For a simple example a single mesh is:
-It has lists for its vertex positions, texturecoords and indicies
-It has single texture assigned
Mesh could be anything a rock, a bush, a wall, anything.
What do you think is it 1. or 2. perform better,
iam only interested in performance
Thank You
A