我有以下代码:
struct shaderData
{
char *shaderCode;
UINT size;
};
struct shaderData *CubeApp::GetShaderByteCode(char *compiledShader)
{
struct shaderData *sData = (struct shaderData *)malloc(sizeof(struct shaderData));
std::ifstream fin(compiledShader, std::ios::binary);
fin.seekg(0, std::ios_base::end);
UINT size = (int)fin.tellg();
fin.seekg(0, std::ios_base::beg);
sData->shaderCode = (char *)malloc(size);
fin.read(sData->shaderCode, size);
fin.close();
sData->size = size;
return sData;
}
void CubeApp::InitShaders()
{
struct shaderData *sData = GetShaderByteCode("PShader.cso");
HRESULT hr = m_d3dDevice->CreatePixelShader(sData->shaderCode, sData->size, NULL, &m_d3dPShader);
}
但是这在调用 CreatePixelShader() 时会返回 E_INVALIDARG,而 m_d3dPShader 是一个 NULL 指针。
有任何想法吗?