drawprimitive 10000 times

Started by
24 comments, last by blue-ice2002 19 years, 2 months ago
hello, i have a question,or maybe a problem.For some reason,i need to draw trianglestrips. s=-512; D3DXMatrixTranslation (&matTranslation, s,384.0f, 0.0f); s--; for(int v=0;v<10000;v++) { g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, x, 2); x+=4; } i do this in the main game loop,every iteration.Calling this function makes the program run slowly i think? Is it the problem? and i also make translation to scroll my tiles.Please help!!!
Advertisement
Yes.. it's probably one reason for it to run slow.
You should use arrays if you whant to draw that many...

/martin
Thats far too many DP calls.

If i knew more of how ur code operates i would suggest optimisation ideas.

ace
Quote:Original post by blue-ice2002
s=-512;
D3DXMatrixTranslation (&matTranslation, s,384.0f, 0.0f);
s--;
for(int v=0;v<10000;v++)
{
g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, x, 2);
x+=4;
}

From looking at the code, you don't actually change the matrix for each pair of triangles drawn. Unless you intentionally *dont* want them to be connected (are each pair a seperate entity?) you can reduce that down to a single draw call unless I'm much mistaken:
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 20000 );

If they are unconnected, and rendering them all together screws things up, convert them to triangle lists instead.

Bottom line - get rid of that loop! it is what is killing you, and while you have it there you're gonna get sucky performance [smile].

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

If you use PureDevice during hardware device creation then DrawPrimitive Calls have generally little or no overhead. Anyway I don't think that's your direct problem at all (although you should keep your draw primitive calls to a minimum), it could be a number of things such as overdraw, but you said they are tiles. Anyway I don't understand the need for a loop that does absolutely nothing except increase the start index by 4 , i mean you are not transforming inside the loop or applying different textures ?? maybe i'm missing something. If you have more code pls. post more.
-------------Become part of developing the specifications of a new language. Visit CodeBASIC.org
Quote:Original post by Codemonger
If you use PureDevice during hardware device creation then DrawPrimitive Calls have generally little or no overhead. Anyway I don't think that's your direct problem at all (although you should keep your draw primitive calls to a minimum), it could be a number of things such as overdraw

hmm, gotta say I disagree... rendering 2 triangles per call (whatever the type of device) will probably make ATI and Nvidia developers cry [smile]. Read up on some of their technote presentations on how to get the most from their respective hardware. I don't have time to search through them all right now - but numbers like 1000-triangles-per-call, no more than 10,000 calls per frame etc pop-up. I don't think I've ever read anywhere that, under any circumstances, a DP call is "generally no overhead" [sad]. Sorry!

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

WAAAAH WAAAAAAAAAAAAH [crying]
Quote:Original post by KrazeIke
WAAAAH WAAAAAAAAAAAAH

I just found that list of statistics in one of the other slides ("Save The Nanosecond").

Interestingly to this thread, it says "No Occurence of Lock(0), DrawPrimitive(), DPUP(), CreateVB() ETC". Already broken one of those then [smile].

Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

In the one I posted, it says "DrawPrimitive() permissible if warranted."
Quote:In the one I posted, it says "DrawPrimitive() permissible if warranted."

Yeah, having read on a bit further - thats a more relevent paper than the one I quoted. Got a lot of good stuff, although the numerous batch/triangle graphs are too cluttered to be easily readable.

I like Slide #14 - "Small batches murder your performance" [smile]

Cheers,
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

This topic is closed to new replies.

Advertisement