Archived

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

Snash

Performance problem...

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));
    CObject2D_D3DDevice->SetVertexShader(PANEL_D3DFVF_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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 don`t 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 this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites
Before you create the vb you transform the vectors of your vertexes with the D3DXVectorMatrixMultiply func. Then you have a buffer of transformed vertexes and you can copy them into the vb!

Share this post


Link to post
Share on other sites