summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-06-12 16:39:59 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-06-13 08:41:39 -0700
commit31bf6719fc845cd83de82b8968b9cd4407f663b7 (patch)
treeaade44100ca17a5901fd68fb5599ec0da9569c2e /scripts
parent5a2dd1b5df6d2f1f37e940b43cc727b95ae08e8a (diff)
downloadqtlocation-mapboxgl-31bf6719fc845cd83de82b8968b9cd4407f663b7.tar.gz
[core] Reduce number of varyings to 8 or less
For #pragmas, don't generate varyings for attributes that aren't used by the fragment shader. Pack other varyings more tightly.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/generate-shaders.js65
1 files changed, 27 insertions, 38 deletions
diff --git a/scripts/generate-shaders.js b/scripts/generate-shaders.js
index 2f1f4c2f9c..2813d27365 100755
--- a/scripts/generate-shaders.js
+++ b/scripts/generate-shaders.js
@@ -61,42 +61,31 @@ ${fragmentPrelude}
'symbol_icon',
'symbol_sdf'
].forEach(function (shaderName) {
- function applyPragmas(source, pragmas) {
- return source.replace(/#pragma mapbox: ([\w]+) ([\w]+) ([\w]+) ([\w]+)/g, (match, operation, precision, type, name) => {
- const a_type = type === "float" ? "vec2" : "vec4";
- return pragmas[operation]
- .join("\n")
- .replace(/\{type\}/g, type)
- .replace(/\{a_type}/g, a_type)
- .replace(/\{precision\}/g, precision)
- .replace(/\{name\}/g, name);
- });
- }
-
- function vertexSource() {
- const source = fs.readFileSync(path.join(inputPath, shaderName + '.vertex.glsl'), 'utf8');
- return applyPragmas(source, {
- define: [
- "uniform lowp float a_{name}_t;",
- "attribute {precision} {a_type} a_{name};",
- "varying {precision} {type} {name};"
- ],
- initialize: [
- "{name} = unpack_mix_{a_type}(a_{name}, a_{name}_t);"
- ]
- });
- }
-
- function fragmentSource() {
- const source = fs.readFileSync(path.join(inputPath, shaderName + '.fragment.glsl'), 'utf8');
- return applyPragmas(source, {
- define: [
- "varying {precision} {type} {name};"
- ],
- initialize: [
- ]
- });
- }
+ const re = /#pragma mapbox: ([\w]+) ([\w]+) ([\w]+) ([\w]+)/g;
+ const fragmentPragmas = new Set();
+
+ let fragmentSource = fs.readFileSync(path.join(inputPath, shaderName + '.fragment.glsl'), 'utf8');
+ let vertexSource = fs.readFileSync(path.join(inputPath, shaderName + '.vertex.glsl'), 'utf8');
+
+ fragmentSource = fragmentSource.replace(re, (match, operation, precision, type, name) => {
+ fragmentPragmas.add(name);
+ return operation === "define" ?
+ `varying ${precision} ${type} ${name};` :
+ ``;
+ });
+
+ 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);`;
+ } 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);`;
+ }
+ });
writeIfModified(path.join(outputPath, `${shaderName}.hpp`), `// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.
@@ -125,10 +114,10 @@ namespace shaders {
const char* ${shaderName}::name = "${shaderName}";
const char* ${shaderName}::vertexSource = R"MBGL_SHADER(
-${vertexSource()}
+${vertexSource}
)MBGL_SHADER";
const char* ${shaderName}::fragmentSource = R"MBGL_SHADER(
-${fragmentSource()}
+${fragmentSource}
)MBGL_SHADER";
} // namespace shaders