File: make_bundled_shaders.cpp

package info (click to toggle)
movit 1.7.2-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 3,248 kB
  • sloc: cpp: 16,677; sh: 3,940; makefile: 167
file content (65 lines) | stat: -rw-r--r-- 1,598 bytes parent folder | download | duplicates (2)
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");
}