1
\$\begingroup\$

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.

\$\endgroup\$

2 Answers 2

2
\$\begingroup\$

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.)

\$\endgroup\$
1
  • \$\begingroup\$ Neat! I hadn't heard of that interface before. (Hi Jaz!) \$\endgroup\$ Commented May 19, 2013 at 5:44
1
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .