Microsoft DirectX 8.1 (C++) |
Assembles an ASCII description of a shader into binary form.
HRESULT D3DXAssembleShaderFromFile( LPCTSTR pSrcFile, DWORD Flags, LPD3DXBUFFER* ppConstants, LPD3DXBUFFER* ppCompiledShader, LPD3DXBUFFER* ppCompilationErrors );
If the function succeeds, the return value is D3D_OK.
If the function fails, the return value can be one of the following values.
D3DERR_INVALIDCALL |
D3DXERR_INVALIDDATA |
E_OUTOFMEMORY |
This method supports both Unicode and ANSI strings.
The following example wrapper function, PreprocessAndAssembleShaderFromFile, shows how you can invoke the C preprocessor on your vertex shader code before invoking the assembler with D3DXAssembleShaderFromFile.
HRESULT PreprocessAndAssembleShaderFromFile( LPCSTR szFile, DWORD Flags, LPD3DXBUFFER* ppConstants, LPD3DXBUFFER* ppCode, LPD3DXBUFFER* ppErrors) { char szPath[_MAX_PATH]; char szTemp[_MAX_PATH]; char szCmd [_MAX_PATH]; GetTempPath(sizeof(szPath), szPath); GetTempFileName(szPath, "vsa", 0, szTemp); _snprintf(szCmd, sizeof(szCmd), "cl /nologo /E %s > %s", szFile, szTemp); if(0 != system(szCmd)) return D3DERR_INVALIDCALL; return D3DXAssembleShaderFromFile(szTemp, Flags, ppConstants, ppCode, ppErrors); }
Note that for this function to work you must have Microsoft® Visual C++® installed and your environment set up so that Cl.exe is in your path.
Header: Declared in D3dx8core.h.
Import Library: Use D3dx8.lib.