vertex buffer improvement

Started by
9 comments, last by cNoob 18 years, 2 months ago
Ive been messing about with my vertex buffer making aload of cubes in 3d space. It was then that i relised that i have vertices being used more than once for each cube. I was woundering if this would slow my program down if so is there a way to improve the speed of my program. Any help would be great.
Advertisement
Take a look at indexbuffers. They will allow you to reuse the vertices.

Cheers
You should be using an index buffer also.

Consider your cube and how it has a total of 8 vertices.
So we label each vertex. 1, 2, 3, 4 ...
And you said that some of the vertices are the same.
So maybe we could say one side has two triangle built like this:
1, 2, 3
2, 3, 4

Notice that the 2 and 3 vertices are the same and are used in both triangles.

Well this is exactly what an index buffer is.
Without it your vertex buffer would be like 1, 2, 3, 2, 3, 4
With it your vertex buffer would be like 1, 2, 3, 4 (no overlaps)

And then you add the index buffer which has 1, 2, 3, 2, 3, 4

There are many benefits to this like the fact that 2 and 3 will be in vertex cache and so they don't have to be recomputed.
thanx guys ill search google for index buffer tutorials. Any of you got any links to what could help me out
The DirectX SDK documentation provides a wealth of information. For example, see the Rendering from Vertex and Index Buffers topic.

Illco
I really likes Andy Pike's tutorials. Here is his index buffer one: Linky
Keep in mind that a vertex is more than just its position. It may also include a normal, colors, and texture coordinates. So, just because two vertexes have the same position, it doesn't always mean they can be the same vertex.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Quote:I was woundering if this would slow my program down if so is there a way to improve the speed of my program. Any help would be great.
.
This really does depend on how many primitives you are rendering. If you are rendering 2 primitives... using an index buffer might be overkill. So use your own discretion when making this decision such as... "right now I have almost 200 000 primitives being rendered, I think using index buffers will improve my 10 000 duplicated vertices."

I hope this helps.
Take care.
im making just a simple random terrain and i needed sharded vertices so i could set the random y values. My terrain will be 32 tiles across and 32 tiles down so does that mean using an index buffer would be more efficient
Quote:Original post by cNoob
im making just a simple random terrain and i needed sharded vertices so i could set the random y values. My terrain will be 32 tiles across and 32 tiles down so does that mean using an index buffer would be more efficient

I don't think it would make a huge amount of difference. Not for those sorts of numbers on modern hardware. Yes, it might go a bit faster - but what does it matter if it's already clocking up a high frame rate? Might be better to wait until it is a known performance problem before you go about changing it.

One area that IB's can help with terrain is if you intend to dynamically update the heights (esp. if you make your water/ocean a form of heightfield). Having 6 triangles sharing a single vertex rather than 6 unique vertices means you have less data to manipulate/write/upload.

hth
Jack

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

This topic is closed to new replies.

Advertisement