Jump to content
  • Advertisement
Sign in to follow this  
johnnyBravo

Is calling d3dDevice-SetTexture() costly?

This topic is 4846 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 I'm organising the way vertices get rendered in my Render class, eg litVertices, unLitVertices, textures And i was wondering if calling d3dDevice->SetTexture() is very costly, because I have the choice of either calling: d3dDevice->SetRenderState(D3DRS_LIGHTING, TRUE/FALSE); or d3dDevice->SetTexture(0, img); ..repeatedly. So which function is more costly in performance wise? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Hi there JohnnyBravo,
How are you doing?

[The problem]
"i was wondering if calling d3dDevice->SetTexture() is very costly"

[The solution]
As far as performance goes, you should keep state changes batched/group. This means that when you set a texture, make sure that you render everything that uses this texture and the other states that you have set. This is the SDK performance tips.

Performance Tips

I hope this helps. Keep cool.

Share this post


Link to post
Share on other sites
I'm good thanks, how are you?

Say some vertices use
1. textureA and no lighting
2. textureB and lighting
3. textureA and lighting

See how it kinda crosses over, so like what should I sacrifice, the setting of the texture or the setting of the lighting?

Share this post


Link to post
Share on other sites
Hi there JohnnyBravo,
How are you doing?

Just a quick answer :)
The DX Docs specifically refer to the use of lights as they involve per-vertex computations. This means that you should keep your light state changes to a minimum.

"Because lights add a per-vertex cost to each rendered frame, you can improve performance significantly by being careful about how you use them in your application. Most of the following tips derive from the maxim, "the fastest code is code that is never called."

I hope this helps
Keep cool.

Share this post


Link to post
Share on other sites
Actually I don't think that turning on and off lighting will affect speed very much at all. The lighting is calculated after the triangles are transformed, so unless you draw something, there will be no overhead from the lighting system. So

SetRenderState(Light, True)
Draw
SetRenderState(Light, False)
Draw
SetRenderState(Light, True)
Draw

Should, in theory, be just about as fast as

SetRenderState(Light, False)
Draw
SetRenderState(Light, True)
Draw
Draw

Since the same number of vertices are getting lit. Of course, there is a small overhead in setting the state itself, but nothing to worry about performancewise.

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!