27 lines
812 B
C++
27 lines
812 B
C++
#include "vulkan_engine/utilities.h"
|
|
|
|
#include <fstream>
|
|
|
|
namespace veng {
|
|
bool streq(gsl::czstring left, gsl::czstring right) {
|
|
return std::strcmp(left, right) == 0;
|
|
}
|
|
std::vector<std::uint8_t> ReadFile(std::filesystem::path shader_path) {
|
|
if (!std::filesystem::exists(shader_path)) return {};
|
|
if (!std::filesystem::is_regular_file(shader_path)) return {};
|
|
|
|
std::ifstream file(shader_path, std::ios::binary);
|
|
|
|
if (!file.is_open()) return {};
|
|
|
|
std::uintmax_t file_size = std::filesystem::file_size(shader_path);
|
|
if (file_size > std::numeric_limits<std::uint32_t>::max()) return {}; // 방어
|
|
|
|
std::uint32_t size = static_cast<std::uint32_t>(file_size);
|
|
std::vector<std::uint8_t> buffer(size);
|
|
file.read(reinterpret_cast<char*>(buffer.data()), size);
|
|
|
|
return buffer;
|
|
}
|
|
} // namespace veng
|