bool QuantumGameEngine::QuantumGraphics::CVertexShader::CompileShaderFromFile(LPCWSTR pSrcFile,
D3D10_SHADER_MACRO* pDefines,
LPD3D10INCLUDE pInclude,
LPCSTR pFunctionName,
LPCSTR pProfile,
UINT Flags1,
UINT Flags2,
ID3DX11ThreadPump* pPump){
//Compile our shader
if(FAILED(D3DX11CompileFromFileW(pSrcFile, pDefines, pInclude, pFunctionName, pProfile, Flags1, Flags2, pPump, &this->pShaderBlob, &this->pErrors, NULL))){
this->log(LEVEL_ERROR, "Failed to compile shaders");
if(this->pShaderBlob){
MessageBox(NULL, reinterpret_cast<LPCWSTR>(this->pShaderBlob->GetBufferPointer()), L"FAIL", MB_OK);
} else {
MessageBox(NULL, L"FAIL", L"FAIL", MB_OK);
}
return false;
}
//Turn the blob into a shader
if(FAILED(this->pGC->pDevice->CreateVertexShader(this->pShaderBlob->GetBufferPointer(), this->pShaderBlob->GetBufferSize(), NULL, &this->pVertexShader))){
this->log(LEVEL_ERROR, "Failed to turn blob into shader object");
return false;
}
//Release the blob because we don't need it
this->pShaderBlob->Release();
this->pShaderBlob = nullptr;
//Release the errors
if(this->pErrors){
this->pErrors->Release();
this->pErrors = nullptr;
}
return true;
}
Code that is used to call shader loading code:
if(!this->pVS->CompileShaderFromFile(L"Shaders\\shaders.hlsl", NULL, NULL, "VertexShader", "vs_5_0", NULL, NULL, NULL)){
this->log(LEVEL_ERROR, "Failed to compile vertex shader");
return false;
}
if(!this->pPS->CompileShaderFromFile(L"Shaders\\shaders.hlsl", NULL, NULL, "PixelShader", "ps_5_0", NULL, NULL, NULL)){
this->log(LEVEL_ERROR, "Failed to compile pixel shader");
return false;
}
The call always returns with D3DX11CompileFromFileW failing and the shader error blob to be null. I never had any troubles with compiling shaders in DX9 and DX10...
EDIT: Here is shader code:
struct VIn {
float4 position : POSITION;
float4 color : COLOR;
};
struct VOut {
float4 position : SV_POSITION;
float4 color : COLOR;
};
VOut VertexShader(VIn in){
VOut out;
out.position = in.position;
out.color = in.color;
return out;
}
float4 PixelShader(VOut in) : SV_TARGET {
return in.color;
}