1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#include <stdio.h>
#include <string>
#include <vector>
#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<BundledShader> 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 <string>\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("\\%o", ch);
} else {
printf("%c", ch);
}
}
printf("\";\n");
printf("\n");
printf("} // namespace movit\n");
}
|