Archived

This topic is now archived and is closed to further replies.

Is it ok to SetTexture with a NULL parameter?

This topic is 5673 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''m getting some left over texture(s) that are messing up my models that only have Materials and no textures. So is it ok to do a m_pd3dDevice->SetTexture( 0, NULL); call before I draw these material only models? Or is there a better way to clear settings and make sure i''m not getting left over texture settings messing up material only models?

Share this post


Link to post
Share on other sites
ei i think you could try this instead,

SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE);

or if it didn''t work, probably there''s a flag in there that would disable the texture,

Share this post


Link to post
Share on other sites
Thanks for the help! Both techniques seem to work, but is one method more proper than the other? Using the SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE); or to just do a SetTexture( 0, NULL); ?

Share this post


Link to post
Share on other sites
G''day!

If textures are conflicting with your drawing, then your states are set up wrong, and that''s where you should do the fix.

I''m assuming at some point you set the TextStageState to use the texture, you should be changing that to whatever is appropriate.

If your states are attempting to read the texture, setting it to NULL may work on some drivers, and not on others.

Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
Here''s what the DirectX documentation has to say about SetTexture:
quote:

This method increments the reference count of the texture surface being assigned and decrements the reference count of the previously selected texture if there is one. When the texture is no longer needed, set the texture at the appropriate stage to NULL. Failure to do this results in a memory leak.



So: yes, it''s ok (and more than ok) to to SetTexture->(0,NULL)

-Neophyte

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GED d- s:+ a- C++$ UL++ P++ L++ E W+ N+ o K? w !O M--(+) V-- PS+
PE Y+ PGP t-- 5++ X+ R(+) rv+(++) b+++ DI+ D(+) G e+>++ h r--> y+
----- END GEEK CODE BLOCK-----
geekcode.com

Share this post


Link to post
Share on other sites
Ahh, somebody beat me to it In fact, you should always call SetTexture with a NULL value if you''ve used textures to render that frame (call before the EndScene). Otherwise, you''ll get small memory leaks. The same goes for SetStreamSource.



Jim Adams
home.att.net/~rpgbook
Author, Programming Role-Playing Games with DirectX

Share this post


Link to post
Share on other sites
Ahh, lots of good info, thanks for letting me know it decrements the texture reference, somehow I had glossed right over that.

Drunken Hyena - these are the SetTextureStageState''s i''m using, any suggestions what would be the appropriate Set''s afterwards to undo them and get things back to normal?


  
m_pd3dDevice->SetTexture( 0, m_ppMeshTextures[i]);

m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
m_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );

m_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );

m_pd3dDevice->SetRenderState(D3DRS_TEXTUREFACTOR, dwTransparency);

// Draw the mesh subset

m_pMesh->DrawSubset( i );

m_pd3dDevice->SetTexture( 0, NULL); //Just added this, thanks for the info

m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_CURRENT);
m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );



I was told a while back that doing
SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_CURRENT);
was the best way to get the texturestagestate back to what it was previously, but now reading up on that a little better, i''m not so sure.

Share this post


Link to post
Share on other sites