Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Is it better to have all vertex data in one structure like this: class MyVertex { int x,y,z; int u,v; int normalx, normaly, normalz; }

Or to have each component (location, normal, texture coordinates) in separate arrays/buffers? To me it always seemed logical to keep the data grouped together in one structure because they'd always be the same for each instance of a shared vertex and that seems to be true for things like character models (ex: the normal should be an average of adjacent normals for smooth lighting). One instance where this doesn't seem to work is other kinds of meshes like say a cube where the texture coordinates for each may be the same but that causes them to be different where the vertices are shared.

Does everybody normally keep them separate? Won't this make them less space efficient if there needs to be an instance of texture coordinates and normals for each triangle vertex (They won't be indexed)? Can OpenGL even handle this mixing of indexed (for location) vs non-indexed buffers in the same VBO?

share|improve this question
add comment

1 Answer

It's typical to keep them together. Then when you're creating your VBO, you can easily generate an interleaved VBO with all the data. This is very fast and a typical method when creating VBOs.

I have a few different data structures for vertices. When I know there isn't going to be any data of a specific type, I will leave out that data type and just interleave the data types present. For example, some of my models have bone information interleaved with the vertex data. Others do not. So I have a vertex structure that has that extra information and one that doesn't. I use both and have separate draw calls for each to set the appropriate pointers.

share|improve this answer
    
I suppose what I'm trying to figure out is how can you also have the VBO indexed at the same time where one or more of the vertex attributes differs for a shared vertex –  kiba2 Dec 18 '12 at 0:56
    
If the vertex attributes differ, then it's not a shared vertex. They are just two vertices that share some data. –  Byte56 Dec 18 '12 at 1:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.