Microsoft DirectX 8.0 (C++) |
Assembles an ASCII description of a shader into binary form, where the source file name is an ANSI string.
HRESULT D3DXAssembleShaderFromFileA( LPCSTR 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 |
D3DXAssembleShaderFromFile maps to either D3DXAssembleShaderFromFileA or D3DXAssembleShaderFromFileW, depending on the inclusion or exclusion of the #define UNICODE switch. Include or exclude the #define UNICODE switch to specify whether your application expects Unicode or ANSI strings.
The following code fragment shows how D3DXAssembleShaderFromFile is defined.
#ifdef UNICODE #define D3DXAssembleShaderFromFile D3DXAssembleShaderFromFileW #else #define D3DXAssembleShaderFromFile D3DXAssembleShaderFromFileA #endif
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.