Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

In Direct3D 9 effect files you can write a sampler state that specifies a texture variable to use, like

Texture2D g_texSkyDome;
SamplerState g_samplerSkyDome
{
    Texture = <g_texSkyDome>;
    // ...other sampler states...
};

Using the ID3DXEffect API, is it possible to extract the texture variable assigned to a given sampler state variable? I've been searching the docs but can't find anything about this.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

I still haven't found an "official" way to do this via the API. In fact, there is no provision for extracting any of the contents of a SamplerState block - either the texture or any of the state settings.

There are some hacky, roundabout ways one could do this:

  1. You could give each sampler state an annotation that names the corresponding texture variable, or vice versa. A variant on this approach is to set up a naming convention, e.g. the texture is named texFoo and sampler samplerFoo. Of course, nothing would prevent these from getting out of sync with the actual texture variable assignments.

  2. Scan the HLSL file for SamplerState definitions and parse them yourself. You'd probably want to run it through the preprocessor first. The parser doesn't have to be too complicated if you make a few simplifying assumptions, e.g. that the word "SamplerState" never occurs anywhere but the definition of a sampler variable.

  3. You could create a dummy texture, assign it to a texture variable with ID3DXBaseEffect::SetTexture, then run through all the texture units with IDirect3DDevice9::GetTexture and see which one ended up with your dummy texture. You could then correlate this with the sampler index obtained by ID3DXConstantTable::GetSamplerIndex from each sampler variable in the effect. You could also use IDirect3DDevice9::GetSamplerState to get the rest of the sampler state.

share|improve this answer

Similar to solution #3 in your answer, but perhaps a little cleaner in that no device state will be modified: you could create an ID3DXEffectStateManager that no-ops all of the operations, but tracks the index to which your dummy texture was assigned. (You could also use your custom state manager to snoop the sampler state settings.)

share|improve this answer
    
Neat! I hadn't heard of that interface before. (Hi Jaz!) –  Nathan Reed May 19 '13 at 5:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.