Updated to simplify logic of shader cli

This commit is contained in:
Alejandro Saucedo 2021-07-21 08:08:05 +01:00
parent 598c843545
commit 7fdb868790

View file

@ -9,19 +9,11 @@ std::vector<uint32_t>
Shader::compileSource(
const std::string& source)
{
std::string cmd = "glslc -fshader-stage=compute -o tmp_kp_shader.comp.spv - << END\n" + source + "\nEND";
system(cmd.c_str());
std::ifstream fileStream("tmp_kp_shader.comp.spv",
std::ios::binary | std::ios::in | std::ios::ate);
size_t shaderFileSize = fileStream.tellg();
fileStream.seekg(0, std::ios::beg);
char* shaderDataRaw = new char[shaderFileSize];
fileStream.read(shaderDataRaw, shaderFileSize);
fileStream.close();
std::vector<uint32_t> tmpResult = {(uint32_t*)shaderDataRaw, (uint32_t*)(shaderDataRaw + shaderFileSize)};
return tmpResult;
system(std::string("glslc -fshader-stage=compute -o tmp_kp_shader.comp.spv - << END\n" + source + "\nEND").c_str());
std::ifstream fileStream("tmp_kp_shader.comp.spv", std::ios::binary);
std::vector<char> buffer;
buffer.insert(buffer.begin(), std::istreambuf_iterator<char>(fileStream), {});
return {(uint32_t*)buffer.data(), (uint32_t*)(buffer.data() + buffer.size())};
}
}