2
votes

In my scene I have a tree of meshes. Each mesh contains a transformation matrix, a list of vertices, normals, uvs and a list of child meshes.

I would like to send my geometry in an 'array of structures' to glsl using a VBO, but I don't know how to handle updating each mesh's matrix in the event of a parent mesh's matrix transformation. Should I traverse the mesh tree and add a matrix for every vertex every frame? Should I premultiply the vertices each frame? Should I hold a list of matrices in a uniform and reference the current vertex's matrix by index? Should I use one glDrawArrays or glDrawElements for every mesh?

1

1 Answers

1
votes

The 'standard' approach would be to use on glDraw call per mesh.

For each mesh, you feed its transform matrix in a single uniform that is applied for the whole mesh. This matrix is then used in the vertex shader to transform the mesh from 'object space' to 'clip space'.

Having multiple matrices for one mesh (or draw call) is generally used for non-rigid transformations on meshes (deformations induced by bones for example).

Another approach, depending on the number of meshes you have to draw, would be to use 'hardware instancing'. Where you can draw a similar mesh multiple times, providing an array of matrices, and let the hardware pick the according matrix given the instanceID being drawn.