self.sort_extensions()
-def detect_core_version(host_api, things):
+def detect_core_version(host_api, things, debug=None):
max_version = Version(1, 0)
max_count = 0
lower_count = 0
print "Warning: Inconsistent core version %s"%max_version
if missing:
+ if debug:
+ print "---"
+ print "%d things missing from core:"%len(missing)
+ for t in missing:
+ print " "+t.name
return None
return max_version
-def detect_deprecated_version(host_api, things):
+def detect_deprecated_version(host_api, things, debug):
min_version = None
deprecated = []
for t in things:
if min_version and len(deprecated)*2<len(things):
print "Warning: Inconsistent deprecation version %s"%min_version
+ if debug:
+ print "---"
+ print "%d things are deprecated:"%len(deprecated)
+ for t in deprecated:
+ print " "+t.name
return min_version
for s in supp.sources:
collect_extensions(s, api, exts)
-def detect_source_extension(host_api, things):
+def detect_source_extension(host_api, things, debug=False):
things_by_ext = {}
for t in things:
exts = []
for e in exts:
things_by_ext.setdefault(e, []).append(t)
+ if debug:
+ print "---"
+ print "Looking for %d things in %d extensions"%(len(things), len(things_by_ext))
+
extensions = []
missing = set(things)
while missing and things_by_ext:
elif count==largest_count and e.preference>largest_ext.preference:
largest_ext = e
+ if debug:
+ print "Found %d things in %s"%(largest_count, largest_ext.name)
+
extensions.append(largest_ext)
for t in things_by_ext[largest_ext]:
missing.remove(t)
del things_by_ext[e]
if missing:
+ if debug:
+ print "%d things still missing:"%len(missing)
+ for t in missing:
+ print " "+t.name
return None
return extensions
class SourceGenerator:
- def __init__(self, host_api, ext_name, things, optional_things):
+ def __init__(self, host_api, ext_name, things, optional_things, debug=False):
self.host_api = host_api
self.api_prefix = "GL"
if self.host_api.name=="gles2":
self.func_typedefs = dict((f.name, "FPtr_"+f.name) for f in self.funcs)
self.enums = filter((lambda t: t.kind==Thing.ENUM), all_things)
self.enums.sort(key=(lambda e: e.value))
- self.core_version = detect_core_version(host_api, things)
- self.deprecated_version = detect_deprecated_version(host_api, things)
+ self.core_version = detect_core_version(host_api, things, debug)
+ self.deprecated_version = detect_deprecated_version(host_api, things, debug)
self.backport_ext = detect_backport_extension(host_api, things);
- self.source_exts = detect_source_extension(host_api, things)
+ self.source_exts = detect_source_extension(host_api, things, debug)
if not self.core_version and not self.backport_ext and not self.source_exts:
print "Warning: Not supportable on host API"
+ def dump_info(self):
+ print "--- Extension information ---"
+ print "Extension %s"%self.ext_name
+ print "Core %s"%self.core_version
+ print "Deprecated %s"%self.deprecated_version
+ if self.backport_ext:
+ print "Backport %s"%self.backport_ext.name
+ if self.source_exts:
+ print "Sources %s"%", ".join(e.name for e in self.source_exts)
+
def write_header_intro(self, out):
out.write("#ifndef MSP_GL_%s_\n"%self.ext_name.upper())
out.write("#define MSP_GL_%s_\n"%self.ext_name.upper())
self.write_source_outro(out)
+def dump_api_support(supp, api, indent):
+ if supp.core_version:
+ print indent+"core in version "+str(supp.core_version)
+ if supp.deprecated_version:
+ print indent+"deprecated in version "+str(supp.deprecated_version)
+ for e in supp.extensions:
+ print indent+"extension %s (preference %d)"%(e.name, e.preference)
+ for r in supp.sources:
+ print indent+"source "+r.name
+ dump_thing_info(r, api, indent+" ")
+
+def dump_thing_info(thing, api, indent):
+ for a in thing.aliases:
+ print indent+"alias "+a
+ if api:
+ supp = thing.api_support.get(api)
+ dump_api_support(supp, api, indent)
+ else:
+ for a, s in thing.api_support.iteritems():
+ print indent+"api "+a
+ dump_api_support(s, a, indent+" ")
+
+
class ExtensionParser:
def __init__(self, host_api):
self.host_api = host_api
replaced with cpp and h."""
sys.exit(1)
- host_api_name = "gl"
-
i = 1
+
+ debug = False
+ if sys.argv[i]=="-g":
+ debug = True
+ i += 1
+
+ host_api_name = "gl"
if sys.argv[i].startswith("gl"):
host_api_name = sys.argv[i]
i += 1
things = collect_extension_things(host_api, target_ext, ext_parser.ignore_things+ext_parser.optional_things)
optional_things = collect_optional_things(target_ext, ext_parser.optional_things)
- generator = SourceGenerator(host_api, target_ext.name, things, optional_things)
+ if debug:
+ print "--- Things included in this extension ---"
+ all_things = things+optional_things
+ all_things.sort(key=(lambda t: t.name))
+ for t in all_things:
+ print t.name
+ if t in optional_things:
+ print " optional"
+ dump_thing_info(t, None, " ")
+
+ generator = SourceGenerator(host_api, target_ext.name, things, optional_things, debug)
if ext_parser.core_version:
generator.core_version = ext_parser.core_version
if ext_parser.deprecated_version:
generator.backport_ext = None
else:
generator.backport_ext = get_extension(xml_parser.apis, ext_parser.backport_ext)
+ if debug:
+ generator.dump_info()
generator.write_header(out_base+".h")
generator.write_source(out_base+".cpp")