我在加载效果文件时遇到问题。我对D3DX10CreateEffectFromFile()的调用与S_OK一起传递,但是函数调用后传入的ID3D10Effect * I仍然为null。这是我的来源(我一直在调试,所以有注释掉的东西,但相关的代码仍然在执行)。
HRESULT hResult;
void fxMgr::LoadEffectFile( char* fxFileName,
char* techniqueName,
ID3D10Effect* pEffect,
dgInputLayoutType layoutType)
{
/*if (L"fx"!=GetFileExtension(fxFileName))
{
pEffect=NULL;
throw dgGameError(L"Could not load specified shader!");
return;
}
*/
if (NULL==fxFileName)
{
pEffect=NULL;
m_pCurEffect=NULL;
m_pCurEffectTechnique=NULL;
m_pCurPass=NULL;
}
return;
HRESULT r = 0;
DWORD shaderFlags = 0;//D3D10_SHADER_ENABLE_STRICTNESS;
/* #if defined( DEBUG ) || defined( _DEBUG )
// Turn on extra debug info when in debug config
shaderFlags |= D3D10_SHADER_DEBUG;
#endif
*/
ID3D10Blob* pErrors = NULL;
// Create the effect
r = D3DX10CreateEffectFromFileA(fxFileName , NULL, NULL, "fx_4_0", shaderFlags, 0,
Graphics()->GetDevice(), NULL, NULL, &pEffect, &pErrors, NULL);
if(pErrors)
{
//MessageBoxA(0, (char*)pErrors->GetBufferPointer(),0, 0);
SafeRelease(pErrors);
}
hResult=r;
/*if(FAILED(r))
{
pEffect=NULL;
return;
}*/
m_pCurEffect=pEffect;
m_pCurEffectTechnique=pEffect->GetTechniqueByName(techniqueName);
m_pCurPass=m_pCurEffectTechnique->GetPassByIndex(0);
if (layoutArray[layoutType]==NULL)
{
D3D10_PASS_DESC descPass;
m_pCurPass->GetDesc(&descPass);
switch(layoutType)
{
case LAYOUT_POS_NORMAL_TEX:
if(1)
{
D3D10_INPUT_ELEMENT_DESC layout[]=
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
{"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT, D3D10_INPUT_PER_VERTEX_DATA, 0},
{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT,D3D10_INPUT_PER_VERTEX_DATA, 0}
};
UINT uiNumElements = sizeof(layout)/sizeof(layout[0]);
Graphics()->GetDevice()->CreateInputLayout( layout, uiNumElements, descPass.pIAInputSignature,
descPass.IAInputSignatureSize, &PosNormalTex);
}
break;
case LAYOUT_POS_TAN_NORMAL_TEX:
if (1)
{
D3D10_INPUT_ELEMENT_DESC layout[]=
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
{"TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT, D3D10_INPUT_PER_VERTEX_DATA, 0},
{"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT, D3D10_INPUT_PER_VERTEX_DATA, 0},
{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT,D3D10_INPUT_PER_VERTEX_DATA, 0}
};
UINT uiNumElements = sizeof(layout)/sizeof(layout[0]);
Graphics()->GetDevice()->CreateInputLayout( layout, uiNumElements, descPass.pIAInputSignature,
descPass.IAInputSignatureSize, &PosTanNormalTex);
}
break;
case LAYOUT_POS:
if (1)
{
D3D10_INPUT_ELEMENT_DESC layout[]=
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0}
};
UINT uiNumElements = sizeof(layout)/sizeof(layout[0]);
Graphics()->GetDevice()->CreateInputLayout( layout, uiNumElements, descPass.pIAInputSignature,
descPass.IAInputSignatureSize, &Pos);
}
break;
case LAYOUT_IGNORE:
break;
default:
throw dgGameError(L"Invalid input layout type specified: cannot properly load shader!");
break;
}
}
}
复制/粘贴有点破坏了空白,对不起!在此先感谢您的帮助!这个让我准备将视觉工作室刻录到光盘上,这样我就可以把它扔出窗外了......
答案 0 :(得分:1)
您应该为Direct3D 10设备启用调试,然后查找任何相关输出。
此外,您应该检查所有HRESULT值是否失败......
请注意,如果您转移到Direct3D 11,那么您将拥有效果11的完整源代码,因为它位于CodePlex而不是操作系统的一部分。