Archived

This topic is now archived and is closed to further replies.

Performance problem...

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

Recommended Posts

I've been working on a simple 2D engine in Direct3D.. Works great but get very choppy when I create lets say 200 sprites. I get about 800 FPS when I draw one. but when I draw 200 i get 60-70 fps. 2 faces * 200 sprites = 400 faces.(not much) Code: my draw code to place a 2D sprite on screen..


void CObject2D::Draw(float X,float Y,float Z,float A,float S)
{
CObject2D_D3DDevice->SetStreamSource(0, VertexBuffer, sizeof(PANEL_CUSTOMVERTEX));

if(Texture != NULL)
{
CObject2D_D3DDevice->SetTexture(0, Texture);
CObject2D_D3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
}
else
{
CObject2D_D3DDevice->SetTexture(0, NULL);
//ERROR

}

D3DXMatrixIdentity(&World);

D3DXMatrixScaling(&Temp,S,S,S);
D3DXMatrixMultiply(&World,&World,&Temp);
D3DXMatrixTranslation(&Temp, X, Y, Z);
D3DXMatrixMultiply(&World,&World,&Temp);
D3DXMatrixRotationZ(&Temp,A);
D3DXMatrixMultiply(&World,&World,&Temp);
D3DXMatrixRotationY(&Temp,-testvar);
D3DXMatrixMultiply(&World,&World,&Temp);

CObject2D_D3DDevice->SetTransform(D3DTS_WORLD, &World);

//	CObject2D_D3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

}

my computer specs: 1800 mhz P4 GeForce 3..

Any idea what I can do to speed this up?

thanks


[edited by - Snash on July 27, 2002 7:14:19 PM]

Share on other sites
I think you problem is that your only rendering two polygons per call with DrawPrimitive.
The graphics card does prep work for each call, which will seriously kill your performance.

I would combine the sprites into one buffer, so that you can render them all with one call to DrawPrimitive

Share on other sites
I see.. How can I put every sprite in the same Buffer? I mean, then I can''t use matrixes and stuff like that.?
since every sprite is the same object.. I might be wrong.

Share on other sites
Well and you are setting the texture for each Sprite which is something that will kill your performance no matter what.
But I too dont have a clue of how to use one buffer for several independent moving sprites.
Although it could be a viable method for an army of 200 soldiers that are exercising .

Im Anfang war die Tat...
Faust

Share on other sites
i think that if you multiply the vertices of the sprite by the tranformed matrix it´ll be amazing. my 3d knowledge is small but i think this thing might work.
so you have your world matrix, and you multiply the vertices of the sprite by it and then copy the results to the buffer and do the same to other sprites and add them to the same buffer and.. then draw.

if i´m not wrong there are some d3dx functions for vector*matrix.

May The Gzoo Be With You!
~Lord Gzoo

Share on other sites
So what you suppose is:
Transform the sprites local coordinates into world coordinates and then add it to the vb?
But won`t it be affected by other transformations?

Im Anfang war die Tat...
Faust

Share on other sites
Thanks for the info.

I tried to move my SetTexture out of the drawing..
so it''s only called Once.. This gave me a boost of 4-8 fps. Not enough

Share on other sites
To make it easier. First you could only try to use one global vb! So you won''t have to call SetStreamSource for each Sprite! I think that would boost it a lot.

Share on other sites
I thought so. But I tried that to, no real change.

Share on other sites
BTW: would it be possible to transform the vertices of all my sprites by hand and stuff them into a VB and have D3D render them as transformed Vertices without them really being ones?

Im Anfang war die Tat...
Faust

• 9
• 13
• 40
• 15
• 11