pleascach/Renderer/Shader.cpp
connellpaxton 952176f4c9 Added file utilities, began work on texture loading.
After that, it will be time to begin graphics pipeline construction
2024-01-22 18:09:11 -05:00

28 lines
652 B
C++

#include <Renderer/Shader.hpp>
#include <util/log.hpp>
#include <util/file.hpp>
Shader::Shader(vk::Device dev, const std::string& fname) : fname(fname) {
std::vector<uint8_t> src;
try {
src = file::slurpb(fname);
} catch (std::exception& e) {
Log::error("Failed to read file " + fname + ": "+ e.what() + "\n");
}
auto module_info = vk::ShaderModuleCreateInfo{
.codeSize = src.size(),
.pCode = reinterpret_cast<const uint32_t*>(src.data()),
};
if (!(module = dev.createShaderModule(module_info))) {
Log::error(fname + ": failed to create shader\n");
}
}
void Shader::cleanup(vk::Device dev) {
dev.destroyShaderModule(module);
}