blob: 21b9422df47c282c79206edd5f06cccc4c8b6832 [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.
16# TODO(jmadill): Support extensions not in gl.xml.
Lingfeng Yanga0648782018-03-12 14:45:25 -070017gles1_extensions = [
18 # ES1 (Possibly the min set of extensions needed by Android)
19 "GL_OES_draw_texture",
20 "GL_OES_framebuffer_object",
21 "GL_OES_matrix_palette",
Geoff Lang2aaa7b42018-01-12 17:17:27 -050022 "GL_OES_point_size_array",
23 "GL_OES_query_matrix",
Lingfeng Yanga0648782018-03-12 14:45:25 -070024 "GL_OES_texture_cube_map",
25]
26
27# List of GLES1 extensions for which we don't need to add Context.h decls.
28gles1_no_context_decl_extensions = [
29 "GL_OES_framebuffer_object",
30]
31
32# List of GLES1 API calls that have had their semantics changed in later GLES versions, but the
33# name was kept the same
34gles1_overloaded = [
35 "glGetPointerv",
36]
37
38supported_extensions = sorted(gles1_extensions + [
Geoff Lang2aaa7b42018-01-12 17:17:27 -050039 # ES2+
Jamie Madillfa920eb2018-01-04 11:45:50 -050040 "GL_ANGLE_framebuffer_blit",
41 "GL_ANGLE_framebuffer_multisample",
42 "GL_ANGLE_instanced_arrays",
43 "GL_ANGLE_translated_shader_source",
44 "GL_EXT_debug_marker",
45 "GL_EXT_discard_framebuffer",
46 "GL_EXT_disjoint_timer_query",
47 "GL_EXT_draw_buffers",
48 "GL_EXT_map_buffer_range",
49 "GL_EXT_occlusion_query_boolean",
50 "GL_EXT_robustness",
51 "GL_EXT_texture_storage",
52 "GL_KHR_debug",
53 "GL_NV_fence",
54 "GL_OES_EGL_image",
55 "GL_OES_get_program_binary",
56 "GL_OES_mapbuffer",
57 "GL_OES_vertex_array_object",
58])
59
60# This is a list of exceptions for entry points which don't want to have
61# the EVENT macro. This is required for some debug marker entry points.
62no_event_marker_exceptions_list = sorted([
63 "glPushGroupMarkerEXT",
64 "glPopGroupMarkerEXT",
65 "glInsertEventMarkerEXT",
66])
67
68# Strip these suffixes from Context entry point names. NV is excluded (for now).
69strip_suffixes = ["ANGLE", "EXT", "KHR", "OES"]
70
Jamie Madill2e16d962017-04-19 14:06:36 -040071template_entry_point_header = """// GENERATED FILE - DO NOT EDIT.
72// Generated by {script_name} using data from {data_source_name}.
73//
74// Copyright {year} The ANGLE Project Authors. All rights reserved.
75// Use of this source code is governed by a BSD-style license that can be
76// found in the LICENSE file.
77//
Jamie Madillc8c9a242018-01-02 13:39:00 -050078// entry_points_gles_{annotation_lower}_autogen.h:
79// Defines the GLES {comment} entry points.
Jamie Madill2e16d962017-04-19 14:06:36 -040080
Jamie Madillc8c9a242018-01-02 13:39:00 -050081#ifndef LIBGLESV2_ENTRY_POINTS_GLES_{annotation_upper}_AUTOGEN_H_
82#define LIBGLESV2_ENTRY_POINTS_GLES_{annotation_upper}_AUTOGEN_H_
Jamie Madill2e16d962017-04-19 14:06:36 -040083
Jamie Madillc8c9a242018-01-02 13:39:00 -050084{includes}
85
Jamie Madill2e16d962017-04-19 14:06:36 -040086namespace gl
87{{
88{entry_points}
89}} // namespace gl
90
Jamie Madillc8c9a242018-01-02 13:39:00 -050091#endif // LIBGLESV2_ENTRY_POINTS_GLES_{annotation_upper}_AUTOGEN_H_
Jamie Madill2e16d962017-04-19 14:06:36 -040092"""
93
Jamie Madillee769dd2017-05-04 11:38:30 -040094template_entry_point_source = """// GENERATED FILE - DO NOT EDIT.
95// Generated by {script_name} using data from {data_source_name}.
96//
97// Copyright {year} The ANGLE Project Authors. All rights reserved.
98// Use of this source code is governed by a BSD-style license that can be
99// found in the LICENSE file.
100//
Jamie Madillc8c9a242018-01-02 13:39:00 -0500101// entry_points_gles_{annotation_lower}_autogen.cpp:
102// Defines the GLES {comment} entry points.
Jamie Madillee769dd2017-05-04 11:38:30 -0400103
Jamie Madillc8c9a242018-01-02 13:39:00 -0500104{includes}
Jamie Madillee769dd2017-05-04 11:38:30 -0400105
106namespace gl
107{{
108{entry_points}}} // namespace gl
109"""
110
111template_entry_points_enum_header = """// GENERATED FILE - DO NOT EDIT.
112// Generated by {script_name} using data from {data_source_name}.
113//
114// Copyright {year} The ANGLE Project Authors. All rights reserved.
115// Use of this source code is governed by a BSD-style license that can be
116// found in the LICENSE file.
117//
118// entry_points_enum_autogen.h:
119// Defines the GLES entry points enumeration.
120
121#ifndef LIBGLESV2_ENTRYPOINTSENUM_AUTOGEN_H_
122#define LIBGLESV2_ENTRYPOINTSENUM_AUTOGEN_H_
123
124namespace gl
125{{
126enum class EntryPoint
127{{
128{entry_points_list}
129}};
130}} // namespace gl
131#endif // LIBGLESV2_ENTRY_POINTS_ENUM_AUTOGEN_H_
132"""
133
Jamie Madill2e16d962017-04-19 14:06:36 -0400134template_entry_point_decl = """ANGLE_EXPORT {return_type}GL_APIENTRY {name}({params});"""
135
Jamie Madillee769dd2017-05-04 11:38:30 -0400136template_entry_point_def = """{return_type}GL_APIENTRY {name}({params})
137{{
Jamie Madillfa920eb2018-01-04 11:45:50 -0500138 {event_comment}EVENT("({format_params})"{comma_if_needed}{pass_params});
Jamie Madillee769dd2017-05-04 11:38:30 -0400139
Geoff Langcae72d62017-06-01 11:53:45 -0400140 Context *context = {context_getter}();
Jamie Madillee769dd2017-05-04 11:38:30 -0400141 if (context)
Corentin Wallez2e568cf2017-09-18 17:05:22 -0400142 {{{packed_gl_enum_conversions}
143 context->gatherParams<EntryPoint::{name}>({internal_params});
Jamie Madillee769dd2017-05-04 11:38:30 -0400144
Jamie Madill53d38412017-04-20 11:33:00 -0400145 if (context->skipValidation() || Validate{name}({validate_params}))
Jamie Madillee769dd2017-05-04 11:38:30 -0400146 {{
Jamie Madillc8c9a242018-01-02 13:39:00 -0500147 {return_if_needed}context->{name_lower_no_suffix}({internal_params});
Jamie Madillee769dd2017-05-04 11:38:30 -0400148 }}
Jamie Madillee769dd2017-05-04 11:38:30 -0400149 }}
150{default_return_if_needed}}}
151"""
152
Lingfeng Yanga0648782018-03-12 14:45:25 -0700153context_gles_header = """// GENERATED FILE - DO NOT EDIT.
154// Generated by {script_name} using data from {data_source_name}.
155//
156// Copyright {year} The ANGLE Project Authors. All rights reserved.
157// Use of this source code is governed by a BSD-style license that can be
158// found in the LICENSE file.
159//
160// Context_gles_{annotation_lower}_autogen.h: Creates a macro for interfaces in Context.
161
162#ifndef ANGLE_CONTEXT_GLES_{annotation_upper}_AUTOGEN_H_
163#define ANGLE_CONTEXT_GLES_{annotation_upper}_AUTOGEN_H_
164
165#define ANGLE_GLES1_CONTEXT_API \\
166{interface}
167
168#endif // ANGLE_CONTEXT_API_{annotation_upper}_AUTOGEN_H_
169"""
170
171context_gles_decl = """ {return_type} {name_lower_no_suffix}({internal_params}); \\"""
172
Jamie Madill16daadb2017-08-26 23:34:31 -0400173def script_relative(path):
174 return os.path.join(os.path.dirname(sys.argv[0]), path)
175
176tree = etree.parse(script_relative('gl.xml'))
177root = tree.getroot()
Jamie Madill2e16d962017-04-19 14:06:36 -0400178commands = root.find(".//commands[@namespace='GL']")
Jamie Madill2e16d962017-04-19 14:06:36 -0400179
Corentin Wallez2e568cf2017-09-18 17:05:22 -0400180with open(script_relative('entry_point_packed_gl_enums.json')) as f:
181 cmd_packed_gl_enums = json.loads(f.read())
182
Jamie Madill2e16d962017-04-19 14:06:36 -0400183def format_entry_point_decl(cmd_name, proto, params):
184 return template_entry_point_decl.format(
185 name = cmd_name[2:],
186 return_type = proto[:-len(cmd_name)],
187 params = ", ".join(params))
188
Jamie Madillee769dd2017-05-04 11:38:30 -0400189def type_name_sep_index(param):
190 space = param.rfind(" ")
191 pointer = param.rfind("*")
192 return max(space, pointer)
193
194def just_the_type(param):
Lingfeng Yanga0648782018-03-12 14:45:25 -0700195 if "*" in param:
196 return param[:type_name_sep_index(param) + 1]
Jamie Madillee769dd2017-05-04 11:38:30 -0400197 return param[:type_name_sep_index(param)]
198
199def just_the_name(param):
200 return param[type_name_sep_index(param)+1:]
201
Lingfeng Yanga0648782018-03-12 14:45:25 -0700202def make_param(param_type, param_name):
203 return param_type + " " + param_name
204
205def just_the_type_packed(param, entry):
206 name = just_the_name(param)
207 if entry.has_key(name):
208 return entry[name]
209 else:
210 return just_the_type(param)
211
Corentin Wallez2e568cf2017-09-18 17:05:22 -0400212def just_the_name_packed(param, reserved_set):
213 name = just_the_name(param)
214 if name in reserved_set:
215 return name + 'Packed'
216 else:
217 return name
218
Jamie Madillee769dd2017-05-04 11:38:30 -0400219format_dict = {
220 "GLbitfield": "0x%X",
221 "GLboolean": "%u",
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500222 "GLclampx": "0x%X",
Jamie Madillee769dd2017-05-04 11:38:30 -0400223 "GLenum": "0x%X",
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500224 "GLfixed": "0x%X",
Jamie Madillee769dd2017-05-04 11:38:30 -0400225 "GLfloat": "%f",
226 "GLint": "%d",
227 "GLintptr": "%d",
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500228 "GLshort": "%d",
Jamie Madillee769dd2017-05-04 11:38:30 -0400229 "GLsizei": "%d",
230 "GLsizeiptr": "%d",
Jamie Madill16daadb2017-08-26 23:34:31 -0400231 "GLsync": "0x%0.8p",
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500232 "GLubyte": "%d",
Jamie Madillff161f82017-08-26 23:49:10 -0400233 "GLuint": "%u",
Jamie Madillfa920eb2018-01-04 11:45:50 -0500234 "GLuint64": "%llu",
235 "GLDEBUGPROC": "0x%0.8p",
236 "GLDEBUGPROCKHR": "0x%0.8p",
237 "GLeglImageOES": "0x%0.8p",
Jamie Madillee769dd2017-05-04 11:38:30 -0400238}
239
240def param_format_string(param):
241 if "*" in param:
242 return param + " = 0x%0.8p"
243 else:
Jamie Madill16daadb2017-08-26 23:34:31 -0400244 type_only = just_the_type(param)
245 if type_only not in format_dict:
246 raise Exception(type_only + " is not a known type in 'format_dict'")
247
248 return param + " = " + format_dict[type_only]
Jamie Madillee769dd2017-05-04 11:38:30 -0400249
Jamie Madill2e29b132017-08-28 17:22:11 -0400250def default_return_value(cmd_name, return_type):
Jamie Madillee769dd2017-05-04 11:38:30 -0400251 if return_type == "void":
252 return ""
Jamie Madill2e29b132017-08-28 17:22:11 -0400253 return "GetDefaultReturnValue<EntryPoint::" + cmd_name[2:] + ", " + return_type + ">()"
Jamie Madillee769dd2017-05-04 11:38:30 -0400254
Geoff Langcae72d62017-06-01 11:53:45 -0400255def get_context_getter_function(cmd_name):
256 if cmd_name == "glGetError":
257 return "GetGlobalContext"
258 else:
259 return "GetValidGlobalContext"
260
Jamie Madillfa920eb2018-01-04 11:45:50 -0500261template_event_comment = """// Don't run an EVENT() macro on the EXT_debug_marker entry points.
262 // It can interfere with the debug events being set by the caller.
263 // """
264
Jamie Madillee769dd2017-05-04 11:38:30 -0400265def format_entry_point_def(cmd_name, proto, params):
Corentin Wallez2e568cf2017-09-18 17:05:22 -0400266 packed_gl_enums = cmd_packed_gl_enums.get(cmd_name, {})
267 internal_params = [just_the_name_packed(param, packed_gl_enums) for param in params]
268 packed_gl_enum_conversions = []
269 for param in params:
270 name = just_the_name(param)
271 if name in packed_gl_enums:
272 internal_name = name + "Packed"
273 internal_type = packed_gl_enums[name]
274 packed_gl_enum_conversions += ["\n " + internal_type + " " + internal_name +" = FromGLenum<" +
275 internal_type + ">(" + name + ");"]
276
Jamie Madillee769dd2017-05-04 11:38:30 -0400277 pass_params = [just_the_name(param) for param in params]
278 format_params = [param_format_string(param) for param in params]
279 return_type = proto[:-len(cmd_name)]
Jamie Madill2e29b132017-08-28 17:22:11 -0400280 default_return = default_return_value(cmd_name, return_type.strip())
Jamie Madillfa920eb2018-01-04 11:45:50 -0500281 event_comment = template_event_comment if cmd_name in no_event_marker_exceptions_list else ""
Jamie Madillc8c9a242018-01-02 13:39:00 -0500282 name_lower_no_suffix = cmd_name[2:3].lower() + cmd_name[3:]
283
Jamie Madillfa920eb2018-01-04 11:45:50 -0500284 for suffix in strip_suffixes:
285 if name_lower_no_suffix.endswith(suffix):
286 name_lower_no_suffix = name_lower_no_suffix[0:-len(suffix)]
287
Jamie Madillee769dd2017-05-04 11:38:30 -0400288 return template_entry_point_def.format(
289 name = cmd_name[2:],
Jamie Madillc8c9a242018-01-02 13:39:00 -0500290 name_lower_no_suffix = name_lower_no_suffix,
Jamie Madillee769dd2017-05-04 11:38:30 -0400291 return_type = return_type,
292 params = ", ".join(params),
Corentin Wallez2e568cf2017-09-18 17:05:22 -0400293 internal_params = ", ".join(internal_params),
294 packed_gl_enum_conversions = "".join(packed_gl_enum_conversions),
Jamie Madillee769dd2017-05-04 11:38:30 -0400295 pass_params = ", ".join(pass_params),
296 comma_if_needed = ", " if len(params) > 0 else "",
Corentin Wallez2e568cf2017-09-18 17:05:22 -0400297 validate_params = ", ".join(["context"] + internal_params),
Jamie Madillee769dd2017-05-04 11:38:30 -0400298 format_params = ", ".join(format_params),
Jamie Madillee769dd2017-05-04 11:38:30 -0400299 return_if_needed = "" if default_return == "" else "return ",
Geoff Langcae72d62017-06-01 11:53:45 -0400300 default_return_if_needed = "" if default_return == "" else "\n return " + default_return + ";\n",
Jamie Madillfa920eb2018-01-04 11:45:50 -0500301 context_getter = get_context_getter_function(cmd_name),
302 event_comment = event_comment)
Jamie Madillee769dd2017-05-04 11:38:30 -0400303
Lingfeng Yanga0648782018-03-12 14:45:25 -0700304def format_context_gles_decl(cmd_name, proto, params):
305 packed_gl_enums = cmd_packed_gl_enums.get(cmd_name, {})
306 internal_params = ", ".join([make_param(just_the_type_packed(param, packed_gl_enums),
307 just_the_name_packed(param, packed_gl_enums)) for param in params])
308
309 return_type = proto[:-len(cmd_name)]
310 name_lower_no_suffix = cmd_name[2:3].lower() + cmd_name[3:]
311
312 for suffix in strip_suffixes:
313 if name_lower_no_suffix.endswith(suffix):
314 name_lower_no_suffix = name_lower_no_suffix[0:-len(suffix)]
315
316 return context_gles_decl.format(
317 return_type = return_type,
318 name_lower_no_suffix = name_lower_no_suffix,
319 internal_params = internal_params)
320
Jiajia Qincb59a902017-11-22 13:03:42 +0800321def path_to(folder, file):
322 return os.path.join(script_relative(".."), "src", folder, file)
Jamie Madill2e16d962017-04-19 14:06:36 -0400323
Jamie Madillc8c9a242018-01-02 13:39:00 -0500324def get_entry_points(all_commands, gles_commands):
Jamie Madillc8c9a242018-01-02 13:39:00 -0500325 decls = []
326 defs = []
Jamie Madillffa2cd02017-12-28 14:57:53 -0500327 for command in all_commands:
328 proto = command.find('proto')
329 cmd_name = proto.find('name').text
330
331 if cmd_name not in gles_commands:
332 continue
333
334 param_text = ["".join(param.itertext()) for param in command.findall('param')]
335 proto_text = "".join(proto.itertext())
Jamie Madillc8c9a242018-01-02 13:39:00 -0500336 decls.append(format_entry_point_decl(cmd_name, proto_text, param_text))
337 defs.append(format_entry_point_def(cmd_name, proto_text, param_text))
Jamie Madillee769dd2017-05-04 11:38:30 -0400338
Jamie Madillc8c9a242018-01-02 13:39:00 -0500339 return decls, defs
Jamie Madill16daadb2017-08-26 23:34:31 -0400340
Lingfeng Yanga0648782018-03-12 14:45:25 -0700341def get_gles1_decls(all_commands, gles_commands):
342 decls = []
343 for command in all_commands:
344 proto = command.find('proto')
345 cmd_name = proto.find('name').text
346
347 if cmd_name not in gles_commands:
348 continue
349
350 if cmd_name in gles1_overloaded:
351 continue
352
353 param_text = ["".join(param.itertext()) for param in command.findall('param')]
354 proto_text = "".join(proto.itertext())
355 decls.append(format_context_gles_decl(cmd_name, proto_text, param_text))
356
357 return decls
358
359
Jamie Madillc8c9a242018-01-02 13:39:00 -0500360def write_file(annotation, comment, template, entry_points, suffix, includes):
Jiajia Qincb59a902017-11-22 13:03:42 +0800361
Jamie Madillc8c9a242018-01-02 13:39:00 -0500362 content = template.format(
363 script_name = os.path.basename(sys.argv[0]),
364 data_source_name = "gl.xml",
365 year = date.today().year,
366 annotation_lower = annotation.lower(),
367 annotation_upper = annotation.upper(),
368 comment = comment,
369 includes = includes,
370 entry_points = entry_points)
Jiajia Qincb59a902017-11-22 13:03:42 +0800371
Jamie Madillc8c9a242018-01-02 13:39:00 -0500372 path = path_to("libGLESv2", "entry_points_gles_{}_autogen.{}".format(
373 annotation.lower(), suffix))
374
375 with open(path, "w") as out:
376 out.write(content)
377 out.close()
378
Lingfeng Yanga0648782018-03-12 14:45:25 -0700379def write_context_api_decls(annotation, template, decls):
380
381 interface_lines = []
382
383 for i in decls['core']:
384 interface_lines.append(i)
385
386 for extname in sorted(decls['exts'].keys()):
387 interface_lines.append(" /* " + extname + " */ \\")
388 interface_lines.extend(decls['exts'][extname])
389
390 content = template.format(
391 annotation_lower = annotation.lower(),
392 annotation_upper = annotation.upper(),
393 script_name = os.path.basename(sys.argv[0]),
394 data_source_name = "gl.xml",
395 year = date.today().year,
396 interface = "\n".join(interface_lines))
397
398 path = path_to("libANGLE", "Context_gles_%s_autogen.h" % annotation.lower())
399
400 with open(path, "w") as out:
401 out.write(content)
402 out.close()
403
Jamie Madillc8c9a242018-01-02 13:39:00 -0500404all_commands = root.findall('commands/command')
405all_cmd_names = []
406
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500407template_header_includes = """#include <GLES{major}/gl{major}{minor}.h>
Jamie Madillc8c9a242018-01-02 13:39:00 -0500408#include <export.h>"""
409
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500410template_sources_includes = """#include "libGLESv2/entry_points_gles_{}_autogen.h"
411
412#include "libANGLE/Context.h"
Jamie Madillc8c9a242018-01-02 13:39:00 -0500413#include "libANGLE/validationES{}{}.h"
414#include "libGLESv2/global_state.h"
415"""
416
Lingfeng Yanga0648782018-03-12 14:45:25 -0700417gles1decls = {}
418
419gles1decls['core'] = []
420gles1decls['exts'] = {}
421
422# First run through the main GLES entry points. Since ES2+ is the primary use
423# case, we go through those first and then add ES1-only APIs at the end.
424for major_version, minor_version in [[2, 0], [3, 0], [3, 1], [1, 0]]:
Jamie Madillc8c9a242018-01-02 13:39:00 -0500425 annotation = "{}_{}".format(major_version, minor_version)
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500426 name_prefix = "GL_ES_VERSION_"
Lingfeng Yanga0648782018-03-12 14:45:25 -0700427
428 is_gles1 = major_version == 1
429 if is_gles1:
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500430 name_prefix = "GL_VERSION_ES_CM_"
Lingfeng Yanga0648782018-03-12 14:45:25 -0700431
Jamie Madillc8c9a242018-01-02 13:39:00 -0500432 comment = annotation.replace("_", ".")
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500433 gles_xpath = ".//feature[@name='{}{}']//command".format(name_prefix, annotation)
Jamie Madillc8c9a242018-01-02 13:39:00 -0500434 gles_commands = [cmd.attrib['name'] for cmd in root.findall(gles_xpath)]
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500435
436 # Remove commands that have already been processed
437 gles_commands = [cmd for cmd in gles_commands if cmd not in all_cmd_names]
438
Jamie Madillc8c9a242018-01-02 13:39:00 -0500439 all_cmd_names += gles_commands
440
441 decls, defs = get_entry_points(all_commands, gles_commands)
442
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500443 major_if_not_one = major_version if major_version != 1 else ""
Jamie Madillc8c9a242018-01-02 13:39:00 -0500444 minor_if_not_zero = minor_version if minor_version != 0 else ""
445
446 header_includes = template_header_includes.format(
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500447 major=major_if_not_one, minor=minor_if_not_zero)
Jamie Madillc8c9a242018-01-02 13:39:00 -0500448
449 # We include the platform.h header since it undefines the conflicting MemoryBarrier macro.
450 if major_version == 3 and minor_version == 1:
451 header_includes += "\n#include \"common/platform.h\"\n"
452
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500453 source_includes = template_sources_includes.format(
454 annotation.lower(), major_version,minor_if_not_zero)
Jamie Madillc8c9a242018-01-02 13:39:00 -0500455
456 write_file(annotation, comment, template_entry_point_header,
457 "\n".join(decls), "h", header_includes)
458 write_file(annotation, comment, template_entry_point_source,
459 "\n".join(defs), "cpp", source_includes)
Lingfeng Yanga0648782018-03-12 14:45:25 -0700460 if is_gles1:
461 gles1decls['core'] = get_gles1_decls(all_commands, gles_commands)
462
Jamie Madill57ae8c12017-08-30 12:14:29 -0400463
Jamie Madillfa920eb2018-01-04 11:45:50 -0500464# After we finish with the main entry points, we process the extensions.
465extension_defs = []
466extension_decls = []
467
468# Use a first step to run through the extensions so we can generate them
469# in sorted order.
470ext_data = {}
471
Lingfeng Yanga0648782018-03-12 14:45:25 -0700472for gles1ext in gles1_extensions:
473 gles1decls['exts'][gles1ext] = []
474
Jamie Madillfa920eb2018-01-04 11:45:50 -0500475for extension in root.findall("extensions/extension"):
476 extension_name = extension.attrib['name']
477 if not extension_name in supported_extensions:
478 continue
479
480 ext_cmd_names = []
481
482 # There's an extra step here to filter out 'api=gl' extensions. This
483 # is necessary for handling KHR extensions, which have separate entry
484 # point signatures (without the suffix) for desktop GL. Note that this
485 # extra step is necessary because of Etree's limited Xpath support.
486 for require in extension.findall('require'):
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500487 if 'api' in require.attrib and require.attrib['api'] != 'gles2' and require.attrib['api'] != 'gles1':
Jamie Madillfa920eb2018-01-04 11:45:50 -0500488 continue
489
490 # Another special case for EXT_texture_storage
491 filter_out_comment = "Supported only if GL_EXT_direct_state_access is supported"
492 if 'comment' in require.attrib and require.attrib['comment'] == filter_out_comment:
493 continue
494
495 extension_commands = require.findall('command')
496 ext_cmd_names += [command.attrib['name'] for command in extension_commands]
497
498 ext_data[extension_name] = sorted(ext_cmd_names)
499
500for extension_name, ext_cmd_names in sorted(ext_data.iteritems()):
501
502 # Detect and filter duplicate extensions.
503 dupes = []
504 for ext_cmd in ext_cmd_names:
505 if ext_cmd in all_cmd_names:
506 dupes.append(ext_cmd)
507
508 for dupe in dupes:
509 ext_cmd_names.remove(dupe)
510
511 all_cmd_names += ext_cmd_names
512
513 decls, defs = get_entry_points(all_commands, ext_cmd_names)
514
515 # Avoid writing out entry points defined by a prior extension.
516 for dupe in dupes:
517 msg = "// {} is already defined.\n".format(dupe[2:])
518 defs.append(msg)
519
520 # Write the extension name as a comment before the first EP.
521 comment = "\n// {}".format(extension_name)
522 defs.insert(0, comment)
523 decls.insert(0, comment)
524
525 extension_defs += defs
526 extension_decls += decls
527
Lingfeng Yanga0648782018-03-12 14:45:25 -0700528 if extension_name in gles1_extensions:
529 if extension_name not in gles1_no_context_decl_extensions:
530 gles1decls['exts'][extension_name] = get_gles1_decls(all_commands, ext_cmd_names)
531
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500532header_includes = template_header_includes.format(
533 major="", minor="")
534header_includes += """
535#include <GLES/gl.h>
536#include <GLES/glext.h>
537#include <GLES2/gl2.h>
538#include <GLES2/gl2ext.h>
539"""
Jamie Madillfa920eb2018-01-04 11:45:50 -0500540
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500541source_includes = template_sources_includes.format("ext", "", "")
542source_includes += """
543#include "libANGLE/validationES.h"
544#include "libANGLE/validationES1.h"
Jamie Madillfa920eb2018-01-04 11:45:50 -0500545#include "libANGLE/validationES3.h"
546#include "libANGLE/validationES31.h"
547"""
548
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500549write_file("ext", "extension", template_entry_point_header,
Jamie Madillfa920eb2018-01-04 11:45:50 -0500550 "\n".join([item for item in extension_decls]), "h", header_includes)
Geoff Lang2aaa7b42018-01-12 17:17:27 -0500551write_file("ext", "extension", template_entry_point_source,
Jamie Madillfa920eb2018-01-04 11:45:50 -0500552 "\n".join([item for item in extension_defs]), "cpp", source_includes)
Jamie Madillc8c9a242018-01-02 13:39:00 -0500553
Lingfeng Yanga0648782018-03-12 14:45:25 -0700554write_context_api_decls("1_0", context_gles_header, gles1decls)
555
Jamie Madillc8c9a242018-01-02 13:39:00 -0500556sorted_cmd_names = ["Invalid"] + [cmd[2:] for cmd in sorted(all_cmd_names)]
557
Jamie Madillee769dd2017-05-04 11:38:30 -0400558entry_points_enum = template_entry_points_enum_header.format(
559 script_name = os.path.basename(sys.argv[0]),
560 data_source_name = "gl.xml",
561 year = date.today().year,
Jamie Madillc8c9a242018-01-02 13:39:00 -0500562 entry_points_list = ",\n".join([" " + cmd for cmd in sorted_cmd_names]))
Jamie Madillee769dd2017-05-04 11:38:30 -0400563
Jamie Madillee769dd2017-05-04 11:38:30 -0400564entry_points_enum_header_path = path_to("libANGLE", "entry_points_enum_autogen.h")
Jamie Madillee769dd2017-05-04 11:38:30 -0400565with open(entry_points_enum_header_path, "w") as out:
566 out.write(entry_points_enum)
Geoff Langcae72d62017-06-01 11:53:45 -0400567 out.close()