无法从.cso文件(DirectX,c++)加载“顶点着色器”
Unable to load Vertex Shader from .cso file (DirectX, c++)
我正在尝试从之前编译的.cso文件加载顶点着色器。
我使用的代码是:
char* bytes = { 0 };
size_t fSize = readFileBytes("vsTex.cso", bytes);
hr = d3d11Device->CreateVertexShader((void*)bytes, fSize, NULL, &TexVertexShader);
if (hr != S_OK){
MessageBox(NULL, "FAIL", "ERROR", NULL);
}
readFileBytes:
long readFileBytes(const char *name, char* bytes)
{
FILE *fl;
fopen_s(&fl, name, "r");
fseek(fl, 0, SEEK_END);
long len = ftell(fl);
bytes = (char*)malloc(len);
fseek(fl, 0, SEEK_SET);
fread(bytes, 1, len, fl);
fclose(fl);
return len;
}
d3d11Device是指向ID3D11设备的指针。我一直在使用D3D11CompileFromFile()创建顶点着色器,没有任何错误,所以据我所知,着色器本身没有任何问题。
我不确定是我只是读错了文件,还是在给函数提供字节之前,我必须对它做其他事情。
我注意到的一些事情可能会导致一些问题。
long readFileBytes(const char *name, char* bytes)
long readFileBytes(const char *name, char*& bytes) //pass in bytes by reference
fopen_s(&fl, name, "r");
fopen_s(&fl, name, "rb"); //open file in binary mode
最后,不要忘记在创建着色器后释放字节。
free(bytes);
相关文章:
- std::原子加载和存储都需要吗
- 如何加载(或映射)文件部分的最大大小,但适合在Windows上的RAM
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 为什么加载SDF会导致Mobilizer创建闭环错误
- C++atioglxx.pdb未加载错误glBufferData OpenGL
- 如何使用tinyxml2从XML加载父实体和子实体
- 如何在C++中使用pybind11加载一个pickle python列表
- 系统.将数组移交给c#中动态加载的c++DLL时发生AccessViolationException
- 当我尝试加载内核模块时,如何修复C++中的这个 malloc() 错误?
- 树莓上的 Libtorch 无法加载 pt 文件,但在 ubuntu 上工作
- CGAL:加载.off文件后,如何访问顶点颜色
- OpenGL:动态更改加载的顶点
- DirectX Toolkit加载了带有自定义HLSL着色器"顶点"着色器输入签名的模型
- 无法从.cso文件(DirectX,c++)加载“顶点着色器”
- 从文件加载后,顶点着色器和片段着色器都不会编译
- 从.dae加载顶点会使我的程序变慢,为什么
- 加载.dae文件时出现问题,索引和顶点加载正确
- OpenGL-加载顶点数据时glBufferData()上的SegFault
- 对象模型加载纹理坐标和顶点位置没有正确加载
- Assimp无法加载PLY模型的顶点颜色