Game Development Reference
In-Depth Information
Compiling a shader file is done with this helper function: CompileShader() :
HRESULT CompileShader(
LPCSTR pSrcData,
SIZE_T SrcDataLen,
LPCSTR pFileName,
LPCSTR szEntryPoint,
LPCSTR szShaderModel,
ID3DBlob** ppBlobOut )
{
HRESULT hr = S_OK;
DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
// Set the D3DCOMPILE_DEBUG flag to embed debug information in the shaders.
// Setting this flag improves the shader debugging experience, but still
// allows the shaders to be optimized and to run exactly the way they will
// run in the release configuration of this program.
dwShaderFlags |= D3DCOMPILE_DEBUG;
#endif
ID3DBlob* pErrorBlob;
hr = D3DX11CompileFromMemory( pSrcData, SrcDataLen,
pFileName, NULL, NULL, szEntryPoint, szShaderModel,
dwShaderFlags, 0, NULL, ppBlobOut, &pErrorBlob, NULL );
if( FAILED(hr) )
{
if( pErrorBlob != NULL )
OutputDebugStringA( (char*)pErrorBlob->GetBufferPointer() );
if( pErrorBlob ) pErrorBlob->Release();
return hr;
}
if( pErrorBlob )
pErrorBlob->Release();
return S_OK;
}
This helper function was lifted almost verbatim from the Direct3D11 samples, with
one important modification. Instead of loading the shader straight from a file, this
code loads it from the resource cache. This means that the resource cache is respon-
sible for loading the shader file into memory, and from there you need to send it to
Search WWH ::




Custom Search