summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-06-02 15:31:21 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-06-02 15:42:42 +0300
commitaf65da1ad79d760481379e20367c5977916f1a57 (patch)
tree65c82b49031297bc3a89222ea54db9d328c78824 /scripts
parent7a7efcf3b73ead9c1d0f9033ebfa3008b14d2dc4 (diff)
downloadqtlocation-mapboxgl-af65da1ad79d760481379e20367c5977916f1a57.tar.gz
[core] Support "#pragma mapbox:" commands in shader code
Fixes https://github.com/mapbox/mapbox-gl-native/issues/5174.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/build-shaders.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/scripts/build-shaders.py b/scripts/build-shaders.py
index 228ba65112..60e8552123 100755
--- a/scripts/build-shaders.py
+++ b/scripts/build-shaders.py
@@ -18,6 +18,35 @@ shader_name, shader_type, extension = os.path.basename(input_file).split('.')
with open(input_file, "r") as f:
data = f.read()
+# Replace uniform pragmas
+
+pragma_mapbox_regex = re.compile("(\s*)\#pragma \mapbox\: (initialize|define) (.*) (lowp|mediump|highp)")
+color_regex = re.compile("(.*)color")
+
+def replace_uniform_pragmas(line):
+ # FIXME We should obtain these from the source code.
+ if pragma_mapbox_regex.match(line):
+ params = line.split()
+ u_method = params[2]
+ u_name = "color" if color_regex.match(params[3]) else params[3]
+ u_precision = params[4]
+ u_type = "vec4" if color_regex.match(u_name) else "float"
+ if u_method == "define":
+ return """uniform {precision} {type_} u_{name};""".format(
+ precision = u_precision,
+ type_ = u_type,
+ name = u_name)
+ else:
+ return """ {precision} {type_} {glsl_name} = u_{name};""".format(
+ precision = u_precision,
+ type_ = u_type,
+ glsl_name = params[3],
+ name = u_name)
+ else:
+ return line
+
+data = "\n".join([replace_uniform_pragmas(line) for line in data.split("\n")])
+
content = """#pragma once
// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.