diff options
author | Vladimir Agafonkin <agafonkin@gmail.com> | 2016-11-08 15:01:53 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-08 15:01:53 -0800 |
commit | efc427f9bbf7fb4b8d8895613dbb29716d5d7b11 (patch) | |
tree | 6c5dd73e81058a59a835ff18580d08445bfda0b4 | |
parent | 2b81dee8d39fc25d71a90d2aac700dd555cc9b68 (diff) | |
download | qtlocation-mapboxgl-efc427f9bbf7fb4b8d8895613dbb29716d5d7b11.tar.gz |
update to mapbox-gl-shaders with vertex/fragment preludes (#6971)
-rw-r--r-- | cmake/shaders.cmake | 4 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rwxr-xr-x | scripts/build-shaders.js | 39 |
3 files changed, 25 insertions, 20 deletions
diff --git a/cmake/shaders.cmake b/cmake/shaders.cmake index 659231fd9a..cbf3b7e3b9 100644 --- a/cmake/shaders.cmake +++ b/cmake/shaders.cmake @@ -5,9 +5,11 @@ function(add_shader VAR name) add_custom_command( OUTPUT ${shader_source_prefix}/${name}.hpp - COMMAND ${shader_build_cmd} ${shader_file_prefix}/${name}.vertex.glsl ${shader_file_prefix}/${name}.fragment.glsl ${shader_source_prefix}/${name}.hpp + COMMAND ${shader_build_cmd} ${name} ${shader_file_prefix} ${shader_source_prefix} DEPENDS ${shader_file_prefix}/${name}.vertex.glsl DEPENDS ${shader_file_prefix}/${name}.fragment.glsl + DEPENDS ${shader_file_prefix}/_prelude.vertex.glsl + DEPENDS ${shader_file_prefix}/_prelude.fragment.glsl VERBATIM ) set(${VAR} ${${VAR}} ${shader_source_prefix}/${name}.hpp PARENT_SCOPE) diff --git a/package.json b/package.json index 2973da533a..083cc0975a 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "ejs": "^2.4.1", "express": "^4.11.1", "lodash": "^4.16.4", - "mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#98a56d538b11fb331aa67a6d632d6ecd6821b007", + "mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#7f1c3bef3692f1d044035a22e65c8758b7630333", "mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#7f62a4fc9f21e619824d68abbc4b03cbc1685572", "mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#8d2d9cb86a7b4a15bc5a59bab531cd102257918d", "mkdirp": "^0.5.1", diff --git a/scripts/build-shaders.js b/scripts/build-shaders.js index dd2de9daf6..d00762acf0 100755 --- a/scripts/build-shaders.js +++ b/scripts/build-shaders.js @@ -4,24 +4,22 @@ var path = require('path'); var fs = require('fs'); var mkdirp = require('mkdirp'); -var vertex_file = process.argv[2]; -var fragment_file = process.argv[3]; -var output_file = process.argv[4]; +var shaderName = process.argv[2]; +var inputPath = process.argv[3]; +var outputPath = process.argv[4]; -if (!vertex_file || !fragment_file || !output_file) { - console.warn('No input or output file given.'); - console.warn('Usage: %s input.vertex.glsl input.fragment.glsl output.hpp', path.basename(process.argv[1])); +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); } -var components = path.basename(vertex_file).split('.'); -var shader_name = components[0]; +var pragmaMapboxRe = /(\s*)#pragma\s+mapbox\s*:\s+(define|initialize)\s+(low|medium|high)p\s+(float|vec(?:2|3|4))\s+(.*)/; -var pragma_mapbox_regex = /(\s*)#pragma\s+mapbox\s*:\s+(define|initialize)\s+(low|medium|high)p\s+(float|vec(?:2|3|4))\s+(.*)/; -function source(file) { - return '\n' + fs.readFileSync(file, 'utf8').split('\n').map(function(line) { - var params = line.match(pragma_mapbox_regex); +function applyPragmas(source) { + return '\n' + source.split('\n').map(function(line) { + var params = line.match(pragmaMapboxRe); if (params) { if (params[2] === 'define') { return params[1] + 'uniform ' + params[3] + 'p ' + params[4] + ' u_' + params[5] + ';'; @@ -34,6 +32,11 @@ function source(file) { }).join('\n'); } +var vertexPrelude = fs.readFileSync(path.join(inputPath, '_prelude.vertex.glsl')); +var fragmentPrelude = fs.readFileSync(path.join(inputPath, '_prelude.fragment.glsl')); +var vertexSource = vertexPrelude + fs.readFileSync(path.join(inputPath, shaderName + '.vertex.glsl'), 'utf8'); +var fragmentSource = fragmentPrelude + fs.readFileSync(path.join(inputPath, shaderName + '.fragment.glsl'), 'utf8'); + var content = "#pragma once\n" + "\n" + "// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.\n" + @@ -43,15 +46,15 @@ var content = "#pragma once\n" + "namespace mbgl {\n" + "namespace shaders {\n" + "\n" + -"class " + shader_name + " {\n" + +"class " + shaderName + " {\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" + +" static constexpr const char* name = \"" + shaderName + "\";\n" + +" static constexpr const char* vertexSource = R\"MBGL_SHADER(" + applyPragmas(vertexSource) + ")MBGL_SHADER\";\n" + +" static constexpr const char* fragmentSource = R\"MBGL_SHADER(" + applyPragmas(fragmentSource) + ")MBGL_SHADER\";\n" + "};\n" + "\n" + "} // namespace shaders\n" + "} // namespace mbgl\n"; -mkdirp.sync(path.dirname(output_file)); -fs.writeFileSync(output_file, content); +mkdirp.sync(outputPath); +fs.writeFileSync(path.join(outputPath, shaderName + '.hpp'), content); |