Jump to content
  • Advertisement
Sign in to follow this  
wease

Help writing efficient direct3d 2d code. Will this slow stuff down?

This topic is 4899 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 want to make efficient code. Is it bad to use multiple LPD3DXSPRITE sprites, one for each animation? I know that I could use just one sprite and if my screen has several moving animations, I could use that sprite to draw each animation. Or, I could use a separate sprite for each animated object. I'm also curious about loading a lot of textures for animations (ie, like loading 150 animation .tga's for the main character or something). Is this bad? Should I load textures just before rendering? It seems to me like this might be slow.

Share this post


Link to post
Share on other sites
Advertisement
I'd use 1 sprite interface, and as few textures as possible.

Lets say you have 100 sprites, 50 with one texture, and 50 with another. It's much faster to ask D3D to draw the 50 sprites with the same texture, then the next 50 with the second texture, than it is to ask it to draw 1 with texture 1, 1 with texture 2, another 1 with texture 1, etc. This results in 100 texture changes, and 100 draw calls, rather than 2 texture changes and 2 draw calls.

D3DXSprite can do this sorting for you if you use the sprite begin and end calls and pass in the correct flags. I'm not sure how D3DXSprite behaves when using multiple sprites, ie: whether it batches between sprite interfaces or not. I'd guess not, which is why I say use 1 sprite interface.

As for animation, DO NOT MAKE 150 TGAs!!! Put the 150 frames into 1 TGA (or some small number of TGAs). Make each TGA a power of 2 size, such as 1024x1024, or 2048x1024, or 2048x2048. Pack as many sprites into a texture page as possible. This allows D3D to draw these sprites together. Once you get a game of a decent size this becomes a critical issue.

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!