Jump to content
  • Advertisement

Archived

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

RageMatrix

Vertex Buffers and objects.

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

Hey all, I have class objects to describe my objects in the game world. Classes such as CCube, etc. At the moment, each object has its own vertex buffer, but I''ve heard that this is a Bad Thing. That you should have one vertex buffer to hold ALL your objects. As far as I understand it, having a vertex buffer for each primitive affects performance. Assuming that each object is made up from an array of class CVertex, how do you guys include ALL objects within the vertex buffer, seeing as you don''t know how many obejcts you might be creating? Do you guys use a vertex buffer encapsulated in a class or what? I''m a little confused about how I would get the relevent information into the following line of code, seeing as my objects are all classes. Is there an elegant way to do this? Can I just pass the size of the object''s CVertex array to this line? How can I dynamically resize the vertex buffer during runtime? Am I barking up the wrong tree totally? pD3DDevice->CreateVertexBuffer(sizeof(CTexturedVertex)*24, NULL, D3DFVF_CTexturedVertex, D3DPOOL_MANAGED, &pTexturedVertexBuffer); Any useful input on this subject would be gratefully received. RM. P.S. Sorry if I''m not making much sense. Its late and I''ve been coding for six hours straight.

Share this post


Link to post
Share on other sites
Advertisement
Bumpity..

I am pondering this same dilemma myself, and have been for several weeks now. Any help would be appreciated by me, as well.

Share this post


Link to post
Share on other sites
I dont know what kind of game world you are trying to create but i would suggest having a vertex buffer only for each whole object/model(for example a tank).
A gameobject class representing one independent entity in your gameworld COULD contain a vertex buffer, but IMHO, you should try to keep the DirectX-specifics away from the game logic. Why dont you have a GraphicsManager class or something that holds all the game objects that have been created, and creates vertex buffers from that, one for each game object.

I dont know if you should put everything into one vertex buffer, because im under the impression that you apply matrix transformations to all vertexes in a vertex buffer(so unless you want to move the whole world, you would be in trouble). I could easily be wrong though, im a newbie to DirectX

Share this post


Link to post
Share on other sites
In my engine, this is done in 2 ways, but I don''t guarantee it''s the best answer, just my solutions that I figured out after wondering for ages. Hopefully these ideas will save you some time:

1/ Yes, you can actually have a different vertex buffer for each different TYPE of object, just not for each INSTANCE of that object. For example, I could have a car with 4 wheels, and use a vertex buffer holding the wheel geometry, which I would re-use 4 times while rendering (by changing the world matrix in between). Whatever you do, make sure you don''t actually use 4 vertex buffers each with the same wheel in, that really is a waste!

2/ For certain types of rendering, such as a landscape or particle engine, use just 1 big vertex buffer. Don''t just fill the vertex buffer at that start of the program and then leave it. Instead, on each render, fill the vertex buffer with new data, and when the vertex buffer runs out, render it''s contents, write some more polys, render again etc. One point to note is that you should make the vertex buffer dynamic, otherwise you might end up writing over the same bit of memory which the graphics card is still busy rendering from.

I''m still sure there''s much better ways, any more suggestions?

Share this post


Link to post
Share on other sites

  • 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!