Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame^] | 1 | #!/usr/bin/python |
| 2 | # |
| 3 | # Copyright 2017 The ANGLE Project Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | # |
| 7 | # generate_entry_points.py: |
| 8 | # Generates the OpenGL bindings and entry point layers for ANGLE. |
| 9 | |
| 10 | import sys, os, pprint |
| 11 | import xml.etree.ElementTree as etree |
| 12 | from datetime import date |
| 13 | |
| 14 | def script_relative(path): |
| 15 | return os.path.join(os.path.dirname(sys.argv[0]), path) |
| 16 | |
| 17 | tree = etree.parse(script_relative('gl.xml')) |
| 18 | root = tree.getroot() |
| 19 | |
| 20 | gles2_xpath = ".//feature[@name='GL_ES_VERSION_2_0']//command" |
| 21 | gles2_commands = [cmd.attrib['name'] for cmd in root.findall(gles2_xpath)] |
| 22 | |
| 23 | template_entry_point_header = """// GENERATED FILE - DO NOT EDIT. |
| 24 | // Generated by {script_name} using data from {data_source_name}. |
| 25 | // |
| 26 | // Copyright {year} The ANGLE Project Authors. All rights reserved. |
| 27 | // Use of this source code is governed by a BSD-style license that can be |
| 28 | // found in the LICENSE file. |
| 29 | // |
| 30 | // entry_points_gles_{major_version}_{minor_version}_autogen.h: |
| 31 | // Defines the GLES {major_version}.{minor_version} entry points. |
| 32 | |
| 33 | #ifndef LIBGLESV2_ENTRYPOINTSGLES{major_version}{minor_version}_AUTOGEN_H_ |
| 34 | #define LIBGLESV2_ENTRYPOINTSGLES{major_version}{minor_version}_AUTOGEN_H_ |
| 35 | |
| 36 | #include <GLES2/gl{major_version}.h> |
| 37 | #include <export.h> |
| 38 | |
| 39 | namespace gl |
| 40 | {{ |
| 41 | {entry_points} |
| 42 | }} // namespace gl |
| 43 | |
| 44 | #endif // LIBGLESV2_ENTRYPOINTSGLES{major_version}{minor_version}_AUTOGEN_H_ |
| 45 | """ |
| 46 | |
| 47 | template_entry_point_decl = """ANGLE_EXPORT {return_type}GL_APIENTRY {name}({params});""" |
| 48 | |
| 49 | commands = root.find(".//commands[@namespace='GL']") |
| 50 | entry_point_decls_gles_2_0 = [] |
| 51 | |
| 52 | def format_entry_point_decl(cmd_name, proto, params): |
| 53 | return template_entry_point_decl.format( |
| 54 | name = cmd_name[2:], |
| 55 | return_type = proto[:-len(cmd_name)], |
| 56 | params = ", ".join(params)) |
| 57 | |
| 58 | for cmd_name in gles2_commands: |
| 59 | command_xpath = "command/proto[name='" + cmd_name + "']/.." |
| 60 | command = commands.find(command_xpath) |
| 61 | params = ["".join(param.itertext()) for param in command.findall("./param")] |
| 62 | proto = "".join(command.find("./proto").itertext()) |
| 63 | entry_point_decls_gles_2_0 += [format_entry_point_decl(cmd_name, proto, params)] |
| 64 | |
| 65 | gles_2_0_header = template_entry_point_header.format( |
| 66 | script_name = os.path.basename(sys.argv[0]), |
| 67 | data_source_name = "gl.xml", |
| 68 | year = date.today().year, |
| 69 | major_version = 2, |
| 70 | minor_version = 0, |
| 71 | entry_points = "\n".join(entry_point_decls_gles_2_0)) |
| 72 | |
| 73 | def path_to(folder, file): |
| 74 | return os.path.join(script_relative(".."), "src", folder, file) |
| 75 | |
| 76 | gles_2_0_header_path = path_to("libGLESv2", "entry_points_gles_2_0_autogen.h") |
| 77 | |
| 78 | with open(gles_2_0_header_path, "w") as out: |
| 79 | out.write(gles_2_0_header) |
| 80 | out.close() |