Sign in to follow this  
Scet

[solved]DrawIndexedPrimitives Parameters

Recommended Posts

Scet    960
Basically the problem is that I can only render a few triangles with DrawIndexedPrimitives before it explodes(exception on the Present call). Can anyone explain what the parameters to DrawIndexedPrimitives are actually for? The MSDN article for it is really vague, baseVertex and startIndex appear to be the same thing. Also is numVertices the number of unique vertices or the amount of vertices to render(wouldn't this equal the number of indices?)? I haven't found much on using DrawIndexedPrimitives for complex scenes online, everything just seems to be the standard "here's how to draw a cube". I would appreciate an help, I've tried passing different things to it, but nothing seems to work. [Edited by - Scet on December 14, 2006 5:04:43 PM]

Share this post


Link to post
Share on other sites
Mastaba    761
A couple years back I wrote a brief overview of SetIndices and DrawIndexedPrimitive for Direct3D 8. For Direct3D 9, it is pretty much the same, except that the BaseVertexIndex term is now in DrawIndexedPrimitive rather than SetIndices. See here. I should update that for DirectX 9.

Share this post


Link to post
Share on other sites
BaseVertexIndex - a number added to the indices read from the index buffer. If this was 5, and the index read was 2, vertex 7 would be used. This is useful if you concatenate two meshes into a vertex buffer and index buffer. Instead of offseting each index before copying into the buffer, you just remember how far into the vertex buffer your mesh starts.

minVertexIndex - the lowest index found in the relevant part of the IB.
If you were to refer to indices 0,1,2, 2,3,1, minIndex would be 0.
If you were to refer to 2,3,0, minIndex would be 0.
If you refered to 2,3,4, minIndex would be 2

numVerticies - the highest index found - the lowest + 1. The number of vertices that need transforming, without skipping any.
If you were to refer to indices 0,1,2, 2,3,1, numVerticies would be 4.
If you were to refer to 2,3,0, numVerticies would be 4.
If you refered to 2,3,4, numVerticies would be 3.

Note, these numbers always refer to the values in the IB, not the values offset by BaseVertexIndex

startIndex - the offset to start reading from the index buffer.
primCount - number of primitives to render.

The number of indices this consumes depends on the primitive type. For trilist, each primitive requires 3 indices. For tristrip, the first need 3 indices, plus 1 index for each next primitive.

Assuming the following IB and trilists...
IB = 0,1,2, 2,3,0, 4,5,6
If startIndex = 0, primcount = 1, we're referring to (0,1,2) (MI=0, NV=3)
If startIndex = 3, primcount = 1, we're referring to (2,3,0) (MI=0, NV=4)
If startIndex = 0, primcount = 2, we're referring to (0,1,2, 2,3,0) (MI=0, NV=4)
If startIndex = 3, primcount = 2, we're referring to (2,3,0, 4,5,6) (MI=0, NV=7)
If startIndex = 6, primcount = 1, we're referring to (4,5,6) (MI=4, NV=3)

Share this post


Link to post
Share on other sites
ItsDoh    162
If I'm remembering correctly, most of those things are optional too, meaning you can specify the entire vertex buffer as the length and it would still render correctly, it's just an optimization technique.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this