Jump to content
  • Advertisement
Sign in to follow this  
x3source

Beginner for Vertex Buffer Implementation

This topic is 4552 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 am working on a 3D/2D Game engine using DirectX9. I'm at the point of just beginning to write the base scene class and finding it very challenging to figure out in what way I should implement vertex buffers. I know how to use them but not when or where. Tutorials show it used in a very simple manner, but not in a way that would work for an engine with multple objects, scenes, etc. How are Vertex Buffers normally implemented? Purhaps have one Vertex Buffer for a scene? But then it would be difficult for me to decide how to handle when an object is taken out of a scene and put into another for example. I guess in simple terms that I know how to create vertex buffers, but not how to make use of them in my engine. How are they implemented?

Share this post


Link to post
Share on other sites
Advertisement
There is no single "right way" of implementing an engine using vertex buffers.

You should think of it more in terms of how you're going to use the content stored in them:

1. Group data with the same FVF/declaration together
2. Group data that is going to be modified regularly, occasionally or never (so you can get the usage/locking flags optimal)
3. Group data that will be rendered with the same pipeline configuration (e.g. effects/textures) - this will help reduce unnecessary state changes.

Also, the size of the VB can be important - some of the older ATI/NV slide decks suggest a maximum of 4mb (or so) for a VB; this might well eliminate the option of having a "super vertex buffer".

Having a single vertex buffer for every object isn't necessarily bad (it's what you'd get if you used lots of ID3DXMesh objects).

Also, give thought to using index buffers - you can then make use of vertex-cache optimizations, reduce storage overhead (by re-using vertices) and so on...

hth
Jack

Share this post


Link to post
Share on other sites
Thanks for that information. It's helping.
So I am looking at having 2 or 3 Vertex Buffers in my scene class. One for moveable objects (Players and things), one for terrain (static), and possibly one for sky.

I'm still struggling with one part that I havn't seen a solution for. So I have my Vertex Buffer and then I remove an object from the scene. Also suppose I add an object to the scene while the game is in progress. I'm not sure it would make sense to rearrange all the data in the buffer to accomodate those situations. Would I just recreate the buffer entirely if something like that changes?

Share this post


Link to post
Share on other sites
It's a good idea to load all your objects up front (i.e., load an entire level). This way you don't get slowdowns while the game is running. (On the other hand, loading a level can be slow this way.) Then you don't have a problem arranging your objects.

But initially I'd suggest just using one vertex buffer per object, since it'd work with any way you load your objects, and is easy to implement. Looking forward, you could code such that it'd be easy to change to fewer vertex buffers later.

Share this post


Link to post
Share on other sites
Quote:
Original post by jollyjeffers
Also, the size of the VB can be important - some of the older ATI/NV slide decks suggest a maximum of 4mb (or so) for a VB; this might well eliminate the option of having a "super vertex buffer".


Why would someone want to do that in the first place? Is there some speed/cache gain from this? I've heard of this before somewhere, but never actually give it any deeper thought...

Isn't having a single buffer forcing your application to manage memory distribution for it? Isn't it better to just let those issues be handled on the driver level? But on the other hand, I could see it having advandages just as using memory pools instead of malloc - is this the case?

--
As for me, I'm using an independent vertex buffer (+index buffer) for each geometry chunk. Only use a "big buffer" for particles.

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!