diff options
| author | ladevieq <ladevie.quentin@gmail.com> | 2020-12-27 13:12:46 +0100 |
|---|---|---|
| committer | ladevieq <ladevie.quentin@gmail.com> | 2020-12-27 13:12:46 +0100 |
| commit | fc6ef799b34ac9ddb147e41b487deaf70da20f55 (patch) | |
| tree | 3d736bb9cd75a94886f585eed67e2d4a489c6d6c /src/utils.cpp | |
| parent | ca0b2f48c5017b5fb615f5db0755e4f730de4fd7 (diff) | |
Util to read shader file content
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; +} |
