LoadShader的文件读取改用ifstream以方便跨平台

This commit is contained in:
hyzboy 2019-04-20 01:02:20 +08:00
parent 9a75f75642
commit 2b99ae9595

View File

@ -14,9 +14,7 @@
#include"VKSemaphore.h" #include"VKSemaphore.h"
#include"VKFormat.h" #include"VKFormat.h"
#include<io.h> #include<fstream>
#include<fcntl.h>
#include<stdlib.h>
using namespace hgl; using namespace hgl;
using namespace hgl::graph; using namespace hgl::graph;
@ -26,22 +24,21 @@ VkShaderModule fs=nullptr;
char *LoadFile(const char *filename,uint32_t &file_length) char *LoadFile(const char *filename,uint32_t &file_length)
{ {
int fp=_open(filename,O_RDONLY|O_BINARY); std::ifstream fs;
if(fp==-1)return(nullptr); fs.open(filename,std::ios_base::binary);
file_length=_filelength(fp); if(!fs.is_open())
return(nullptr);
fs.seekg(0,std::ios_base::end);
file_length=fs.tellg();
char *data=new char[file_length]; char *data=new char[file_length];
const int result=_read(fp,data,file_length); fs.seekg(0,std::ios_base::beg);
fs.read(data,file_length);
if(result!=file_length)
{
delete[] data;
return(nullptr);
}
_close(fp); fs.close();
return data; return data;
} }
@ -180,7 +177,7 @@ int main(int,char **)
if(!pipeline) if(!pipeline)
return(-4); return(-4);
delete pipeline; delete pipeline;
delete sem; delete sem;