Jump to content
  • Advertisement
Sign in to follow this  
conman

how do you manage objects in a vertex buffer

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

Hi! I am interested in how to manage multiple objects in one vertex buffer. Does anyone have some expiriences in that area? Do you hold a pointer to the vertex buffer and the first vertex index in you object and if render() is called on this object you render this part of the vertex buffer? Did you write a wrapper around the vertex buffer for adding/removing the vertices of an object? Or are there better ways to go I didn't think of? Thanks! Constantin

Share this post


Link to post
Share on other sites
Advertisement
Hi there conman,
How are you doing?
Experiment with a static vertex buffer. Firstly you create the vertex buffer and when you call the render method, the 3rd parameter is the start vertex

StartVertex
[in] Index of the first vertex to load. Beginning at StartVertex the correct number of vertices will be read out of the vertex buffer.

So you can manage what you want to draw out of the vertex buffer using the render method in the IDirect3DDevice9 interface.

Share this post


Link to post
Share on other sites
Hi,

A common solution is to hold one! single index buffer for each model you want to render. The index buffer points to the vertices in the vertex buffer. This method works for both, opengl and direct3d. Remember that you can have multiple instances of your models, all sharing the same vertex and indexbuffer. You can draw them multiple times in different locations using transformations and multiple calls to DrawIndexBuffer().

Share this post


Link to post
Share on other sites
Thanks for the replies!

But I would also like to know if it's reasonable to write kind of a wrapper around the vertex buffer, because (as far as I know) I cannot say: add this vertices to it. I need to lock and unlock etc...

Also in my scene are objects with different vertex formats, so there may be multiple vertex buffers.
So maybe a vertex buffer manager would make sense...?

What do you think?

Constantin

Share this post


Link to post
Share on other sites
Quote:
because (as far as I know) I cannot say: add this vertices to it. I need to lock and unlock etc...

You could write a wrapper around a vertex buffer if you wanted, but I'd be very careful about the performance of a AddVertex() or AddTriangle() type function... locking/writing/unlocking for each call would destroy performance. You'd ideally want to add multiple/many vertices/triangles in a single Lock() operation...


The main advantage of putting all common geometry in the same buffer is to reduce the amount of resource switching required - you don't have to call a SetStreamSource() each time you want to render a different model.

However, based on the presentations by ATI/Nvidia on optimal vertex buffer sizes you don't necessarily want some Super-VB© that's 50mb in size [grin]

At the end of the day it's difficult to tell if the extra complexity of your code will give you a decent performance increase, but there is definitely some scope in the idea for improving things.

hth
Jack

Share this post


Link to post
Share on other sites
Thanks for your point of view, Jack.

A few further questions though:

Quote:
However, based on the presentations by ATI/Nvidia on optimal vertex buffer sizes you don't necessarily want some Super-VB© that's 50mb in size


What presentations do you mean? And what is a good vertex buffer size, is there a rule of thumb?

What do you do if the scene becomes very big? multiple vertex buffers and switching with 'SetStreamSource, or space partitioning and reloading parts of the scene into one smaller vertex buffer?

Thanks in advance,
Constantin

Share this post


Link to post
Share on other sites
Quote:
Original post by conman
Quote:
However, based on the presentations by ATI/Nvidia on optimal vertex buffer sizes you don't necessarily want some Super-VB© that's 50mb in size


What presentations do you mean? And what is a good vertex buffer size, is there a rule of thumb?

I can't remember the exact names of the files, but look around on the ATI Developer site or Nvidia Developer site - they're basically presentations that they gave at conferences like GDC/Meltdown/SIGGRAPH etc...

I think it was a 1mb vertex buffer for dynamic usage and a 4mb vertex buffer for static usage. 32-byte aligned vertices fit the cache a lot better than 24-byte vertices and consequently get a reasonable "free" performance boost.

Quote:
Original post by conman
What do you do if the scene becomes very big? multiple vertex buffers and switching with 'SetStreamSource, or space partitioning and reloading parts of the scene into one smaller vertex buffer?

There isn't really an answer to this - all of what you've specified is valid so to speak.

It's these sorts of choices (and the eventual solutions) that engine programmers tend to spend their time on... all of the algorithms and choices have their advantages/disadvantages - you just have to pick the ones that suit your intended usage.

hth
Jack

Share this post


Link to post
Share on other sites
Thanks a lot! I found the discussions on nvidia's and ati's dev pages and they are exactly what I wanted!


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!