blob: 27c8682875cb5481f061b6403c4feffffe02b91b (
plain)
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
|
/*
Responsible for generating .h files from GLSL files.
*/
const path = require('path');
const fs = require('fs');
const directory = path.join(__dirname, "..", "_shaders");
const out_directory = path.join(__dirname, "..", "shaders");
const files = fs.readdirSync(directory);
files.forEach(file => {
const filePath = path.join(directory, file);
const text = String(fs.readFileSync(filePath));
const splitText = text.split('\n');
const splitName = file.split('.');
const def = `SHADER_${splitName.join('_').toUpperCase()}`;
let result = `#ifndef ${def} \n`;
result += `#define ${def} \n`;
result += `const char* ${def.toLowerCase()} = `
splitText.forEach((line, index) => {
result += "\"" + line + " \\n\"";
if (index == splitText.length - 1)
result += ";\n";
else
result += "\n";
});
result += '#endif\n';
fs.writeFileSync(path.join(out_directory, splitName.join('_') + '.h'), result);
});
|