Directx 11 - CompileFromFile() is not compiling
Directx 11 - CompileFromFile() is not compiling
所以,我不确定我是否错过了什么。
我有一个着色器类,我想从包含 DirectX 函数D3DCompileFromFile()
的函数LoadFromFile()
的文件加载和编译着色器,这是执行此操作所需的
void Shader::LoadFromFile(const char* file, const char* vsEntry, const char* psEntry)
{
DXCall(D3DCompileFromFile((LPCWSTR)file, 0, D3D_COMPILE_STANDARD_FILE_INCLUDE, vsEntry, "vs_5_0", 0, 0, &m_vsb, 0));
DXCall(D3DCompileFromFile((LPCWSTR)file, 0, D3D_COMPILE_STANDARD_FILE_INCLUDE, psEntry, "ps_5_0", 0, 0, &m_psb, 0));
DXCall(Renderer::Get()->GetDevice()->CreateVertexShader(m_vsb->GetBufferPointer(), m_vsb->GetBufferSize(), 0, &m_vs));
DXCall(Renderer::Get()->GetDevice()->CreatePixelShader(m_psb->GetBufferPointer(), m_psb->GetBufferSize(), 0, &m_ps));
...
}
我想像这样在 main 中调用该函数
Shader shader;
shader.LoadFromFile("res/Default.hlsl", "VS", "PS");
但是,当它到达创建顶点着色器函数时,我不断收到以下错误:
Exception thrown: read access violation. this->m_vsb was nullptr.
只是找不到文件还是着色器文件中有一些错误的代码?
struct VOut;
{
float4 Position : SV_POSITION;
float4 COLOR : COLOR;
};
VOut VS(float4 position : POSITION, float4 color : COLOR)
{
VOut output;
output.Position = position;
output.Color = color;
return output;
};
float4 PS(VOut input) : SV_TARGET
{
return input.Color;
};
D3DCompileFromFile
是一个仅宽字符的函数。您的file
无效:
void Shader::LoadFromFile(const char* file, const char* vsEntry, const char* psEntry)
{
DXCall(D3DCompileFromFile((LPCWSTR)file, 0, D3D_COMPILE_STANDARD_FILE_INCLUDE, vsEntry, "vs_5_0", 0, 0, &m_vsb, 0));
DXCall(D3DCompileFromFile((LPCWSTR)file, 0, D3D_COMPILE_STANDARD_FILE_INCLUDE, psEntry, "ps_5_0", 0, 0, &m_psb, 0));
您应该切换LoadFromFile
以采用const wchar_t*
而不是const char*
,或者执行转换:
void Shader::LoadFromFile(const char* file, const char* vsEntry, const char* psEntry)
{
wchar_t filePath[MAX_PATH] = {};
int oldLen = strlen(file);
const int newLen = MultiByteToWideChar(
CP_UTF8,
MB_ERR_INVALID_CHARS,
file,
oldLen,
filePath,
MAX_PATH);
DXCall(D3DCompileFromFile(filePath, 0, D3D_COMPILE_STANDARD_FILE_INCLUDE, vsEntry, "vs_5_0", 0, 0, &m_vsb, 0));
DXCall(D3DCompileFromFile(filePath, 0, D3D_COMPILE_STANDARD_FILE_INCLUDE, psEntry, "ps_5_0", 0, 0, &m_psb, 0));
相关文章:
- Directx 11 - CompileFromFile() is not compiling
- Centos7 g++ "to_string is not in a member of std"
- 将成员函数作为构造函数参数调用时出错 "Variable is not a type name"
- reference_wrapper导致"incomplete type is not allowed"
- 结构中的错误"Incomplete type is not allowed"
- "Called Object Type is Not a Function or Pointer" 与 typedef 和类
- 无法创建 DLL:获取 DLL "is not a valid Win32 application"
- Atom gpp编译器给出"'C:UsersadminUser' is not recognized as an internal or..."错误
- 当我编译XG-Bosst时,出现错误"error: 'Split' is not a member of 'xgboost::common' ……"
- C++ DLL 运行时错误"abc.dll is not a valid WIN32 application" 。请帮助解决这个问题
- 如何修复 eigen3 中的'non-type template argument is not a constant expression'?
- 我的代码应该接受一个数字,并返回字母等级或"Grade is not valid"但 else 语句不起作用
- 如何修复此错误"the value of 'x1' is not usable in a constant expression"?static_assert
- 加载安全区图像"A device attached to the system is not functioning"
- 巴泽尔中的错误"name 'new_local_repository' is not defined"
- 如何修复 SDL2 "GLSL 3.30 is not supported"错误
- 函数模板(它是类模板的成员)的显式专用化会产生"partial specialization is not allowed"错误,为什么?
- 为什么"an inherited constructor is not a candidate for initialization from an expression of the same or
- CGAL 绘制函数在 Visual Studio 中给出'CGAL_USE_BASIC_VIEWER is not defined'错误
- "OpenCV Error: The function/feature is not implemented"安卓应用程序