1
\$\begingroup\$

When rendering primitives in XNA, does it matter if I use DrawIndexedPrimitives() versus DrawUserIndexedPrimitives()? RB Whitaker uses the former, while Reimer's uses the latter.

From what I can tell, the intent is that if you're using a premade type that ships with XNA (such as VertexPositionNormalTexture), you should use the normal draw primitives function, while if you create a custom struct which satisfies IVertexType and/or VertexDeclaration, you should use the DrawUserPrimitives instead.

However, XNA places no such restriction on how they're used, and I am wondering why it wasn't just all rolled into one generic function to begin with.

\$\endgroup\$
1
\$\begingroup\$

DrawUserIndexedPrimitives() takes your vertices and indices from RAM, sends them to buffers on the GPU, then draws them. That means the data is sent to the gpu every time you call this function.

DrawIndexedPrimitives() requires you to create and set both a vertex and index buffer before calling it, and the data will stay on the gpu until those buffers are disposed. (See MSDN's example.)

So the latter takes a few extra lines to get working, but will perform at least as well as the former in every situation I can think of, and a lot better in most situations. This is true even if the vertex data changes every frame, because of dynamic buffers.

If you're only going to draw something once, then the User function is just easier to use. Otherwise, I would avoid it.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ So really, DrawUserIndexed just does a little more all at once but is slightly less flexible, but usually sufficient? Cool. By the way, where are you getting that information from? I glanced at the MSDN pages, but didn't seem to see anything of that sort. \$\endgroup\$ – Kyle Baran Oct 8 '14 at 0:57
  • \$\begingroup\$ DrawUserIndexed does more at once, but it does it all every time you call the function, where normal DrawIndexed can do most of it one time and one time only, making it much faster if you call it more than once. \$\endgroup\$ – Icy Defiance Oct 8 '14 at 2:04
  • 1
    \$\begingroup\$ About how I got the information: It was implied from the parameters the functions require, combined with my knowledge of how DirectX works. Then I googled it to be sure and found some blog and forum posts saying the same thing, which I figured was enough evidence. \$\endgroup\$ – Icy Defiance Oct 8 '14 at 2:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.