I'm trying to wrap my head around some of the openGL render options.
For now my sudo code goes in something like this:
void paint() {
...
for (auto &obj:objList) {
obj.draw(matrix)
}
}
void draw(matrix &m){
shaderProgram->bind();
meshVao->bind();
meshVertex->bind();
meshIndices->bind();
shaderProgram->setUniformValue("mvp_matrix", m * getObjTrans());
shaderProgram->setUniformValue("un_color", QVector4D(1, 1, 1, 1));
shaderProgram->enableAttributeArray("position");
shaderProgram->setAttributeBuffer("position", GL_FLOAT, 0, 3);
glDrawElements(GL_TRIANGLES, mMeshData->mIndices.size(), GL_UNSIGNED_INT, 0);
}
Now this just binds every object 1 by 1, sets its matrix, and draw it. Its fairly inneficient with lets say 5-20k+objects.
Now I was reading lately and from what I can say I could also load all objects data in to 1-2 VBO under 1 VAO and then draw them all in 1 call. So if I take all indices in to 1 vector and all vertex in to 1 vector, I can then bind just these 2 vbo objects and draw all objects in 1 call. The probem I try to understand is, how do I pass a matrix for each object in the vectors? In function above, I pass a matrix to each obj before drawing it, but if all my objects are in 1-2 vectors, how am I to pass matrix to them separately?
A rough last second idea would be to create a vector matrix. And pass all matrices in to that 1 vector and pass that in to the fragment/pixel shader. Then have an offset counter in there and every next object render, just do matrix[offset*16] and this will give me matrix for that object. Once thats there all I need is matrix[offset*16] until matrix[offset*16+16] to get all 16 floats to create matrix and use to draw the object?
Is this the right direction?