summaryrefslogtreecommitdiff
path: root/scripts/generate-shaders.js
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-08-01 13:03:53 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-08-02 09:59:50 -0700
commit466728b441308de4bb0579d8b871c587607c76ae (patch)
tree097d5117cc4a39567e2a4f80ae2cc4fac18625cc /scripts/generate-shaders.js
parentae1d9eceadb0c7ab556b76e746af567e0a0b9835 (diff)
downloadqtlocation-mapboxgl-466728b441308de4bb0579d8b871c587607c76ae.tar.gz
[core] Simplify generate-shaders.js
We moved the #pragma ⇢ #ifndef logic into gl-js.
Diffstat (limited to 'scripts/generate-shaders.js')
-rwxr-xr-xscripts/generate-shaders.js88
1 files changed, 11 insertions, 77 deletions
diff --git a/scripts/generate-shaders.js b/scripts/generate-shaders.js
index a10e505278..39aed3053e 100755
--- a/scripts/generate-shaders.js
+++ b/scripts/generate-shaders.js
@@ -3,14 +3,11 @@
const path = require('path');
const fs = require('fs');
-const inputPath = 'mapbox-gl-js/src/shaders';
+const shaders = require('../mapbox-gl-js/src/shaders');
const outputPath = 'src/mbgl/shaders';
require('./style-code');
-const vertexPrelude = fs.readFileSync(path.join(inputPath, '_prelude.vertex.glsl'));
-const fragmentPrelude = fs.readFileSync(path.join(inputPath, '_prelude.fragment.glsl'));
-
writeIfModified(path.join(outputPath, 'preludes.hpp'), `// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.
#pragma once
@@ -33,84 +30,21 @@ namespace mbgl {
namespace shaders {
const char* vertexPrelude = R"MBGL_SHADER(
-${vertexPrelude}
+${shaders.prelude.vertexSource}
)MBGL_SHADER";
const char* fragmentPrelude = R"MBGL_SHADER(
-${fragmentPrelude}
+${shaders.prelude.fragmentSource}
)MBGL_SHADER";
} // namespace shaders
} // namespace mbgl
`);
-[
- 'circle',
- 'collision_box',
- 'debug',
- 'extrusion_texture',
- 'fill',
- 'fill_extrusion',
- 'fill_extrusion_pattern',
- 'fill_outline',
- 'fill_outline_pattern',
- 'fill_pattern',
- 'line',
- 'line_pattern',
- 'line_sdf',
- 'raster',
- 'symbol_icon',
- 'symbol_sdf'
-].forEach(function (shaderName) {
- 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" ? `
-#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" ? `
-#ifndef 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" ? `
-#ifndef 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`;
- }
- });
+for (const key in shaders) {
+ if (key === 'prelude')
+ continue;
+
+ const shaderName = key.replace(/[A-Z]+/g, (match) => `_${match.toLowerCase()}`);
writeIfModified(path.join(outputPath, `${shaderName}.hpp`), `// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.
@@ -139,13 +73,13 @@ namespace shaders {
const char* ${shaderName}::name = "${shaderName}";
const char* ${shaderName}::vertexSource = R"MBGL_SHADER(
-${vertexSource}
+${shaders[key].vertexSource}
)MBGL_SHADER";
const char* ${shaderName}::fragmentSource = R"MBGL_SHADER(
-${fragmentSource}
+${shaders[key].fragmentSource}
)MBGL_SHADER";
} // namespace shaders
} // namespace mbgl
`);
-});
+}