diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/build-shaders.py | 29 |
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. |