Jump to content
  • Advertisement
Sign in to follow this  
DeadlyDan

ID3DXSprite slow performance

This topic is 3905 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

Hi guys, I'm using the ID3DXSprite in Direct3D8 for rendering textures. The problem is, that i get a big performance hit when rendering textures loaded from a file. The performance hit is when ID3DXSprite::Draw is being called. I know it isn't anything in my code that i'm aware of, since i've used D3DXCreateTextureFromFileInMemory for a (blank) texture and the performance was fine. It is fine with about 1 or 2 images but any more and i start to see the framerate drop quickyly... Here is my function call for loading the texture:
D3DXCreateTextureFromFileEx ( D3D, m_szFilename.c_str ( ), D3DX_DEFAULT, D3DX_DEFAULT,
								1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT,
								0, NULL, NULL, &m_pTexture );
And here is my call for rendering the sprite:
m_pSprite->Begin ( ); 
m_pSprite->Draw ( m_pTexture, &offset, &scal, NULL, NULL, &position, 0xFFFFFFFF );
m_pSprite->End ( ); 
The images i'm trying to load are PNG and TGA images with alpha channels. Any help is greatly appreciated, thanks :)

Share this post


Link to post
Share on other sites
Advertisement
If you aren't doing multiple Begin() End() blocks, are you creating and destroying some sort of cDrawableObject which has those m_pTexture and m_szFileName members every time you render a frame?

Share this post


Link to post
Share on other sites
If possible, I'd advise moving to DX9. The D3DX classes (ID3DXSprite and ID3DXFont in particular) have been optimised a fair bit since DX8.

Aside from that, I don't really have anything to add over the previous two posters. Make sure you're not creating and destroying the sprite every time you draw particularly; You should have one ID3DXSprite for the life of your device, and one ID3DXFont for each different font face/size for the life of your device (If you use fonts).
You should never be creating or destroying resources at render time (With very few exceptions), only at init / shutdown time.

Share this post


Link to post
Share on other sites
Thanks for the help guys, it seems all the suggestions are things i've already taken into account. I've managed to improve the speed-hit a bit by decreasing the size of the textures. I can display about 30-40 sprites now with hardly any FPS hit.

Thanks. :)

Share this post


Link to post
Share on other sites

Hi,

I noticed that your D3DXCreateTextureFromFileEx sets mipmap level count to 1. Usually using mipmapping will improve the performance (also make images blurrier) as the accelerator is able to choose a texture size appropriate to the output size. As you mentioned, decreasing the texture size improved your performance.

Of course, if you don't need scaling and you'll know the final size of the sprites, one mipmap level is enough and saves (a little) of memory.

Cheers!

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!