Archived

This topic is now archived and is closed to further replies.

d3d9 vertex buffers

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

I was wondering if it was possible to store vertex data of different formats in the same vertex buffer? Like, if I have a mesh with just D3DFVF_XYZ|D3DFVF_NORMAL, can I add vertices with format D3DFVF_XYZRHW later on in the vertex buffer? I''m not at a computer with the D3D9 SDK, so I can''t test it right now.

Share this post


Link to post
Share on other sites
No. you cant really add new things but you can leave them out. in other words if you have normals texture coords and position in your VB then you can still store that box that has no normals. So if you want to use one VB make sure it can hold all your data. Hope this helps.

Share this post


Link to post
Share on other sites
Yes. Use a non-FVF buffer (Set FVF to 0).

The data stride is specified only on SetStreamSource.

You can use OffsetInBytes of SetStreamSource to get byte specific alignment between types, but only if a card supports it.

If a card doesn''t support OffsetInBytes, you can simulate it with an appropriate BaseVertexIndex in DrawIndexedPrimitive and a small amount of waste.

For example, say you had a FVF with just xyz, and for example, had only two of these, then you wanted xyz,diffuse for the next vertices, you would have:

x,y,z, x,y,z - stride 12.

now we want x,y,z,d stride is 20. Now we want to get a BaseVertexIndex that will work for this, so we must round up the current size to a multiple of 20.

current offset = 12 * 2 = 24
need 16 bytes of padding to get offset of 40.

x,y,z,x,y,z, 0,0,0,0, x,y,z,d,x,y,z,d

And our basevertexindex is 2 (offset of 40 / stride of 20 = 2).

Share this post


Link to post
Share on other sites
So I can do this kind of manipulation, without the drivers/Direct3D messing with my vertex buffer? That''s good to know, too bad I''ll have to add ugly-looking code to keep track of the byte offsets and such.

Share this post


Link to post
Share on other sites