All loading and parsing for shader effect files takes place in the parser. A typical function that uses the new method of IEffectParser
is shown in the following code sample:
bool MaxEffectParser::LoadEffectFile(LPVOID pDevice, IEffectManager * em,TCHAR * fileName, bool forceReload)
{
int index;
HRESULT hr;
LPDIRECT3DDEVICE9 pd3dDevice = static_cast<LPDIRECT3DDEVICE9>(pDevice); //Used later when we have a Dx10 version of the parser.
bDirectX9 = em->GetDirectXVersion() == IEffectManager::kDirectX9?true:false;
index = IDxShaderCache::GetIDxShaderCache()->FindShader(fileName);
if(index<0)
{
D3DXMACRO macros[5 =
{
{ "_3DSMAX_", NULL },
{ "_MAX_",NULL },
{ "MAX",NULL },
{ "3DSMAX",NULL },
{ NULL,NULL }
};
hr = D3DXCreateEffectFromFile(pd3dDevice,fileName,macros,NULL,NULL,NULL,&m_pEffect,NULL);
if(FAILED(hr) || !m_pEffect){
return false ;
}
IDxShaderCache::GetIDxShaderCache()->SetShader(fileName,(LPCVOID)m_pEffect);
}
else
{
m_pEffect = (LPD3DXEFFECT) IDxShaderCache::GetIDxShaderCache()->GetShader(index);
}
return true;
}