Jump to content
  • Advertisement
Sign in to follow this  
Spanky

Combining info to make buffers

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

Hey, I've been thinking about this for a bit and I'm interested in an efficient way to take seperate buffers, each with seperate indices, and combine then into a single vertex buffer/index buffer combo. To keep it simple, I have a position buffer and a uv buffer. There are two index buffers, one for each set, and they are both the same size obviously. I want to take that information and create a vertex with the position and uv coords in it and create a single vertex buffer since I've heard that interleaved data performs better with vb's. My problem is that although two vertices may reference the same position vertex, they may have seperate uv coords. I don't particularly feel like scanning through every "combined" vertex created so far and seeing if it matches and if so, create an index to that position. Otherwise I create another vertex with the position and uv coords. I will if I have to but if anyone else has any other ideas, that'd be great to hear. Thanks Shawn

Share this post


Link to post
Share on other sites
Advertisement
Almost forgot. I'm not combining this information to create just a single vertex buffer, I want to use indexed data so there will be a new index buffer as well. I could obviously just iterate through the original buffers and create a new vertex each time with the position and uv coords but I'd like to re-use previous vertices if the position and uv match, that is, they had the same indices in the original buffers.

Share this post


Link to post
Share on other sites
Its not possible to do what you want to do -- you can only have one set of indexes. Instancing will almost get you there, but still falls short.

Share this post


Link to post
Share on other sites
Quote:
Original post by Spanky
Almost forgot. I'm not combining this information to create just a single vertex buffer, I want to use indexed data so there will be a new index buffer as well. I could obviously just iterate through the original buffers and create a new vertex each time with the position and uv coords but I'd like to re-use previous vertices if the position and uv match, that is, they had the same indices in the original buffers.


Sounds like you are parsing OBJ files. Like JohnBolton said you cannot have multiple indexes in DirectX, still it is possible to merge the indexes. It probably won't be easy though. If you are parsing OBJ files than a key to your solution may be that a vertex should not have more than one texcoord in each matlib. In other words you should not have to worry about duplicates wonce you have split your data into material groups. Another solution is to "bloat and weld" that is remove the index entirely by duplicating every referenced vertex and then weld using DirectX's weld functions or your own weld functions. Welding is not hard, but can be very time consuming.

Hope this helps.

Share this post


Link to post
Share on other sites
Hey,

I didn't mean that I would have multiple index buffers. I currently have a few buffers for various things (not used for rendering) like position and texture coords and what not.

I want to take all that and combine it into a single vertex/index buffer. I could just loop over and create a new vertex and grab the information from each of the various buffers but I want to recombine it in an efficient manner.

I'm looking at Quake 2 MD2 format right now in particular. I've got a few other uses as well. Basically, the format has a list of positions and a list of texture coords. You also get a position index buffer and a texture coord buffer. So for vertex 5, you need to look up the index in the position index buffer to get it as well as in the texture buffer.

I'm just looking at a decent way to combine as much duplicate info as possible and a fast way to determine that there isn't a duplicate and a new vertex is needed.

Shawn

EDIT: That is, combine this info into a new, single vertex/index combo.

Share this post


Link to post
Share on other sites
The only way I've reliably figured out to do this is to completely de-index the mesh (since you have a definitive list of faces to work with) and then re-index it with a single index buffer. The second step I hand off to NvTriStrip, and the first step is fairly easy to do. You can brute force the de-indexing in O(n^2), but clever use of data structures can get you O(n log n).

Share this post


Link to post
Share on other sites
I'm just looking at the welding functions through D3DX and it seems that would solve my problem. Only thing is I have to create a Mesh first and use that. Problem being is that I need to be able to load any given md2 on the fly so I can't exactly move that to an offline operation. I could try doing my own welding but again, I end up with the question of efficient algorithms to perform this in.

Shawn

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!