• Advertisement
Sign in to follow this  

Importing vertex/index buffer data

This topic is 1235 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

Hello,

 

I am currently working on the geometry importer code for a simple engine I'm working on purely as a way to teach myself more about game engines and low-level graphics programming.  The file I am reading in segregates and independently indexes each input element's vertex data.  As an example, consider a basic cube containing just position and normal elements.  The position buffer contains eight items (one per corner), and the normal buffer contains 6 items (one per side).  In triangle list form, the two index buffers both contain 36 indices (with different values).

 

Given that I'm working with DirectX, I need to have the data arranged to be indexed by a single set of indices.  This means that the element data I read in needs to be reordered and individual elements duplicated so as to share a common indexing.  Currently, I am using a non-optimal approach of just re-sizing the vertex buffers to match 1-for-1 the number of triangles and restoring the data by stepping through the indices.  Obviously this is not idea as the vertex buffers are not reduced to their minimal size (making the benefits of using an index buffer moot).  In the cube example, I should have a single index buffer with 36 indices and position and normal buffers each having 24 items ordered identically.

 

Does anyone have any references or tips on the algorithm (or better yet, library implementation) to use to reduce the vertex buffers to their minimal size without loss of information?

 

I conceptually can see how it's just a sort and merge where duplicates are removed based on a comparison of all elements for an index.  But where my attempts have gotten messy is handling an arbitrary number of input elements and seemingly allocating multiple (potentially) massive blocks of memory just for temporary usage.

 

Thanks

 

Share this post


Link to post
Share on other sites
Advertisement

Apologies, as this really wasn't a graphics-specific question, despite dealing with vertex and index buffers.  It's more just a basic data structure/algorithm issue.  Doing some more research I've realized there isn't a good way to avoid multiple nested loops.  This code will only be called outside the runtime in building resources for the target platform, so it's not a big deal as long as it works I suppose.

 

In case anyone is curious, I ended up utilizing some of the responses in this StackOverflow question.  Nothing groundbreaking.

Share this post


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

  • Advertisement