Automates adding #define directives to GLSL shader files for conditional compilation.
Let's say you have a GLSL shader file in.glsl
// some comments
#version 460
// other code
and you would like to add #define A 1 and #define B 2 to it before compiling. Then running
python precompiler.py -D A=1 -D B=2 -i in.glsl -o out.glsl
produces out.glsl
// some comments
#version 460
#define A 1
#define B 2
// other code
with the desired defines inserted after #version directive. Defines are inserted after #version directive because it must occur in a shader before anything else, except for comments and white space.
- Python (minimal tested version is 3.8)