def main(): # auto_script parameters. if len(sys.argv) > 1: inputs = [ '../../angle_format.py', 'texture_format_data.json', 'texture_format_map.json' ] outputs = ['texture_format_table_autogen.cpp'] if sys.argv[1] == 'inputs': print ','.join(inputs) elif sys.argv[1] == 'outputs': print ','.join(outputs) else: print('Invalid script parameters') return 1 return 0 json_map = angle_format.load_with_override( os.path.abspath('texture_format_map.json')) data_source_name = 'texture_format_data.json' json_data = angle_format.load_json(data_source_name) angle_format_cases = parse_json_into_switch_angle_format_string( json_map, json_data) output_cpp = template_texture_format_table_autogen_cpp.format( script_name=sys.argv[0], angle_format_info_cases=angle_format_cases, data_source_name=data_source_name) with open('texture_format_table_autogen.cpp', 'wt') as out_file: out_file.write(output_cpp) out_file.close() return 0
def main(): # auto_script parameters. if len(sys.argv) > 1: inputs = ['angle_format.py', 'load_texture_border_functions_data.json'] outputs = ['load_texture_border_functions_table_autogen.cpp'] if sys.argv[1] == 'inputs': print(','.join(inputs)) elif sys.argv[1] == 'outputs': print(','.join(outputs)) else: print('Invalid script parameters') return 1 return 0 json_data = angle_format.load_json('load_texture_border_functions_data.json') switch_data, load_functions_data = parse_json(json_data) output = template.format( internal_format=internal_format_param, angle_format=angle_format_param, switch_data=switch_data, load_functions_data=load_functions_data) with open('load_texture_border_functions_table_autogen.cpp', 'wt') as out_file: out_file.write(output) out_file.close() return 0
def main(): # auto_script parameters. if len(sys.argv) > 1: inputs = ['load_functions_data.json'] outputs = ['load_functions_table_autogen.cpp'] if sys.argv[1] == 'inputs': print ','.join(inputs) elif sys.argv[1] == 'outputs': print ','.join(outputs) else: print('Invalid script parameters') return 1 return 0 json_data = angle_format.load_json('load_functions_data.json') switch_data, load_functions_data = parse_json(json_data) output = template.format( internal_format=internal_format_param, angle_format=angle_format_param, switch_data=switch_data, load_functions_data=load_functions_data, copyright_year=date.today().year) with open('load_functions_table_autogen.cpp', 'wt') as out_file: out_file.write(output) out_file.close() return 0
def main(): # auto_script parameters. if len(sys.argv) > 1: inputs = ['../../angle_format.py', 'texture_format_data.json', 'texture_format_map.json'] outputs = ['texture_format_table_autogen.cpp'] if sys.argv[1] == 'inputs': print ','.join(inputs) elif sys.argv[1] == 'outputs': print ','.join(outputs) else: print('Invalid script parameters') return 1 return 0 json_map = angle_format.load_with_override(os.path.abspath('texture_format_map.json')) data_source_name = 'texture_format_data.json' json_data = angle_format.load_json(data_source_name) angle_format_cases = parse_json_into_switch_angle_format_string(json_map, json_data) output_cpp = template_texture_format_table_autogen_cpp.format( script_name=sys.argv[0], copyright_year=date.today().year, angle_format_info_cases=angle_format_cases, data_source_name=data_source_name) with open('texture_format_table_autogen.cpp', 'wt') as out_file: out_file.write(output_cpp) out_file.close() return 0
def main(): # auto_script parameters. if len(sys.argv) > 1: inputs = ['mtl_format_map.json'] outputs = ['mtl_format_table_autogen.mm'] if sys.argv[1] == 'inputs': print ','.join(inputs) elif sys.argv[1] == 'outputs': print ','.join(outputs) else: print('Invalid script parameters') return 1 return 0 data_source_name = 'mtl_format_map.json' map_json = angle_format.load_json(data_source_name) map_image = map_json["image"] map_vertex = map_json["vertex"] image_switch_data = gen_image_map_switch_string(map_image) vertex_switch_data = gen_vertex_map_switch_string(map_vertex) output_cpp = template_autogen_inl.format( script_name=sys.argv[0], copyright_year=date.today().year, data_source_name=data_source_name, angle_image_format_switch=image_switch_data, angle_vertex_format_switch=vertex_switch_data) with open('mtl_format_table_autogen.mm', 'wt') as out_file: out_file.write(output_cpp) out_file.close()
def main(): input_file_name = 'vk_mandatory_format_support_data.json' vk_format_map_path = 'vk_format_map.json' out_file_name = 'vk_mandatory_format_support_table_autogen.cpp' vk_xml_file = '../../../../third_party/vulkan-deps/vulkan-headers/src/registry/vk.xml' # auto_script parameters. if len(sys.argv) > 1: inputs = [ '../angle_format.py', input_file_name, vk_format_map_path, vk_xml_file, ] outputs = [out_file_name] if sys.argv[1] == 'inputs': print ','.join(inputs) elif sys.argv[1] == 'outputs': print ','.join(outputs) else: print('Invalid script parameters') return 1 return 0 tree = etree.parse(script_relative(vk_xml_file)) root = tree.getroot() vk_format_enums = root.findall(".//enums[@name='VkFormat']/enum") vk_map = angle_format.load_json(input_file_name) vk_format_map = angle_format.load_json(vk_format_map_path) vk_cases = [ gen_format_case(format_id, vk_format, vk_map) for format_id, vk_format in vk_format_map["map"].iteritems() ] output_cpp = TEMPLATE_TABLE_AUTOGEN_CPP.format( format_case_data=",\n".join(vk_cases), script_name=__file__, out_file_name=out_file_name, input_file_name=input_file_name) with open(out_file_name, 'wt') as out_file: out_file.write(output_cpp) out_file.close() return 0
def main(): input_file_name = 'vk_format_map.json' out_file_name = 'vk_format_table_autogen.cpp' # auto_script parameters. if len(sys.argv) > 1: inputs = [ '../angle_format.py', '../angle_format_map.json', input_file_name ] outputs = [out_file_name] if sys.argv[1] == 'inputs': print(','.join(inputs)) elif sys.argv[1] == 'outputs': print(','.join(outputs)) else: print('Invalid script parameters') return 1 return 0 angle_to_gl = angle_format.load_inverse_table( os.path.join('..', 'angle_format_map.json')) vk_json_data = angle_format.load_json(input_file_name) if not verify_vk_map_keys(angle_to_gl, vk_json_data): return 1 format_id_cases = [ get_format_id_case(format_id, vk_format) for format_id, vk_format in sorted(vk_json_data["map"].items()) ] vk_format_cases = [ get_vk_format_case(format_id, vk_format) for format_id, vk_format in sorted(vk_json_data["map"].items()) ] vk_cases = [ gen_format_case(angle, gl, vk_json_data) for angle, gl in sorted(angle_to_gl.items()) ] output_cpp = template_table_autogen_cpp.format( format_case_data="\n".join(vk_cases), format_id_cases=",\n".join(format_id_cases), vk_format_cases="".join(vk_format_cases), script_name=os.path.basename(__file__), out_file_name=out_file_name, input_file_name=input_file_name) with open(out_file_name, 'wt') as out_file: out_file.write(output_cpp) out_file.close() return 0
def main(): input_file_name = 'vk_mandatory_format_support_data.json' out_file_name = 'vk_mandatory_format_support_table_autogen.cpp' vk_xml_file = '../../../../third_party/vulkan-headers/src/registry/vk.xml' # auto_script parameters. if len(sys.argv) > 1: inputs = [ '../angle_format.py', input_file_name, vk_xml_file, ] outputs = [out_file_name] if sys.argv[1] == 'inputs': print ','.join(inputs) elif sys.argv[1] == 'outputs': print ','.join(outputs) else: print('Invalid script parameters') return 1 return 0 tree = etree.parse(script_relative(vk_xml_file)) root = tree.getroot() vk_format_enums = root.findall(".//enums[@name='VkFormat']/enum") vk_format_name_to_index_map = {} num_formats = len(vk_format_enums) for format_enum in vk_format_enums: index = int(format_enum.attrib['value']) vk_format = format_enum.attrib['name'] vk_format_name_to_index_map[index] = vk_format vk_map = angle_format.load_json(input_file_name) vk_cases = [ gen_format_case(index, vk_format_name_to_index_map, vk_map) for index in vk_format_name_to_index_map ] output_cpp = template_table_autogen_cpp.format( copyright_year=date.today().year, num_formats=num_formats, format_case_data="\n,".join(vk_cases), script_name=__file__, out_file_name=out_file_name, input_file_name=input_file_name) with open(out_file_name, 'wt') as out_file: out_file.write(output_cpp) out_file.close() return 0
def main(): input_file_name = 'vk_mandatory_format_support_data.json' out_file_name = 'vk_mandatory_format_support_table_autogen.cpp' vk_xml_file = '../../../../third_party/vulkan-deps/vulkan-headers/src/registry/vk.xml' # auto_script parameters. if len(sys.argv) > 1: inputs = [ '../angle_format.py', input_file_name, vk_xml_file, ] outputs = [out_file_name] if sys.argv[1] == 'inputs': print ','.join(inputs) elif sys.argv[1] == 'outputs': print ','.join(outputs) else: print('Invalid script parameters') return 1 return 0 tree = etree.parse(script_relative(vk_xml_file)) root = tree.getroot() vk_format_enums = root.findall(".//enums[@name='VkFormat']/enum") vk_format_name_to_index_map = {} num_formats = len(vk_format_enums) for format_enum in vk_format_enums: index = int(format_enum.attrib['value']) vk_format = format_enum.attrib['name'] vk_format_name_to_index_map[index] = vk_format vk_map = angle_format.load_json(input_file_name) vk_cases = [ gen_format_case(index, vk_format_name_to_index_map, vk_map) for index in vk_format_name_to_index_map ] output_cpp = template_table_autogen_cpp.format( copyright_year=date.today().year, num_formats=num_formats, format_case_data="\n,".join(vk_cases), script_name=__file__, out_file_name=out_file_name, input_file_name=input_file_name) with open(out_file_name, 'wt') as out_file: out_file.write(output_cpp) out_file.close() return 0
def main(): # auto_script parameters. if len(sys.argv) > 1: inputs = [ 'angle_format.py', 'angle_format_data.json', 'angle_format_map.json' ] outputs = ['Format_table_autogen.cpp', 'FormatID_autogen.h'] if sys.argv[1] == 'inputs': print ','.join(inputs) elif sys.argv[1] == 'outputs': print ','.join(outputs) else: print('Invalid script parameters') return 1 return 0 gl_to_angle = angle_format.load_forward_table('angle_format_map.json') angle_to_gl = angle_format.load_inverse_table('angle_format_map.json') data_source_name = 'angle_format_data.json' json_data = angle_format.load_json(data_source_name) all_angle = angle_to_gl.keys() angle_format_cases = parse_angle_format_table(all_angle, json_data, angle_to_gl) switch_data = gen_map_switch_string(gl_to_angle) output_cpp = template_autogen_inl.format( script_name=sys.argv[0], copyright_year=date.today().year, angle_format_info_cases=angle_format_cases, angle_format_switch=switch_data, data_source_name=data_source_name) with open('Format_table_autogen.cpp', 'wt') as out_file: out_file.write(output_cpp) out_file.close() enum_data = gen_enum_string(all_angle) num_angle_formats = len(all_angle) output_h = template_autogen_h.format(script_name=sys.argv[0], copyright_year=date.today().year, angle_format_enum=enum_data, data_source_name=data_source_name, num_angle_formats=num_angle_formats) with open('FormatID_autogen.h', 'wt') as out_file: out_file.write(output_h) out_file.close() return 0
def main(): # auto_script parameters. if len(sys.argv) > 1: inputs = ['angle_format.py', 'angle_format_data.json', 'angle_format_map.json'] outputs = ['Format_table_autogen.cpp', 'FormatID_autogen.h'] if sys.argv[1] == 'inputs': print ','.join(inputs) elif sys.argv[1] == 'outputs': print ','.join(outputs) else: print('Invalid script parameters') return 1 return 0 gl_to_angle = angle_format.load_forward_table('angle_format_map.json') angle_to_gl = angle_format.load_inverse_table('angle_format_map.json') data_source_name = 'angle_format_data.json' json_data = angle_format.load_json(data_source_name) all_angle = angle_to_gl.keys() angle_format_cases = parse_angle_format_table(all_angle, json_data, angle_to_gl) switch_data = gen_map_switch_string(gl_to_angle) output_cpp = template_autogen_inl.format( script_name=sys.argv[0], copyright_year=date.today().year, angle_format_info_cases=angle_format_cases, angle_format_switch=switch_data, data_source_name=data_source_name) with open('Format_table_autogen.cpp', 'wt') as out_file: out_file.write(output_cpp) out_file.close() enum_data = gen_enum_string(all_angle) num_angle_formats = len(all_angle) output_h = template_autogen_h.format( script_name=sys.argv[0], copyright_year=date.today().year, angle_format_enum=enum_data, data_source_name=data_source_name, num_angle_formats=num_angle_formats) with open('FormatID_autogen.h', 'wt') as out_file: out_file.write(output_h) out_file.close() return 0
def main(): # auto_script parameters. if len(sys.argv) > 1: inputs = [data_source_name] outputs = [out_file_name] if sys.argv[1] == 'inputs': print ','.join(inputs) elif sys.argv[1] == 'outputs': print ','.join(outputs) else: print('Invalid script parameters') return 1 return 0 json_data = angle_format.load_json(data_source_name) all_functions = {} for description, functions in json_data.iteritems(): for function in functions: if function.startswith("gl"): all_functions[function] = "gl::" + function[2:] # Special handling for EGL_ANGLE_explicit_context extension if support_egl_ANGLE_explicit_context: all_functions[function + "ContextANGLE"] = "gl::" + function[2:] + "ContextANGLE" elif function.startswith("egl"): all_functions[function] = "EGL_" + function[3:] else: all_functions[function] = function proc_data = [(' {"%s", P(%s)}' % (func, angle_func)) for func, angle_func in sorted(all_functions.iteritems())] with open(out_file_name, 'w') as out_file: output_cpp = template_cpp.format( script_name=sys.argv[0], data_source_name=data_source_name, copyright_year=date.today().year, proc_data=",\n".join(proc_data), num_procs=len(proc_data)) out_file.write(output_cpp) out_file.close() return 0
def main(): # auto_script parameters. if len(sys.argv) > 1: inputs = [data_source_name] outputs = [out_file_name] if sys.argv[1] == 'inputs': print ','.join(inputs) elif sys.argv[1] == 'outputs': print ','.join(outputs) else: print('Invalid script parameters') return 1 return 0 json_data = angle_format.load_json(data_source_name) all_functions = {} for description, functions in json_data.iteritems(): for function in functions: if function.startswith("gl"): all_functions[function] = "gl::" + function[2:] # Special handling for EGL_ANGLE_explicit_context extension if support_egl_ANGLE_explicit_context: all_functions[function + "ContextANGLE"] = "gl::" + function[ 2:] + "ContextANGLE" elif function.startswith("egl"): all_functions[function] = "EGL_" + function[3:] else: all_functions[function] = function proc_data = [(' {"%s", P(%s)}' % (func, angle_func)) for func, angle_func in sorted(all_functions.iteritems())] with open(out_file_name, 'w') as out_file: output_cpp = template_cpp.format(script_name=sys.argv[0], data_source_name=data_source_name, copyright_year=date.today().year, proc_data=",\n".join(proc_data), num_procs=len(proc_data)) out_file.write(output_cpp) out_file.close() return 0
def main(): data_source_name = 'es3_copy_conversion_formats.json' out_file_name = 'es3_copy_conversion_table_autogen.cpp' # auto_script parameters. if len(sys.argv) > 1: inputs = ['renderer/angle_format.py', data_source_name] outputs = [out_file_name] if sys.argv[1] == 'inputs': print ','.join(inputs) elif sys.argv[1] == 'outputs': print ','.join(outputs) else: print('Invalid script parameters') return 1 return 0 json_data = angle_format.load_json(data_source_name) format_map = {} for description, data in json_data.iteritems(): for texture_format, framebuffer_format in data: if texture_format not in format_map: format_map[texture_format] = [] format_map[texture_format] += [framebuffer_format] texture_format_cases = "" for texture_format, framebuffer_formats in sorted(format_map.iteritems()): texture_format_cases += parse_texture_format_case( texture_format, framebuffer_formats) with open(out_file_name, 'wt') as out_file: output_cpp = template_cpp.format( script_name=sys.argv[0], data_source_name=data_source_name, copyright_year=date.today().year, texture_format_cases=texture_format_cases) out_file.write(output_cpp) out_file.close() return 0
def main(): data_source_name = 'mtl_format_map.json' # auto_script parameters. if len(sys.argv) > 1: inputs = [ '../angle_format.py', '../angle_format_map.json', data_source_name ] outputs = ['mtl_format_table_autogen.mm'] if sys.argv[1] == 'inputs': print(','.join(inputs)) elif sys.argv[1] == 'outputs': print(','.join(outputs)) else: print('Invalid script parameters') return 1 return 0 angle_to_gl = angle_format_utils.load_inverse_table( '../angle_format_map.json') map_json = angle_format_utils.load_json(data_source_name) map_image = map_json["image"] map_vertex = map_json["vertex"] image_switch_data = gen_image_map_switch_string(map_image, angle_to_gl) image_mtl_to_angle_switch_data = gen_image_mtl_to_angle_switch_string( map_image) vertex_switch_data = gen_vertex_map_switch_string(map_vertex) caps_init_str = gen_mtl_format_caps_init_string(map_image) output_cpp = template_autogen_inl.format( script_name=sys.argv[0], data_source_name=data_source_name, angle_image_format_switch=image_switch_data, mtl_pixel_format_switch=image_mtl_to_angle_switch_data, angle_vertex_format_switch=vertex_switch_data, metal_format_caps=caps_init_str) with open('mtl_format_table_autogen.mm', 'wt') as out_file: out_file.write(output_cpp) out_file.close()
def main(): data_source_name = 'es3_copy_conversion_formats.json' out_file_name = 'es3_copy_conversion_table_autogen.cpp' # auto_script parameters. if len(sys.argv) > 1: inputs = [data_source_name] outputs = [out_file_name] if sys.argv[1] == 'inputs': print ','.join(inputs) elif sys.argv[1] == 'outputs': print ','.join(outputs) else: print('Invalid script parameters') return 1 return 0 json_data = angle_format.load_json(data_source_name) format_map = {} for description, data in json_data.iteritems(): for texture_format, framebuffer_format in data: if texture_format not in format_map: format_map[texture_format] = [] format_map[texture_format] += [framebuffer_format] texture_format_cases = "" for texture_format, framebuffer_formats in sorted(format_map.iteritems()): texture_format_cases += parse_texture_format_case(texture_format, framebuffer_formats) with open(out_file_name, 'wt') as out_file: output_cpp = template_cpp.format( script_name=sys.argv[0], data_source_name=data_source_name, copyright_year=date.today().year, texture_format_cases=texture_format_cases) out_file.write(output_cpp) out_file.close() return 0
def main(): input_file_name = 'vk_format_map.json' out_file_name = 'vk_format_table_autogen.cpp' # auto_script parameters. if len(sys.argv) > 1: inputs = [ '../angle_format.py', '../angle_format_map.json', input_file_name ] outputs = [out_file_name] if sys.argv[1] == 'inputs': print ','.join(inputs) elif sys.argv[1] == 'outputs': print ','.join(outputs) else: print('Invalid script parameters') return 1 return 0 angle_to_gl = angle_format.load_inverse_table( os.path.join('..', 'angle_format_map.json')) vk_json_data = angle_format.load_json(input_file_name) vk_cases = [ gen_format_case(angle, gl, vk_json_data) for angle, gl in sorted(angle_to_gl.iteritems()) ] output_cpp = template_table_autogen_cpp.format( copyright_year=date.today().year, format_case_data="\n".join(vk_cases), script_name=__file__, out_file_name=out_file_name, input_file_name=input_file_name) with open(out_file_name, 'wt') as out_file: out_file.write(output_cpp) out_file.close() return 0
def main(): input_file_name = 'vk_format_map.json' out_file_name = 'vk_format_table_autogen.cpp' # auto_script parameters. if len(sys.argv) > 1: inputs = ['../angle_format.py', '../angle_format_map.json', input_file_name] outputs = [out_file_name] if sys.argv[1] == 'inputs': print ','.join(inputs) elif sys.argv[1] == 'outputs': print ','.join(outputs) else: print('Invalid script parameters') return 1 return 0 angle_to_gl = angle_format.load_inverse_table(os.path.join('..', 'angle_format_map.json')) vk_json_data = angle_format.load_json(input_file_name) vk_cases = [ gen_format_case(angle, gl, vk_json_data) for angle, gl in sorted(angle_to_gl.iteritems()) ] output_cpp = template_table_autogen_cpp.format( copyright_year=date.today().year, format_case_data="\n".join(vk_cases), script_name=__file__, out_file_name=out_file_name, input_file_name=input_file_name) with open(out_file_name, 'wt') as out_file: out_file.write(output_cpp) out_file.close() return 0
for internal_format, format_name in sorted(json_map.iteritems()): if format_name not in vk_map: continue native_format = vk_map[format_name] table_data += ' case ' + internal_format + ':\n' table_data += parse_format_case(internal_format, format_name, native_format) return table_data input_file_name = 'vk_format_map.json' out_file_name = 'vk_format_table' json_map = angle_format.load_without_override() vk_map = angle_format.load_json(input_file_name) format_case_data = parse_json_into_cases(json_map, vk_map) output_cpp = template_table_autogen_cpp.format( copyright_year = date.today().year, format_case_data = format_case_data, script_name = __file__, out_file_name = out_file_name, input_file_name = input_file_name) with open(out_file_name + '_autogen.cpp', 'wt') as out_file: out_file.write(output_cpp) out_file.close()
angle_to_type_map, internal_format) else: has_break_in_switch = True table_data += s + ' break;\n' if do_switch: s = s[4:] table_data += s + '}\n' if has_break_in_switch: # If the inner switch contains a break statement, add a break # statement after the switch as well. table_data += s + 'break;\n' s = s[4:] table_data += s + '}\n' return table_data, load_functions_data json_data = angle_format.load_json('load_functions_data.json') switch_data, load_functions_data = parse_json(json_data) output = template.format(internal_format=internal_format_param, angle_format=angle_format_param, switch_data=switch_data, load_functions_data=load_functions_data, copyright_year=date.today().year) with open('load_functions_table_autogen.cpp', 'wt') as out_file: out_file.write(output) out_file.close()
if support_test != None: table_data += " {\n" table_data += json_to_table_data(internal_format, format_name, "if (" + support_test + ")", supported_case) table_data += json_to_table_data(internal_format, format_name, "else", unsupported_case) table_data += " }\n" else: table_data += json_to_table_data(internal_format, format_name, "", supported_case) return table_data json_map = angle_format.load_with_override( os.path.abspath('texture_format_map.json')) data_source_name = 'texture_format_data.json' json_data = angle_format.load_json(data_source_name) angle_format_cases = parse_json_into_switch_angle_format_string( json_map, json_data) output_cpp = template_texture_format_table_autogen_cpp.format( script_name=sys.argv[0], copyright_year=date.today().year, angle_format_info_cases=angle_format_cases, data_source_name=data_source_name) with open('texture_format_table_autogen.cpp', 'wt') as out_file: out_file.write(output_cpp) out_file.close()
def main(): # auto_script parameters. if len(sys.argv) > 1: inputs = [ '../../../../scripts/gl.xml', '../angle_format.py', 'gl_bindings_data.json', ] outputs = [ 'DispatchTableGL_autogen.cpp', 'DispatchTableGL_autogen.h', 'null_functions.cpp', 'null_functions.h', ] if sys.argv[1] == 'inputs': print(','.join(inputs)) elif sys.argv[1] == 'outputs': print(','.join(outputs)) else: print('Invalid script parameters') return 1 return 0 gl_xml_path = os.path.join('..', '..', '..', '..', 'scripts', 'gl.xml') dispatch_header_path = 'DispatchTableGL_autogen.h' dispatch_source_path = 'DispatchTableGL_autogen.cpp' null_functions_header_path = 'null_functions.h' null_functions_source_path = 'null_functions.cpp' # Load the JSON and XML data. data_source_name = 'gl_bindings_data.json' json_data = angle_format.load_json(data_source_name) xml_root = etree.parse(gl_xml_path).getroot() api_feature_info = {} core_removed_eps = [] for core_removed_ep in xml_root.findall('feature/remove'): assert (core_removed_ep.attrib['profile'] == 'core') for command in core_removed_ep.findall('./command'): core_removed_eps.append(command.attrib['name']) for feature in xml_root.findall('feature'): api = feature.attrib['api'] name = feature.attrib['name'] number = feature.attrib['number'] # OpenGL ES 3.x versions are listed as api 'gles2' if api != 'gl' and api != 'gles2': continue for command in feature.findall('./require/command'): command_name = command.attrib['name'] safe_append(api_feature_info, command_name, (api, name, number)) gl_extension_commands = {} gles2_extension_commands = {} both_extension_commands = {} for extension in xml_root.findall('extensions/extension'): extension_name = extension.attrib['name'] support = extension.attrib['supported'].split('|') for command in extension.findall('./require/command'): command_name = command.attrib['name'] if 'gl' in support and 'gles2' in support: # Special case for KHR extensions, since in GLES they are suffixed. if '_KHR_' in extension_name and not command_name.endswith( 'KHR'): safe_append(gl_extension_commands, command_name, extension_name) safe_append(gles2_extension_commands, command_name, extension_name) else: safe_append(both_extension_commands, command_name, extension_name) elif 'gl' in support: safe_append(gl_extension_commands, command_name, extension_name) elif 'gles2' in support: safe_append(gles2_extension_commands, command_name, extension_name) gl_requirements = {} gles2_requirements = {} gl_extension_requirements = {} gles2_extension_requirements = {} both_extension_requirements = {} # Used later in the NULL bindings. all_entry_points = [] for comment, entry_points in sorted(json_data.items()): for entry_point_no_prefix in entry_points: entry_point = "gl" + entry_point_no_prefix all_entry_points.append(entry_point) gl_required = None gles2_required = None if entry_point in api_feature_info: for api, name, number in api_feature_info[entry_point]: major, minor = number.split(".") reqs = (major, minor) if api == 'gl': if not gl_required: gl_required = reqs elif entry_point in core_removed_eps: print('Upgrade ' + entry_point + ' to ' + str(reqs) + ' instead of ' + str(gl_required)) gl_required = reqs else: print('Keep ' + entry_point + ' at ' + str(gl_required) + ' instead of ' + str(reqs)) elif api == 'gles2': if not gles2_required: gles2_required = reqs else: print("Duplicate for " + entry_point + ": " + str(reqs) + " and " + str(gles2_required)) else: raise Exception('Bad api type: ' + api) if gl_required: safe_append(gl_requirements, gl_required, entry_point) if gles2_required: safe_append(gles2_requirements, gles2_required, entry_point) # Special case for finding extensions that overlap with core functions. extension = False for ep in [ entry_point, entry_point + "EXT", entry_point + "ARB", entry_point + "OES" ]: if ep in both_extension_commands: extension = True for extension in both_extension_commands[ep]: safe_append(both_extension_requirements, extension, (entry_point, ep)) else: if ep in gl_extension_commands: extension = True for extension in gl_extension_commands[ep]: safe_append(gl_extension_requirements, extension, (entry_point, ep)) if ep in gles2_extension_commands: extension = True for extension in gles2_extension_commands[ep]: full_ep = ep if '_KHR_' in extension: full_ep += 'KHR' safe_append(gles2_extension_requirements, extension, (entry_point, full_ep)) if not (gl_required or gles2_required or extension): raise Exception('Entry point ' + entry_point + ' not found in the xml.') table_data = [] for comment, entry_points in sorted(json_data.items()): formatted = [" // " + comment] formatted += [ format_ep_decl(entry_point) for entry_point in sorted(entry_points) ] table_data.append("\n".join(formatted)) dispatch_table_header = dispatch_table_header_template.format( script_name=os.path.basename(sys.argv[0]), data_source_name=data_source_name, file_name=dispatch_header_path, table_data="\n\n".join(table_data)) with open(dispatch_header_path, "w") as out: out.write(dispatch_table_header) gl_data = [] for gl_required, entry_points in sorted(gl_requirements.items()): gl_data.append(format_requirements_lines(gl_required, entry_points)) gl_extensions_data = [] for extension, entry_points in sorted(gl_extension_requirements.items()): gl_extensions_data.append( format_extension_requirements_lines(extension, entry_points, "gl")) gles2_data = [] for gles2_required, entry_points in sorted(gles2_requirements.items()): gles2_data.append( format_requirements_lines(gles2_required, entry_points)) gles2_extensions_data = [] for extension, entry_points in sorted( gles2_extension_requirements.items()): gles2_extensions_data.append( format_extension_requirements_lines(extension, entry_points, "gles2")) both_extensions_data = [] for extension, entry_points in sorted(both_extension_requirements.items()): both_extensions_data.append( format_extension_requirements_lines(extension, entry_points, "gles2|gl")) dispatch_table_source = dispatch_table_source_template.format( script_name=os.path.basename(sys.argv[0]), data_source_name=data_source_name, file_name=dispatch_source_path, gl_data="\n\n".join(gl_data), gl_extensions_data="\n\n".join(gl_extensions_data), gles2_data="\n\n".join(gles2_data), gles2_extensions_data="\n\n".join(gles2_extensions_data), both_extensions_data="\n\n".join(both_extensions_data), gl_null_data="\n\n".join(nullify(gl_data)), gl_null_extensions_data="\n\n".join(nullify(gl_extensions_data)), gles2_null_data="\n\n".join(nullify(gles2_data)), gles2_null_extensions_data="\n\n".join(nullify(gles2_extensions_data)), both_null_extensions_data="\n\n".join(nullify(both_extensions_data))) with open(dispatch_source_path, "w") as out: out.write(dispatch_table_source) # Generate the NULL/stub entry points. # Process the whole set of commands command_defs = {} command_decls = {} for command in xml_root.findall('commands/command'): proto = command.find('proto') command_name = proto.find('name').text entry = ''.join(proto.itertext()) return_type = entry[:-len(command_name)] entry = return_type + ' INTERNAL_GL_APIENTRY ' + entry[ len(return_type):] + 'NULL(' param_text = [ format_param(param) for param in command.findall('param') ] entry += ', '.join(param_text) + ')' command_decls[command_name] = entry + ';' entry += '\n{\n' if return_type != 'void ': entry += ' return static_cast<' + return_type + '>(0);\n' entry += '}' command_defs[command_name] = entry null_decls = [ command_decls[entry_point] for entry_point in sorted(all_entry_points) ] null_stubs = [ command_defs[entry_point] for entry_point in sorted(all_entry_points) ] null_functions_header = null_functions_header_template.format( script_name=os.path.basename(sys.argv[0]), data_source_name=data_source_name, file_name=null_functions_header_path, table_data="\n".join(null_decls)) with open(null_functions_header_path, "w") as out: out.write(null_functions_header) null_functions_source = null_functions_source_template.format( script_name=os.path.basename(sys.argv[0]), data_source_name=data_source_name, file_name=null_functions_source_path, table_data="\n\n".join(null_stubs)) with open(null_functions_source_path, "w") as out: out.write(null_functions_source) return 0
def main(): # auto_script parameters. if len(sys.argv) > 1: inputs = [ '../../angle_format.py', '../../angle_format_map.json', 'dxgi_format_data.json', ] outputs = ['dxgi_format_map_autogen.cpp'] if sys.argv[1] == 'inputs': print ','.join(inputs) elif sys.argv[1] == 'outputs': print ','.join(outputs) else: print('Invalid script parameters') return 1 return 0 component_cases = "" format_cases = "" input_data = 'dxgi_format_data.json' dxgi_map = angle_format.load_json(input_data) types = { 'SNORM': 'GL_SIGNED_NORMALIZED', 'UNORM': 'GL_UNSIGNED_NORMALIZED', 'SINT': 'GL_INT', 'UINT': 'GL_UNSIGNED_INT', 'FLOAT': 'GL_FLOAT', 'SHAREDEXP': 'GL_FLOAT' } all_angle = angle_format.get_all_angle_formats() for dxgi_format, a_format in sorted(dxgi_map.iteritems()): found = [ctype in dxgi_format for ctype in types.keys()] count = reduce((lambda a, b: int(a) + int(b)), found) component_type = 'GL_NONE' if count == 1: gltype = next(gltype for ctype, gltype in types.iteritems() if ctype in dxgi_format) component_cases += format_case(dxgi_format, gltype) else: component_cases += undefined_case(dxgi_format) if a_format == "": a_format = dxgi_format if a_format in all_angle: a_format = "Format::Get(FormatID::" + a_format + ")" format_cases += format_case(dxgi_format, a_format) else: format_cases += undefined_case(dxgi_format) with open('dxgi_format_map_autogen.cpp', 'wt') as out_file: output_cpp = template_cpp.format(script_name=sys.argv[0], data_source_name=input_data, copyright_year=date.today().year, component_type_cases=component_cases, format_cases=format_cases) out_file.write(output_cpp) out_file.close() return 0
def parse_type_case(type, internal_format): return template_type_case.format(type=type, internal_format=internal_format) def parse_format_case(format, type_map): type_cases = "" for type, internal_format in sorted(type_map.iteritems()): type_cases += parse_type_case(type, internal_format) return template_format_case.format(format=format, type_cases=type_cases) input_script = 'format_map_data.json' format_map = angle_format.load_json(input_script) format_cases = "" for format, type_map in sorted(format_map.iteritems()): format_cases += parse_format_case(format, type_map) with open('format_map_autogen.cpp', 'wt') as out_file: output_cpp = template_cpp.format(script_name=sys.argv[0], data_source_name=input_script, copyright_year=date.today().year, format_cases=format_cases) out_file.write(output_cpp) out_file.close()
table_data += ' case ID::' + format_id + ':\n' table_data += json_to_table_data(format_id, format_info, angle_to_gl) return table_data def gen_enum_string(all_angle): enum_data = ' NONE' for format_id in sorted(all_angle): if format_id == 'NONE': continue enum_data += ',\n ' + format_id return enum_data gl_to_angle = angle_format.load_forward_table('angle_format_map.json') angle_to_gl = angle_format.load_inverse_table('angle_format_map.json') json_data = angle_format.load_json('angle_format_data.json') all_angle = angle_to_gl.keys() angle_format_cases = parse_json_into_angle_format_switch_string( all_angle, json_data, angle_to_gl) output_cpp = template_autogen_cpp.format( copyright_year=date.today().year, angle_format_info_cases=angle_format_cases) with open('Format_autogen.cpp', 'wt') as out_file: out_file.write(output_cpp) out_file.close() enum_data = gen_enum_string(all_angle) output_h = template_autogen_h.format( copyright_year=date.today().year, angle_format_enum=enum_data)
if angle_format_unknown in angle_to_type_map: table_data += s + " return " + unknown_func_name(internal_format) + ";\n" load_functions_data += get_unknown_load_func(angle_to_type_map, internal_format) else: table_data += s + " break;\n" if do_switch: s = s[4:] table_data += s + "}\n" s = s[4:] table_data += s + "}\n" return table_data, load_functions_data json_data = angle_format.load_json("load_functions_data.json") switch_data, load_functions_data = parse_json(json_data) output = template.format( internal_format=internal_format_param, angle_format=angle_format_param, switch_data=switch_data, load_functions_data=load_functions_data, copyright_year=date.today().year, ) with open("load_functions_table_autogen.cpp", "wt") as out_file: out_file.write(output) out_file.close()
def main(): # auto_script parameters. if len(sys.argv) > 1: inputs = [ '../../../../scripts/gl.xml', '../angle_format.py', 'gl_bindings_data.json', ] outputs = [ 'DispatchTableGL_autogen.cpp', 'DispatchTableGL_autogen.h', 'null_functions.cpp', 'null_functions.h', ] if sys.argv[1] == 'inputs': print ','.join(inputs) elif sys.argv[1] == 'outputs': print ','.join(outputs) else: print('Invalid script parameters') return 1 return 0 gl_xml_path = os.path.join('..', '..', '..', '..', 'scripts', 'gl.xml') dispatch_header_path = 'DispatchTableGL_autogen.h' dispatch_source_path = 'DispatchTableGL_autogen.cpp' null_functions_header_path = 'null_functions.h' null_functions_source_path = 'null_functions.cpp' # Load the JSON and XML data. data_source_name = 'gl_bindings_data.json' json_data = angle_format.load_json(data_source_name) xml_root = etree.parse(gl_xml_path).getroot() api_feature_info = {} core_removed_eps = [] for core_removed_ep in xml_root.findall('feature/remove'): assert (core_removed_ep.attrib['profile'] == 'core') for command in core_removed_ep.findall('./command'): core_removed_eps.append(command.attrib['name']) for feature in xml_root.findall('feature'): api = feature.attrib['api'] name = feature.attrib['name'] number = feature.attrib['number'] # OpenGL ES 3.x versions are listed as api 'gles2' if api != 'gl' and api != 'gles2': continue for command in feature.findall('./require/command'): command_name = command.attrib['name'] safe_append(api_feature_info, command_name, (api, name, number)) gl_extension_commands = {} gles2_extension_commands = {} both_extension_commands = {} for extension in xml_root.findall('extensions/extension'): extension_name = extension.attrib['name'] support = extension.attrib['supported'].split('|') for command in extension.findall('./require/command'): command_name = command.attrib['name'] if 'gl' in support and 'gles2' in support: # Special case for KHR extensions, since in GLES they are suffixed. if '_KHR_' in extension_name and not command_name.endswith('KHR'): safe_append(gl_extension_commands, command_name, extension_name) safe_append(gles2_extension_commands, command_name, extension_name) else: safe_append(both_extension_commands, command_name, extension_name) elif 'gl' in support: safe_append(gl_extension_commands, command_name, extension_name) elif 'gles2' in support: safe_append(gles2_extension_commands, command_name, extension_name) gl_requirements = {} gles2_requirements = {} gl_extension_requirements = {} gles2_extension_requirements = {} both_extension_requirements = {} # Used later in the NULL bindings. all_entry_points = [] for comment, entry_points in json_data.iteritems(): for entry_point_no_prefix in entry_points: entry_point = "gl" + entry_point_no_prefix all_entry_points.append(entry_point) gl_required = None gles2_required = None if entry_point in api_feature_info: for api, name, number in api_feature_info[entry_point]: major, minor = number.split(".") reqs = (major, minor) if api == 'gl': if not gl_required: gl_required = reqs elif entry_point in core_removed_eps: print('Upgrade ' + entry_point + ' to ' + str(reqs) + ' instead of ' + str(gl_required)) gl_required = reqs else: print('Keep ' + entry_point + ' at ' + str(gl_required) + ' instead of ' + str(reqs)) elif api == 'gles2': if not gles2_required: gles2_required = reqs else: print("Duplicate for " + entry_point + ": " + str(reqs) + " and " + str(gles2_required)) else: raise Exception('Bad api type: ' + api) if gl_required: safe_append(gl_requirements, gl_required, entry_point) if gles2_required: safe_append(gles2_requirements, gles2_required, entry_point) # Special case for finding extensions that overlap with core functions. extension = False for ep in [entry_point, entry_point + "EXT", entry_point + "ARB", entry_point + "OES"]: if ep in both_extension_commands: extension = True for extension in both_extension_commands[ep]: safe_append(both_extension_requirements, extension, (entry_point, ep)) else: if ep in gl_extension_commands: extension = True for extension in gl_extension_commands[ep]: safe_append(gl_extension_requirements, extension, (entry_point, ep)) if ep in gles2_extension_commands: extension = True for extension in gles2_extension_commands[ep]: full_ep = ep if '_KHR_' in extension: full_ep += 'KHR' safe_append(gles2_extension_requirements, extension, (entry_point, full_ep)) if not (gl_required or gles2_required or extension): raise Exception('Entry point ' + entry_point + ' not found in the xml.') table_data = [] for comment, entry_points in sorted(json_data.iteritems()): formatted = [" // " + comment] formatted += [format_ep_decl(entry_point) for entry_point in sorted(entry_points)] table_data.append("\n".join(formatted)) dispatch_table_header = dispatch_table_header_template.format( script_name=os.path.basename(sys.argv[0]), data_source_name=data_source_name, year=date.today().year, file_name=dispatch_header_path, table_data="\n\n".join(table_data)) with open(dispatch_header_path, "w") as out: out.write(dispatch_table_header) gl_data = [] for gl_required, entry_points in sorted(gl_requirements.iteritems()): gl_data.append(format_requirements_lines(gl_required, entry_points)) gl_extensions_data = [] for extension, entry_points in sorted(gl_extension_requirements.iteritems()): gl_extensions_data.append( format_extension_requirements_lines(extension, entry_points, "gl")) gles2_data = [] for gles2_required, entry_points in sorted(gles2_requirements.iteritems()): gles2_data.append(format_requirements_lines(gles2_required, entry_points)) gles2_extensions_data = [] for extension, entry_points in sorted(gles2_extension_requirements.iteritems()): gles2_extensions_data.append( format_extension_requirements_lines(extension, entry_points, "gles2")) both_extensions_data = [] for extension, entry_points in sorted(both_extension_requirements.iteritems()): both_extensions_data.append( format_extension_requirements_lines(extension, entry_points, "gles2|gl")) dispatch_table_source = dispatch_table_source_template.format( script_name=os.path.basename(sys.argv[0]), data_source_name=data_source_name, year=date.today().year, file_name=dispatch_source_path, gl_data="\n\n".join(gl_data), gl_extensions_data="\n\n".join(gl_extensions_data), gles2_data="\n\n".join(gles2_data), gles2_extensions_data="\n\n".join(gles2_extensions_data), both_extensions_data="\n\n".join(both_extensions_data), gl_null_data="\n\n".join(nullify(gl_data)), gl_null_extensions_data="\n\n".join(nullify(gl_extensions_data)), gles2_null_data="\n\n".join(nullify(gles2_data)), gles2_null_extensions_data="\n\n".join(nullify(gles2_extensions_data)), both_null_extensions_data="\n\n".join(nullify(both_extensions_data))) with open(dispatch_source_path, "w") as out: out.write(dispatch_table_source) # Generate the NULL/stub entry points. # Process the whole set of commands command_defs = {} command_decls = {} for command in xml_root.findall('commands/command'): proto = command.find('proto') command_name = proto.find('name').text entry = ''.join(proto.itertext()) return_type = entry[:-len(command_name)] entry = return_type + ' INTERNAL_GL_APIENTRY ' + entry[len(return_type):] + 'NULL(' param_text = [format_param(param) for param in command.findall('param')] entry += ', '.join(param_text) + ')' command_decls[command_name] = entry + ';' entry += '\n{\n' if return_type != 'void ': entry += ' return static_cast<' + return_type + '>(0);\n' entry += '}' command_defs[command_name] = entry null_decls = [command_decls[entry_point] for entry_point in sorted(all_entry_points)] null_stubs = [command_defs[entry_point] for entry_point in sorted(all_entry_points)] null_functions_header = null_functions_header_template.format( script_name=os.path.basename(sys.argv[0]), data_source_name=data_source_name, year=date.today().year, file_name=null_functions_header_path, table_data="\n".join(null_decls)) with open(null_functions_header_path, "w") as out: out.write(null_functions_header) null_functions_source = null_functions_source_template.format( script_name=os.path.basename(sys.argv[0]), data_source_name=data_source_name, year=date.today().year, file_name=null_functions_source_path, table_data="\n\n".join(null_stubs)) with open(null_functions_source_path, "w") as out: out.write(null_functions_source) return 0
buffer_template=buffer_template, buffer=buffer_format, vk_buffer_format=vk_map[buffer_format], vertex_load_function=angle_format.get_vertex_copy_function(angle, buffer_format), vertex_load_converts='false' if angle == buffer_format else 'true', buffer_fallback=buffer_fallback, vk_buffer_format_fallback=vk_map[buffer_fallback], vertex_load_function_fallback=angle_format.get_vertex_copy_function(angle, buffer_fallback), ) return format_entry_template.format(**args).format(**args) input_file_name = 'vk_format_map.json' out_file_name = 'vk_format_table' angle_to_gl = angle_format.load_inverse_table(os.path.join('..', 'angle_format_map.json')) vk_json_data = angle_format.load_json(input_file_name) vk_cases = [gen_format_case(angle, gl, vk_json_data) for angle, gl in sorted(angle_to_gl.iteritems())] output_cpp = template_table_autogen_cpp.format( copyright_year = date.today().year, format_case_data = "\n".join(vk_cases), script_name = __file__, out_file_name = out_file_name, input_file_name = input_file_name) with open(out_file_name + '_autogen.cpp', 'wt') as out_file: out_file.write(output_cpp) out_file.close()
if len(buffers) == 1: args.update(buffer_template=buffer_basic_template) args.update(buffer_args(buffers[0])) elif len(buffers) > 1: args.update( buffer_template=buffer_fallback_template, buffer_list=", ".join( buffer_struct_template.format(**buffer_args(i)) for i in buffers)) return format_entry_template.format(**args).format(**args) input_file_name = 'vk_format_map.json' out_file_name = 'vk_format_table' angle_to_gl = angle_format.load_inverse_table(os.path.join('..', 'angle_format_map.json')) vk_json_data = angle_format.load_json(input_file_name) vk_cases = [gen_format_case(angle, gl, vk_json_data) for angle, gl in sorted(angle_to_gl.iteritems())] output_cpp = template_table_autogen_cpp.format( copyright_year = date.today().year, format_case_data = "\n".join(vk_cases), script_name = __file__, out_file_name = out_file_name, input_file_name = input_file_name) with open(out_file_name + '_autogen.cpp', 'wt') as out_file: out_file.write(output_cpp) out_file.close()
table_data += json_to_table_data(format_id, format_info, angle_to_gl) return table_data def gen_enum_string(all_angle): enum_data = ' NONE' for format_id in sorted(all_angle): if format_id == 'NONE': continue enum_data += ',\n ' + format_id return enum_data gl_to_angle = angle_format.load_forward_table('angle_format_map.json') angle_to_gl = angle_format.load_inverse_table('angle_format_map.json') data_source_name = 'angle_format_data.json' json_data = angle_format.load_json(data_source_name) all_angle = angle_to_gl.keys() angle_format_cases = parse_angle_format_table( all_angle, json_data, angle_to_gl) output_cpp = template_autogen_inl.format( script_name = sys.argv[0], copyright_year = date.today().year, angle_format_info_cases = angle_format_cases, data_source_name = data_source_name) with open('Format_table_autogen.cpp', 'wt') as out_file: out_file.write(output_cpp) out_file.close() enum_data = gen_enum_string(all_angle) output_h = template_autogen_h.format(
def format_case(dxgi_format, result): return template_format_case.format(dxgi_format=dxgi_format, result=result) def undefined_case(dxgi_format): return template_undefined_case.format(dxgi_format=dxgi_format) component_cases = "" format_cases = "" input_data = 'dxgi_format_data.json' dxgi_map = angle_format.load_json(input_data) types = { 'SNORM': 'GL_SIGNED_NORMALIZED', 'UNORM': 'GL_UNSIGNED_NORMALIZED', 'SINT': 'GL_INT', 'UINT': 'GL_UNSIGNED_INT', 'FLOAT': 'GL_FLOAT', 'SHAREDEXP': 'GL_FLOAT' } angle_to_gl = angle_format.load_inverse_table('../../angle_format_map.json') all_angle = angle_to_gl.keys() for dxgi_format, angle_format in sorted(dxgi_map.iteritems()):
""" def parse_type_case(type, result): return template_simple_case.format( key = type, result = result) def parse_format_case(format, type_map): type_cases = "" for type, internal_format in sorted(type_map.iteritems()): type_cases += parse_type_case(type, internal_format) return template_format_case.format( format = format, type_cases = type_cases) input_script = 'format_map_data.json' format_map = angle_format.load_json(input_script) format_cases = "" for format, type_map in sorted(format_map.iteritems()): format_cases += parse_format_case(format, type_map) combo_data_file = 'es3_format_type_combinations.json' es3_combo_data = angle_format.load_json(combo_data_file) combo_data = [combo for sublist in es3_combo_data.values() for combo in sublist] types = set() formats = set() combos = {} for internal_format, format, type in combo_data:
""" def format_case(dxgi_format, result): return template_format_case.format( dxgi_format = dxgi_format, result = result) def undefined_case(dxgi_format): return template_undefined_case.format(dxgi_format = dxgi_format) component_cases = "" format_cases = "" input_data = 'dxgi_format_data.json' dxgi_map = angle_format.load_json(input_data) types = { 'SNORM': 'GL_SIGNED_NORMALIZED', 'UNORM': 'GL_UNSIGNED_NORMALIZED', 'SINT': 'GL_INT', 'UINT': 'GL_UNSIGNED_INT', 'FLOAT': 'GL_FLOAT', 'SHAREDEXP': 'GL_FLOAT' } angle_to_gl = angle_format.load_inverse_table('../../angle_format_map.json') all_angle = angle_to_gl.keys() for dxgi_format, angle_format in sorted(dxgi_map.iteritems()):
def main(): # auto_script parameters. if len(sys.argv) > 1: inputs = [ 'renderer/angle_format.py', 'es3_format_type_combinations.json', 'format_map_data.json' ] outputs = ['format_map_autogen.cpp'] if sys.argv[1] == 'inputs': print ','.join(inputs) elif sys.argv[1] == 'outputs': print ','.join(outputs) else: print('Invalid script parameters') return 1 return 0 input_script = 'format_map_data.json' format_map = angle_format.load_json(input_script) format_cases = "" for format, type_map in sorted(format_map.iteritems()): format_cases += parse_format_case(format, type_map) combo_data_file = 'es3_format_type_combinations.json' es3_combo_data = angle_format.load_json(combo_data_file) combo_data = [ combo for sublist in es3_combo_data.values() for combo in sublist ] types = set() formats = set() combos = {} for internal_format, format, type in combo_data: types.update([type]) formats.update([format]) if format not in combos: combos[format] = {} if type not in combos[format]: combos[format][type] = [internal_format] else: combos[format][type] += [internal_format] es3_format_cases = "" for format in sorted(formats): es3_format_cases += " case " + format + ":\n" es3_type_cases = "" for type in sorted(types): es3_type_cases += " case " + type + ":\n" es3_combo_cases = "" for format, type_combos in combos.iteritems(): this_type_cases = "" for type, combos in type_combos.iteritems(): internal_format_cases = "" for internal_format in combos: internal_format_cases += " case " + internal_format + ":\n" this_type_cases += template_es3_combo_type_case.format( type=type, internal_format_cases=internal_format_cases) es3_combo_cases += template_format_case.format( format=format, type_cases=this_type_cases) with open('format_map_autogen.cpp', 'wt') as out_file: output_cpp = template_cpp.format(script_name=sys.argv[0], data_source_name=input_script, es3_data_source_name=combo_data_file, format_cases=format_cases, es3_format_cases=es3_format_cases, es3_type_cases=es3_type_cases, es3_combo_cases=es3_combo_cases) out_file.write(output_cpp) return 0