Sign in to follow this  

XNA setting same texture over and over... slow!

This topic is 3728 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 was checking out PIX to see what my program was doing and I noticed SetTexture over and over again, as expected really. I also noticed it's time consuming, verifying something I already knew. Before I started using XNA I called SetTexture myself, so if I was going to use the same texture over and over I would only set it once. When drawing the tree models, however, XNA seems to set it every time. It even sets one texture 3 times for each model since 3 meshes use it... all in a row. Is there some kind of solution to this? ~ C

Share this post


Link to post
Share on other sites
BTW... when drawing 300 trees in a row it's doing several things over and over that it shouldn't need to since they don't change. Every mesh has its own copy of the effect. Seems like I should be able to set up the effect and then draw 300 trees without doing it again 299 extra times.

These things over and over seem horribly redundant and wasteful...

SetTexture(0, 0x05D4B400)
SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_NONE)
SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_NONE)
SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE)
SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_MIRROR)
SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_MIRROR)
SetVertexDeclaration(0x0A400708)

Share this post


Link to post
Share on other sites
Are you using the default Model class? If so that could be why. The default Model class is set up to be independently used; not for batching. There was a new tutorial released showing custom model classes at the creators.xna.com site. My suggestion would be to create a custom model class that takes into account texture sharing and effect sharing.

The default Model class was designed to be very basic and the overall structure was just put there to give a jump-start for beginners. It's rather easy to create a custom model class and then you could easily batch together rendering models and parts of models without switching all those states.

Share this post


Link to post
Share on other sites

This topic is 3728 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this