# vertex buffer improvement

This topic is 4747 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
Take a look at indexbuffers. They will allow you to reuse the vertices.

Cheers

##### Share on other sites
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.

##### Share on other sites
thanx guys ill search google for index buffer tutorials. Any of you got any links to what could help me out

##### Share on other sites
The DirectX SDK documentation provides a wealth of information. For example, see the Rendering from Vertex and Index Buffers topic.

Illco

##### Share on other sites
I really likes Andy Pike's tutorials. Here is his index buffer one: Linky

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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

##### Share on other sites
Quote:
 Original post by cNoobim 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

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 28
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634104
• Total Posts
3015541
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!