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