Vertex Buffers

Started by
2 comments, last by Endemoniada 19 years, 2 months ago
Hi guys, Is it alright to have a bunch of different vertex buffers ? I'm rendering different sized quads (16x16,32x32, etc.) and although I can put them all in a single vertex buffer it seems easier to manage with a seperate one for each quad size. What do you think ?
Advertisement
Although i am no expert on this i feel that i should try and help as others have helped me:)

From what i know, the thing you want to keep to a minimum is the number of locks/unlock calls on the vertex buffer (i.e. the number of times you write new data to the buffer). Therefore, while it is perfectly legal to have many different vertex buffers these are not going to be the most effcient way of doing things both because:

a) Yuo will have lots of lock/unlock calls each time you write a buffer
b) There is lest chance of continuos memory usage = less efficient.

Now it may be that this is not a problem for you, but i would recommend trying to put all the vertexes that share a Vertex format in the same buffer and, if possible, put all this data in in one go (using a memcpy function).

I hope this helps, but like i said i am no expert on the matter so it may be i get corrected pretty soon!

Matt
Having a bunch of different vertex buffers is completely fine, as with most things when it comes to graphics the main variables are "how big" and "how many". Stick to reasonable sizes and amounts and there shouldn't be any problem.

What you want to avoid is swapping vertex buffers (i.e. SetStreamSource()) and Lock()/Unlock() calls.

SetStreamSource() calls are unavoidable, just like SetTexture() calls - all you can do is minimise them as best you can by sorting your drawing appropriately.

Lock/Unlock calls are easy to avoid. Write all your data to the vertex buffer once during initialisation, and don't touch your VBs again. If you need frequent locking support (typically you might need it for particles or animation, depending on which methods you're using) use dynamic buffers.

-Mezz
Thanks guys.

Yeah, I'm making sure to call Lock/Unlock only once so I only do them at initialization time. I wasn't sure about the SetStreamSource() call, to me it just seemed like setting a pointer but maybe a lot more goes on in there.

I guess for my quads I'm better off with just one vertex buffer, then I can use elements 0-3 for my first quad, 4-7 for my next quad and so on. I'll set up the quads so I don't have to scale them, so the 0-3 vertices will be for the 16x16 quads, 4-7 for the 32x32 quads and so on.

It should work out nicely as long as I do the housekeeping correctly.

Take care.

This topic is closed to new replies.

Advertisement