summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-02-06 12:24:39 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-02-07 11:27:36 -0600
commit74eb8b360904be0c1d1818d0bf94a03fb0e8a687 (patch)
tree5a3403b84b3d2db483c85c62599ff36803f3adbb /scripts
parent9f2f7ddd12a4aaab0faddbe60cfb7c1e526fa7ff (diff)
downloadqtlocation-mapboxgl-74eb8b360904be0c1d1818d0bf94a03fb0e8a687.tar.gz
[core] Use cpp files for shader source
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/generate-shaders.js74
1 files changed, 46 insertions, 28 deletions
diff --git a/scripts/generate-shaders.js b/scripts/generate-shaders.js
index 7660a6e66e..eb15ea907b 100755
--- a/scripts/generate-shaders.js
+++ b/scripts/generate-shaders.js
@@ -1,10 +1,10 @@
#!/usr/bin/env node
-var path = require('path');
-var fs = require('fs');
+const path = require('path');
+const fs = require('fs');
-var inputPath = 'mapbox-gl-js/shaders';
-var outputPath = 'src/mbgl/shaders';
+const inputPath = 'mapbox-gl-js/shaders';
+const outputPath = 'src/mbgl/shaders';
require('./style-code');
@@ -34,8 +34,8 @@ require('./style-code');
}
function vertexSource() {
- var prelude = fs.readFileSync(path.join(inputPath, '_prelude.vertex.glsl'));
- var source = fs.readFileSync(path.join(inputPath, shaderName + '.vertex.glsl'), 'utf8');
+ const prelude = fs.readFileSync(path.join(inputPath, '_prelude.vertex.glsl'));
+ const source = fs.readFileSync(path.join(inputPath, shaderName + '.vertex.glsl'), 'utf8');
return prelude + applyPragmas(source, {
define: [
"uniform lowp float a_{name}_t;",
@@ -50,8 +50,8 @@ require('./style-code');
}
function fragmentSource() {
- var prelude = fs.readFileSync(path.join(inputPath, '_prelude.fragment.glsl'));
- var source = fs.readFileSync(path.join(inputPath, shaderName + '.fragment.glsl'), 'utf8');
+ const prelude = fs.readFileSync(path.join(inputPath, '_prelude.fragment.glsl'));
+ const source = fs.readFileSync(path.join(inputPath, shaderName + '.fragment.glsl'), 'utf8');
return prelude + applyPragmas(source, {
define: [
"varying {precision} {type} {name};"
@@ -61,24 +61,42 @@ require('./style-code');
});
}
- 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);
+ writeIfModified(path.join(outputPath, `${shaderName}.hpp`), `// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.
+
+#pragma once
+
+#include <mbgl/gl/gl.hpp>
+
+namespace mbgl {
+namespace shaders {
+
+class ${shaderName} {
+public:
+ static const char* name;
+ static const char* vertexSource;
+ static const char* fragmentSource;
+};
+
+} // namespace shaders
+} // namespace mbgl
+`);
+
+ writeIfModified(path.join(outputPath, `${shaderName}.cpp`), `// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.
+
+#include <mbgl/shaders/${shaderName}.hpp>
+
+namespace mbgl {
+namespace shaders {
+
+const char* ${shaderName}::name = "${shaderName}";
+const char* ${shaderName}::vertexSource = R"MBGL_SHADER(
+${vertexSource()}
+)MBGL_SHADER";
+const char* ${shaderName}::fragmentSource = R"MBGL_SHADER(
+${fragmentSource()}
+)MBGL_SHADER";
+
+} // namespace shaders
+} // namespace mbgl
+`);
});