Is calling d3dDevice-SetTexture() costly?

Started by
3 comments, last by Drakex 18 years, 8 months ago
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
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.
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?
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.
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.
_______________________________________________________________________Hoo-rah.

This topic is closed to new replies.

Advertisement