summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-03-08 08:55:55 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-03-08 13:49:24 -0800
commitb83b14feb0b99d669fb84a52ab356051368de637 (patch)
treeadc86e0e415db7d7f0371471e1d3fe4b95146968 /scripts
parent84aac92b4eaf264de66c07b98e267364e34e14f0 (diff)
downloadqtlocation-mapboxgl-b83b14feb0b99d669fb84a52ab356051368de637.tar.gz
[core] De-duplicate shader prelude source
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/generate-shaders.js41
1 files changed, 37 insertions, 4 deletions
diff --git a/scripts/generate-shaders.js b/scripts/generate-shaders.js
index 2949ebd007..892620cf21 100755
--- a/scripts/generate-shaders.js
+++ b/scripts/generate-shaders.js
@@ -8,6 +8,41 @@ 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
+
+namespace mbgl {
+namespace shaders {
+
+extern const char* vertexPrelude;
+extern const char* fragmentPrelude;
+
+} // namespace shaders
+} // namespace mbgl
+`);
+
+writeIfModified(path.join(outputPath, 'preludes.cpp'), `// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.
+
+#include <mbgl/shaders/preludes.hpp>
+
+namespace mbgl {
+namespace shaders {
+
+const char* vertexPrelude = R"MBGL_SHADER(
+${vertexPrelude}
+)MBGL_SHADER";
+const char* fragmentPrelude = R"MBGL_SHADER(
+${fragmentPrelude}
+)MBGL_SHADER";
+
+} // namespace shaders
+} // namespace mbgl
+`);
+
[
'circle',
'collision_box',
@@ -34,9 +69,8 @@ require('./style-code');
}
function vertexSource() {
- 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, {
+ return applyPragmas(source, {
define: [
"uniform lowp float a_{name}_t;",
"attribute {precision} {type} a_{name}_min;",
@@ -50,9 +84,8 @@ require('./style-code');
}
function fragmentSource() {
- 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, {
+ return applyPragmas(source, {
define: [
"varying {precision} {type} {name};"
],