diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2017-06-04 15:43:27 +0200 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-06-13 12:21:50 -0700 |
commit | 2cbc3d3332e32054e9fdc5323fef8e98f5f99a79 (patch) | |
tree | 05f2564ff02eeccc6b27e567df20daca5ca425bb /scripts | |
parent | 978363a47f3c15aa4f3ac42bd63d5f65a4f827b0 (diff) | |
download | qtlocation-mapboxgl-2cbc3d3332e32054e9fdc5323fef8e98f5f99a79.tar.gz |
[core] add shader defines for enabling/disabling attributes/uniforms for DDS
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/generate-shaders.js | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/scripts/generate-shaders.js b/scripts/generate-shaders.js index 2813d27365..159817f62f 100755 --- a/scripts/generate-shaders.js +++ b/scripts/generate-shaders.js @@ -69,21 +69,52 @@ ${fragmentPrelude} fragmentSource = fragmentSource.replace(re, (match, operation, precision, type, name) => { fragmentPragmas.add(name); - return operation === "define" ? - `varying ${precision} ${type} ${name};` : - ``; + return operation === "define" ? ` +#ifndef HAS_UNIFORM_u_${name} +varying ${precision} ${type} ${name}; +#else +uniform ${precision} ${type} u_${name}; +#endif +` : ` +#ifdef HAS_UNIFORM_u_${name} + ${precision} ${type} ${name} = u_${name}; +#endif +`; }); vertexSource = vertexSource.replace(re, (match, operation, precision, type, name) => { const a_type = type === "float" ? "vec2" : "vec4"; if (fragmentPragmas.has(name)) { - return operation === "define" ? - `uniform lowp float a_${name}_t;\nattribute ${precision} ${a_type} a_${name};\nvarying ${precision} ${type} ${name};` : - `${name} = unpack_mix_${a_type}(a_${name}, a_${name}_t);`; + return operation === "define" ? ` +#ifdef HAS_UNIFORM_u_${name} +uniform lowp float a_${name}_t; +attribute ${precision} ${a_type} a_${name}; +varying ${precision} ${type} ${name}; +#else +uniform ${precision} ${type} u_${name}; +#endif +` : ` +#ifndef HAS_UNIFORM_u_${name} + ${name} = unpack_mix_${a_type}(a_${name}, a_${name}_t); +#else + ${precision} ${type} ${name} = u_${name}; +#endif +`; } else { - return operation === "define" ? - `uniform lowp float a_${name}_t;\nattribute ${precision} ${a_type} a_${name};` : - `${precision} ${type} ${name} = unpack_mix_${a_type}(a_${name}, a_${name}_t);`; + return operation === "define" ? ` +#ifdef HAS_UNIFORM_u_${name} +uniform lowp float a_${name}_t; +attribute ${precision} ${a_type} a_${name}; +#else +uniform ${precision} ${type} u_${name}; +#endif +` : ` +#ifndef HAS_UNIFORM_u_${name} + ${precision} ${type} ${name} = unpack_mix_${a_type}(a_${name}, a_${name}_t); +#else + ${precision} ${type} ${name} = u_${name}; +#endif +`; } }); |