diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-10-28 18:17:33 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-11-08 08:09:29 -0800 |
commit | 66bdbc3b969083b9d647abdf72784be64a125949 (patch) | |
tree | 9f2f1c6eb3d0569926420459c2c9afda50c66fd0 /scripts | |
parent | 36210fe4e9c68a52dedc90548d90e77cf39a2228 (diff) | |
download | qtlocation-mapboxgl-66bdbc3b969083b9d647abdf72784be64a125949.tar.gz |
[core] Introduce gl::Program template
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/build-shaders.js | 86 |
1 files changed, 36 insertions, 50 deletions
diff --git a/scripts/build-shaders.js b/scripts/build-shaders.js index 9090f19e6d..dd2de9daf6 100755 --- a/scripts/build-shaders.js +++ b/scripts/build-shaders.js @@ -4,68 +4,54 @@ var path = require('path'); var fs = require('fs'); var mkdirp = require('mkdirp'); -var input_file = process.argv[2] -var output_file = process.argv[3]; +var vertex_file = process.argv[2]; +var fragment_file = process.argv[3]; +var output_file = process.argv[4]; -if (!input_file || !output_file) { +if (!vertex_file || !fragment_file || !output_file) { console.warn('No input or output file given.'); - console.warn('Usage: %s [input.vertex.glsl] [output.vertex.hpp]', path.basename(process.argv[1])); + console.warn('Usage: %s input.vertex.glsl input.fragment.glsl output.hpp', path.basename(process.argv[1])); process.exit(1); } -var components = path.basename(input_file).split('.'); - +var components = path.basename(vertex_file).split('.'); var shader_name = components[0]; -var shader_type = components[1]; -var extension = components[2]; - -var data = fs.readFileSync(input_file, 'utf8'); - -// Replace uniform pragmas var pragma_mapbox_regex = /(\s*)#pragma\s+mapbox\s*:\s+(define|initialize)\s+(low|medium|high)p\s+(float|vec(?:2|3|4))\s+(.*)/; -var data = data.split('\n').map(function(line) { - var params = line.match(pragma_mapbox_regex); - if (params) { - if (params[2] === 'define') { - return params[1] + 'uniform ' + params[3] + 'p ' + params[4] + ' u_' + params[5] + ';'; +function source(file) { + return '\n' + fs.readFileSync(file, 'utf8').split('\n').map(function(line) { + var params = line.match(pragma_mapbox_regex); + if (params) { + if (params[2] === 'define') { + return params[1] + 'uniform ' + params[3] + 'p ' + params[4] + ' u_' + params[5] + ';'; + } else { + return params[1] + params[3] + 'p ' + params[4] + ' ' + params[5] + ' = u_' + params[5] + ';'; + } } else { - return params[1] + params[3] + 'p ' + params[4] + ' ' + params[5] + ' = u_' + params[5] + ';'; + return line; } - } else { - return line; - } -}).join('\n'); - + }).join('\n'); +} -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' + - 'namespace ' + shader_name + ' {\n' + - '\n' + - '#ifndef MBGL_SHADER_NAME_' + shader_name.toUpperCase() + '\n' + - '#define MBGL_SHADER_NAME_' + shader_name.toUpperCase() + '\n' + - 'constexpr const char* name = "' + shader_name + '";\n' + - '#endif // MBGL_SHADER_NAME_' + shader_name.toUpperCase() + '\n' + - '\n' + - 'constexpr const char* ' + shader_type + ' =\n' + - '#ifdef GL_ES_VERSION_2_0\n' + - ' "precision highp float;"\n' + - '#else\n' + - ' "#version 120"\n' + - '#endif\n' + - ' R"MBGL_SHADER(\n' + data + ')MBGL_SHADER";\n' + - '\n' + - '} // namespace ' + shader_name + '\n' + - '} // namespace shaders\n' + - '} // namespace mbgl\n'; +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 " + shader_name + " {\n" + +"public:\n" + +" static constexpr const char* name = \"" + shader_name + "\";" + +" static constexpr const char* vertexSource = R\"MBGL_SHADER(" + source(vertex_file) + ")MBGL_SHADER\";\n" + +" static constexpr const char* fragmentSource = R\"MBGL_SHADER(" + source(fragment_file) + ")MBGL_SHADER\";\n" + +"};\n" + +"\n" + +"} // namespace shaders\n" + +"} // namespace mbgl\n"; mkdirp.sync(path.dirname(output_file)); fs.writeFileSync(output_file, content); |