Currently my scene consists of models. Models consist of meshes. Each mesh has its own buffers, there are 8 of them (vertices, normals, texCoords, tangents, bitangents, boneWeights). I render each frame like this:
void drawModel(Model &model) {
...
for (size_t i = 0; i < model.shape->meshes.size(); i++) {
...
pointer(cs.inPosition, 3, model.shape->meshes[i].getVerticesBuffer());
pointer(cs.inNormal, 3, model.shape->meshes[i].getNormalsBuffer());
pointer(cs.inTangent, 3, model.shape->meshes[i].getTangentsBuffer());
pointer(cs.inBitangent, 3, model.shape->meshes[i].getBitangentsBuffer());
pointer(cs.inTexCoord, 2, model.shape->meshes[i].getTexCoordsBuffer());
...
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, model.shape->meshes[i].getIndicesBuffer());
glDrawElements(GL_TRIANGLES, model.shape->meshes[i].indices.size(), GL_UNSIGNED_INT, nullptr);
}
}
pointer() code:
inline void pointer(GLint location, int count, GLuint buffer) {
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glVertexAttribPointer(
location, // attribute location
count, // count (1, 2, 3 or 4)
GL_FLOAT, // type
GL_FALSE, // is normalized?
0, // step
nullptr // offset
);
}
I also use only one VAO for the whole scene.
How can I optimize this code (Maybe I should create these buffers only for the model, not for each mesh? Maybe it is worth allocating a separate VAO for each model?)? My scene consists of a fairly large number of vertices (about 500k), and shows a fairly low FPS (about 35).