每次将shader转为spv都需要通过命令行执行指令,真是太麻烦了,因此顺手写了一个小程序,使用非常简单,将要转换的着色器文件拖动到小程序上就可以了。
源码如下:
#include <iostream>
#include <list>
#include <set>
int main(int argc, char** argv)
{
std::set<std::string> setExtensions = {
".vert",
".frag",
".comp",
".tesc",
".tesc"
};
std::cout << "begin ************************************************\n";
if (argc <=1)
{
goto end;
}
for (int i = 1; i < argc; i++)
{
std::string src(argv[i]);
size_t idx = src.find_last_of(".");
std::string strExtension = src.substr(idx);
if (setExtensions.count(strExtension) == 0)
{
std::cout << "can not process extension " << strExtension << std::endl;
continue;
}
std::string dst = src + ".spv";
std::string cmd = "glslangvalidator -V \"" + src + "\" -o \"" + dst + "\"";
system(cmd.c_str());
}
end:
std::cout << "end ************************************************\n";
system("pause");
}