how do you manage objects in a vertex buffer

Started by
6 comments, last by conman 18 years, 8 months ago
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
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.
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().
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
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Thanks a lot! I found the discussions on nvidia's and ati's dev pages and they are exactly what I wanted!


This topic is closed to new replies.

Advertisement