# cutting down on DrawPrimitive() calls

This topic is 3626 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

from what i've read, DrawPrimitive calls are reallyu expensive, so i'm wondering if its possible to draw multiple primitives with a single call, i'll give you an example.. here's code to render 2 cubes

device->SetStreamSource(0,vBuffer,0,sizeof(triangleVertex));

//Transform The First Cube

worldTrans2();

// Draw the 1st cube

device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
device->DrawPrimitive(D3DPT_TRIANGLESTRIP,4,2);
device->DrawPrimitive(D3DPT_TRIANGLESTRIP,8,2);
device->DrawPrimitive(D3DPT_TRIANGLESTRIP,12,2);
device->DrawPrimitive(D3DPT_TRIANGLESTRIP,16,2);
device->DrawPrimitive(D3DPT_TRIANGLESTRIP,20,2);

//Transform the 2nd cube

worldTrans();

//Draw The Second Cube

device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
device->DrawPrimitive(D3DPT_TRIANGLESTRIP,4,2);
device->DrawPrimitive(D3DPT_TRIANGLESTRIP,8,2);
device->DrawPrimitive(D3DPT_TRIANGLESTRIP,12,2);
device->DrawPrimitive(D3DPT_TRIANGLESTRIP,16,2);
device->DrawPrimitive(D3DPT_TRIANGLESTRIP,20,2);


ok, i was wondering, since they're in the same vertex buffer, if there's a way i can make one draw call per cube, such as.. device->DrawPrimitive(D3DPT_TRAINGLESTRIP,0,12); i've tried it, but it doesn't draw all of them, is this possible to do?

##### Share on other sites
As one triangle strip, probably not (at least not without using degenerate triangles), but you can use an index buffer and a triangle list.

##### Share on other sites
In this case it would be pretty simple: either use separate triangles or add strip jumps... in either cases, it's a rather extreme case.

Furthermore, not all Draw calls are equally expensive, I wouldn't expect much performance difference in the first place considering the batch size is far from being optimal anyway.

Sadly enough, besides instancing, drawing dynamic content will always take multiple calls. For static content pre-transforming is your friend but things quickly go out of control as textures, shaders and such are changed over the primitives.

In this... pretty oversimplified case, a cube it's just a cube. It doesn't make sense to draw a face a time... but you're doing this because you want to have different color/textures for each face so you get the above picture.

##### Share on other sites
Just to pretty much reitterate what others have said; It's not really worthwhile trying to do this with triangle strips, in fact graphics hardware is often optimised to use indexed triangle lists. That would let you draw both cubes in a single DrawPrimitive() call.

As for DrawPrimitive() being expensive, that's not strictly speaking true (I know that even I say "DrawPrimitive() is expensive" some times). It's the batches that are expensive. I suppose it's possible that if you make two consecutive DrawPrimitive calls without modifying any other device state that the device driver could optimise that into a single batch, but to be honest I don't think that's likely.
Generally, cutting down on the number of DrawPrimitives is good though. There was a presentation somewhere (I think it was ATI?) that essentially said that making over 500 or so DP() calls per frame used up 100% of a 1 GHz CPU - all the CPU was doing was submitting batches to the driver, it didn't have time to do anything else. Obviously that was a while ago, but the concept is still the same.

##### Share on other sites

This topic is 3626 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628662
• Total Posts
2984095

• 10
• 9
• 9
• 10
• 21