From 2b99ae95959f65d82ce884a672dadef93a740fe0 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Sat, 20 Apr 2019 01:02:20 +0800 Subject: [PATCH] =?UTF-8?q?LoadShader=E7=9A=84=E6=96=87=E4=BB=B6=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E6=94=B9=E7=94=A8ifstream=E4=BB=A5=E6=96=B9=E4=BE=BF?= =?UTF-8?q?=E8=B7=A8=E5=B9=B3=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/Vulkan/main.cpp | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/example/Vulkan/main.cpp b/example/Vulkan/main.cpp index da2356a4..ed55f531 100644 --- a/example/Vulkan/main.cpp +++ b/example/Vulkan/main.cpp @@ -14,9 +14,7 @@ #include"VKSemaphore.h" #include"VKFormat.h" -#include -#include -#include +#include using namespace hgl; using namespace hgl::graph; @@ -26,22 +24,21 @@ VkShaderModule fs=nullptr; 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]; - const int result=_read(fp,data,file_length); - - if(result!=file_length) - { - delete[] data; - return(nullptr); - } + fs.seekg(0,std::ios_base::beg); + fs.read(data,file_length); - _close(fp); + fs.close(); return data; } @@ -180,7 +177,7 @@ int main(int,char **) if(!pipeline) return(-4); - + delete pipeline; delete sem;