Proper use of Vertex Buffers
I understand the main concept of vertex buffer / index buffers but what is the best way to use them?
The vertex buffer should be initialized only once, and it shouldn''t be too big or too small. (nvidia proposes a 4k vb)
Lets say the scene will have about 10000 vertices. Creating a vb this size would be a little bit to big I think, so what I would do is create a vb with size 4000 and fill it each time before calling DrawIndexedPrimitive.
Is this really that fast or am I doing something wrong?
ALex
I think you''re right, look at these steps :
INITIALIZATION
- Create the vertex buffer with a big size
- Create te index buffer with a big size (could be static if your objects does not morph)
LOOP
2 Options:
#1
- Fill an array with transformed/untransformed vertices
- Lock the vertex buffer
- memcpy the array into the vertex buffer
- Unlock the vertex buffer
#2
- Do step #1 once in INITIALIZATION
- Apply world transformations on vertices in the vertex buffer
SHUTDOWN
- Destroy the vertex buffer
These are methods. Maybe there are others, but I think these are the most straightforward.
Cya
/* Bullmax */
-------------
Reality has many forms : good and evil, black and white, ying and yang.
INITIALIZATION
- Create the vertex buffer with a big size
- Create te index buffer with a big size (could be static if your objects does not morph)
LOOP
2 Options:
#1
- Fill an array with transformed/untransformed vertices
- Lock the vertex buffer
- memcpy the array into the vertex buffer
- Unlock the vertex buffer
#2
- Do step #1 once in INITIALIZATION
- Apply world transformations on vertices in the vertex buffer
SHUTDOWN
- Destroy the vertex buffer
These are methods. Maybe there are others, but I think these are the most straightforward.
Cya
/* Bullmax */
-------------
Reality has many forms : good and evil, black and white, ying and yang.
dont use 4000, use 4096 if you want 4k.
should better align to page/cache-line bounds.
besides i read an ati doc. that suggested 4MB(!) vertex buffer.
i think the VB should be quit big.
just dont fire all your polys at once.
one important thing if you use dynamic geometry (and hence dynamic index/vertex buffers) is to create them with the "dynamic" flag and fill them with "nooverwrite"/"discard" flags set appropriately.
read more on this in the SDK.
bye,
-- foobar
--- foobar
We push more polygons before breakfast than most people do in a day
should better align to page/cache-line bounds.
besides i read an ati doc. that suggested 4MB(!) vertex buffer.
i think the VB should be quit big.
just dont fire all your polys at once.
one important thing if you use dynamic geometry (and hence dynamic index/vertex buffers) is to create them with the "dynamic" flag and fill them with "nooverwrite"/"discard" flags set appropriately.
read more on this in the SDK.
bye,
-- foobar
--- foobar
We push more polygons before breakfast than most people do in a day
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement