blob: ec73d75446a42f4737072325989f19c48edf5755 [file] [log] [blame]
Jamie Madill2e16d962017-04-19 14:06:36 -04001#!/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
10import sys, os, pprint
11import xml.etree.ElementTree as etree
12from datetime import date
13
14def script_relative(path):
15 return os.path.join(os.path.dirname(sys.argv[0]), path)
16
17tree = etree.parse(script_relative('gl.xml'))
18root = tree.getroot()
19
20gles2_xpath = ".//feature[@name='GL_ES_VERSION_2_0']//command"
21gles2_commands = [cmd.attrib['name'] for cmd in root.findall(gles2_xpath)]
22
23template_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
39namespace gl
40{{
41{entry_points}
42}} // namespace gl
43
44#endif // LIBGLESV2_ENTRYPOINTSGLES{major_version}{minor_version}_AUTOGEN_H_
45"""
46
47template_entry_point_decl = """ANGLE_EXPORT {return_type}GL_APIENTRY {name}({params});"""
48
49commands = root.find(".//commands[@namespace='GL']")
50entry_point_decls_gles_2_0 = []
51
52def 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
58for 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
65gles_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
73def path_to(folder, file):
74 return os.path.join(script_relative(".."), "src", folder, file)
75
76gles_2_0_header_path = path_to("libGLESv2", "entry_points_gles_2_0_autogen.h")
77
78with open(gles_2_0_header_path, "w") as out:
79 out.write(gles_2_0_header)
80 out.close()