Jump to content
  • Advertisement
Sign in to follow this  

Vertex structs and different vertex declarations?

This topic is 2436 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Different Models require different vertex elements (position, uv, normal, tangent, skin weights etc..)

When i load a model, i have to load its vertices but i'm not sure how. I can only think of two options:

1- Load the model vertices into a vector<float>. But then what if i want to add integer data? For example Bone Indices.

2- Store the vertices in a vector<Vertex> where Vertex is a predefined struct. If so, do i have to create a Vertex struct for every vertex element combination i can think of/might use? Doesn't sound practical to me.

Share this post


Link to post
Share on other sites
Advertisement
You can load and save vertices as a generic buffer (array of bytes) and then some method to describe the layout of vertices. Then you can use that description to retrieve the byte offset of whatever vertex component you need. This is how Direct3D Flexible Vertex Formats (FVF) work in essence. Even if you're not programming for Direct3D, read about FVF to understand the concept.

Alternatively, you can place different vertex components into different buffers. One buffer for vertex positions, one for texture coordinates... etc. All these buffers will have the same number of elements in them (but different sizes), which is the number of vertices in your mesh. Then a vertex is simply an index into these buffers. Check out this Direct3D sample that demonstrates this (or find the equivalent OpenGL sample from there): multiple vertex buffers sample

Hope this helps.

Share this post


Link to post
Share on other sites

2- Store the vertices in a vector<Vertex> where Vertex is a predefined struct. If so, do i have to create a Vertex struct for every vertex element combination i can think of/might use? Doesn't sound practical to me.


These structs are usually very lightweight and easy to create. While there are myriad ways to solve this problem, this is certainly one of the more straightforward and easiest to read/grok. Also, you don't need to create a struct for every conceivable permutation of vertex data. You will find that you only need a few to process the data that you need for your application.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!