multiple vertexformats in same buffer?

Started by
9 comments, last by andi_bold2 18 years, 8 months ago
Lets say I want to have multiple objects in the same vertexbuffer. My question is, does every vertex need to have the same format if they are in same vertexbuffer or can some object vertices I put in there have different formats? e.g. Can object1 have position and normals while object2 only has position if object1's and object2's vertices are in the same vertexbuffer? Thanks [Edited by - andi_bold2 on August 3, 2005 11:40:03 AM]
Advertisement
I have hard believing it would be possible...

But EVEN if it was possible, what would be the use?
I can't see how it would help you at all as you would eitherway have to draw the seperatly, know the split points, and so on and on.


dont think thats possible cause when u create the vertex buffer u specify the Vertex format.
Ok, here's the use:

Shaders!

I want to have an engine where all objects in a scene are in the same vertexbuffer so I don't have to set the vertexbuffer hundreds of times every fram cause that's really slow.

Then if I want to use different shader effects for different objects, then eventually some of the shaders will require different information to be stored.

But if it doesn't work, then I will of course have to modify my idea.

Thanks anyway.
You'll need non-FVF buffers (ie: FVF=0 when creating the buffer), but after that sure, but you have to be aware of a few things.

The easiest is all formats are the same stride, in this case you need nothing special, you just need to store both a format and base index in your mesh.

If the formats mis-match, then it can be done, but it's a bit more tricky. For example.
Format1 = 16 bytes
Format2 = 8 bytes
For simplicity we'll say meshes only have 1 vertex. ;)
offset 0x00: 1 format1 vertex.
offset 0x10: 1 format2 vertex.
offset 0x18: 1 format1 vertex.
When you try to draw, it will be like this:
Draw, starting at index 0.
Draw, starting at index 2, (0x10 / 8) = 2
Draw, starting at index 1.5 (0x18 / 0x10) ... note the problem

solutions

offset 0x00: 1 format1 vertex.
offset 0x10: 1 format2 vertex.
offset 0x18: padding
offset 0x20: 1 format1 vertex.
Draw format1 starting at index 0.
Draw format2 starting at index 2, (0x10 / 8) = 2
Draw format1 starting at index 2 (0x20 / 0x10)

or, if you're running on a newer card which supports stream offset:
Draw format1 starting at index 0, stream offset 0
Draw format2 starting at index 0, stream offset 0x10
Draw format1 starting at index 0, stream offset 0x18

In general though, in order to support the largest variety of cards you'll need to insert padding, and compute indices based on the offset and size of the format. Stream offset is useful to avoid the padding, but older cards won't have it. The lost space because of format mismatches is going to be 1 wasted vertex after, at most, each full mesh, which isn't really a big deal.

Stream offset is useful when using SM3.0 instancing as your instance data will likely go into a dynamic buffer, and won't have the same index as the static on-card data unless you use the offset feature. Another good use of stream offset is when wanting to store multiple possible secondary streams in one vertex buffer.
Namethatnobodyelsetook, you've been most helpful. Thank you. I really understood the idea. By the way, do you know which card generations support stream offsets?
StreamOffsets were a DX9 feature, so you'd expect only DX9 cards to support it, however my GeForce3 (a DX8 card) supports it.

Checking here I see that even GeForce2MX and Radeon 7500s have support.

Checking here I see that GeForce2MX cards don't have support, and neither does the Radeon 7500, but it does say that yes, a GeForce3 supports it, and a Radeon 8200.

The second site is making it look like pretty much any DX8 card will support it. The first site implies even DX7 cards have support, which I doubt, as DX7 didn't even have streams.
Ok, that's what I wanted to hear. I don't think anybody will use those older cards anymore after a couple of years (when the game is finished [smile]) and either way, they don't support shaders. So I think I'll be using stream offsets.

Thanks!
Moved to new thread

[Edited by - andi_bold2 on August 3, 2005 11:34:35 AM]
Hmmm. I don't see anything wrong. I'm assuming you've tested that it works if you just uncomment the previous vertex buffer creation. As far as I know, the only time you need an FVF buffer is for a destination for ProcessVertices(), which you aren't using. Some of the newer SDKs even point out (every draw, grrr) that "INFO: FVF vertex buffer used with programmable pipeline.". This is so annoying that I've stopped specifying any FVF buffers, and just allocate them all with FVF=0... so I know that should work.

I'd suggest trying the debug runtimes, and try using the REF device. See if D3D complains about anything. If you still can't get anywhere, make a new thread. This is a different issue and lots of people are probably skipping this one as it's been solved at one point.

This topic is closed to new replies.

Advertisement