2
\$\begingroup\$

I started working with shaders recently in DirectX9. I noticed that there is a D3DXCompileShaderFromFile function for IDirect3DVertexShader9 and pixel shader. Which compiles the shader and gives you the compiled code so you can put that into a file and then read it.

But is there a way to do it with the ID3DXEffect or is IDirect3DVertexShader9 the only way?

\$\endgroup\$
1

1 Answer 1

4
\$\begingroup\$

Use the D3DXCreateEffectFromFile function.

The parameter list is a bit daunting, but most of the parameters are optional and can support null values. Do note, however, the comment for the flags parameter:

If pSrcFile contains a text effect, flags can be a combination of D3DXSHADER Flags and D3DXFX flags; otherwise, pSrcFile contains a binary effect and the only flags honored are D3DXFX flags. The Direct3D 10 HLSL compiler is now the default. See Effect-Compiler Tool for details.

Typical usage would be:

LPD3DXEFFECT effect = nullptr;
LPD3DXBUFFER errors = nullptr;
HRESULT result = D3DXCreateEffectFromFile(
  direct3DDevice,
  "Path/To/Your/Effect.fx",
  nullptr,
  nullptr,
  0,
  nullptr,
  &effect,
  &errors
)

If the HRESULT isn't successful, compilation errors can be recovered from the errors buffer (it's just a string; you can case the void * returned from GetBufferPointer).

\$\endgroup\$
3
  • \$\begingroup\$ Thanks for the answer. I currently use this function to create the effects. Just to make sure I've got everything right. If I compile the effect with the Effect-Compiler tool and then try to load it with this function it will work fine correct? \$\endgroup\$
    – MisterArch
    Commented Jun 9, 2014 at 16:11
  • \$\begingroup\$ The function supports binary effects, yes. Although not all the flags are supported (it's covered in the docs). \$\endgroup\$
    – user1430
    Commented Jun 9, 2014 at 16:18
  • \$\begingroup\$ Note you can actually use D3DCompile directly and not use D3DX at all to compile. Of course, if you are using the FX9 framework, you have to use D3DX9. \$\endgroup\$ Commented Jul 15, 2014 at 7:00

You must log in to answer this question.

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