Attribute buffer and DrawIndexedPrimitive() in DX9 issue

kurlyak 101 Feb 29, 2012 at 08:58

Suppose I have code Dx9 and VC++ 2005:

m_pD3DDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST,
0, //BaseVertexIndex
pAttr[k].VertexStart, //MinIndex
pAttr[k].VertexCount, //NumVertices
pAttr[k].FaceStart*3, //StartIndex
pAttr[k].FaceCount ); //NumPrimitives

I don`t figure out what is VertexStart and VertexCount. For example I have:

Face number




Vert in IndxBuff





What is VertexStart? This is vert 40 from face 0 or min vert indx 20 which is in face 0 and face 1? That is VertexStart is min index of vert in index buffer or first index vert in indx buffer?

Furthemore what is VertexCount? This is value 12, that is we have 4 face by 3 vert each = 12. Or this value = 10 because vert 20 repeat twice in face 0 and face 1 and vert 24 repeat twice in face 0 and face3 ?

And how I understand FaceStart = 40 and FaceCount = 4.

Thanks in advance.

3 Replies

Please log in or register to post a reply.

__________Smile_ 101 Feb 29, 2012 at 15:35

VertexStart = min(index),
VertexCount = max(index) - min(index) + 1.

Or you can simply set (dunno about performance though):

VertexStart = 0,
VertexCount = VertexTotal.

kurlyak 101 Feb 29, 2012 at 18:20

Nothing understand… Sorry.

Stainless 151 Mar 01, 2012 at 09:37

Okay, say you have a mass of vertices in memory.

You have loaded in a 3d mesh that has 1000 vertices.

The first 100 you want to texture with a red texture.
The next 400 you want to texture with a blue texture
The last 500 you want to texture with a white texture.

You could sort each vertex by texture and store them in separate vertex buffers, but more commonly you store them in a single vertex buffer.

So when you want to render this object you need a mechanism to render the vertex buffer bit by bit.

bind red texture
render red triangles
bind blue texture
render blue triangles
bind white texture
render white polygons

To allow you to do things like this, all rendering libraries allow you to specify a start index and length with the rendering calls.

They normally also allow for combining meshes into a single vertex buffer for performance, so if you had a single triangle it’s indices would obviously be 0,1,2 but if you had already added 100 verts to the buffer you need them to be 100,101,102.

That’s all it is, it allows you to lump stuff together so you are not constantly sending vertex buffers across the bus into the graphics card