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.

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?

share|improve this question
    
Take a look at D3DXCreateEffectFromFile. –  user000user Jun 9 at 12:52
add comment

1 Answer 1

up vote 4 down vote accepted

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

share|improve this answer
    
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? –  MisterArch Jun 9 at 16:11
    
The function supports binary effects, yes. Although not all the flags are supported (it's covered in the docs). –  Josh Petrie Jun 9 at 16:18
    
Thank you again! –  MisterArch Jun 9 at 16:47
    
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. –  Chuck Walbourn Jul 15 at 7:00
add comment

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.