diff options
| author | Matt Kosarek <matt.kosarek@canonical.com> | 2026-07-08 09:07:55 -0400 |
|---|---|---|
| committer | Matt Kosarek <matt.kosarek@canonical.com> | 2026-07-08 09:07:55 -0400 |
| commit | c8938fe29132a11126013ed1b010c3092f5645e4 (patch) | |
| tree | f6a6cd0603f25d51c08e302cc4342c28f9e10806 /themes/src/tools/shader.cjs | |
| parent | 418396ee5100eda8f6bc036ea35dbbe44db2f91a (diff) | |
feature: improved summer scene
Diffstat (limited to 'themes/src/tools/shader.cjs')
| -rw-r--r-- | themes/src/tools/shader.cjs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/themes/src/tools/shader.cjs b/themes/src/tools/shader.cjs new file mode 100644 index 0000000..10889db --- /dev/null +++ b/themes/src/tools/shader.cjs @@ -0,0 +1,41 @@ +/* + 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"); + +if (!fs.existsSync(out_directory)){ + fs.mkdirSync(out_directory); +} + +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 header_result = `#ifndef ${def} \n`; + const filename = splitName.join('_'); + const header_name = filename + ".h"; + const cpp_name = filename + ".cpp"; + header_result += `#define ${def} \n`; + header_result += `extern const char* ${def.toLowerCase()};\n`; + header_result += '#endif\n'; + fs.writeFileSync(path.join(out_directory, header_name), header_result); + + let cpp_result = `#include "${header_name}"\n\n` + cpp_result += `const char* ${def.toLowerCase()} = ` + splitText.forEach((line, index) => { + cpp_result += "\"" + line + " \\n\""; + if (index == splitText.length - 1) + cpp_result += ";\n"; + else + cpp_result += "\n"; + }); + fs.writeFileSync(path.join(out_directory, cpp_name), cpp_result); +}); |
