Sign in to follow this  
KnightAdz

OOP and vertex/index buffers

Recommended Posts

KnightAdz    100
I have a quick question about using buffers in an object-oriented program, it may be more of a beginner question but I thought I would ask here as it specifically relates to directx. Would each object have its own buffer? This way you wouldn't need to lock/unlock the buffer as often. Or would you just have objects pass the number of vertices they need and their positions etc. to a single buffer that all objects can access? This would require a lot of locking and unlocking and transferring of data between objects and the buffers, so I don't know which way it should be done. Thank you

Share this post


Link to post
Share on other sites
godsenddeath    182
I give each object its own buffer. Remember that buffers are different sizes, so to share it among different objects, you'd have to make it big enough for hte biggest object.

That being said, don't be too worried about locking/unlocking, it's very common to lock/unlock many object's buffers per frame, such as model animation.

Share this post


Link to post
Share on other sites
KnightAdz    100
Ah, I wasn't sure how costly it was, but if it is not too heavy then I guess I might aswell give each object its own buffer. Thanks for the quick reply!

Share this post


Link to post
Share on other sites
ET3D    810
Often more than one object is kept in the same buffer. In some cases that's the natural thing to do (such as for particles, though perhaps not everyone will call them "objects"). At other times it's just a way to save buffer switches, which have a little bit of overhead.

Quote:
Would each object have its own buffer? This way you wouldn't need to lock/unlock the buffer as often.

What do you mean? There's usually not much of a relation between locking/unlocking and the number of objects in a buffer. If you have a bunch of static objects in a buffer, then they buffer is filled once, and then you just access subsets of it, which doesn't require locking/unlocking. If everything is dynamic (such as with particles), then you change the entire buffer anyway. If some stuff is dynamic and some is static, then you'll need at least one static buffer and one dynamic buffer, but ...

It tends to be simpler to have one buffer per object, and I'd recommend it as a first implementation (to get something working as quickly as possible) but since you're talking OOP, I think that abstracting this is the way to go. That'd probably mean putting the management of buffers in a different class, and having an opaque definition of an object's buffers, which in the naive buffer manager (one buffer per object) will just include the buffer, but in a more complex one will include the position as well.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this