I’m currently upgrading my calls to be using glDrawElementsInstanced instead the typical glDrawElementsInstanced times N, but while investigating, I came across different ways of doing it, mostly by using the matrices and instance data inside the VAO separated by glVertexAttribDivisor.
The issue here is that I have a preloaded set of VAOs, and then at runtime, depending on some logical conditions those will be rendered using glDrawElements or glDrawElementsInstanced, there is no way to know beforehand when will they be used, therefore I cant generate the meshes with the vertex data for the instance matrices.
So what I’m asking/leaving for discuss here is, if I can use glDrawElementsInstanced with UBOs in order to pass the many object data onto the shader, for instance:
- Creating the object meshes with VAOs (vertices, normals and uvs)
- Creating UBO and UniformBlock
- Having 20K logical objects
- Updating ModelViewMat x ModelViewProjMat x NormalMat UBO for each object (20K times)
- Calling the glDrawElementsInstanced
The main idea here is having a way to render repetitive object data and also keeping the old way of rendering VAOs normally when needed on the fly.
- Would this flow be a good starting approach?
- Isn’t updating of the UBO 20.000 times as bad as calling glDrawElements 20.000 times?
- Can I have that many data in the UBO being stored that way?