Optimal way of storing vertex data...

Hi!

I guess this is a pretty basic question:

Which is the optimal way of storing vertex data (flexibility, performance)? That is vertex positions, texture coords, normals.

I have implemented 3 global arrays (pos, norm, tex) with the data and each mesh has a bunch of indices representing the arrays. I can then call:

glVertexPointer
glNormalPointergl
TexCoordPointer

once when all my models has been loaded

when i want to render i simply enable the arrays i want for a specific mesh, enable textures, ligthing (whaterver) and call

glDrawElements with the indices for my mesh.

This is all simple enough but maybesomewhat wastefull since the arrays must be aligned according to the indices. The other problem i’m now facing is how to handle multiple textures.

I have a simple shader script technology implemented which can render in multiple passes, but only with the same texture coordinates (since i only have one array). It does not seem right to add more global arrays. Does anyone have a better idea on how to store vertex data (per mesh maybe, but will this make a performance hit)? I’m also wondering if it will happen in reality that a mesh needs more than one set of texture coordinates?

regards!

Your on the right track. According to documentation vertex arrays are the fastest ways to draw data. Combined with display lists you should do very well. If all of your data does not change each frame I recommend that you use display lists for the static/semi static data and recreate the DL if a semi static object changes.

Hi!

I’m also wondering if it will happen in reality that a mesh needs more than one set of texture coordinates?

Well… it depends on what you want to do.
But if you want to have vertexs with more than one set of coords, you will have to duplicate the vertexes, since all the arrays must have the same size (indexed with the same index array). I mean, you can not have a texture coordinates array that doubles the vertex array size…
To speed up all that stuff, you can try with Vertex Array Range.

Hope it helps!
-nemesis-