Jeff Gilbert | 1b605ee | 2017-10-30 18:41:46 -0700 | [diff] [blame] | 1 | #!/usr/bin/python2 |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 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 | |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 10 | import sys, os, pprint, json |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 11 | import xml.etree.ElementTree as etree |
| 12 | from datetime import date |
| 13 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 14 | # List of supported extensions. Add to this list to enable new extensions |
| 15 | # available in gl.xml. |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 16 | |
| 17 | angle_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 Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 29 | gles1_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 Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 34 | "GL_OES_point_size_array", |
| 35 | "GL_OES_query_matrix", |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 36 | "GL_OES_texture_cube_map", |
| 37 | ] |
| 38 | |
| 39 | # List of GLES1 extensions for which we don't need to add Context.h decls. |
| 40 | gles1_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 |
| 46 | gles1_overloaded = [ |
| 47 | "glGetPointerv", |
| 48 | ] |
| 49 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 50 | supported_extensions = sorted(angle_extensions + gles1_extensions + [ |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 51 | # ES2+ |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 52 | "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 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 72 | # The EGL_ANGLE_explicit_context extension is generated differently from other extensions. |
| 73 | # Toggle generation here. |
| 74 | support_EGL_ANGLE_explicit_context = True |
| 75 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 76 | # This is a list of exceptions for entry points which don't want to have |
| 77 | # the EVENT macro. This is required for some debug marker entry points. |
| 78 | no_event_marker_exceptions_list = sorted([ |
| 79 | "glPushGroupMarkerEXT", |
| 80 | "glPopGroupMarkerEXT", |
| 81 | "glInsertEventMarkerEXT", |
| 82 | ]) |
| 83 | |
| 84 | # Strip these suffixes from Context entry point names. NV is excluded (for now). |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 85 | strip_suffixes = ["ANGLE", "EXT", "KHR", "OES", "CHROMIUM"] |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 86 | |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 87 | template_entry_point_header = """// GENERATED FILE - DO NOT EDIT. |
| 88 | // Generated by {script_name} using data from {data_source_name}. |
| 89 | // |
| 90 | // Copyright {year} The ANGLE Project Authors. All rights reserved. |
| 91 | // Use of this source code is governed by a BSD-style license that can be |
| 92 | // found in the LICENSE file. |
| 93 | // |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 94 | // entry_points_gles_{annotation_lower}_autogen.h: |
| 95 | // Defines the GLES {comment} entry points. |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 96 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 97 | #ifndef LIBGLESV2_ENTRY_POINTS_GLES_{annotation_upper}_AUTOGEN_H_ |
| 98 | #define LIBGLESV2_ENTRY_POINTS_GLES_{annotation_upper}_AUTOGEN_H_ |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 99 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 100 | {includes} |
| 101 | |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 102 | namespace gl |
| 103 | {{ |
| 104 | {entry_points} |
| 105 | }} // namespace gl |
| 106 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 107 | #endif // LIBGLESV2_ENTRY_POINTS_GLES_{annotation_upper}_AUTOGEN_H_ |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 108 | """ |
| 109 | |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 110 | template_entry_point_source = """// GENERATED FILE - DO NOT EDIT. |
| 111 | // Generated by {script_name} using data from {data_source_name}. |
| 112 | // |
| 113 | // Copyright {year} The ANGLE Project Authors. All rights reserved. |
| 114 | // Use of this source code is governed by a BSD-style license that can be |
| 115 | // found in the LICENSE file. |
| 116 | // |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 117 | // entry_points_gles_{annotation_lower}_autogen.cpp: |
| 118 | // Defines the GLES {comment} entry points. |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 119 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 120 | {includes} |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 121 | |
| 122 | namespace gl |
| 123 | {{ |
| 124 | {entry_points}}} // namespace gl |
| 125 | """ |
| 126 | |
| 127 | template_entry_points_enum_header = """// GENERATED FILE - DO NOT EDIT. |
| 128 | // Generated by {script_name} using data from {data_source_name}. |
| 129 | // |
| 130 | // Copyright {year} The ANGLE Project Authors. All rights reserved. |
| 131 | // Use of this source code is governed by a BSD-style license that can be |
| 132 | // found in the LICENSE file. |
| 133 | // |
| 134 | // entry_points_enum_autogen.h: |
| 135 | // Defines the GLES entry points enumeration. |
| 136 | |
| 137 | #ifndef LIBGLESV2_ENTRYPOINTSENUM_AUTOGEN_H_ |
| 138 | #define LIBGLESV2_ENTRYPOINTSENUM_AUTOGEN_H_ |
| 139 | |
| 140 | namespace gl |
| 141 | {{ |
| 142 | enum class EntryPoint |
| 143 | {{ |
| 144 | {entry_points_list} |
| 145 | }}; |
| 146 | }} // namespace gl |
| 147 | #endif // LIBGLESV2_ENTRY_POINTS_ENUM_AUTOGEN_H_ |
| 148 | """ |
| 149 | |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 150 | template_libgles_entry_point_source = """// GENERATED FILE - DO NOT EDIT. |
| 151 | // Generated by {script_name} using data from {data_source_name}. |
| 152 | // |
| 153 | // Copyright {year} The ANGLE Project Authors. All rights reserved. |
| 154 | // Use of this source code is governed by a BSD-style license that can be |
| 155 | // found in the LICENSE file. |
| 156 | // |
| 157 | // libGLESv2.cpp: Implements the exported OpenGL ES functions. |
| 158 | |
| 159 | {includes} |
| 160 | extern "C" {{ |
| 161 | {entry_points} |
| 162 | }} // extern "C" |
| 163 | """ |
| 164 | |
| 165 | template_libgles_entry_point_export = """; 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 | LIBRARY libGLESv2 |
| 172 | EXPORTS |
| 173 | {exports} |
| 174 | """ |
| 175 | |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 176 | template_entry_point_decl = """ANGLE_EXPORT {return_type}GL_APIENTRY {name}({params});""" |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 177 | template_entry_point_decl = """ANGLE_EXPORT {return_type}GL_APIENTRY {name}{explicit_context_suffix}({explicit_context_param}{explicit_context_comma}{params});""" |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 178 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 179 | template_entry_point_def = """{return_type}GL_APIENTRY {name}{explicit_context_suffix}({explicit_context_param}{explicit_context_comma}{params}) |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 180 | {{ |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 181 | {event_comment}EVENT("({format_params})"{comma_if_needed}{pass_params}); |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 182 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 183 | Context *context = {context_getter}; |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 184 | if (context) |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 185 | {{{assert_explicit_context}{packed_gl_enum_conversions} |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 186 | context->gatherParams<EntryPoint::{name}>({internal_params}); |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 187 | |
Jamie Madill | 53d3841 | 2017-04-20 11:33:00 -0400 | [diff] [blame] | 188 | if (context->skipValidation() || Validate{name}({validate_params})) |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 189 | {{ |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 190 | {return_if_needed}context->{name_lower_no_suffix}({internal_params}); |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 191 | }} |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 192 | }} |
| 193 | {default_return_if_needed}}} |
| 194 | """ |
| 195 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 196 | context_gles_header = """// GENERATED FILE - DO NOT EDIT. |
| 197 | // Generated by {script_name} using data from {data_source_name}. |
| 198 | // |
| 199 | // Copyright {year} The ANGLE Project Authors. All rights reserved. |
| 200 | // Use of this source code is governed by a BSD-style license that can be |
| 201 | // found in the LICENSE file. |
| 202 | // |
| 203 | // Context_gles_{annotation_lower}_autogen.h: Creates a macro for interfaces in Context. |
| 204 | |
| 205 | #ifndef ANGLE_CONTEXT_GLES_{annotation_upper}_AUTOGEN_H_ |
| 206 | #define ANGLE_CONTEXT_GLES_{annotation_upper}_AUTOGEN_H_ |
| 207 | |
| 208 | #define ANGLE_GLES1_CONTEXT_API \\ |
| 209 | {interface} |
| 210 | |
| 211 | #endif // ANGLE_CONTEXT_API_{annotation_upper}_AUTOGEN_H_ |
| 212 | """ |
| 213 | |
| 214 | context_gles_decl = """ {return_type} {name_lower_no_suffix}({internal_params}); \\""" |
| 215 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 216 | libgles_entry_point_def = """{return_type}GL_APIENTRY gl{name}{explicit_context_suffix}({explicit_context_param}{explicit_context_comma}{params}) |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 217 | {{ |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 218 | return gl::{name}{explicit_context_suffix}({explicit_context_internal_param}{explicit_context_comma}{internal_params}); |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 219 | }} |
| 220 | """ |
| 221 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 222 | libgles_entry_point_export = """ {name}{explicit_context_suffix}{spaces}@{ordinal}""" |
| 223 | |
| 224 | template_glext_explicit_context_inc = """// GENERATED FILE - DO NOT EDIT. |
| 225 | // Generated by {script_name} using data from {data_source_name}. |
| 226 | // |
| 227 | // Copyright {year} The ANGLE Project Authors. All rights reserved. |
| 228 | // Use of this source code is governed by a BSD-style license that can be |
| 229 | // found in the LICENSE file. |
| 230 | // |
| 231 | // gl{version}ext_explicit_context_autogen.inc: |
| 232 | // Function declarations for the EGL_ANGLE_explicit_context extension |
| 233 | |
| 234 | {function_pointers} |
| 235 | #ifdef GL_GLEXT_PROTOTYPES |
| 236 | {function_prototypes} |
| 237 | #endif |
| 238 | """ |
| 239 | |
| 240 | template_glext_function_pointer = """typedef {return_type}(GL_APIENTRYP PFN{name_upper}{explicit_context_suffix_upper})({explicit_context_param}{explicit_context_comma}{params});""" |
| 241 | template_glext_function_prototype = """{apicall} {return_type}GL_APIENTRY {name}{explicit_context_suffix}({explicit_context_param}{explicit_context_comma}{params});""" |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 242 | |
Jamie Madill | 16daadb | 2017-08-26 23:34:31 -0400 | [diff] [blame] | 243 | def script_relative(path): |
| 244 | return os.path.join(os.path.dirname(sys.argv[0]), path) |
| 245 | |
| 246 | tree = etree.parse(script_relative('gl.xml')) |
| 247 | root = tree.getroot() |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 248 | commands = root.find(".//commands[@namespace='GL']") |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 249 | |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 250 | with open(script_relative('entry_point_packed_gl_enums.json')) as f: |
| 251 | cmd_packed_gl_enums = json.loads(f.read()) |
| 252 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 253 | def format_entry_point_decl(cmd_name, proto, params, is_explicit_context): |
| 254 | comma_if_needed = ", " if len(params) > 0 else "" |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 255 | return template_entry_point_decl.format( |
| 256 | name = cmd_name[2:], |
| 257 | return_type = proto[:-len(cmd_name)], |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 258 | params = ", ".join(params), |
| 259 | comma_if_needed = comma_if_needed, |
| 260 | explicit_context_suffix = "ContextANGLE" if is_explicit_context else "", |
| 261 | explicit_context_param = "GLeglContext ctx" if is_explicit_context else "", |
| 262 | explicit_context_comma = ", " if is_explicit_context and len(params) > 0 else "") |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 263 | |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 264 | def type_name_sep_index(param): |
| 265 | space = param.rfind(" ") |
| 266 | pointer = param.rfind("*") |
| 267 | return max(space, pointer) |
| 268 | |
| 269 | def just_the_type(param): |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 270 | if "*" in param: |
| 271 | return param[:type_name_sep_index(param) + 1] |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 272 | return param[:type_name_sep_index(param)] |
| 273 | |
| 274 | def just_the_name(param): |
| 275 | return param[type_name_sep_index(param)+1:] |
| 276 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 277 | def make_param(param_type, param_name): |
| 278 | return param_type + " " + param_name |
| 279 | |
| 280 | def just_the_type_packed(param, entry): |
| 281 | name = just_the_name(param) |
| 282 | if entry.has_key(name): |
| 283 | return entry[name] |
| 284 | else: |
| 285 | return just_the_type(param) |
| 286 | |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 287 | def just_the_name_packed(param, reserved_set): |
| 288 | name = just_the_name(param) |
| 289 | if name in reserved_set: |
| 290 | return name + 'Packed' |
| 291 | else: |
| 292 | return name |
| 293 | |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 294 | format_dict = { |
| 295 | "GLbitfield": "0x%X", |
| 296 | "GLboolean": "%u", |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 297 | "GLclampx": "0x%X", |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 298 | "GLenum": "0x%X", |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 299 | "GLfixed": "0x%X", |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 300 | "GLfloat": "%f", |
| 301 | "GLint": "%d", |
| 302 | "GLintptr": "%d", |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 303 | "GLshort": "%d", |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 304 | "GLsizei": "%d", |
| 305 | "GLsizeiptr": "%d", |
Jamie Madill | 16daadb | 2017-08-26 23:34:31 -0400 | [diff] [blame] | 306 | "GLsync": "0x%0.8p", |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 307 | "GLubyte": "%d", |
Jamie Madill | ff161f8 | 2017-08-26 23:49:10 -0400 | [diff] [blame] | 308 | "GLuint": "%u", |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 309 | "GLuint64": "%llu", |
| 310 | "GLDEBUGPROC": "0x%0.8p", |
| 311 | "GLDEBUGPROCKHR": "0x%0.8p", |
| 312 | "GLeglImageOES": "0x%0.8p", |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | def param_format_string(param): |
| 316 | if "*" in param: |
| 317 | return param + " = 0x%0.8p" |
| 318 | else: |
Jamie Madill | 16daadb | 2017-08-26 23:34:31 -0400 | [diff] [blame] | 319 | type_only = just_the_type(param) |
| 320 | if type_only not in format_dict: |
| 321 | raise Exception(type_only + " is not a known type in 'format_dict'") |
| 322 | |
| 323 | return param + " = " + format_dict[type_only] |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 324 | |
Jamie Madill | 2e29b13 | 2017-08-28 17:22:11 -0400 | [diff] [blame] | 325 | def default_return_value(cmd_name, return_type): |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 326 | if return_type == "void": |
| 327 | return "" |
Jamie Madill | 2e29b13 | 2017-08-28 17:22:11 -0400 | [diff] [blame] | 328 | return "GetDefaultReturnValue<EntryPoint::" + cmd_name[2:] + ", " + return_type + ">()" |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 329 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 330 | def get_context_getter_function(cmd_name, is_explicit_context): |
Geoff Lang | cae72d6 | 2017-06-01 11:53:45 -0400 | [diff] [blame] | 331 | if cmd_name == "glGetError": |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 332 | return "GetGlobalContext()" |
| 333 | elif is_explicit_context: |
| 334 | return "static_cast<gl::Context *>(ctx)" |
Geoff Lang | cae72d6 | 2017-06-01 11:53:45 -0400 | [diff] [blame] | 335 | else: |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 336 | return "GetValidGlobalContext()" |
Geoff Lang | cae72d6 | 2017-06-01 11:53:45 -0400 | [diff] [blame] | 337 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 338 | template_event_comment = """// Don't run an EVENT() macro on the EXT_debug_marker entry points. |
| 339 | // It can interfere with the debug events being set by the caller. |
| 340 | // """ |
| 341 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 342 | def format_entry_point_def(cmd_name, proto, params, is_explicit_context): |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 343 | packed_gl_enums = cmd_packed_gl_enums.get(cmd_name, {}) |
| 344 | internal_params = [just_the_name_packed(param, packed_gl_enums) for param in params] |
| 345 | packed_gl_enum_conversions = [] |
| 346 | for param in params: |
| 347 | name = just_the_name(param) |
| 348 | if name in packed_gl_enums: |
| 349 | internal_name = name + "Packed" |
| 350 | internal_type = packed_gl_enums[name] |
| 351 | packed_gl_enum_conversions += ["\n " + internal_type + " " + internal_name +" = FromGLenum<" + |
| 352 | internal_type + ">(" + name + ");"] |
| 353 | |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 354 | pass_params = [just_the_name(param) for param in params] |
| 355 | format_params = [param_format_string(param) for param in params] |
| 356 | return_type = proto[:-len(cmd_name)] |
Jamie Madill | 2e29b13 | 2017-08-28 17:22:11 -0400 | [diff] [blame] | 357 | default_return = default_return_value(cmd_name, return_type.strip()) |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 358 | event_comment = template_event_comment if cmd_name in no_event_marker_exceptions_list else "" |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 359 | name_lower_no_suffix = cmd_name[2:3].lower() + cmd_name[3:] |
| 360 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 361 | for suffix in strip_suffixes: |
| 362 | if name_lower_no_suffix.endswith(suffix): |
| 363 | name_lower_no_suffix = name_lower_no_suffix[0:-len(suffix)] |
| 364 | |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 365 | return template_entry_point_def.format( |
| 366 | name = cmd_name[2:], |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 367 | name_lower_no_suffix = name_lower_no_suffix, |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 368 | return_type = return_type, |
| 369 | params = ", ".join(params), |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 370 | internal_params = ", ".join(internal_params), |
| 371 | packed_gl_enum_conversions = "".join(packed_gl_enum_conversions), |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 372 | pass_params = ", ".join(pass_params), |
| 373 | comma_if_needed = ", " if len(params) > 0 else "", |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 374 | validate_params = ", ".join(["context"] + internal_params), |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 375 | format_params = ", ".join(format_params), |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 376 | return_if_needed = "" if default_return == "" else "return ", |
Geoff Lang | cae72d6 | 2017-06-01 11:53:45 -0400 | [diff] [blame] | 377 | default_return_if_needed = "" if default_return == "" else "\n return " + default_return + ";\n", |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 378 | context_getter = get_context_getter_function(cmd_name, is_explicit_context), |
| 379 | event_comment = event_comment, |
| 380 | explicit_context_suffix = "ContextANGLE" if is_explicit_context else "", |
| 381 | explicit_context_param = "GLeglContext ctx" if is_explicit_context else "", |
| 382 | explicit_context_comma = ", " if is_explicit_context and len(params) > 0 else "", |
| 383 | assert_explicit_context = "\nASSERT(context == GetValidGlobalContext());" |
| 384 | if is_explicit_context else "") |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 385 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 386 | def format_context_gles_decl(cmd_name, proto, params): |
| 387 | packed_gl_enums = cmd_packed_gl_enums.get(cmd_name, {}) |
| 388 | internal_params = ", ".join([make_param(just_the_type_packed(param, packed_gl_enums), |
| 389 | just_the_name_packed(param, packed_gl_enums)) for param in params]) |
| 390 | |
| 391 | return_type = proto[:-len(cmd_name)] |
| 392 | name_lower_no_suffix = cmd_name[2:3].lower() + cmd_name[3:] |
| 393 | |
| 394 | for suffix in strip_suffixes: |
| 395 | if name_lower_no_suffix.endswith(suffix): |
| 396 | name_lower_no_suffix = name_lower_no_suffix[0:-len(suffix)] |
| 397 | |
| 398 | return context_gles_decl.format( |
| 399 | return_type = return_type, |
| 400 | name_lower_no_suffix = name_lower_no_suffix, |
| 401 | internal_params = internal_params) |
| 402 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 403 | def format_libgles_entry_point_def(cmd_name, proto, params, is_explicit_context): |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 404 | internal_params = [just_the_name(param) for param in params] |
| 405 | return_type = proto[:-len(cmd_name)] |
| 406 | |
| 407 | return libgles_entry_point_def.format( |
| 408 | name = cmd_name[2:], |
| 409 | return_type = return_type, |
| 410 | params = ", ".join(params), |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 411 | internal_params = ", ".join(internal_params), |
| 412 | explicit_context_suffix = "ContextANGLE" if is_explicit_context else "", |
| 413 | explicit_context_param = "GLeglContext ctx" if is_explicit_context else "", |
| 414 | explicit_context_comma = ", " if is_explicit_context and len(params) > 0 else "", |
| 415 | explicit_context_internal_param = "ctx" if is_explicit_context else "") |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 416 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 417 | def format_libgles_entry_point_export(cmd_name, ordinal, is_explicit_context): |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 418 | return libgles_entry_point_export.format( |
| 419 | name = cmd_name, |
| 420 | ordinal = ordinal, |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 421 | spaces = " "*(50 - len(cmd_name)), |
| 422 | explicit_context_suffix = "ContextANGLE" if is_explicit_context else "") |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 423 | |
Jiajia Qin | cb59a90 | 2017-11-22 13:03:42 +0800 | [diff] [blame] | 424 | def path_to(folder, file): |
| 425 | return os.path.join(script_relative(".."), "src", folder, file) |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 426 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 427 | def get_entry_points(all_commands, gles_commands, ordinal, is_explicit_context): |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 428 | decls = [] |
| 429 | defs = [] |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 430 | export_defs = [] |
| 431 | exports = [] |
| 432 | |
Jamie Madill | ffa2cd0 | 2017-12-28 14:57:53 -0500 | [diff] [blame] | 433 | for command in all_commands: |
| 434 | proto = command.find('proto') |
| 435 | cmd_name = proto.find('name').text |
| 436 | |
| 437 | if cmd_name not in gles_commands: |
| 438 | continue |
| 439 | |
| 440 | param_text = ["".join(param.itertext()) for param in command.findall('param')] |
| 441 | proto_text = "".join(proto.itertext()) |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 442 | decls.append(format_entry_point_decl(cmd_name, proto_text, param_text, |
| 443 | is_explicit_context)) |
| 444 | defs.append(format_entry_point_def(cmd_name, proto_text, param_text, is_explicit_context)) |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 445 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 446 | export_defs.append(format_libgles_entry_point_def(cmd_name, proto_text, param_text, |
| 447 | is_explicit_context)) |
| 448 | exports.append(format_libgles_entry_point_export(cmd_name, ordinal, is_explicit_context)) |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 449 | ordinal = ordinal + 1 |
| 450 | |
| 451 | return decls, defs, export_defs, exports |
Jamie Madill | 16daadb | 2017-08-26 23:34:31 -0400 | [diff] [blame] | 452 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 453 | def get_gles1_decls(all_commands, gles_commands): |
| 454 | decls = [] |
| 455 | for command in all_commands: |
| 456 | proto = command.find('proto') |
| 457 | cmd_name = proto.find('name').text |
| 458 | |
| 459 | if cmd_name not in gles_commands: |
| 460 | continue |
| 461 | |
| 462 | if cmd_name in gles1_overloaded: |
| 463 | continue |
| 464 | |
| 465 | param_text = ["".join(param.itertext()) for param in command.findall('param')] |
| 466 | proto_text = "".join(proto.itertext()) |
| 467 | decls.append(format_context_gles_decl(cmd_name, proto_text, param_text)) |
| 468 | |
| 469 | return decls |
| 470 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 471 | def get_glext_decls(all_commands, gles_commands, version, is_explicit_context): |
| 472 | glext_ptrs = [] |
| 473 | glext_protos = [] |
| 474 | is_gles1 = False |
| 475 | |
| 476 | if(version == ""): |
| 477 | is_gles1 = True |
| 478 | |
| 479 | for command in all_commands: |
| 480 | proto = command.find('proto') |
| 481 | cmd_name = proto.find('name').text |
| 482 | |
| 483 | if cmd_name not in gles_commands: |
| 484 | continue |
| 485 | |
| 486 | param_text = ["".join(param.itertext()) for param in command.findall('param')] |
| 487 | proto_text = "".join(proto.itertext()) |
| 488 | |
| 489 | return_type = proto_text[:-len(cmd_name)] |
| 490 | params = ", ".join(param_text) |
| 491 | |
| 492 | format_params = { |
| 493 | "apicall": "GL_API" if is_gles1 else "GL_APICALL", |
| 494 | "name": cmd_name, |
| 495 | "name_upper": cmd_name.upper(), |
| 496 | "return_type": return_type, |
| 497 | "params": params, |
| 498 | "explicit_context_comma": ", " if is_explicit_context and len(params) > 0 else "", |
| 499 | "explicit_context_suffix": "ContextANGLE" if is_explicit_context else "", |
| 500 | "explicit_context_suffix_upper": "CONTEXTANGLE" if is_explicit_context else "", |
| 501 | "explicit_context_param": "GLeglContext ctx" if is_explicit_context else ""} |
| 502 | |
| 503 | glext_ptrs.append(template_glext_function_pointer.format( |
| 504 | **format_params)) |
| 505 | glext_protos.append(template_glext_function_prototype.format( |
| 506 | **format_params)) |
| 507 | |
| 508 | return glext_ptrs, glext_protos |
| 509 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 510 | def write_file(annotation, comment, template, entry_points, suffix, includes, file): |
Jiajia Qin | cb59a90 | 2017-11-22 13:03:42 +0800 | [diff] [blame] | 511 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 512 | content = template.format( |
| 513 | script_name = os.path.basename(sys.argv[0]), |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 514 | data_source_name = file, |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 515 | year = date.today().year, |
| 516 | annotation_lower = annotation.lower(), |
| 517 | annotation_upper = annotation.upper(), |
| 518 | comment = comment, |
| 519 | includes = includes, |
| 520 | entry_points = entry_points) |
Jiajia Qin | cb59a90 | 2017-11-22 13:03:42 +0800 | [diff] [blame] | 521 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 522 | path = path_to("libGLESv2", "entry_points_gles_{}_autogen.{}".format( |
| 523 | annotation.lower(), suffix)) |
| 524 | |
| 525 | with open(path, "w") as out: |
| 526 | out.write(content) |
| 527 | out.close() |
| 528 | |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 529 | def write_export_files(entry_points, includes, exports): |
| 530 | |
| 531 | content = template_libgles_entry_point_source.format( |
| 532 | script_name = os.path.basename(sys.argv[0]), |
| 533 | data_source_name = "gl.xml and gl_angle_ext.xml", |
| 534 | year = date.today().year, |
| 535 | includes = includes, |
| 536 | entry_points = entry_points) |
| 537 | |
| 538 | path = path_to("libGLESv2", "libGLESv2_autogen.cpp") |
| 539 | |
| 540 | with open(path, "w") as out: |
| 541 | out.write(content) |
| 542 | out.close() |
| 543 | |
| 544 | content = template_libgles_entry_point_export.format( |
| 545 | script_name = os.path.basename(sys.argv[0]), |
| 546 | data_source_name = "gl.xml and gl_angle_ext.xml", |
| 547 | exports = exports, |
| 548 | year = date.today().year) |
| 549 | |
| 550 | path = path_to("libGLESv2", "libGLESv2_autogen.def") |
| 551 | |
| 552 | with open(path, "w") as out: |
| 553 | out.write(content) |
| 554 | out.close() |
| 555 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 556 | def write_context_api_decls(annotation, template, decls): |
| 557 | |
| 558 | interface_lines = [] |
| 559 | |
| 560 | for i in decls['core']: |
| 561 | interface_lines.append(i) |
| 562 | |
| 563 | for extname in sorted(decls['exts'].keys()): |
| 564 | interface_lines.append(" /* " + extname + " */ \\") |
| 565 | interface_lines.extend(decls['exts'][extname]) |
| 566 | |
| 567 | content = template.format( |
| 568 | annotation_lower = annotation.lower(), |
| 569 | annotation_upper = annotation.upper(), |
| 570 | script_name = os.path.basename(sys.argv[0]), |
| 571 | data_source_name = "gl.xml", |
| 572 | year = date.today().year, |
| 573 | interface = "\n".join(interface_lines)) |
| 574 | |
| 575 | path = path_to("libANGLE", "Context_gles_%s_autogen.h" % annotation.lower()) |
| 576 | |
| 577 | with open(path, "w") as out: |
| 578 | out.write(content) |
| 579 | out.close() |
| 580 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 581 | def write_glext_explicit_context_inc(version, ptrs, protos): |
| 582 | folder_version = version if version != "31" else "3" |
| 583 | |
| 584 | content = template_glext_explicit_context_inc.format( |
| 585 | script_name = os.path.basename(sys.argv[0]), |
| 586 | data_source_name = "gl.xml and gl_angle_ext.xml", |
| 587 | year = date.today().year, |
| 588 | version = version, |
| 589 | function_pointers = ptrs, |
| 590 | function_prototypes = protos) |
| 591 | |
Brandon Jones | 795ab71 | 2018-05-24 15:45:40 -0700 | [diff] [blame] | 592 | path = os.path.join(script_relative(".."), "include", "GLES{}".format(folder_version), |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 593 | "gl{}ext_explicit_context_autogen.inc".format(version)) |
| 594 | |
| 595 | with open(path, "w") as out: |
| 596 | out.write(content) |
| 597 | out.close() |
| 598 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 599 | def append_angle_extensions(base_root): |
| 600 | angle_ext_tree = etree.parse(script_relative('gl_angle_ext.xml')) |
| 601 | angle_ext_root = angle_ext_tree.getroot() |
| 602 | |
| 603 | insertion_point = base_root.findall("./commands")[0] |
| 604 | for command in angle_ext_root.iter('commands'): |
| 605 | insertion_point.extend(command) |
| 606 | |
| 607 | insertion_point = base_root.findall("./extensions")[0] |
| 608 | for extension in angle_ext_root.iter('extensions'): |
| 609 | insertion_point.extend(extension) |
| 610 | return base_root |
| 611 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 612 | class GLCommandNames: |
| 613 | def __init__(self): |
| 614 | self.command_names = {} |
| 615 | |
| 616 | def get_commands(self, version): |
| 617 | return self.command_names[version] |
| 618 | |
| 619 | def get_all_commands(self): |
| 620 | cmd_names = [] |
| 621 | # Combine all the version lists into a single list |
| 622 | for version, version_cmd_names in sorted(self.command_names.iteritems()): |
| 623 | cmd_names += version_cmd_names |
| 624 | |
| 625 | return cmd_names |
| 626 | |
| 627 | def add_commands(self, version, commands): |
| 628 | # Add key if it doesn't exist |
| 629 | if version not in self.command_names: |
| 630 | self.command_names[version] = [] |
| 631 | # Add the commands that aren't duplicates |
| 632 | self.command_names[version] += commands |
| 633 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 634 | root = append_angle_extensions(root) |
| 635 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 636 | all_commands = root.findall('commands/command') |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 637 | all_cmd_names = GLCommandNames() |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 638 | |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 639 | template_header_includes = """#include <GLES{major}/gl{major}{minor}.h> |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 640 | #include <export.h>""" |
| 641 | |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 642 | template_sources_includes = """#include "libGLESv2/entry_points_gles_{}_autogen.h" |
| 643 | |
| 644 | #include "libANGLE/Context.h" |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 645 | #include "libANGLE/validationES{}{}.h" |
| 646 | #include "libGLESv2/global_state.h" |
| 647 | """ |
| 648 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 649 | gles1decls = {} |
| 650 | |
| 651 | gles1decls['core'] = [] |
| 652 | gles1decls['exts'] = {} |
| 653 | |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 654 | libgles_ep_defs = [] |
| 655 | libgles_ep_exports = [] |
| 656 | |
| 657 | ordinal_start = 1 |
| 658 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 659 | # First run through the main GLES entry points. Since ES2+ is the primary use |
| 660 | # case, we go through those first and then add ES1-only APIs at the end. |
| 661 | for major_version, minor_version in [[2, 0], [3, 0], [3, 1], [1, 0]]: |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 662 | annotation = "{}_{}".format(major_version, minor_version) |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 663 | name_prefix = "GL_ES_VERSION_" |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 664 | |
| 665 | is_gles1 = major_version == 1 |
| 666 | if is_gles1: |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 667 | name_prefix = "GL_VERSION_ES_CM_" |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 668 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 669 | comment = annotation.replace("_", ".") |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 670 | gles_xpath = ".//feature[@name='{}{}']//command".format(name_prefix, annotation) |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 671 | gles_commands = [cmd.attrib['name'] for cmd in root.findall(gles_xpath)] |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 672 | |
| 673 | # Remove commands that have already been processed |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 674 | gles_commands = [cmd for cmd in gles_commands if cmd not in all_cmd_names.get_all_commands()] |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 675 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 676 | all_cmd_names.add_commands(annotation, gles_commands) |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 677 | |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 678 | decls, defs, libgles_defs, libgles_exports = get_entry_points( |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 679 | all_commands, gles_commands, ordinal_start, False) |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 680 | |
| 681 | # Increment the ordinal before inserting the version comment |
| 682 | ordinal_start += len(libgles_exports) |
| 683 | |
| 684 | # Write the version as a comment before the first EP. |
| 685 | libgles_defs.insert(0, "\n// OpenGL ES {}.{}".format(major_version, minor_version)) |
| 686 | libgles_exports.insert(0, "\n ; OpenGL ES {}.{}".format(major_version, minor_version)) |
| 687 | |
| 688 | libgles_ep_defs += libgles_defs |
| 689 | libgles_ep_exports += libgles_exports |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 690 | |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 691 | major_if_not_one = major_version if major_version != 1 else "" |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 692 | minor_if_not_zero = minor_version if minor_version != 0 else "" |
| 693 | |
| 694 | header_includes = template_header_includes.format( |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 695 | major=major_if_not_one, minor=minor_if_not_zero) |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 696 | |
| 697 | # We include the platform.h header since it undefines the conflicting MemoryBarrier macro. |
| 698 | if major_version == 3 and minor_version == 1: |
| 699 | header_includes += "\n#include \"common/platform.h\"\n" |
| 700 | |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 701 | source_includes = template_sources_includes.format( |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 702 | annotation.lower(), major_version, minor_if_not_zero) |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 703 | |
| 704 | write_file(annotation, comment, template_entry_point_header, |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 705 | "\n".join(decls), "h", header_includes, "gl.xml") |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 706 | write_file(annotation, comment, template_entry_point_source, |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 707 | "\n".join(defs), "cpp", source_includes, "gl.xml") |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 708 | if is_gles1: |
| 709 | gles1decls['core'] = get_gles1_decls(all_commands, gles_commands) |
| 710 | |
Jamie Madill | 57ae8c1 | 2017-08-30 12:14:29 -0400 | [diff] [blame] | 711 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 712 | # After we finish with the main entry points, we process the extensions. |
| 713 | extension_defs = [] |
| 714 | extension_decls = [] |
| 715 | |
| 716 | # Use a first step to run through the extensions so we can generate them |
| 717 | # in sorted order. |
| 718 | ext_data = {} |
| 719 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 720 | for gles1ext in gles1_extensions: |
| 721 | gles1decls['exts'][gles1ext] = [] |
| 722 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 723 | for extension in root.findall("extensions/extension"): |
| 724 | extension_name = extension.attrib['name'] |
| 725 | if not extension_name in supported_extensions: |
| 726 | continue |
| 727 | |
| 728 | ext_cmd_names = [] |
| 729 | |
| 730 | # There's an extra step here to filter out 'api=gl' extensions. This |
| 731 | # is necessary for handling KHR extensions, which have separate entry |
| 732 | # point signatures (without the suffix) for desktop GL. Note that this |
| 733 | # extra step is necessary because of Etree's limited Xpath support. |
| 734 | for require in extension.findall('require'): |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 735 | if 'api' in require.attrib and require.attrib['api'] != 'gles2' and require.attrib['api'] != 'gles1': |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 736 | continue |
| 737 | |
| 738 | # Another special case for EXT_texture_storage |
| 739 | filter_out_comment = "Supported only if GL_EXT_direct_state_access is supported" |
| 740 | if 'comment' in require.attrib and require.attrib['comment'] == filter_out_comment: |
| 741 | continue |
| 742 | |
| 743 | extension_commands = require.findall('command') |
| 744 | ext_cmd_names += [command.attrib['name'] for command in extension_commands] |
| 745 | |
| 746 | ext_data[extension_name] = sorted(ext_cmd_names) |
| 747 | |
| 748 | for extension_name, ext_cmd_names in sorted(ext_data.iteritems()): |
| 749 | |
| 750 | # Detect and filter duplicate extensions. |
| 751 | dupes = [] |
| 752 | for ext_cmd in ext_cmd_names: |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 753 | if ext_cmd in all_cmd_names.get_all_commands(): |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 754 | dupes.append(ext_cmd) |
| 755 | |
| 756 | for dupe in dupes: |
| 757 | ext_cmd_names.remove(dupe) |
| 758 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 759 | if extension_name in gles1_extensions: |
| 760 | all_cmd_names.add_commands("glext", ext_cmd_names) |
| 761 | else: |
| 762 | all_cmd_names.add_commands("gl2ext", ext_cmd_names) |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 763 | |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 764 | decls, defs, libgles_defs, libgles_exports = get_entry_points( |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 765 | all_commands, ext_cmd_names, ordinal_start, False) |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 766 | |
| 767 | # Avoid writing out entry points defined by a prior extension. |
| 768 | for dupe in dupes: |
| 769 | msg = "// {} is already defined.\n".format(dupe[2:]) |
| 770 | defs.append(msg) |
| 771 | |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 772 | # Increment starting ordinal before adding extension comment |
| 773 | ordinal_start += len(libgles_exports) |
| 774 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 775 | # Write the extension name as a comment before the first EP. |
| 776 | comment = "\n// {}".format(extension_name) |
| 777 | defs.insert(0, comment) |
| 778 | decls.insert(0, comment) |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 779 | libgles_defs.insert(0, comment) |
| 780 | libgles_exports.insert(0, "\n ; {}".format(extension_name)) |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 781 | |
| 782 | extension_defs += defs |
| 783 | extension_decls += decls |
| 784 | |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 785 | libgles_ep_defs += libgles_defs |
| 786 | libgles_ep_exports += libgles_exports |
| 787 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 788 | if extension_name in gles1_extensions: |
| 789 | if extension_name not in gles1_no_context_decl_extensions: |
| 790 | gles1decls['exts'][extension_name] = get_gles1_decls(all_commands, ext_cmd_names) |
| 791 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 792 | # Special handling for EGL_ANGLE_explicit_context extension |
| 793 | if support_EGL_ANGLE_explicit_context: |
| 794 | comment = "\n// EGL_ANGLE_explicit_context" |
| 795 | extension_defs.append(comment) |
| 796 | extension_decls.append(comment) |
| 797 | libgles_ep_defs.append(comment) |
| 798 | libgles_ep_exports.append("\n ; EGL_ANGLE_explicit_context") |
| 799 | |
| 800 | # Get the explicit context entry points |
| 801 | decls, defs, libgles_defs, libgles_exports = get_entry_points(all_commands, |
| 802 | all_cmd_names.get_all_commands(), ordinal_start, True) |
| 803 | |
| 804 | # Append the explicit context entry points |
| 805 | extension_decls += decls |
| 806 | extension_defs += defs |
| 807 | libgles_ep_defs += libgles_defs |
| 808 | libgles_ep_exports += libgles_exports |
| 809 | |
| 810 | # Generate .inc files for extension function pointers and declarations |
| 811 | for major, minor in [[2, 0], [3, 0], [3, 1], [1, 0]]: |
| 812 | annotation = "{}_{}".format(major, minor) |
| 813 | |
| 814 | major_if_not_one = major if major != 1 else "" |
| 815 | minor_if_not_zero = minor if minor != 0 else "" |
| 816 | version = "{}{}".format(major_if_not_one, minor_if_not_zero) |
| 817 | |
| 818 | glext_ptrs, glext_protos = get_glext_decls(all_commands, |
| 819 | all_cmd_names.get_commands(annotation), version, True) |
| 820 | |
| 821 | glext_ext_ptrs = [] |
| 822 | glext_ext_protos = [] |
| 823 | |
| 824 | # Append extensions for 1.0 and 2.0 |
| 825 | if(annotation == "1_0"): |
| 826 | glext_ext_ptrs, glext_ext_protos = get_glext_decls(all_commands, |
| 827 | all_cmd_names.get_commands("glext"), version, True) |
| 828 | elif(annotation == "2_0"): |
| 829 | glext_ext_ptrs, glext_ext_protos = get_glext_decls(all_commands, |
| 830 | all_cmd_names.get_commands("gl2ext"), version, True) |
| 831 | |
| 832 | glext_ptrs += glext_ext_ptrs |
| 833 | glext_protos += glext_ext_protos |
| 834 | |
| 835 | write_glext_explicit_context_inc(version, "\n".join(glext_ptrs), "\n".join(glext_protos)) |
| 836 | |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 837 | header_includes = template_header_includes.format( |
| 838 | major="", minor="") |
| 839 | header_includes += """ |
| 840 | #include <GLES/gl.h> |
| 841 | #include <GLES/glext.h> |
| 842 | #include <GLES2/gl2.h> |
| 843 | #include <GLES2/gl2ext.h> |
| 844 | """ |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 845 | |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 846 | source_includes = template_sources_includes.format("ext", "", "") |
| 847 | source_includes += """ |
| 848 | #include "libANGLE/validationES.h" |
| 849 | #include "libANGLE/validationES1.h" |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 850 | #include "libANGLE/validationES3.h" |
| 851 | #include "libANGLE/validationES31.h" |
| 852 | """ |
| 853 | |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 854 | write_file("ext", "extension", template_entry_point_header, |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 855 | "\n".join([item for item in extension_decls]), "h", header_includes, |
| 856 | "gl.xml and gl_angle_ext.xml") |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 857 | write_file("ext", "extension", template_entry_point_source, |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 858 | "\n".join([item for item in extension_defs]), "cpp", source_includes, |
| 859 | "gl.xml and gl_angle_ext.xml") |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 860 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 861 | write_context_api_decls("1_0", context_gles_header, gles1decls) |
| 862 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 863 | sorted_cmd_names = ["Invalid"] + [cmd[2:] for cmd in sorted(all_cmd_names.get_all_commands())] |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 864 | |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 865 | entry_points_enum = template_entry_points_enum_header.format( |
| 866 | script_name = os.path.basename(sys.argv[0]), |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 867 | data_source_name = "gl.xml and gl_angle_ext.xml", |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 868 | year = date.today().year, |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 869 | entry_points_list = ",\n".join([" " + cmd for cmd in sorted_cmd_names])) |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 870 | |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 871 | entry_points_enum_header_path = path_to("libANGLE", "entry_points_enum_autogen.h") |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 872 | with open(entry_points_enum_header_path, "w") as out: |
| 873 | out.write(entry_points_enum) |
Geoff Lang | cae72d6 | 2017-06-01 11:53:45 -0400 | [diff] [blame] | 874 | out.close() |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 875 | |
| 876 | source_includes = """ |
| 877 | #include "angle_gl.h" |
| 878 | |
| 879 | #include "libGLESv2/entry_points_gles_1_0_autogen.h" |
| 880 | #include "libGLESv2/entry_points_gles_2_0_autogen.h" |
| 881 | #include "libGLESv2/entry_points_gles_3_0_autogen.h" |
| 882 | #include "libGLESv2/entry_points_gles_3_1_autogen.h" |
| 883 | #include "libGLESv2/entry_points_gles_ext_autogen.h" |
| 884 | |
| 885 | #include "common/event_tracer.h" |
| 886 | """ |
| 887 | |
| 888 | write_export_files("\n".join([item for item in libgles_ep_defs]), source_includes, "\n".join([item for item in libgles_ep_exports])) |