Jump to content
  • Advertisement
Sign in to follow this  
brekehan

binding vertex and index buffers - optimize

This topic is 3564 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 started thinking today about situations where many simular objects might be rendered. I came up with a few scenarios: Many objects may be rendered that: 1) share the same geometry share the same material differ in transform 2) share the same geometry differ in material differ in transform I already handled optimizing materials such that effect variables did not need to change unless the material differs, so I won't discuss that system. However, I am wondering if there is some optimization I can make with the vertex and index buffers such that the same procedure didnt need to be carried out needlessly over and over for rendering objects that have the same geometry? Right now, my class for objects to be rendered all have thier own vertex and index buffers, thier own material, thier own vertex format, look up for an effect, and look up for technique. So, say my game wanted to render 100 tanks that were all exactly the same, my engine is still creating all that data 100 times, and going through the entire rendering procedure 100 times, when all I really need to do is change the world matrix for each. Surely, this needs some work. Where do you fellas put your vertex and index buffers? Is it a member of your mesh? your render queue? something else? How do you go about your design as to not create duplicates and know the difference between an object that shares the same shape and a unique object? I was thinking of creating a seperate "shape" or "geometry" class that solely contained the vertices and indices, then having my "mesh" class just store the name of the shape that it uses, along with the material and transform. Does that seem feasable? I guess I would have some "shape manager" that contains all these along with the vertex and index buffers. I am also confused about the ability to start at an index when rendering, this implies that it may be better to only have one huge vertex buffer that stores everything and draw at different indices. Or perhaps one vertex buffer per renderable object which can consist of more than one shape? In what situations do you have a vertex buffer that contains more than the data for one shape?

Share this post


Link to post
Share on other sites
Advertisement
For the case of the 100 tanks. Since they are all the same, you should only have 1 set of vertices and indices. Draw your 100 copies using hardware instancing so that you can put all 100 tanks on screen in a single draw call. On your application side, you would probably need to design classes to allow instance copy of your meshes, probably through the shape class you have described or some other ways.

The way I did it was to have all my mesh load as a prototype. Instances are created from these prototype class. The prototype maintains the VB/IB as well as the instance buffer and other generic specific data. To draw, only the prototype class is sent to the renderer. Which then draw the tanks using the VB, IB and instance buffer.

As to making one huge vertex buffer for everything and then just drawing at different indices, it would work if your stride are all the same. However, I don't think models are going to have the same stride everytime.

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!