blob: 2843877004aa8af451f7f98e63f6d734594511ac [file] [log] [blame]
Jeff Gilbert1b605ee2017-10-30 18:41:46 -07001#!/usr/bin/python2
Jamie Madill2e16d962017-04-19 14:06:36 -04002#
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
Corentin Wallez2e568cf2017-09-18 17:05:22 -040010import sys, os, pprint, json
Jamie Madill2e16d962017-04-19 14:06:36 -040011import xml.etree.ElementTree as etree
12from datetime import date
13
Jamie Madillfa920eb2018-01-04 11:45:50 -050014# List of supported extensions. Add to this list to enable new extensions
15# available in gl.xml.
Brandon Jones416aaf92018-04-10 08:10:16 -070016
17angle_extensions = [
18 # ANGLE extensions
19 "GL_CHROMIUM_bind_uniform_location",
20 "GL_CHROMIUM_framebuffer_mixed_samples",
21 "GL_CHROMIUM_path_rendering",
22 "GL_CHROMIUM_copy_texture",
23 "GL_CHROMIUM_copy_compressed_texture",
24 "GL_ANGLE_request_extension",
25 "GL_ANGLE_robust_client_memory",
26 "GL_ANGLE_multiview",
27]
28
Lingfeng Yanga0648782018-03-12 14:45:25 -070029gles1_extensions = [
30 # ES1 (Possibly the min set of extensions needed by Android)
31 "GL_OES_draw_texture",
32 "GL_OES_framebuffer_object",
33 "GL_OES_matrix_palette",
Geoff Lang2aaa7b42018-01-12 17:17:27 -050034 "GL_OES_point_size_array",
35 "GL_OES_query_matrix",
Lingfeng Yanga0648782018-03-12 14:45:25 -070036 "GL_OES_texture_cube_map",
37]
38
39# List of GLES1 extensions for which we don't need to add Context.h decls.
40gles1_no_context_decl_extensions = [
41 "GL_OES_framebuffer_object",
42]
43
44# List of GLES1 API calls that have had their semantics changed in later GLES versions, but the
45# name was kept the same
46gles1_overloaded = [
47 "glGetPointerv",
48]
49
Brandon Jones416aaf92018-04-10 08:10:16 -070050supported_extensions = sorted(angle_extensions + gles1_extensions + [
Geoff Lang2aaa7b42018-01-12 17:17:27 -050051 # ES2+
Jamie Madillfa920eb2018-01-04 11:45:50 -050052 "GL_ANGLE_framebuffer_blit",
53 "GL_ANGLE_framebuffer_multisample",
54 "GL_ANGLE_instanced_arrays",
55 "GL_ANGLE_translated_shader_source",
56 "GL_EXT_debug_marker",
57 "GL_EXT_discard_framebuffer",
58 "GL_EXT_disjoint_timer_query",
59 "GL_EXT_draw_buffers",
60 "GL_EXT_map_buffer_range",
61 "GL_EXT_occlusion_query_boolean",
62 "GL_EXT_robustness",
63 "GL_EXT_texture_storage",
64 "GL_KHR_debug",
65 "GL_NV_fence",
66 "GL_OES_EGL_image",
67 "GL_OES_get_program_binary",
68 "GL_OES_mapbuffer",
69 "GL_OES_vertex_array_object",
70])
71
72# This is a list of exceptions for entry points which don't want to have
73# the EVENT macro. This is required for some debug marker entry points.
74no_event_marker_exceptions_list = sorted([
75 "glPushGroupMarkerEXT",
76 "glPopGroupMarkerEXT",
77 "glInsertEventMarkerEXT",
78])
79
80# Strip these suffixes from Context entry point names. NV is excluded (for now).
Brandon Jones416aaf92018-04-10 08:10:16 -070081strip_suffixes = ["ANGLE", "EXT", "KHR", "OES", "CHROMIUM"]
Jamie Madillfa920eb2018-01-04 11:45:50 -050082
Jamie Madill2e16d962017-04-19 14:06:36 -040083template_entry_point_header = """// GENERATED FILE - DO NOT EDIT.
84// Generated by {script_name} using data from {data_source_name}.
85//
86// Copyright {year} The ANGLE Project Authors. All rights reserved.
87// Use of this source code is governed by a BSD-style license that can be
88// found in the LICENSE file.
89//
Jamie Madillc8c9a242018-01-02 13:39:00 -050090// entry_points_gles_{annotation_lower}_autogen.h:
91// Defines the GLES {comment} entry points.
Jamie Madill2e16d962017-04-19 14:06:36 -040092
Jamie Madillc8c9a242018-01-02 13:39:00 -050093#ifndef LIBGLESV2_ENTRY_POINTS_GLES_{annotation_upper}_AUTOGEN_H_
94#define LIBGLESV2_ENTRY_POINTS_GLES_{annotation_upper}_AUTOGEN_H_
Jamie Madill2e16d962017-04-19 14:06:36 -040095
Jamie Madillc8c9a242018-01-02 13:39:00 -050096{includes}
97
Jamie Madill2e16d962017-04-19 14:06:36 -040098namespace gl
99{{
100{entry_points}
101}} // namespace gl
102
Jamie Madillc8c9a242018-01-02 13:39:00 -0500103#endif // LIBGLESV2_ENTRY_POINTS_GLES_{annotation_upper}_AUTOGEN_H_
Jamie Madill2e16d962017-04-19 14:06:36 -0400104"""
105
Jamie Madillee769dd2017-05-04 11:38:30 -0400106template_entry_point_source = """// GENERATED FILE - DO NOT EDIT.
107// Generated by {script_name} using data from {data_source_name}.
108//
109// Copyright {year} The ANGLE Project Authors. All rights reserved.
110// Use of this source code is governed by a BSD-style license that can be
111// found in the LICENSE file.
112//
Jamie Madillc8c9a242018-01-02 13:39:00 -0500113// entry_points_gles_{annotation_lower}_autogen.cpp:
114// Defines the GLES {comment} entry points.
Jamie Madillee769dd2017-05-04 11:38:30 -0400115
Jamie Madillc8c9a242018-01-02 13:39:00 -0500116{includes}
Jamie Madillee769dd2017-05-04 11:38:30 -0400117
118namespace gl
119{{
120{entry_points}}} // namespace gl
121"""
122
123template_entry_points_enum_header = """// GENERATED FILE - DO NOT EDIT.
124// Generated by {script_name} using data from {data_source_name}.
125//
126// Copyright {year} The ANGLE Project Authors. All rights reserved.
127// Use of this source code is governed by a BSD-style license that can be
128// found in the LICENSE file.
129//
130// entry_points_enum_autogen.h:
131// Defines the GLES entry points enumeration.
132
133#ifndef LIBGLESV2_ENTRYPOINTSENUM_AUTOGEN_H_
134#define LIBGLESV2_ENTRYPOINTSENUM_AUTOGEN_H_
135
136namespace gl
137{{
138enum class EntryPoint
139{{
140{entry_points_list}
141}};
142}} // namespace gl
143#endif // LIBGLESV2_ENTRY_POINTS_ENUM_AUTOGEN_H_
144"""
145
Jamie Madill2e16d962017-04-19 14:06:36 -0400146template_entry_point_decl = """ANGLE_EXPORT {return_type}GL_APIENTRY {name}({params});"""
147
Jamie Madillee769dd2017-05-04 11:38:30 -0400148template_entry_point_def = """{return_type}GL_APIENTRY {name}({params})
149{{
Jamie Madillfa920eb2018-01-04 11:45:50 -0500150 {event_comment}EVENT("({format_params})"{comma_if_needed}{pass_params});
Jamie Madillee769dd2017-05-04 11:38:30 -0400151
Geoff Langcae72d62017-06-01 11:53:45 -0400152 Context *context = {context_getter}();
Jamie Madillee769dd2017-05-04 11:38:30 -0400153 if (context)
Corentin Wallez2e568cf2017-09-18 17:05:22 -0400154 {{{packed_gl_enum_conversions}
155 context->gatherParams<EntryPoint::{name}>({internal_params});
Jamie Madillee769dd2017-05-04 11:38:30 -0400156
Jamie Madill53d38412017-04-20 11:33:00 -0400157 if (context->skipValidation() || Validate{name}({validate_params}))
Jamie Madillee769dd2017-05-04 11:38:30 -0400158 {{
Jamie Madillc8c9a242018-01-02 13:39:00 -0500159 {return_if_needed}context->{name_lower_no_suffix}({internal_params});
Jamie Madillee769dd2017-05-04 11:38:30 -0400160 }}
Jamie Madillee769dd2017-05-04 11:38:30 -0400161 }}
162{default_return_if_needed}}}
163"""
164
Lingfeng Yanga0648782018-03-12 14:45:25 -0700165context_gles_header = """// GENERATED FILE - DO NOT EDIT.
166// Generated by {script_name} using data from {data_source_name}.
167//
168// Copyright {year} The ANGLE Project Authors. All rights reserved.
169// Use of this source code is governed by a BSD-style license that can be
170// found in the LICENSE file.
171//
172// Context_gles_{annotation_lower}_autogen.h: Creates a macro for interfaces in Context.
173
174#ifndef ANGLE_CONTEXT_GLES_{annotation_upper}_AUTOGEN_H_
175#define ANGLE_CONTEXT_GLES_{annotation_upper}_AUTOGEN_H_
176
177#define ANGLE_GLES1_CONTEXT_API \\
178{interface}
179
180#endif // ANGLE_CONTEXT_API_{annotation_upper}_AUTOGEN_H_
181"""
182
183context_gles_decl = """ {return_type} {name_lower_no_suffix}({internal_params}); \\"""
184
Jamie Madill16daadb2017-08-26 23:34:31 -0400185def script_relative(path):
186 return os.path.join(os.path.dirname(sys.argv[0]), path)
187
188tree = etree.parse(script_relative('gl.xml'))
189root = tree.getroot()
Jamie Madill2e16d962017-04-19 14:06:36 -0400190commands = root.find(".//commands[@namespace='GL']")
Jamie Madill2e16d962017-04-19 14:06:36 -0400191
Corentin Wallez2e568cf2017-09-18 17:05:22 -0400192with open(script_relative('entry_point_packed_gl_enums.json')) as f:
193 cmd_packed_gl_enums = json.loads(f.read())
194
Jamie Madill2e16d962017-04-19 14:06:36 -0400195def format_entry_point_decl(cmd_name, proto, params):
196 return template_entry_point_decl.format(
197 name = cmd_name[2:],
198 return_type = proto[:-len(cmd_name)],
199 params = ", ".join(params))
200
Jamie Madillee769dd2017-05-04 11:38:30 -0400201def type_name_sep_index(param):
202 space = param.rfind(" ")
203 pointer = param.rfind("*")
204 return max(space, pointer)
205
206def just_the_type(param):
Lingfeng Yanga0648782018-03-12 14:45:25 -0700207 if "*" in param:
208 return param[:type_name_sep_index(param) + 1]
Jamie Madillee769dd2017-05-04 11:38:30 -0400209 return param[:type_name_sep_index(param)]
210
211def just_the_name(param):
212 return param[type_name_sep_index(param)+1:]
213
Lingfeng Yanga0648782018-03-12 14:45:25 -0700214def make_param(param_type, param_name):
215 return param_type + " " + param_name
216
217def just_the_type_packed(param, entry):
218 name = just_the_name(param)
219 if entry.has_key(name):
220 return entry[name]
221 else:
222 return just_the_type(param)
223
Corentin Wallez2e568cf2017-09-18 17:05:22 -0400224def just_the_name_packed(param, reserved_set):
225 name = just_the_name(param)
226 if name in reserved_set:
227 return name + 'Packed'
228 else:
229 return name
230
Jamie Madillee769dd2017-05-04 11:38:30 -0400231format_dict = {
232 "GLbitfield": "0x%X",
233 "GLboolean": "%u",
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500234 "GLclampx": "0x%X",
Jamie Madillee769dd2017-05-04 11:38:30 -0400235 "GLenum": "0x%X",
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500236 "GLfixed": "0x%X",
Jamie Madillee769dd2017-05-04 11:38:30 -0400237 "GLfloat": "%f",
238 "GLint": "%d",
239 "GLintptr": "%d",
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500240 "GLshort": "%d",
Jamie Madillee769dd2017-05-04 11:38:30 -0400241 "GLsizei": "%d",
242 "GLsizeiptr": "%d",
Jamie Madill16daadb2017-08-26 23:34:31 -0400243 "GLsync": "0x%0.8p",
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500244 "GLubyte": "%d",
Jamie Madillff161f82017-08-26 23:49:10 -0400245 "GLuint": "%u",
Jamie Madillfa920eb2018-01-04 11:45:50 -0500246 "GLuint64": "%llu",
247 "GLDEBUGPROC": "0x%0.8p",
248 "GLDEBUGPROCKHR": "0x%0.8p",
249 "GLeglImageOES": "0x%0.8p",
Jamie Madillee769dd2017-05-04 11:38:30 -0400250}
251
252def param_format_string(param):
253 if "*" in param:
254 return param + " = 0x%0.8p"
255 else:
Jamie Madill16daadb2017-08-26 23:34:31 -0400256 type_only = just_the_type(param)
257 if type_only not in format_dict:
258 raise Exception(type_only + " is not a known type in 'format_dict'")
259
260 return param + " = " + format_dict[type_only]
Jamie Madillee769dd2017-05-04 11:38:30 -0400261
Jamie Madill2e29b132017-08-28 17:22:11 -0400262def default_return_value(cmd_name, return_type):
Jamie Madillee769dd2017-05-04 11:38:30 -0400263 if return_type == "void":
264 return ""
Jamie Madill2e29b132017-08-28 17:22:11 -0400265 return "GetDefaultReturnValue<EntryPoint::" + cmd_name[2:] + ", " + return_type + ">()"
Jamie Madillee769dd2017-05-04 11:38:30 -0400266
Geoff Langcae72d62017-06-01 11:53:45 -0400267def get_context_getter_function(cmd_name):
268 if cmd_name == "glGetError":
269 return "GetGlobalContext"
270 else:
271 return "GetValidGlobalContext"
272
Jamie Madillfa920eb2018-01-04 11:45:50 -0500273template_event_comment = """// Don't run an EVENT() macro on the EXT_debug_marker entry points.
274 // It can interfere with the debug events being set by the caller.
275 // """
276
Jamie Madillee769dd2017-05-04 11:38:30 -0400277def format_entry_point_def(cmd_name, proto, params):
Corentin Wallez2e568cf2017-09-18 17:05:22 -0400278 packed_gl_enums = cmd_packed_gl_enums.get(cmd_name, {})
279 internal_params = [just_the_name_packed(param, packed_gl_enums) for param in params]
280 packed_gl_enum_conversions = []
281 for param in params:
282 name = just_the_name(param)
283 if name in packed_gl_enums:
284 internal_name = name + "Packed"
285 internal_type = packed_gl_enums[name]
286 packed_gl_enum_conversions += ["\n " + internal_type + " " + internal_name +" = FromGLenum<" +
287 internal_type + ">(" + name + ");"]
288
Jamie Madillee769dd2017-05-04 11:38:30 -0400289 pass_params = [just_the_name(param) for param in params]
290 format_params = [param_format_string(param) for param in params]
291 return_type = proto[:-len(cmd_name)]
Jamie Madill2e29b132017-08-28 17:22:11 -0400292 default_return = default_return_value(cmd_name, return_type.strip())
Jamie Madillfa920eb2018-01-04 11:45:50 -0500293 event_comment = template_event_comment if cmd_name in no_event_marker_exceptions_list else ""
Jamie Madillc8c9a242018-01-02 13:39:00 -0500294 name_lower_no_suffix = cmd_name[2:3].lower() + cmd_name[3:]
295
Jamie Madillfa920eb2018-01-04 11:45:50 -0500296 for suffix in strip_suffixes:
297 if name_lower_no_suffix.endswith(suffix):
298 name_lower_no_suffix = name_lower_no_suffix[0:-len(suffix)]
299
Jamie Madillee769dd2017-05-04 11:38:30 -0400300 return template_entry_point_def.format(
301 name = cmd_name[2:],
Jamie Madillc8c9a242018-01-02 13:39:00 -0500302 name_lower_no_suffix = name_lower_no_suffix,
Jamie Madillee769dd2017-05-04 11:38:30 -0400303 return_type = return_type,
304 params = ", ".join(params),
Corentin Wallez2e568cf2017-09-18 17:05:22 -0400305 internal_params = ", ".join(internal_params),
306 packed_gl_enum_conversions = "".join(packed_gl_enum_conversions),
Jamie Madillee769dd2017-05-04 11:38:30 -0400307 pass_params = ", ".join(pass_params),
308 comma_if_needed = ", " if len(params) > 0 else "",
Corentin Wallez2e568cf2017-09-18 17:05:22 -0400309 validate_params = ", ".join(["context"] + internal_params),
Jamie Madillee769dd2017-05-04 11:38:30 -0400310 format_params = ", ".join(format_params),
Jamie Madillee769dd2017-05-04 11:38:30 -0400311 return_if_needed = "" if default_return == "" else "return ",
Geoff Langcae72d62017-06-01 11:53:45 -0400312 default_return_if_needed = "" if default_return == "" else "\n return " + default_return + ";\n",
Jamie Madillfa920eb2018-01-04 11:45:50 -0500313 context_getter = get_context_getter_function(cmd_name),
314 event_comment = event_comment)
Jamie Madillee769dd2017-05-04 11:38:30 -0400315
Lingfeng Yanga0648782018-03-12 14:45:25 -0700316def format_context_gles_decl(cmd_name, proto, params):
317 packed_gl_enums = cmd_packed_gl_enums.get(cmd_name, {})
318 internal_params = ", ".join([make_param(just_the_type_packed(param, packed_gl_enums),
319 just_the_name_packed(param, packed_gl_enums)) for param in params])
320
321 return_type = proto[:-len(cmd_name)]
322 name_lower_no_suffix = cmd_name[2:3].lower() + cmd_name[3:]
323
324 for suffix in strip_suffixes:
325 if name_lower_no_suffix.endswith(suffix):
326 name_lower_no_suffix = name_lower_no_suffix[0:-len(suffix)]
327
328 return context_gles_decl.format(
329 return_type = return_type,
330 name_lower_no_suffix = name_lower_no_suffix,
331 internal_params = internal_params)
332
Jiajia Qincb59a902017-11-22 13:03:42 +0800333def path_to(folder, file):
334 return os.path.join(script_relative(".."), "src", folder, file)
Jamie Madill2e16d962017-04-19 14:06:36 -0400335
Jamie Madillc8c9a242018-01-02 13:39:00 -0500336def get_entry_points(all_commands, gles_commands):
Jamie Madillc8c9a242018-01-02 13:39:00 -0500337 decls = []
338 defs = []
Jamie Madillffa2cd02017-12-28 14:57:53 -0500339 for command in all_commands:
340 proto = command.find('proto')
341 cmd_name = proto.find('name').text
342
343 if cmd_name not in gles_commands:
344 continue
345
346 param_text = ["".join(param.itertext()) for param in command.findall('param')]
347 proto_text = "".join(proto.itertext())
Jamie Madillc8c9a242018-01-02 13:39:00 -0500348 decls.append(format_entry_point_decl(cmd_name, proto_text, param_text))
349 defs.append(format_entry_point_def(cmd_name, proto_text, param_text))
Jamie Madillee769dd2017-05-04 11:38:30 -0400350
Jamie Madillc8c9a242018-01-02 13:39:00 -0500351 return decls, defs
Jamie Madill16daadb2017-08-26 23:34:31 -0400352
Lingfeng Yanga0648782018-03-12 14:45:25 -0700353def get_gles1_decls(all_commands, gles_commands):
354 decls = []
355 for command in all_commands:
356 proto = command.find('proto')
357 cmd_name = proto.find('name').text
358
359 if cmd_name not in gles_commands:
360 continue
361
362 if cmd_name in gles1_overloaded:
363 continue
364
365 param_text = ["".join(param.itertext()) for param in command.findall('param')]
366 proto_text = "".join(proto.itertext())
367 decls.append(format_context_gles_decl(cmd_name, proto_text, param_text))
368
369 return decls
370
371
Brandon Jones416aaf92018-04-10 08:10:16 -0700372def write_file(annotation, comment, template, entry_points, suffix, includes, file):
Jiajia Qincb59a902017-11-22 13:03:42 +0800373
Jamie Madillc8c9a242018-01-02 13:39:00 -0500374 content = template.format(
375 script_name = os.path.basename(sys.argv[0]),
Brandon Jones416aaf92018-04-10 08:10:16 -0700376 data_source_name = file,
Jamie Madillc8c9a242018-01-02 13:39:00 -0500377 year = date.today().year,
378 annotation_lower = annotation.lower(),
379 annotation_upper = annotation.upper(),
380 comment = comment,
381 includes = includes,
382 entry_points = entry_points)
Jiajia Qincb59a902017-11-22 13:03:42 +0800383
Jamie Madillc8c9a242018-01-02 13:39:00 -0500384 path = path_to("libGLESv2", "entry_points_gles_{}_autogen.{}".format(
385 annotation.lower(), suffix))
386
387 with open(path, "w") as out:
388 out.write(content)
389 out.close()
390
Lingfeng Yanga0648782018-03-12 14:45:25 -0700391def write_context_api_decls(annotation, template, decls):
392
393 interface_lines = []
394
395 for i in decls['core']:
396 interface_lines.append(i)
397
398 for extname in sorted(decls['exts'].keys()):
399 interface_lines.append(" /* " + extname + " */ \\")
400 interface_lines.extend(decls['exts'][extname])
401
402 content = template.format(
403 annotation_lower = annotation.lower(),
404 annotation_upper = annotation.upper(),
405 script_name = os.path.basename(sys.argv[0]),
406 data_source_name = "gl.xml",
407 year = date.today().year,
408 interface = "\n".join(interface_lines))
409
410 path = path_to("libANGLE", "Context_gles_%s_autogen.h" % annotation.lower())
411
412 with open(path, "w") as out:
413 out.write(content)
414 out.close()
415
Brandon Jones416aaf92018-04-10 08:10:16 -0700416def append_angle_extensions(base_root):
417 angle_ext_tree = etree.parse(script_relative('gl_angle_ext.xml'))
418 angle_ext_root = angle_ext_tree.getroot()
419
420 insertion_point = base_root.findall("./commands")[0]
421 for command in angle_ext_root.iter('commands'):
422 insertion_point.extend(command)
423
424 insertion_point = base_root.findall("./extensions")[0]
425 for extension in angle_ext_root.iter('extensions'):
426 insertion_point.extend(extension)
427 return base_root
428
429root = append_angle_extensions(root)
430
Jamie Madillc8c9a242018-01-02 13:39:00 -0500431all_commands = root.findall('commands/command')
432all_cmd_names = []
433
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500434template_header_includes = """#include <GLES{major}/gl{major}{minor}.h>
Jamie Madillc8c9a242018-01-02 13:39:00 -0500435#include <export.h>"""
436
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500437template_sources_includes = """#include "libGLESv2/entry_points_gles_{}_autogen.h"
438
439#include "libANGLE/Context.h"
Jamie Madillc8c9a242018-01-02 13:39:00 -0500440#include "libANGLE/validationES{}{}.h"
441#include "libGLESv2/global_state.h"
442"""
443
Lingfeng Yanga0648782018-03-12 14:45:25 -0700444gles1decls = {}
445
446gles1decls['core'] = []
447gles1decls['exts'] = {}
448
449# First run through the main GLES entry points. Since ES2+ is the primary use
450# case, we go through those first and then add ES1-only APIs at the end.
451for major_version, minor_version in [[2, 0], [3, 0], [3, 1], [1, 0]]:
Jamie Madillc8c9a242018-01-02 13:39:00 -0500452 annotation = "{}_{}".format(major_version, minor_version)
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500453 name_prefix = "GL_ES_VERSION_"
Lingfeng Yanga0648782018-03-12 14:45:25 -0700454
455 is_gles1 = major_version == 1
456 if is_gles1:
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500457 name_prefix = "GL_VERSION_ES_CM_"
Lingfeng Yanga0648782018-03-12 14:45:25 -0700458
Jamie Madillc8c9a242018-01-02 13:39:00 -0500459 comment = annotation.replace("_", ".")
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500460 gles_xpath = ".//feature[@name='{}{}']//command".format(name_prefix, annotation)
Jamie Madillc8c9a242018-01-02 13:39:00 -0500461 gles_commands = [cmd.attrib['name'] for cmd in root.findall(gles_xpath)]
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500462
463 # Remove commands that have already been processed
464 gles_commands = [cmd for cmd in gles_commands if cmd not in all_cmd_names]
465
Jamie Madillc8c9a242018-01-02 13:39:00 -0500466 all_cmd_names += gles_commands
467
468 decls, defs = get_entry_points(all_commands, gles_commands)
469
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500470 major_if_not_one = major_version if major_version != 1 else ""
Jamie Madillc8c9a242018-01-02 13:39:00 -0500471 minor_if_not_zero = minor_version if minor_version != 0 else ""
472
473 header_includes = template_header_includes.format(
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500474 major=major_if_not_one, minor=minor_if_not_zero)
Jamie Madillc8c9a242018-01-02 13:39:00 -0500475
476 # We include the platform.h header since it undefines the conflicting MemoryBarrier macro.
477 if major_version == 3 and minor_version == 1:
478 header_includes += "\n#include \"common/platform.h\"\n"
479
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500480 source_includes = template_sources_includes.format(
481 annotation.lower(), major_version,minor_if_not_zero)
Jamie Madillc8c9a242018-01-02 13:39:00 -0500482
483 write_file(annotation, comment, template_entry_point_header,
Brandon Jones416aaf92018-04-10 08:10:16 -0700484 "\n".join(decls), "h", header_includes, "gl.xml")
Jamie Madillc8c9a242018-01-02 13:39:00 -0500485 write_file(annotation, comment, template_entry_point_source,
Brandon Jones416aaf92018-04-10 08:10:16 -0700486 "\n".join(defs), "cpp", source_includes, "gl.xml")
Lingfeng Yanga0648782018-03-12 14:45:25 -0700487 if is_gles1:
488 gles1decls['core'] = get_gles1_decls(all_commands, gles_commands)
489
Jamie Madill57ae8c12017-08-30 12:14:29 -0400490
Jamie Madillfa920eb2018-01-04 11:45:50 -0500491# After we finish with the main entry points, we process the extensions.
492extension_defs = []
493extension_decls = []
494
495# Use a first step to run through the extensions so we can generate them
496# in sorted order.
497ext_data = {}
498
Lingfeng Yanga0648782018-03-12 14:45:25 -0700499for gles1ext in gles1_extensions:
500 gles1decls['exts'][gles1ext] = []
501
Jamie Madillfa920eb2018-01-04 11:45:50 -0500502for extension in root.findall("extensions/extension"):
503 extension_name = extension.attrib['name']
504 if not extension_name in supported_extensions:
505 continue
506
507 ext_cmd_names = []
508
509 # There's an extra step here to filter out 'api=gl' extensions. This
510 # is necessary for handling KHR extensions, which have separate entry
511 # point signatures (without the suffix) for desktop GL. Note that this
512 # extra step is necessary because of Etree's limited Xpath support.
513 for require in extension.findall('require'):
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500514 if 'api' in require.attrib and require.attrib['api'] != 'gles2' and require.attrib['api'] != 'gles1':
Jamie Madillfa920eb2018-01-04 11:45:50 -0500515 continue
516
517 # Another special case for EXT_texture_storage
518 filter_out_comment = "Supported only if GL_EXT_direct_state_access is supported"
519 if 'comment' in require.attrib and require.attrib['comment'] == filter_out_comment:
520 continue
521
522 extension_commands = require.findall('command')
523 ext_cmd_names += [command.attrib['name'] for command in extension_commands]
524
525 ext_data[extension_name] = sorted(ext_cmd_names)
526
527for extension_name, ext_cmd_names in sorted(ext_data.iteritems()):
528
529 # Detect and filter duplicate extensions.
530 dupes = []
531 for ext_cmd in ext_cmd_names:
532 if ext_cmd in all_cmd_names:
533 dupes.append(ext_cmd)
534
535 for dupe in dupes:
536 ext_cmd_names.remove(dupe)
537
538 all_cmd_names += ext_cmd_names
539
540 decls, defs = get_entry_points(all_commands, ext_cmd_names)
541
542 # Avoid writing out entry points defined by a prior extension.
543 for dupe in dupes:
544 msg = "// {} is already defined.\n".format(dupe[2:])
545 defs.append(msg)
546
547 # Write the extension name as a comment before the first EP.
548 comment = "\n// {}".format(extension_name)
549 defs.insert(0, comment)
550 decls.insert(0, comment)
551
552 extension_defs += defs
553 extension_decls += decls
554
Lingfeng Yanga0648782018-03-12 14:45:25 -0700555 if extension_name in gles1_extensions:
556 if extension_name not in gles1_no_context_decl_extensions:
557 gles1decls['exts'][extension_name] = get_gles1_decls(all_commands, ext_cmd_names)
558
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500559header_includes = template_header_includes.format(
560 major="", minor="")
561header_includes += """
562#include <GLES/gl.h>
563#include <GLES/glext.h>
564#include <GLES2/gl2.h>
565#include <GLES2/gl2ext.h>
566"""
Jamie Madillfa920eb2018-01-04 11:45:50 -0500567
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500568source_includes = template_sources_includes.format("ext", "", "")
569source_includes += """
570#include "libANGLE/validationES.h"
571#include "libANGLE/validationES1.h"
Jamie Madillfa920eb2018-01-04 11:45:50 -0500572#include "libANGLE/validationES3.h"
573#include "libANGLE/validationES31.h"
574"""
575
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500576write_file("ext", "extension", template_entry_point_header,
Brandon Jones416aaf92018-04-10 08:10:16 -0700577 "\n".join([item for item in extension_decls]), "h", header_includes,
578 "gl.xml and gl_angle_ext.xml")
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500579write_file("ext", "extension", template_entry_point_source,
Brandon Jones416aaf92018-04-10 08:10:16 -0700580 "\n".join([item for item in extension_defs]), "cpp", source_includes,
581 "gl.xml and gl_angle_ext.xml")
Jamie Madillc8c9a242018-01-02 13:39:00 -0500582
Lingfeng Yanga0648782018-03-12 14:45:25 -0700583write_context_api_decls("1_0", context_gles_header, gles1decls)
584
Jamie Madillc8c9a242018-01-02 13:39:00 -0500585sorted_cmd_names = ["Invalid"] + [cmd[2:] for cmd in sorted(all_cmd_names)]
586
Jamie Madillee769dd2017-05-04 11:38:30 -0400587entry_points_enum = template_entry_points_enum_header.format(
588 script_name = os.path.basename(sys.argv[0]),
Brandon Jones416aaf92018-04-10 08:10:16 -0700589 data_source_name = "gl.xml and gl_angle_ext.xml",
Jamie Madillee769dd2017-05-04 11:38:30 -0400590 year = date.today().year,
Jamie Madillc8c9a242018-01-02 13:39:00 -0500591 entry_points_list = ",\n".join([" " + cmd for cmd in sorted_cmd_names]))
Jamie Madillee769dd2017-05-04 11:38:30 -0400592
Jamie Madillee769dd2017-05-04 11:38:30 -0400593entry_points_enum_header_path = path_to("libANGLE", "entry_points_enum_autogen.h")
Jamie Madillee769dd2017-05-04 11:38:30 -0400594with open(entry_points_enum_header_path, "w") as out:
595 out.write(entry_points_enum)
Geoff Langcae72d62017-06-01 11:53:45 -0400596 out.close()