diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-02-03 13:51:51 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-02-07 11:27:36 -0600 |
commit | 9f2f7ddd12a4aaab0faddbe60cfb7c1e526fa7ff (patch) | |
tree | 4350fce48dd97f6088dae94245265cd900f3de1f /scripts | |
parent | d9f2cd5df50f5eee141b0a17e4e2ec8a4a7c4f78 (diff) | |
download | qtlocation-mapboxgl-9f2f7ddd12a4aaab0faddbe60cfb7c1e526fa7ff.tar.gz |
[core] Check in generated shader code
One step toward eliminating the node/npm dependency for platforms other than node.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/build-shaders.js | 75 | ||||
-rwxr-xr-x | scripts/generate-shaders.js | 84 |
2 files changed, 84 insertions, 75 deletions
diff --git a/scripts/build-shaders.js b/scripts/build-shaders.js deleted file mode 100755 index 00ced5f23b..0000000000 --- a/scripts/build-shaders.js +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env node - -var path = require('path'); -var fs = require('fs'); -var mkdirp = require('mkdirp'); - -var shaderName = process.argv[2]; -var inputPath = process.argv[3]; -var outputPath = process.argv[4]; - -if (!shaderName || !inputPath || !outputPath) { - console.warn('Not enough arguments.'); - console.warn('Usage: %s shaderName /path-to-shader-sources /output-path', path.basename(process.argv[1])); - process.exit(1); -} - -function applyPragmas(source, pragmas) { - return source.replace(/#pragma mapbox: ([\w]+) ([\w]+) ([\w]+) ([\w]+)/g, (match, operation, precision, type, name) => { - return pragmas[operation] - .join("\n") - .replace(/\{type\}/g, type) - .replace(/\{precision\}/g, precision) - .replace(/\{name\}/g, name); - }); -} - -function vertexSource() { - var prelude = fs.readFileSync(path.join(inputPath, '_prelude.vertex.glsl')); - var source = fs.readFileSync(path.join(inputPath, shaderName + '.vertex.glsl'), 'utf8'); - return prelude + applyPragmas(source, { - define: [ - "uniform lowp float a_{name}_t;", - "attribute {precision} {type} a_{name}_min;", - "attribute {precision} {type} a_{name}_max;", - "varying {precision} {type} {name};" - ], - initialize: [ - "{name} = mix(a_{name}_min, a_{name}_max, a_{name}_t);" - ] - }); -} - -function fragmentSource() { - var prelude = fs.readFileSync(path.join(inputPath, '_prelude.fragment.glsl')); - var source = fs.readFileSync(path.join(inputPath, shaderName + '.fragment.glsl'), 'utf8'); - return prelude + applyPragmas(source, { - define: [ - "varying {precision} {type} {name};" - ], - initialize: [ - ] - }); -} - -var content = "#pragma once\n" + -"\n" + -"// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.\n" + -"\n" + -"#include <mbgl/gl/gl.hpp>\n" + -"\n" + -"namespace mbgl {\n" + -"namespace shaders {\n" + -"\n" + -"class " + shaderName + " {\n" + -"public:\n" + -" static constexpr const char* name = \"" + shaderName + "\";\n" + -" static constexpr const char* vertexSource = R\"MBGL_SHADER(\n" + vertexSource() + ")MBGL_SHADER\";\n" + -" static constexpr const char* fragmentSource = R\"MBGL_SHADER(\n" + fragmentSource() + ")MBGL_SHADER\";\n" + -"};\n" + -"\n" + -"} // namespace shaders\n" + -"} // namespace mbgl\n"; - -mkdirp.sync(outputPath); -fs.writeFileSync(path.join(outputPath, shaderName + '.hpp'), content); diff --git a/scripts/generate-shaders.js b/scripts/generate-shaders.js new file mode 100755 index 0000000000..7660a6e66e --- /dev/null +++ b/scripts/generate-shaders.js @@ -0,0 +1,84 @@ +#!/usr/bin/env node + +var path = require('path'); +var fs = require('fs'); + +var inputPath = 'mapbox-gl-js/shaders'; +var outputPath = 'src/mbgl/shaders'; + +require('./style-code'); + +[ + 'circle', + 'collision_box', + 'debug', + 'fill', + 'fill_outline', + 'fill_outline_pattern', + 'fill_pattern', + 'line', + 'line_pattern', + 'line_sdf', + 'raster', + '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) => { + return pragmas[operation] + .join("\n") + .replace(/\{type\}/g, type) + .replace(/\{precision\}/g, precision) + .replace(/\{name\}/g, name); + }); + } + + function vertexSource() { + var prelude = fs.readFileSync(path.join(inputPath, '_prelude.vertex.glsl')); + var source = fs.readFileSync(path.join(inputPath, shaderName + '.vertex.glsl'), 'utf8'); + return prelude + applyPragmas(source, { + define: [ + "uniform lowp float a_{name}_t;", + "attribute {precision} {type} a_{name}_min;", + "attribute {precision} {type} a_{name}_max;", + "varying {precision} {type} {name};" + ], + initialize: [ + "{name} = mix(a_{name}_min, a_{name}_max, a_{name}_t);" + ] + }); + } + + function fragmentSource() { + var prelude = fs.readFileSync(path.join(inputPath, '_prelude.fragment.glsl')); + var source = fs.readFileSync(path.join(inputPath, shaderName + '.fragment.glsl'), 'utf8'); + return prelude + applyPragmas(source, { + define: [ + "varying {precision} {type} {name};" + ], + initialize: [ + ] + }); + } + + var content = "#pragma once\n" + + "\n" + + "// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.\n" + + "\n" + + "#include <mbgl/gl/gl.hpp>\n" + + "\n" + + "namespace mbgl {\n" + + "namespace shaders {\n" + + "\n" + + "class " + shaderName + " {\n" + + "public:\n" + + " static constexpr const char* name = \"" + shaderName + "\";\n" + + " static constexpr const char* vertexSource = R\"MBGL_SHADER(\n" + vertexSource() + ")MBGL_SHADER\";\n" + + " static constexpr const char* fragmentSource = R\"MBGL_SHADER(\n" + fragmentSource() + ")MBGL_SHADER\";\n" + + "};\n" + + "\n" + + "} // namespace shaders\n" + + "} // namespace mbgl\n"; + + writeIfModified(path.join(outputPath, shaderName + '.hpp'), content); +}); |