Reputation: 170
I usually use the Microsoft DirectX SDK (June 2010) which is deprecated. I download vs2015 which includes newest directx sdk and latest version FX11 on github. I don't know how to compile shader now.
before I can compile shader like this
ID3D10Blob *compiledShader = 0;
ID3D10Blob *compilationMsgs = 0;
result = D3DX11CompileFromFile("SolidColor.fx", 0, 0, 0, "fx_5_0", shaderFlags,
0, 0, &compiledShader, &compilationMsgs, 0);
if (compilationMsgs != 0)
{
MessageBox(0, (char*)compilationMsgs->GetBufferPointer(), 0, 0);
compilationMsgs->Release();
compilationMsgs = 0;
}
if (FAILED(result))
{
MessageBox(0, "error", 0, 0);
return false;
}
result = D3DX11CreateEffectFromMemory(compiledShader->GetBufferPointer(), compiledShader->GetBufferSize(),
0, m_pd3dDevice, &m_pFx);
compiledShader->Release();
if (FAILED(result))
{
MessageBox(0, "error", 0, 0);
return false;
}
m_pTechnique = m_pFx->GetTechniqueByName("ColorTech");
m_pFxWorldViewProj = m_pFx->GetVariableByName("gWorldViewProj")->AsMatrix();
But now how to compile shader? use D3DX11CompileEffectFromFile or D3DX11CreateEffectFromFile? Please give sample code,thank you.
Upvotes: 1
Views: 374
Reputation: 170
I know, it is so easy, just one function D3DX11CompileEffectFromFile
is OK.
//compile shader
ID3DBlob* errorBlob;
DWORD shaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined _DEBUG || defined DEBUG
shaderFlags = D3DCOMPILE_DEBUG;
#endif
hr = D3DX11CompileEffectFromFile(L"color.fx", nullptr, D3D_COMPILE_STANDARD_FILE_INCLUDE, shaderFlags,
0, m_pd3dDevice, &m_pFx, &errorBlob);
if (FAILED(hr))
{
MessageBox(nullptr, (LPCWSTR)errorBlob->GetBufferPointer(), L"error", MB_OK);
return hr;
}
m_pTechnique = m_pFx->GetTechniqueByName("ColorTech");
m_pFxWorldViewProj = m_pFx->GetVariableByName("gWorldViewProj")->AsMatrix();
Upvotes: 3