DrawIndexedPrimitive help
by Vincent BILLET · in Torque Game Engine Advanced · 09/11/2005 (3:27 am) · 6 replies
Can someone, for my next project, give me some explanation about drawIndexedPrimitive.
What's drawIndexedPrimitive?
When calling indexed primitive?
What are these parameters?
Why do we need drawIndexedPrimitive?
Simply drawIndexedPrimitive How To...
Thanx in advance...
What's drawIndexedPrimitive?
When calling indexed primitive?
What are these parameters?
Why do we need drawIndexedPrimitive?
Simply drawIndexedPrimitive How To...
Thanx in advance...
#2
09/11/2005 (5:31 am)
Westy, thank you for your reply, I checked ou DirectX documentation... But I don't understand utility of this function (sorry for my ignorance)... I'm going to check Torque source code in hope to find reasons of these calls. But if someone can give me a better explanation, I'll be happy.
#3
The idea of this is that you can balance the vertex processing to be optimal. Getting the right number draw primitve calls with the number of vertices can sometimes be crucial.
09/11/2005 (6:26 am)
Ok, it just means it uses indices to a vertex list to draw.The idea of this is that you can balance the vertex processing to be optimal. Getting the right number draw primitve calls with the number of vertices can sometimes be crucial.
#4
Say I have an array of vertices:
Vertex v[6];
v[0] = { 0, 0, 0 };
v[1] = { 0, 1, 0 };
v[2] = { 1, 0, 0 };
v[3] = { 0, 0, 0 };
v[4] = { 0, 1, 0 };
v[5] = { 1, 0, 1 };
drawPrimitive(v); // This would draw two triangles with a couple of the vertices shared
Notice that 0 == 3 and 1 == 4
I could get rid of 3 and 4 and index them like this and index them to come up with the same two triangles like this:
Vertex v[4];
v[0] = { 0, 0, 0 };
v[1] = { 0, 1, 0 };
v[2] = { 1, 0, 0 };
v[3] = { 1, 0, 1 };
U16 index[6] = { 0, 1, 2, 0, 1, 3 };
drawIndexedPrimitives(v, index);
Get the idea? Because of the way meshes work, there's generally a lot of shared vertices. In fact, if the mesh is closed you can pretty much guarantee that every vertex will be used at least twice, more often three times or more.
I could port the TSE version of the fxRenderObject to use indexed primitives instead of regular primitives if you'd like. That might make a pretty easy-to-follow tutorial.
09/11/2005 (3:19 pm)
Simply put (and this is pseudo code and is only just to get the point across... not to be used as a tutorial)Say I have an array of vertices:
Vertex v[6];
v[0] = { 0, 0, 0 };
v[1] = { 0, 1, 0 };
v[2] = { 1, 0, 0 };
v[3] = { 0, 0, 0 };
v[4] = { 0, 1, 0 };
v[5] = { 1, 0, 1 };
drawPrimitive(v); // This would draw two triangles with a couple of the vertices shared
Notice that 0 == 3 and 1 == 4
I could get rid of 3 and 4 and index them like this and index them to come up with the same two triangles like this:
Vertex v[4];
v[0] = { 0, 0, 0 };
v[1] = { 0, 1, 0 };
v[2] = { 1, 0, 0 };
v[3] = { 1, 0, 1 };
U16 index[6] = { 0, 1, 2, 0, 1, 3 };
drawIndexedPrimitives(v, index);
Get the idea? Because of the way meshes work, there's generally a lot of shared vertices. In fact, if the mesh is closed you can pretty much guarantee that every vertex will be used at least twice, more often three times or more.
I could port the TSE version of the fxRenderObject to use indexed primitives instead of regular primitives if you'd like. That might make a pretty easy-to-follow tutorial.
#5
There's also a lot of tutorials on the subject, I'd recommend checking them out. :)
09/11/2005 (6:53 pm)
There's no rocket science here. It's the same as glDrawElements, D3D::DrawIndexedPrimitive, and many other similar APIs. You give it some verts, you give it some indices, and it draws the verts you index, in order, according to the primitive type you specify.There's also a lot of tutorials on the subject, I'd recommend checking them out. :)
#6
09/12/2005 (12:31 am)
@Tony and Ben : Thank you for your answers... All is clear Now. In fact it's very usefull...:)
Torque Owner Westy