Jump to content
  • Advertisement
Sign in to follow this  
TaxCollector

need to speed up ID3DXSPRITE::Draw()

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm making an isometric 2D tycoon game. Every game cycle I have to draw the ground tiles, buildings, people, terrain transitions. To do that I have to run through this kind of loop a few times per game cycle.

#define mapSize 32
LPD3DXSPRITE d3dspt;

//draw groundtiles
for (int j=0; j<mapSize*4; j++)
{
	for (int i=0; i<mapSize; i++)
	{
		D3DXVECTOR3 center(0.0f, 0.0f, 0.0f);
		int plotX=i*IMAGESIZE+(j % 2)*(IMAGESIZE/2)-l;
		int plotY=j*(IMAGESIZE/4)-m-IMAGESIZE;
		D3DXVECTOR3 position(plotX,plotY, 1.0f); 
		d3dspt->Draw(tile[j].spri, NULL, &center, &position, D3DCOLOR_XRGB(255, 255, 255));
	}
}




In this loop I draw 4096 times and this takes 12ms. Is there a way I can speed it up? It's hogging cpu and creating noticable lag so I need to find a way to solve it. [Edited by - TaxCollector on April 16, 2010 5:54:15 PM]

Share this post


Link to post
Share on other sites
Advertisement
Well the first thing you need to do is figure out exactly where that time is being spent. It could be your code, it could code inside the the sprite class that transforms vertices on the CPU, or it could be time spent in the driver due to too many SetTexture or DrawPrimitive calls. Standard CPU profilers can help with this, as can graphics-specific tools like PIX or PerfHUD.

If you find that SetTexture/DrawPrimitive calls are what's slowing you down, you should try grouping multiple tiles onto a single texture. This will allow ID3DXSprite to batch multiple sprites into a single SetTexture/DrawPrimitive call.

Share this post


Link to post
Share on other sites
I ran some tests with PIX and it seems I have about 3000 SetTexture calls per frame when using 1920x1200 resolution. I'm pretty sure that's what is slowing me down.

Grouping tiles onto a single texture sounds like an interesting idea. Which methods should I look in to to achieve this?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!