1#!/usr/bin/python3 2# 3# Copyright 2018 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# registry_xml.py: 8# Parses information from Khronos registry files.. 9 10# List of supported extensions. Add to this list to enable new extensions 11# available in gl.xml. 12 13import difflib 14import os 15import sys 16import xml.etree.ElementTree as etree 17 18from enum import Enum 19 20khronos_xml_inputs = [ 21 '../third_party/EGL-Registry/src/api/egl.xml', 22 '../third_party/OpenCL-Docs/src/xml/cl.xml', 23 '../third_party/OpenGL-Registry/src/xml/gl.xml', 24 '../third_party/OpenGL-Registry/src/xml/glx.xml', 25 '../third_party/OpenGL-Registry/src/xml/wgl.xml', 26] 27 28angle_xml_inputs = [ 29 'gl_angle_ext.xml', 30 'egl_angle_ext.xml', 31 'registry_xml.py', 32] 33 34xml_inputs = sorted(khronos_xml_inputs + angle_xml_inputs) 35 36# Notes on categories of extensions: 37# 'Requestable' extensions are extensions that can be enabled with ANGLE_request_extension 38# 'ES-Only' extensions are always implicitly enabled. 39# 'Toggleable' extensions are like 'Requestable' except they can be also disabled. 40# 'ANGLE' extensions are extensions that are not yet officially upstreamed to Khronos. 41# We document those extensions in gl_angle_ext.xml instead of the canonical gl.xml. 42 43angle_toggleable_extensions = [ 44 "GL_ANGLE_texture_rectangle", 45] 46 47angle_requestable_extensions = [ 48 "GL_ANGLE_base_vertex_base_instance", 49 "GL_ANGLE_base_vertex_base_instance_shader_builtin", 50 "GL_ANGLE_clip_cull_distance", 51 "GL_ANGLE_compressed_texture_etc", 52 "GL_ANGLE_copy_texture_3d", 53 "GL_ANGLE_framebuffer_multisample", 54 "GL_ANGLE_get_image", 55 "GL_ANGLE_get_tex_level_parameter", 56 "GL_ANGLE_logic_op", 57 "GL_ANGLE_lossy_etc_decode", 58 "GL_ANGLE_memory_object_flags", 59 "GL_ANGLE_memory_object_fuchsia", 60 "GL_ANGLE_memory_size", 61 "GL_ANGLE_multi_draw", 62 "GL_ANGLE_multiview_multisample", 63 "GL_ANGLE_polygon_mode", 64 "GL_ANGLE_provoking_vertex", 65 "GL_ANGLE_read_only_depth_stencil_feedback_loops", 66 "GL_ANGLE_renderability_validation", 67 "GL_ANGLE_robust_fragment_shader_output", 68 "GL_ANGLE_semaphore_fuchsia", 69 "GL_ANGLE_shader_pixel_local_storage", 70 "GL_ANGLE_shader_pixel_local_storage_coherent", 71 "GL_ANGLE_stencil_texturing", 72 "GL_ANGLE_texture_compression_dxt3", 73 "GL_ANGLE_texture_compression_dxt5", 74 "GL_ANGLE_texture_external_update", 75 "GL_ANGLE_texture_multisample", 76 "GL_ANGLE_vulkan_image", 77 "GL_ANGLE_yuv_internal_format", 78 "GL_CHROMIUM_color_buffer_float_rgb", 79 "GL_CHROMIUM_color_buffer_float_rgba", 80 "GL_CHROMIUM_lose_context", 81 "GL_CHROMIUM_sync_query", 82 "GL_CHROMIUM_texture_filtering_hint", 83] 84 85gles_requestable_extensions = [ 86 "GL_ANGLE_framebuffer_blit", 87 "GL_ANGLE_instanced_arrays", 88 "GL_ANGLE_pack_reverse_row_order", 89 "GL_ANGLE_texture_usage", 90 "GL_APPLE_clip_distance", 91 "GL_ARB_sync", 92 "GL_ARM_shader_framebuffer_fetch", 93 "GL_EXT_base_instance", 94 "GL_EXT_blend_func_extended", 95 "GL_EXT_blend_minmax", 96 "GL_EXT_buffer_storage", 97 "GL_EXT_clip_control", 98 "GL_EXT_clip_cull_distance", 99 "GL_EXT_color_buffer_float", 100 "GL_EXT_color_buffer_half_float", 101 "GL_EXT_compressed_ETC1_RGB8_sub_texture", 102 "GL_EXT_conservative_depth", 103 "GL_EXT_copy_image", 104 "GL_EXT_depth_clamp", 105 "GL_EXT_disjoint_timer_query", 106 "GL_EXT_draw_buffers", 107 "GL_EXT_draw_buffers_indexed", 108 "GL_EXT_draw_elements_base_vertex", 109 "GL_EXT_EGL_image_array", 110 "GL_EXT_EGL_image_external_wrap_modes", 111 "GL_EXT_EGL_image_storage", 112 "GL_EXT_external_buffer", 113 "GL_EXT_float_blend", 114 "GL_EXT_frag_depth", 115 "GL_EXT_geometry_shader", 116 "GL_EXT_gpu_shader5", 117 "GL_EXT_instanced_arrays", 118 "GL_EXT_map_buffer_range", 119 "GL_EXT_memory_object", 120 "GL_EXT_memory_object_fd", 121 "GL_EXT_multi_draw_indirect", 122 "GL_EXT_multisampled_render_to_texture", 123 "GL_EXT_multisampled_render_to_texture2", 124 "GL_EXT_occlusion_query_boolean", 125 "GL_EXT_polygon_offset_clamp", 126 "GL_EXT_protected_textures", 127 "GL_EXT_pvrtc_sRGB", 128 "GL_EXT_read_format_bgra", 129 "GL_EXT_render_snorm", 130 "GL_EXT_semaphore", 131 "GL_EXT_semaphore_fd", 132 "GL_EXT_separate_shader_objects", 133 "GL_EXT_shader_framebuffer_fetch", 134 "GL_EXT_shader_framebuffer_fetch_non_coherent", 135 "GL_EXT_shader_io_blocks", 136 "GL_EXT_shader_non_constant_global_initializers", 137 "GL_EXT_shader_texture_lod", 138 "GL_EXT_shadow_samplers", 139 "GL_EXT_sRGB", 140 "GL_EXT_tessellation_shader", 141 "GL_EXT_texture_border_clamp", 142 "GL_EXT_texture_buffer", 143 "GL_EXT_texture_compression_astc_decode_mode", 144 "GL_EXT_texture_compression_astc_decode_mode_rgb9e5", 145 "GL_EXT_texture_compression_bptc", 146 "GL_EXT_texture_compression_dxt1", 147 "GL_EXT_texture_compression_rgtc", 148 "GL_EXT_texture_compression_s3tc", 149 "GL_EXT_texture_compression_s3tc_srgb", 150 "GL_EXT_texture_cube_map_array", 151 "GL_EXT_texture_filter_anisotropic", 152 "GL_EXT_texture_filter_minmax", 153 "GL_EXT_texture_format_BGRA8888", 154 "GL_EXT_texture_mirror_clamp_to_edge", 155 "GL_EXT_texture_norm16", 156 "GL_EXT_texture_rg", 157 "GL_EXT_texture_sRGB_R8", 158 "GL_EXT_texture_sRGB_RG8", 159 "GL_EXT_texture_storage", 160 "GL_EXT_texture_type_2_10_10_10_REV", 161 "GL_EXT_unpack_subimage", 162 "GL_EXT_YUV_target", 163 "GL_IMG_texture_compression_pvrtc", 164 "GL_IMG_texture_compression_pvrtc2", 165 "GL_KHR_parallel_shader_compile", 166 "GL_KHR_texture_compression_astc_hdr", 167 "GL_KHR_texture_compression_astc_ldr", 168 "GL_KHR_texture_compression_astc_sliced_3d", 169 "GL_MESA_framebuffer_flip_y", 170 "GL_NV_depth_buffer_float2", 171 "GL_NV_EGL_stream_consumer_external", 172 "GL_NV_framebuffer_blit", 173 "GL_NV_pack_subimage", 174 "GL_NV_pixel_buffer_object", 175 "GL_NV_polygon_mode", 176 "GL_NV_read_depth", 177 "GL_NV_read_depth_stencil", 178 "GL_NV_read_stencil", 179 "GL_NV_shader_noperspective_interpolation", 180 "GL_OES_compressed_EAC_R11_signed_texture", 181 "GL_OES_compressed_EAC_R11_unsigned_texture", 182 "GL_OES_compressed_EAC_RG11_signed_texture", 183 "GL_OES_compressed_EAC_RG11_unsigned_texture", 184 "GL_OES_compressed_ETC1_RGB8_texture", 185 "GL_OES_compressed_ETC2_punchthroughA_RGBA8_texture", 186 "GL_OES_compressed_ETC2_punchthroughA_sRGB8_alpha_texture", 187 "GL_OES_compressed_ETC2_RGB8_texture", 188 "GL_OES_compressed_ETC2_RGBA8_texture", 189 "GL_OES_compressed_ETC2_sRGB8_alpha8_texture", 190 "GL_OES_compressed_ETC2_sRGB8_texture", 191 "GL_OES_compressed_paletted_texture", 192 "GL_OES_copy_image", 193 "GL_OES_depth_texture_cube_map", 194 "GL_OES_draw_buffers_indexed", 195 "GL_OES_draw_elements_base_vertex", 196 "GL_OES_EGL_image", 197 "GL_OES_EGL_image_external", 198 "GL_OES_EGL_image_external_essl3", 199 "GL_OES_element_index_uint", 200 "GL_OES_fbo_render_mipmap", 201 "GL_OES_geometry_shader", 202 "GL_OES_get_program_binary", 203 "GL_OES_mapbuffer", 204 "GL_OES_rgb8_rgba8", 205 "GL_OES_sample_shading", 206 "GL_OES_sample_variables", 207 "GL_OES_shader_image_atomic", 208 "GL_OES_shader_io_blocks", 209 "GL_OES_shader_multisample_interpolation", 210 "GL_OES_standard_derivatives", 211 "GL_OES_texture_3D", 212 "GL_OES_texture_border_clamp", 213 "GL_OES_texture_buffer", 214 "GL_OES_texture_compression_astc", 215 "GL_OES_texture_cube_map_array", 216 "GL_OES_texture_float", 217 "GL_OES_texture_float_linear", 218 "GL_OES_texture_half_float", 219 "GL_OES_texture_half_float_linear", 220 "GL_OES_texture_npot", 221 "GL_OES_texture_stencil8", 222 "GL_OES_texture_storage_multisample_2d_array", 223 "GL_OES_vertex_array_object", 224 "GL_OES_vertex_half_float", 225 "GL_OES_vertex_type_10_10_10_2", 226 "GL_OVR_multiview", 227 "GL_OVR_multiview2", 228 "GL_QCOM_render_shared_exponent", 229 "GL_QCOM_shading_rate", 230 "GL_WEBGL_video_texture", 231] 232 233angle_es_only_extensions = [ 234 "GL_ANGLE_client_arrays", 235 "GL_ANGLE_get_serialized_context_string", 236 "GL_ANGLE_program_binary", 237 "GL_ANGLE_program_cache_control", 238 "GL_ANGLE_relaxed_vertex_attribute_type", 239 "GL_ANGLE_request_extension", 240 "GL_ANGLE_rgbx_internal_format", 241 "GL_ANGLE_robust_client_memory", 242 "GL_ANGLE_robust_resource_initialization", 243 "GL_ANGLE_shader_binary", 244 "GL_ANGLE_webgl_compatibility", 245 "GL_CHROMIUM_bind_generates_resource", 246 "GL_CHROMIUM_bind_uniform_location", 247 "GL_CHROMIUM_copy_compressed_texture", 248 "GL_CHROMIUM_copy_texture", 249 "GL_CHROMIUM_framebuffer_mixed_samples", 250] 251 252gles_es_only_extensions = [ 253 "GL_AMD_performance_monitor", 254 "GL_ANDROID_extension_pack_es31a", 255 "GL_ANGLE_depth_texture", 256 "GL_ANGLE_translated_shader_source", 257 "GL_EXT_debug_label", 258 "GL_EXT_debug_marker", 259 "GL_EXT_discard_framebuffer", 260 "GL_EXT_multisample_compatibility", 261 "GL_EXT_primitive_bounding_box", 262 "GL_EXT_robustness", 263 "GL_EXT_sRGB_write_control", 264 "GL_EXT_texture_format_sRGB_override", 265 "GL_EXT_texture_sRGB_decode", 266 "GL_KHR_blend_equation_advanced", 267 "GL_KHR_debug", 268 "GL_KHR_no_error", 269 "GL_KHR_robust_buffer_access_behavior", 270 "GL_NV_fence", 271 "GL_NV_robustness_video_memory_purge", 272 "GL_OES_depth24", 273 "GL_OES_depth32", 274 "GL_OES_depth_texture", 275 "GL_OES_EGL_sync", 276 "GL_OES_packed_depth_stencil", 277 "GL_OES_primitive_bounding_box", 278 "GL_OES_surfaceless_context", 279] 280 281# ES1 (Possibly the min set of extensions needed by Android) 282gles1_extensions = [ 283 "GL_OES_draw_texture", 284 "GL_OES_framebuffer_object", 285 "GL_OES_matrix_palette", 286 "GL_OES_point_size_array", 287 "GL_OES_point_sprite", 288 "GL_OES_query_matrix", 289 "GL_OES_texture_cube_map", 290] 291 292 293def check_sorted(name, l): 294 unidiff = difflib.unified_diff(l, sorted(l, key=str.casefold), 'unsorted', 'sorted') 295 diff_lines = list(unidiff) 296 assert not diff_lines, '\n\nPlease sort "%s":\n%s' % (name, '\n'.join(diff_lines)) 297 298 299angle_extensions = angle_requestable_extensions + angle_es_only_extensions + angle_toggleable_extensions 300gles_extensions = gles_requestable_extensions + gles_es_only_extensions 301supported_extensions = sorted(angle_extensions + gles1_extensions + gles_extensions) 302 303assert len(supported_extensions) == len(set(supported_extensions)), 'Duplicates in extension list' 304check_sorted('angle_requestable_extensions', angle_requestable_extensions) 305check_sorted('angle_es_only_extensions', angle_es_only_extensions) 306check_sorted('angle_toggleable_extensions', angle_toggleable_extensions) 307check_sorted('gles_requestable_extensions', gles_requestable_extensions) 308check_sorted('gles_es_only_extensions', gles_es_only_extensions) 309check_sorted('gles_extensions', gles1_extensions) 310 311supported_egl_extensions = [ 312 "EGL_ANDROID_blob_cache", 313 "EGL_ANDROID_create_native_client_buffer", 314 "EGL_ANDROID_framebuffer_target", 315 "EGL_ANDROID_get_frame_timestamps", 316 "EGL_ANDROID_get_native_client_buffer", 317 "EGL_ANDROID_native_fence_sync", 318 "EGL_ANDROID_presentation_time", 319 "EGL_ANGLE_create_surface_swap_interval", 320 "EGL_ANGLE_d3d_share_handle_client_buffer", 321 "EGL_ANGLE_device_creation", 322 "EGL_ANGLE_device_d3d", 323 "EGL_ANGLE_display_semaphore_share_group", 324 "EGL_ANGLE_display_texture_share_group", 325 "EGL_ANGLE_external_context_and_surface", 326 "EGL_ANGLE_feature_control", 327 "EGL_ANGLE_ggp_stream_descriptor", 328 "EGL_ANGLE_metal_create_context_ownership_identity", 329 "EGL_ANGLE_metal_shared_event_sync", 330 "EGL_ANGLE_power_preference", 331 "EGL_ANGLE_prepare_swap_buffers", 332 "EGL_ANGLE_program_cache_control", 333 "EGL_ANGLE_query_surface_pointer", 334 "EGL_ANGLE_stream_producer_d3d_texture", 335 "EGL_ANGLE_surface_d3d_texture_2d_share_handle", 336 "EGL_ANGLE_swap_with_frame_token", 337 "EGL_ANGLE_sync_control_rate", 338 "EGL_ANGLE_vulkan_image", 339 "EGL_ANGLE_wait_until_work_scheduled", 340 "EGL_ANGLE_window_fixed_size", 341 "EGL_CHROMIUM_sync_control", 342 "EGL_EXT_create_context_robustness", 343 "EGL_EXT_device_query", 344 "EGL_EXT_gl_colorspace_display_p3", 345 "EGL_EXT_gl_colorspace_display_p3_linear", 346 "EGL_EXT_gl_colorspace_display_p3_passthrough", 347 "EGL_EXT_gl_colorspace_scrgb", 348 "EGL_EXT_gl_colorspace_scrgb_linear", 349 "EGL_EXT_image_dma_buf_import", 350 "EGL_EXT_image_dma_buf_import_modifiers", 351 "EGL_EXT_image_gl_colorspace", 352 "EGL_EXT_pixel_format_float", 353 "EGL_EXT_platform_base", 354 "EGL_EXT_platform_device", 355 "EGL_EXT_protected_content", 356 "EGL_IMG_context_priority", 357 "EGL_KHR_debug", 358 "EGL_KHR_fence_sync", 359 "EGL_KHR_gl_colorspace", 360 "EGL_KHR_image", 361 "EGL_KHR_lock_surface3", 362 "EGL_KHR_mutable_render_buffer", 363 "EGL_KHR_no_config_context", 364 "EGL_KHR_partial_update", 365 "EGL_KHR_reusable_sync", 366 "EGL_KHR_stream", 367 "EGL_KHR_stream_consumer_gltexture", 368 "EGL_KHR_surfaceless_context", 369 "EGL_KHR_swap_buffers_with_damage", 370 "EGL_KHR_wait_sync", 371 "EGL_NV_post_sub_buffer", 372 "EGL_NV_stream_consumer_gltexture_yuv", 373] 374 375check_sorted('supported_egl_extensions', supported_egl_extensions) 376 377supported_cl_extensions = [ 378 # Since OpenCL 1.1 379 "cl_khr_byte_addressable_store", 380 "cl_khr_global_int32_base_atomics", 381 "cl_khr_global_int32_extended_atomics", 382 "cl_khr_local_int32_base_atomics", 383 "cl_khr_local_int32_extended_atomics", 384 385 # OpenCL 2.0 - 2.2 386 "cl_khr_3d_image_writes", 387 "cl_khr_depth_images", 388 "cl_khr_image2d_from_buffer", 389 390 # Optional 391 "cl_khr_extended_versioning", 392 "cl_khr_fp64", 393 "cl_khr_icd", 394 "cl_khr_int64_base_atomics", 395 "cl_khr_int64_extended_atomics", 396] 397 398# Strip these suffixes from Context entry point names. NV is excluded (for now). 399strip_suffixes = ["AMD", "ANDROID", "ANGLE", "CHROMIUM", "EXT", "KHR", "OES", "OVR", "QCOM"] 400check_sorted('strip_suffixes', strip_suffixes) 401 402# The EGL_ANGLE_explicit_context extension is generated differently from other extensions. 403# Toggle generation here. 404support_EGL_ANGLE_explicit_context = True 405 406# Group names that appear in command/param, but not present in groups/group 407unsupported_enum_group_names = { 408 'GetMultisamplePNameNV', 409 'BufferPNameARB', 410 'BufferPointerNameARB', 411 'VertexAttribPointerPropertyARB', 412 'VertexAttribPropertyARB', 413 'FenceParameterNameNV', 414 'FenceConditionNV', 415 'BufferPointerNameARB', 416 'MatrixIndexPointerTypeARB', 417 'PointParameterNameARB', 418 'ClampColorTargetARB', 419 'ClampColorModeARB', 420} 421 422# Versions (major, minor). Note that GLES intentionally places 1.0 last. 423DESKTOP_GL_VERSIONS = [(1, 0), (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (2, 0), (2, 1), (3, 0), 424 (3, 1), (3, 2), (3, 3), (4, 0), (4, 1), (4, 2), (4, 3), (4, 4), (4, 5), 425 (4, 6)] 426GLES_VERSIONS = [(2, 0), (3, 0), (3, 1), (3, 2), (1, 0)] 427EGL_VERSIONS = [(1, 0), (1, 1), (1, 2), (1, 3), (1, 4), (1, 5)] 428WGL_VERSIONS = [(1, 0)] 429GLX_VERSIONS = [(1, 0), (1, 1), (1, 2), (1, 3), (1, 4)] 430CL_VERSIONS = [(1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2), (3, 0)] 431 432 433# API types 434class apis: 435 GL = 'GL' 436 GLES = 'GLES' 437 WGL = 'WGL' 438 GLX = 'GLX' 439 EGL = 'EGL' 440 CL = 'CL' 441 442# For GLenum types 443api_enums = {apis.GL: 'BigGLEnum', apis.GLES: 'GLESEnum'} 444default_enum_group_name = 'AllEnums' 445 446 447def script_relative(path): 448 return os.path.join(os.path.dirname(sys.argv[0]), path) 449 450 451def path_to(folder, file): 452 return os.path.join(script_relative(".."), "src", folder, file) 453 454 455def strip_api_prefix(cmd_name): 456 return cmd_name.lstrip("cwegl") 457 458 459def find_xml_input(xml_file): 460 for found_xml in xml_inputs: 461 if found_xml == xml_file or found_xml.endswith('/' + xml_file): 462 return found_xml 463 raise Exception('Could not find XML input: ' + xml_file) 464 465 466def get_cmd_name(command_node): 467 proto = command_node.find('proto') 468 cmd_name = proto.find('name').text 469 return cmd_name 470 471 472class CommandNames: 473 474 def __init__(self): 475 self.command_names = {} 476 477 def get_commands(self, version): 478 return self.command_names[version] 479 480 def get_all_commands(self): 481 cmd_names = [] 482 # Combine all the version lists into a single list 483 for version, version_cmd_names in sorted(self.command_names.items()): 484 cmd_names += version_cmd_names 485 486 return cmd_names 487 488 def add_commands(self, version, commands): 489 # Add key if it doesn't exist 490 if version not in self.command_names: 491 self.command_names[version] = [] 492 # Add the commands that aren't duplicates 493 self.command_names[version] += commands 494 495 496class RegistryXML: 497 498 def __init__(self, xml_file, ext_file=None): 499 tree = etree.parse(script_relative(find_xml_input(xml_file))) 500 self.root = tree.getroot() 501 if (ext_file): 502 self._AppendANGLEExts(find_xml_input(ext_file)) 503 self.all_commands = self.root.findall('commands/command') 504 self.all_cmd_names = CommandNames() 505 self.commands = {} 506 507 def _AppendANGLEExts(self, ext_file): 508 angle_ext_tree = etree.parse(script_relative(ext_file)) 509 angle_ext_root = angle_ext_tree.getroot() 510 511 insertion_point = self.root.findall("./commands")[0] 512 for command in angle_ext_root.iter('commands'): 513 insertion_point.extend(command) 514 515 insertion_point = self.root.findall("./extensions")[0] 516 for extension in angle_ext_root.iter('extensions'): 517 insertion_point.extend(extension) 518 519 insertion_point = self.root 520 for enums in angle_ext_root.iter('enums'): 521 insertion_point.append(enums) 522 523 def AddCommands(self, feature_name, annotation): 524 xpath = ".//feature[@name='%s']//command" % feature_name 525 commands = [cmd.attrib['name'] for cmd in self.root.findall(xpath)] 526 527 # Remove commands that have already been processed 528 current_cmds = self.all_cmd_names.get_all_commands() 529 commands = [cmd for cmd in commands if cmd not in current_cmds] 530 531 self.all_cmd_names.add_commands(annotation, commands) 532 self.commands[annotation] = commands 533 534 def _ClassifySupport(self, extension): 535 supported = extension.attrib['supported'] 536 # Desktop GL extensions exposed in ANGLE GLES for Chrome. 537 if extension.attrib['name'] in ['GL_ARB_sync', 'GL_NV_robustness_video_memory_purge']: 538 supported += "|gles2" 539 if 'gles2' in supported: 540 return 'gl2ext' 541 elif 'gles1' in supported: 542 return 'glext' 543 elif 'egl' in supported: 544 return 'eglext' 545 elif 'wgl' in supported: 546 return 'wglext' 547 elif 'glx' in supported: 548 return 'glxext' 549 elif 'cl' in supported: 550 return 'clext' 551 else: 552 assert False, 'Cannot classify support for %s: %s' % (extension.attrib['name'], 553 supported) 554 return 'unknown' 555 556 def AddExtensionCommands(self, supported_extensions, apis): 557 # Use a first step to run through the extensions so we can generate them 558 # in sorted order. 559 self.ext_data = {} 560 self.ext_dupes = {} 561 ext_annotations = {} 562 563 for extension in self.root.findall("extensions/extension"): 564 extension_name = extension.attrib['name'] 565 if not extension_name in supported_extensions: 566 continue 567 568 ext_annotations[extension_name] = self._ClassifySupport(extension) 569 570 ext_cmd_names = [] 571 572 # There's an extra step here to filter out 'api=gl' extensions. This 573 # is necessary for handling KHR extensions, which have separate entry 574 # point signatures (without the suffix) for desktop GL. Note that this 575 # extra step is necessary because of Etree's limited Xpath support. 576 for require in extension.findall('require'): 577 if 'api' in require.attrib and require.attrib['api'] not in apis: 578 continue 579 580 # A special case for EXT_texture_storage 581 filter_out_comment = "Supported only if GL_EXT_direct_state_access is supported" 582 if 'comment' in require.attrib and require.attrib['comment'] == filter_out_comment: 583 continue 584 585 extension_commands = require.findall('command') 586 ext_cmd_names += [command.attrib['name'] for command in extension_commands] 587 588 self.ext_data[extension_name] = sorted(ext_cmd_names) 589 590 for extension_name, ext_cmd_names in sorted(self.ext_data.items()): 591 592 # Detect and filter duplicate extensions. 593 dupes = [] 594 for ext_cmd in ext_cmd_names: 595 if ext_cmd in self.all_cmd_names.get_all_commands(): 596 dupes.append(ext_cmd) 597 598 for dupe in dupes: 599 ext_cmd_names.remove(dupe) 600 601 self.ext_data[extension_name] = sorted(ext_cmd_names) 602 self.ext_dupes[extension_name] = dupes 603 self.all_cmd_names.add_commands(ext_annotations[extension_name], ext_cmd_names) 604 605 def GetEnums(self, override_prefix=None): 606 cmd_names = [] 607 for cmd in self.all_cmd_names.get_all_commands(): 608 stripped = strip_api_prefix(cmd) 609 prefix = override_prefix or cmd[:(len(cmd) - len(stripped))] 610 cmd_names.append( 611 ('%s%s' % (prefix.upper(), stripped), '%s%s' % (prefix.lower(), stripped))) 612 return cmd_names 613 614 615class EntryPoints: 616 617 def __init__(self, api, xml, commands): 618 self.api = api 619 self._cmd_info = [] 620 621 for command_node in xml.all_commands: 622 cmd_name = get_cmd_name(command_node) 623 624 if api == apis.WGL: 625 cmd_name = cmd_name if cmd_name.startswith('wgl') else 'wgl' + cmd_name 626 627 if cmd_name not in commands: 628 continue 629 630 param_text = ["".join(param.itertext()) for param in command_node.findall('param')] 631 632 # Treat (void) as () 633 if len(param_text) == 1 and param_text[0].strip() == 'void': 634 param_text = [] 635 636 proto = command_node.find('proto') 637 proto_text = "".join(proto.itertext()) 638 639 self._cmd_info.append((cmd_name, command_node, param_text, proto_text)) 640 641 def get_infos(self): 642 return self._cmd_info 643 644 645def GetEGL(): 646 egl = RegistryXML('egl.xml', 'egl_angle_ext.xml') 647 for major_version, minor_version in EGL_VERSIONS: 648 version = "%d_%d" % (major_version, minor_version) 649 name_prefix = "EGL_VERSION_" 650 feature_name = "%s%s" % (name_prefix, version) 651 egl.AddCommands(feature_name, version) 652 egl.AddExtensionCommands(supported_egl_extensions, ['egl']) 653 return egl 654 655 656def GetGLES(): 657 gles = RegistryXML('gl.xml', 'gl_angle_ext.xml') 658 for major_version, minor_version in GLES_VERSIONS: 659 version = "{}_{}".format(major_version, minor_version) 660 name_prefix = "GL_ES_VERSION_" 661 if major_version == 1: 662 name_prefix = "GL_VERSION_ES_CM_" 663 feature_name = "{}{}".format(name_prefix, version) 664 gles.AddCommands(feature_name, version) 665 gles.AddExtensionCommands(supported_extensions, ['gles2', 'gles1']) 666 return gles 667