diff options
Diffstat (limited to 'src/utils.cpp')
| -rw-r--r-- | src/utils.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/utils.cpp b/src/utils.cpp new file mode 100644 index 0000000..9aaf93a --- /dev/null +++ b/src/utils.cpp @@ -0,0 +1,31 @@ +#include "utils.hpp" + +#include <cstdio> +#include <cstring> +#include <iostream> + +std::vector<uint8_t> get_shader_code(const char* path) { + FILE* f = fopen(path, "r"); + + if (f == nullptr) { + std::cerr << "Cannot open compute shader file !" << std::endl; + return {}; + } + + if (fseek(f, 0, SEEK_END) != 0) { + return {}; + } + + std::vector<uint8_t> shader_code(ftell(f)); + + if (fseek(f, 0, SEEK_SET) != 0) { + return {}; + } + + if (fread(shader_code.data(), sizeof(uint8_t), shader_code.size(), f) != shader_code.size()) { + std::cerr << "Reading shader code failed" << std::endl; + return {}; + } + + return shader_code; +} |
