3 # (C) Copyright Zack Rusin 2005. All Rights Reserved.
4 # Copyright (C) 2015 Intel Corporation
5 # Copyright (C) 2015 Broadcom Corporation
7 # Permission is hereby granted, free of charge, to any person obtaining a
8 # copy of this software and associated documentation files (the "Software"),
9 # to deal in the Software without restriction, including without limitation
10 # on the rights to use, copy, modify, merge, publish, distribute, sub
11 # license, and/or sell copies of the Software, and to permit persons to whom
12 # the Software is furnished to do so, subject to the following conditions:
14 # The above copyright notice and this permission notice (including the next
15 # paragraph) shall be included in all copies or substantial portions of the
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 # IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 # Zack Rusin <zack@kde.org>
33 import xml
.etree
.ElementTree
as ET
37 class PrintGlEnums(gl_XML
.gl_print_base
):
40 gl_XML
.gl_print_base
.__init
__(self
)
42 self
.name
= "gl_enums.py (from Mesa)"
43 self
.license
= license
.bsd_license_template
% ( \
44 """Copyright (C) 1999-2005 Brian Paul All Rights Reserved.""", "BRIAN PAUL")
45 # Mapping from enum value to (name, priority) tuples.
47 # Mapping from enum name to value
48 self
.string_to_int
= {}
51 def printRealHeader(self
):
52 print '#include "main/glheader.h"'
53 print '#include "main/enums.h"'
54 print '#include "main/imports.h"'
55 print '#include "main/mtypes.h"'
57 print 'typedef struct PACKED {'
58 print ' uint16_t offset;'
66 typedef int (*cfunc)(const void *, const void *);
69 * Compare a key enum value to an element in the \c enum_string_table_offsets array.
71 * \c bsearch always passes the key as the first parameter and the pointer
72 * to the array element as the second parameter. We can elimiate some
73 * extra work by taking advantage of that fact.
75 * \param a Pointer to the desired enum name.
76 * \param b Pointer into the \c enum_string_table_offsets array.
78 static int compar_nr( const int *a, enum_elt *b )
84 static char token_tmp[20];
86 const char *_mesa_enum_to_string( int nr )
90 STATIC_ASSERT(sizeof(enum_string_table) < (1 << 16));
92 elt = bsearch(& nr, enum_string_table_offsets,
93 ARRAY_SIZE(enum_string_table_offsets),
94 sizeof(enum_string_table_offsets[0]),
98 return &enum_string_table[elt->offset];
101 /* this is not re-entrant safe, no big deal here */
102 _mesa_snprintf(token_tmp, sizeof(token_tmp) - 1, "0x%x", nr);
103 token_tmp[sizeof(token_tmp) - 1] = '\\0';
111 static const char *prim_names[PRIM_MAX+3] = {
122 "GL_LINES_ADJACENCY",
123 "GL_LINE_STRIP_ADJACENCY",
124 "GL_TRIANGLES_ADJACENCY",
125 "GL_TRIANGLE_STRIP_ADJACENCY",
132 /* Get the name of an enum given that it is a primitive type. Avoids
133 * GL_FALSE/GL_POINTS ambiguity and others.
136 _mesa_lookup_prim_by_nr(GLuint nr)
138 if (nr < ARRAY_SIZE(prim_names))
139 return prim_names[nr];
141 return "invalid mode";
149 def printBody(self
, xml
):
150 self
.process_enums(xml
)
152 sorted_enum_values
= sorted(self
.enum_table
.keys())
155 print '#if defined(__GNUC__)'
156 print '# define LONGSTRING __extension__'
158 print '# define LONGSTRING'
161 print 'LONGSTRING static const char enum_string_table[] = '
162 for enum
in sorted_enum_values
:
163 (name
, pri
) = self
.enum_table
[enum
]
164 print ' "%s\\0"' % (name
)
165 string_offsets
[ enum
] = i
172 print 'static const enum_elt enum_string_table_offsets[%u] =' % (len(self
.enum_table
))
174 for enum
in sorted_enum_values
:
175 (name
, pri
) = self
.enum_table
[enum
]
176 print ' { %5u, 0x%08X }, /* %s */' % (string_offsets
[enum
], enum
, name
)
183 def add_enum_provider(self
, name
, priority
):
184 # Skip some enums, to reduce the diffs from this commit.
185 if name
in ['GL_NEXT_BUFFER_NV',
186 # Mesa was choosing GL_LINES for this, which wasn't great.
188 # Old names for things where Mesa was using the new names.
189 'GL_VERTEX_PROGRAM_POINT_SIZE',
190 'GL_MAX_VARYING_FLOATS',
197 'GL_MAX_CLIP_PLANES',
198 'GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS',
200 'GL_CURRENT_FOG_COORDINATE',
201 'GL_COMPARE_R_TO_TEXTURE',
202 # GL 2.0 name when Mesa was using GLES 1.0.
203 'GL_BLEND_EQUATION_RGB',
204 # GL3.x compat names that Mesa was missing.
206 'GL_LUMINANCE_SNORM',
207 'GL_LUMINANCE_ALPHA_SNORM',
208 'GL_INTENSITY_SNORM',
210 'GL_LUMINANCE8_SNORM',
211 'GL_LUMINANCE8_ALPHA8_SNORM',
212 'GL_INTENSITY8_SNORM',
214 'GL_LUMINANCE16_SNORM',
215 'GL_LUMINANCE16_ALPHA16_SNORM',
216 'GL_INTENSITY16_SNORM',
217 # ARB_imaging names that Mesa was missing.
218 'GL_COLOR_INDEX1_EXT',
219 'GL_COLOR_INDEX2_EXT',
220 'GL_COLOR_INDEX4_EXT',
221 'GL_COLOR_INDEX8_EXT',
222 'GL_COLOR_INDEX12_EXT',
223 'GL_COLOR_INDEX16_EXT',
224 'GL_CONSTANT_BORDER',
225 'GL_REPLICATE_BORDER',
226 'GL_TABLE_TOO_LARGE',
227 # ARB_texture_view names that Mesa was missing.
228 'GL_TEXTURE_VIEW_MIN_LEVEL',
229 'GL_TEXTURE_VIEW_NUM_LEVELS',
230 'GL_TEXTURE_VIEW_MIN_LAYER',
231 'GL_TEXTURE_VIEW_NUM_LAYERS',
232 # GL4.2 BPTC names that Mesa was missing.
233 'GL_COMPRESSED_RGBA_BPTC_UNORM',
234 'GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM',
235 'GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT',
236 'GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT',
237 # Mesa was choosing the EXT names for these
240 'GL_PROGRAM_SEPARABLE',
241 'GL_PROGRAM_PIPELINE_BINDING',
242 'GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS',
243 # Mesa was choosing the ARB names for these instead of core.
244 'GL_TEXTURE_CUBE_MAP_ARRAY',
245 'GL_TEXTURE_BINDING_CUBE_MAP_ARRAY',
246 'GL_PROXY_TEXTURE_CUBE_MAP_ARRAY',
247 'GL_SAMPLER_CUBE_MAP_ARRAY',
248 'GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW',
249 'GL_INT_SAMPLER_CUBE_MAP_ARRAY',
250 'GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY',
251 'GL_TRANSFORM_FEEDBACK_PAUSED',
252 'GL_TRANSFORM_FEEDBACK_ACTIVE',
253 'GL_VERTEX_ATTRIB_ARRAY_DIVISOR',
254 # Mesa was choosing the ANGLE names for these
256 'GL_COMPRESSED_RGBA_S3TC_DXT3_EXT',
257 'GL_COMPRESSED_RGBA_S3TC_DXT5_EXT',
261 # Mesa didn't know about the second half of this set of enums.
262 m
= re
.match('GL_COLOR_ATTACHMENT([0-9]*)', name
)
263 if m
and int(m
.group(1)) >= 16:
266 value
= self
.string_to_int
[name
]
268 # We don't want the weird GL_SKIP_COMPONENTS1_NV enums.
271 # We don't want the 64-bit GL_TIMEOUT_IGNORED "enums"
272 if value
> 0xffffffff:
275 if name
.endswith('_BIT'):
278 if value
in self
.enum_table
:
279 (n
, p
) = self
.enum_table
[value
]
281 self
.enum_table
[value
] = (name
, priority
)
283 self
.enum_table
[value
] = (name
, priority
)
285 def process_extension(self
, extension
):
286 # Skip some of the extensions, to reduce the diffs from this commit.
287 extension_name
= extension
.get('name')
288 whitelist
= ['GL_ANGLE_texture_compression_dxt3',
289 'GL_ANGLE_texture_compression_dxt5',
290 'GL_APPLE_flush_buffer_range',
291 'GL_APPLE_object_purgeable',
292 'GL_APPLE_texture_range',
293 'GL_SGIS_texture_color_mask',
295 'GL_SGIX_texture_coordinate_clamp',
296 'GL_SGIX_fog_offset',
297 'GL_SGIX_texture_scale_bias',
298 'GL_SGIX_texture_lod_bias',
300 'GL_APPLE_ycbcr_422']
301 whitelist_only_prefixes
= ['GL_APPLE',
321 for prefix
in whitelist_only_prefixes
:
322 if extension_name
.startswith(prefix
):
323 if extension_name
not in whitelist
:
326 if extension_name
in ['GL_ATI_element_array',
328 'GL_ATI_text_fragment_shader',
329 'GL_ATI_pixel_format_float',
330 'GL_ATI_pn_triangles',
331 'GL_ATI_vertex_array_object',
332 'GL_ATI_vertex_streams',
333 'GL_AMD_blend_minmax_factor',
334 'GL_AMD_compressed_3DC_texture',
335 'GL_AMD_compressed_ATC_texture',
336 'GL_AMD_debug_output',
337 'GL_AMD_depth_clamp_separate',
338 'GL_AMD_gpu_shader_int64',
339 'GL_AMD_query_buffer_object',
340 'GL_AMD_interleaved_elements',
341 'GL_AMD_name_gen_delete',
342 'GL_AMD_occlusion_query_event',
343 'GL_AMD_program_binary_Z400',
344 'GL_AMD_sample_positions',
345 'GL_AMD_sparse_texture',
346 'GL_AMD_stencil_operation_extended',
347 'GL_AMD_transform_feedback4',
348 'GL_AMD_vertex_shader_tessellator',
349 'GL_ARB_bindless_texture',
351 'GL_ARB_compute_variable_group_size',
352 'GL_ARB_cull_distance',
353 'GL_ARB_enhanced_layouts',
354 'GL_ARB_indirect_parameters',
355 'GL_ARB_internalformat_query2',
356 'GL_ARB_query_buffer_object',
357 'GL_ARB_shading_language_include',
358 'GL_ARB_sparse_buffer',
359 'GL_ARB_sparse_texture',
360 'GL_ARB_texture_compression_bptc',
361 'GL_ARB_texture_mirror_clamp_to_edge',
362 'GL_ARB_texture_view',
363 'GL_ARB_transform_feedback_overflow_query',
365 'GL_EXT_bindable_uniform',
367 'GL_EXT_coordinate_frame',
368 'GL_EXT_debug_label',
369 'GL_EXT_direct_state_access',
370 'GL_EXT_disjoint_timer_query',
371 'GL_EXT_geometry_shader',
372 'GL_EXT_light_texture',
374 'GL_EXT_tessellation_shader',
375 'GL_EXT_texture_compression_latc',
376 'GL_EXT_texture_filter_minmax',
377 'GL_EXT_texture_sRGB_R8',
378 'GL_EXT_texture_sRGB_RG8',
379 'GL_EXT_framebuffer_multisample_blit_scaled',
380 'GL_EXT_multisample',
381 'GL_EXT_multisampled_render_to_texture',
382 'GL_EXT_multiview_draw_buffers',
383 'GL_EXT_pixel_transform',
384 'GL_EXT_primitive_bounding_box',
386 'GL_EXT_raster_multisample',
387 'GL_EXT_shader_framebuffer_fetch',
388 'GL_EXT_shader_pixel_local_storage',
389 'GL_EXT_sparse_texture',
390 'GL_EXT_stencil_clear_tag',
391 'GL_EXT_tesselation_shader',
392 'GL_EXT_texture_perturb_normal',
393 'GL_EXT_texture_sRGB',
394 'GL_EXT_texture_storage',
395 'GL_EXT_texture_view',
396 'GL_EXT_vertex_shader',
397 'GL_EXT_vertex_weighting',
398 'GL_EXT_x11_sync_object',
400 'GL_IBM_cull_vertex',
401 'GL_IBM_static_data',
402 'GL_IBM_vertex_array_lists',
403 'GL_INTEL_map_texture',
404 'GL_INTEL_parallel_arrays',
405 'GL_HP_image_transform',
406 'GL_HP_texture_lighting',
407 'GL_KHR_blend_equation_advanced',
408 'GL_KHR_blend_equation_advanced_coherent',
410 'GL_NV_blend_equation_advanced',
411 'GL_NV_blend_equation_advanced_coherent',
412 'GL_NV_command_list',
413 'GL_NV_compute_program5',
414 'GL_NV_conservative_raster',
415 'GL_NV_coverage_sample',
416 'GL_NV_deep_texture3D',
417 'GL_NV_depth_buffer_float',
418 'GL_NV_depth_nonlinear',
420 'GL_NV_explicit_multisample',
422 'GL_NV_fill_rectangle',
423 'GL_NV_float_buffer',
424 'GL_NV_fragment_coverage_to_color',
425 'GL_NV_framebuffer_mixed_samples',
426 'GL_NV_framebuffer_multisample_coverage',
427 'GL_NV_geometry_program4',
428 'GL_NV_gpu_program4',
429 'GL_NV_gpu_program5',
431 'GL_NV_internalformat_sample_query',
432 'GL_NV_multisample_coverage',
433 'GL_NV_parameter_buffer_object',
434 'GL_NV_path_rendering',
435 'GL_NV_path_rendering_shared_edge',
436 'GL_NV_pixel_data_range',
437 'GL_NV_present_video',
438 'GL_NV_register_combiners',
439 'GL_NV_register_combiners2',
440 'GL_NV_sample_locations',
441 'GL_NV_shader_buffer_load',
442 'GL_NV_shader_image_load_store',
443 'GL_NV_shader_thread_group',
444 'GL_NV_sRGB_formats',
445 'GL_NV_tessellation_program5',
446 'GL_NV_texgen_emboss',
447 'GL_NV_texture_multisample',
448 'GL_NV_texture_shader',
449 'GL_NV_texture_shader2',
450 'GL_NV_texture_shader3',
451 'GL_NV_transform_feedback',
452 'GL_NV_uniform_buffer_unified_memory',
453 'GL_NV_vertex_array_range',
454 'GL_NV_vertex_array_range2',
455 'GL_NV_vertex_attrib_integer_64bit',
456 'GL_NV_vertex_buffer_unified_memory',
457 'GL_NV_video_capture',
458 'GL_OES_geometry_shader',
459 'GL_OES_primitive_bounding_box',
460 'GL_OES_tessellation_shader',
461 'GL_OES_texture_compression_astc',
462 'GL_OES_texture_view',
463 'GL_SGI_color_table',
464 'GL_SUN_global_alpha',
465 'GL_SUN_triangle_list',
466 'GL_SUNX_constant_data',
468 'GL_EXT_index_array_formats',
469 'GL_EXT_index_material']:
472 if extension
.get('name').startswith('GL_ARB_'):
474 elif extension
.get('name').startswith('GL_EXT_'):
479 for enum
in extension
.findall('require/enum'):
480 self
.add_enum_provider(enum
.get('name'), extension_prio
)
482 # Part of 4.4, but Mesa added it early.
483 self
.add_enum_provider('GL_MAX_VERTEX_ATTRIB_STRIDE', 44)
485 def process_enums(self
, xml
):
486 # First, process the XML entries that define the hex values
487 # for all of the enum names.
488 for enum
in xml
.findall('enums/enum'):
489 name
= enum
.get('name')
490 value
= int(enum
.get('value'), base
=16)
492 if name
== 'GL_ALL_ATTRIB_BITS':
493 # Khronos XML defines this one as 0xffffffff, but Mesa
494 # has always had the original definition of
498 # If the same name ever maps to multiple values, that can
499 # confuse us. GL_ACTIVE_PROGRAM_EXT is OK to lose because
500 # we choose GL_ACTIVE PROGRAM instead.
501 if name
in self
.string_to_int
and name
!= "GL_ACTIVE_PROGRAM_EXT":
502 print "#error Renumbering {0} from {1} to {2}".format(name
, self
.string_to_int
[name
], value
)
504 self
.string_to_int
[name
] = value
506 # Now, process all of the API versions and extensions that
507 # provide enums, so we can decide what name to call any hex
509 for feature
in xml
.findall('feature'):
510 feature_name
= feature
.get('name')
511 # Skip some of the extensions, to reduce the diffs from this commit.
512 if feature_name
in ['GL_VERSION_4_3',
515 'GL_ES_VERSION_3_1']:
518 # Give priority to the older versions of various symbol
519 # names, since Mesa tended to have the older ones.
520 m
= re
.match('GL_VERSION_([0-9])_([0-9])', feature_name
)
522 feature_prio
= int(m
.group(1) + m
.group(2))
524 m
= re
.match('GL_ES_VERSION_([0-9])_([0-9])', feature_name
)
526 feature_prio
= int(m
.group(1) + m
.group(2))
530 for enum
in feature
.findall('require/enum'):
531 self
.add_enum_provider(enum
.get('name'), feature_prio
)
533 for extension
in xml
.findall('extensions/extension'):
534 self
.process_extension(extension
)
538 parser
= argparse
.ArgumentParser()
539 parser
.add_argument('-f', '--input_file',
541 help="Choose an xml file to parse.")
542 return parser
.parse_args()
547 xml
= ET
.parse(args
.input_file
)
549 printer
= PrintGlEnums()
553 if __name__
== '__main__':