[core] Support "#pragma mapbox:" commands in shader code
Fixes https://github.com/mapbox/mapbox-gl-native/issues/5174.
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user