X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=futatabi%2Fflow.cpp;h=a10d83b11f725e19b11e86cab888fd60e25aa3f2;hb=abb8008f34e6ad7fd7665c4bb808259bce46b5b2;hp=5125d26b53a5d2f09bde21132136d2a6ec333b5c;hpb=827606868bf9f1dd16208882f0e3ca424b3e9e0a;p=nageru diff --git a/futatabi/flow.cpp b/futatabi/flow.cpp index 5125d26..a10d83b 100644 --- a/futatabi/flow.cpp +++ b/futatabi/flow.cpp @@ -5,6 +5,7 @@ #include "embedded_files.h" #include "gpu_timers.h" #include "util.h" +#include "shared/read_file.h" #include #include @@ -50,53 +51,6 @@ int find_num_levels(int width, int height) return levels; } -string read_file(const string &filename, const unsigned char *start = nullptr, const size_t size = 0) -{ - FILE *fp = fopen(filename.c_str(), "r"); - if (fp == nullptr) { - // Fall back to the version we compiled in. (We prefer disk if we can, - // since that makes it possible to work on shaders without recompiling - // all the time.) - if (start != nullptr) { - return string(reinterpret_cast(start), - reinterpret_cast(start) + size); - } - - perror(filename.c_str()); - exit(1); - } - - int ret = fseek(fp, 0, SEEK_END); - if (ret == -1) { - perror("fseek(SEEK_END)"); - exit(1); - } - - int disk_size = ftell(fp); - - ret = fseek(fp, 0, SEEK_SET); - if (ret == -1) { - perror("fseek(SEEK_SET)"); - exit(1); - } - - string str; - str.resize(disk_size); - ret = fread(&str[0], disk_size, 1, fp); - if (ret == -1) { - perror("fread"); - exit(1); - } - if (ret == 0) { - fprintf(stderr, "Short read when trying to read %d bytes from %s\n", - disk_size, filename.c_str()); - exit(1); - } - fclose(fp); - - return str; -} - GLuint compile_shader(const string &shader_src, GLenum type) { GLuint obj = glCreateShader(type);