Jump to content
  • Advertisement
Sign in to follow this  
ProgrammerDX

[D3D9] Is it recommended to clear unused SetTexture to NULL?

Recommended Posts

Posted (edited)

Hello,

Consider you render something with 2 textures:

SetTexture(0, <texture_ptr>);
SetTexture(1, <texture_ptr>);

 

After you render something with 1 texture:

SetTexture(0, <texture_ptr>);

 

Is it recommended to SetTexture(1, NULL)?

Edited by ProgrammerDX

Share this post


Link to post
Share on other sites
Advertisement

It's recommended to keep them assigned, like for instance a texture atlas (holding all textures) which is assigned to a slot once upon startup and kept there.. Because there's some overhead for each texture assignment call :)

Share this post


Link to post
Share on other sites

Hm I see, so Direct3D will not bother sending texture data to the second shader that doesn't use the second texture anyway.

What about SetRenderState, is this expensive to do?

SetRenderState( D3DRS_CULLMODE, D3DCULL_CW );
SetRenderState( D3DRS_CULLMODE, D3DCULL_CW );

Two rendering jobs that use the same Cull Mode, but sending the Render State twice. (In between the cull mode isn't changed). The question is is this expensive or doesn't cost anything (D3D doesn't do anything under the hood because it understands it already set this Cull Mode)?

Share this post


Link to post
Share on other sites

For renderstates etc. you'll want to only set them when they change, DirectX doesn't check that for you - so write a small wrapper that keeps track of stuff for you and only set states when needed :)

 

Share this post


Link to post
Share on other sites
Posted (edited)

Hm, I see.

I was doing GetRenderState( D3DRS_CULLMODE ) on a "PURE DEVICE" and it actually returns the correct value that I set before. However the MSDN documentation says GetRenderState() can't be used for Pure Device. Do you know why it's working for me anyway?

https://docs.microsoft.com/en-us/windows/desktop/api/d3d9/nf-d3d9-idirect3ddevice9-getrenderstate

Edited by ProgrammerDX

Share this post


Link to post
Share on other sites

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  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!