Jump to content
  • Advertisement
Sign in to follow this  
realkiran

Trouble with ID3DXEffect::SetTexture( )

This topic is 3690 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 having a little trouble using ID3DXEffect::SetTexture( ). Here's a simplified version of my code:
//loop through each submesh and render
for(int i = 0; i < m_num_submeshes; i++)
{
        //set texture for submesh
        int texture_index = GetTextureIndexForSubmesh(i);
        shader->SetTexture("albedo_texture", m_textures[ texture_index ]);

        //draw
        m_mesh->DrawSubset(i);
}
Everything in the scene ends up being textured with only one texture. It seems like the SetTexture( ) call doesn't work fast enough to actually affect the shader. If this is the case, how should I be switching textures?

Share this post


Link to post
Share on other sites
Advertisement
You need to call Begin as well as a variable amount of BeginPass calls on the effect before rendering (and EndPass/End after that) so that the render state changes specified on the effect actually take place.

It is a little bit misleading to call your effect "shader", by the way; the effect might not set any shader states at all, and still be perfectly valid.

Share this post


Link to post
Share on other sites
Or, if you've already called BeginPass and haven't called EndPass yet, then you need to call CommitChanges() to send your changes to the device before rendering.

Share this post


Link to post
Share on other sites
Ah thank you both. I ultimately went with the CommitChanges() solution.

Quote:
"the effect might not set any shader states at all, and still be perfectly valid."
Could somebody explain this to me?

Share this post


Link to post
Share on other sites
Quote:
Original post by realkiran
Ah thank you both. I ultimately went with the CommitChanges() solution.

Quote:
"the effect might not set any shader states at all, and still be perfectly valid."
Could somebody explain this to me?


While an effect instance is frequently used to set active shader instances, this is not a mandatory activity for an effect. In your passes, you could do something else, like set some other render states such as alpha blending. The device would then keep using other states (and shaders) as they were before the application of the effect.

It is important to understand that the D3DX effect system is just an advanced device state manager (and a compiler configuration manager) on top of the "raw" device interfaces, nothing else.

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.

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!