Browse code

Add vendors

Robert Cranston authored on 11/01/2023 14:29:12
Showing 2 changed files

... ...
@@ -13,6 +13,12 @@ appropriate each line is in a widely supported format, usable with e.g.
13 13
 -q`][]` <(glregistry audit)`) and [GNU Emacs][]' [Compilation Mode][] ([`M-x
14 14
 compile`][]` glregistry audit`).
15 15
 
16
+The vendors `KHR` (Khronos), `ARB` (Architecture Review Board), and `EXT`
17
+(Extension) are treated specially and are sorted before other vendors. When
18
+querying for enums, either directly or indirectly, enums with the same name,
19
+except for one of these vendors added as a suffix, and the same value is
20
+matched as well.
21
+
16 22
 Note that only the OpenGL (not OpenGL ES) API, and only the core (not
17 23
 compatibility) [profile][] is considered.
18 24
 
... ...
@@ -52,7 +58,9 @@ Usage:
52 58
   glregistry exts
53 59
   glregistry exts-download
54 60
   glregistry exts-all       <name>
61
+  glregistry vendors
55 62
   glregistry type           <type>
63
+  glregistry aliases        <enum>
56 64
   glregistry value          <enum>
57 65
   glregistry enum           <value>
58 66
   glregistry supports       <name>
... ...
@@ -83,8 +91,12 @@ Commands:
83 91
     Download all extension specs.
84 92
   exts-all <name>
85 93
     Print all downloaded extensions that mention <name>.
94
+  vendors
95
+    Print all vendor abbreviations.
86 96
   type <type>
87 97
     Print the definition of <type>.
98
+  aliases <enum>
99
+    Print the KHR, ARB, and EXT aliases of <enum>.
88 100
   value <enum>
89 101
     Print the value of <enum>.
90 102
   enum <value>
... ...
@@ -15,7 +15,9 @@ Usage:
15 15
   glregistry exts
16 16
   glregistry exts-download
17 17
   glregistry exts-all       <name>
18
+  glregistry vendors
18 19
   glregistry type           <type>
20
+  glregistry aliases        <enum>
19 21
   glregistry value          <enum>
20 22
   glregistry enum           <value>
21 23
   glregistry supports       <name>
... ...
@@ -46,8 +48,12 @@ Commands:
46 48
     Download all extension specs.
47 49
   exts-all <name>
48 50
     Print all downloaded extensions that mention <name>.
51
+  vendors
52
+    Print all vendor abbreviations.
49 53
   type <type>
50 54
     Print the definition of <type>.
55
+  aliases <enum>
56
+    Print the KHR, ARB, and EXT aliases of <enum>.
51 57
   value <enum>
52 58
     Print the value of <enum>.
53 59
   enum <value>
... ...
@@ -166,8 +172,11 @@ CHANGE_PREFIXES = [
166 172
     [REQUIRE, '' ],
167 173
     [REMOVE,  '<'],
168 174
 ]
175
+VENDORS = ['KHR', 'ARB', 'EXT']
169 176
 KEY_SUBS = [
170
-    *[[f'^{prefix}', f''] for _, prefix in CHANGE_PREFIXES],
177
+    *[[f'^{   prefix}',  f''       ] for _, prefix in CHANGE_PREFIXES],
178
+    *[[f'{    vendor}$', f'{   i}' ] for i, vendor in enumerate(VENDORS)],
179
+    *[[f'^GL_{vendor}_', f'GL_{i}_'] for i, vendor in enumerate(VENDORS)],
171 180
 ]
172 181
 
173 182
 
... ...
@@ -295,7 +304,7 @@ def ext(extension):
295 304
 def exts(xml):
296 305
     category, attrib = CATEGORY_ATTRIBS['EXTENSION']
297 306
     exts = xml.xpath(f"{category}/@{attrib}")
298
-    return sorted(exts)
307
+    return sorted(exts, key=key)
299 308
 
300 309
 
301 310
 ### `exts_download`
... ...
@@ -318,7 +327,13 @@ def exts_all(xml, name):
318 327
         for file, *_ in
319 328
         grep(os.path.join(CACHE, 'extensions'), rf'\b{name}\b', [], [])
320 329
     )
321
-    return sorted(exts_all)
330
+    return sorted(exts_all, key=key)
331
+
332
+
333
+### `vendors`
334
+def vendors(xml):
335
+    vendors = set(extension.split('_')[1] for extension in exts(xml))
336
+    return sorted(vendors, key=key)
322 337
 
323 338
 
324 339
 ### `type`
... ...
@@ -326,6 +341,29 @@ def type(xml, type):
326 341
     return [xml.xpath(f"string({TYPES}/type/name[text()='{type}']/..)")]
327 342
 
328 343
 
344
+### `aliases`
345
+def aliases(xml, name, supports_=None, vendors_=[]):
346
+    if not vendors_:
347
+        vendors_[:] = vendors(xml)
348
+    for vendor in vendors_:
349
+        if name.endswith(f'_{vendor}'):
350
+            return []
351
+    value_  = value(xml, name)
352
+    if not value_:
353
+        return []
354
+    if not supports_:
355
+        supports_ = supports(xml, name, False)
356
+    if not supports_:
357
+        return []
358
+    aliases = []
359
+    # for vendor in vendors_:
360
+    for vendor in VENDORS:
361
+        alias = f'{name}_{vendor}'
362
+        if supports(xml, alias, False) and value(xml, alias) == value_:
363
+            aliases.append(alias)
364
+    return sorted(aliases, key=key)
365
+
366
+
329 367
 ### `value`
330 368
 def value(xml, enum):
331 369
     return xml.xpath(f"{ENUMS}/enum[@name='{enum}']/@value")
... ...
@@ -334,11 +372,11 @@ def value(xml, enum):
334 372
 ### `enum`
335 373
 def enum(xml, value):
336 374
     enum = xml.xpath(f"{ENUMS}/enum[@value='{value}']/@name")
337
-    return sorted(enum)
375
+    return sorted(enum, key=key)
338 376
 
339 377
 
340 378
 ### `supports`
341
-def supports(xml, name):
379
+def supports(xml, name, use_aliases=True):
342 380
     category, attrib = CATEGORY_ATTRIBS['EXTENSION']
343 381
     if xml.xpath(f"{category}[@{attrib}='{name}']"):
344 382
         return ['EXTENSION']
... ...
@@ -349,6 +387,12 @@ def supports(xml, name):
349 387
         for support in
350 388
         xml.xpath(f"{category}/{change}/*[@name='{name}']/../../@{attrib}")
351 389
     ]
390
+    if supports_ and use_aliases:
391
+        supports_.extend(
392
+            support
393
+            for alias   in aliases (xml, name, supports_)
394
+            for support in supports(xml, alias, False)
395
+        )
352 396
     return sorted(supports_, key=key)
353 397
 
354 398
 
... ...
@@ -375,7 +419,7 @@ def names(xml, support=None):
375 419
         for name in
376 420
         xml.xpath(f"{category}{attrib}/{REQUIRE}/*/@name")
377 421
     )
378
-    return sorted(names)
422
+    return sorted(names, key=key)
379 423
 
380 424
 
381 425
 ### `groups`
... ...
@@ -406,7 +450,7 @@ def enums(xml, group=None):
406 450
         for _, enums in enums_(xml, group).items()
407 451
         for enum     in enums
408 452
     ]
409
-    return sorted(enums)
453
+    return sorted(enums, key=key)
410 454
 
411 455
 
412 456
 ### `enums_tree`
... ...
@@ -548,7 +592,9 @@ def main():
548 592
     if args['exts']:          page(exts         (xml_()))
549 593
     if args['exts-download']: page(exts_download(xml_()))
550 594
     if args['exts-all']:      page(exts_all     (xml_(), args['<name>']))
595
+    if args['vendors']:       page(vendors      (xml_()))
551 596
     if args['type']:          page(type         (xml_(), args['<type>']))
597
+    if args['aliases']:       page(aliases      (xml_(), args['<enum>']))
552 598
     if args['value']:         page(value        (xml_(), args['<enum>']))
553 599
     if args['enum']:          page(enum         (xml_(), args['<value>']))
554 600
     if args['supports']:      page(supports     (xml_(), args['<name>']))