# Attribute buffer and DrawIndexedPrimitive() in DX9 issue

3 replies to this topic

### #1kurlyak

Member

• Members
• 93 posts

Posted 29 February 2012 - 08:58 AM

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 dont figure out what is VertexStart and VertexCount. For example I have:

Face number-----------0----------------1------------------2-------------------3
Vert in IndxBuff--------40,20,24-------20,92,42---------43,34,25---------92,63,24

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.

### #2}:+()___ (Smile)

Member

• Members
• 169 posts

Posted 29 February 2012 - 03:35 PM

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

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

VertexStart = 0,
VertexCount = VertexTotal.
Sorry my broken english!

### #3kurlyak

Member

• Members
• 93 posts

Posted 29 February 2012 - 06:20 PM

Nothing understand... Sorry.

### #4Stainless

Member

• Members
• 579 posts
• LocationSouthampton

Posted 01 March 2012 - 09:37 AM

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

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users