X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=make_bundled_shaders.cpp;fp=make_bundled_shaders.cpp;h=53ce13fac597d37cf69f9bb1781cb88f48bc107b;hp=0000000000000000000000000000000000000000;hb=9a436a9406d5eb7fb01ada465a84034343e0c398;hpb=0b1705581552217b0e387bd687d65e4e3410ab91 diff --git a/make_bundled_shaders.cpp b/make_bundled_shaders.cpp new file mode 100644 index 0000000..53ce13f --- /dev/null +++ b/make_bundled_shaders.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +#include "util.h" +#include "bundled_shaders.h" + +using namespace std; +using namespace movit; + +namespace movit { + +// We need a fake (empty) list of shaders, since we reuse read_file(). +BundledShader bundled_shaders[] = { + { nullptr, 0, 0 } +}; +const char *shader_bundle = ""; +extern string *movit_data_directory; + +} // namespace movit + +int main(int argc, char **argv) +{ + std::vector shaders; + std::string bundle; + + movit_data_directory = new string("."); + + for (int i = 1; i < argc; ++i) { + string contents = read_file(argv[i]); + shaders.push_back(BundledShader{ argv[i], /*offset=*/bundle.size(), /*length=*/contents.size() }); + bundle += contents; + } + + printf("// Autogenerated by make_bundled_shaders.cpp. Do not edit by hand!\n"); + printf("#include \n"); + printf("#include \"bundled_shaders.h\"\n"); + printf("\n"); + printf("namespace movit {\n"); + printf("\n"); + printf("BundledShader bundled_shaders[] = {\n"); + for (const BundledShader &shader : shaders) { + printf("\t{ \"%s\", %zu, %zu },\n", shader.filename, shader.offset, shader.length); + } + printf("\t{ nullptr, 0, 0 }\n"); + printf("};\n"); + printf("const char *shader_bundle = \""); + for (unsigned char ch : bundle) { + if (ch == '\n') { + printf("\\n"); + } else if (ch == '\t') { + printf("\\t"); + } else if (ch == '"') { + printf("\\\""); + } else if (ch == '\\') { + printf("\\\\"); + } else if (!isprint(ch)) { + printf("\\0%o", ch); + } else { + printf("%c", ch); + } + } + printf("\";\n"); + printf("\n"); + printf("} // namespace movit\n"); +}