X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=scripts%2Fextgen.py;h=e6edd42bf944aad566c811202873282dc730f072;hb=5b539e1264a2a1342ee955ca0da978e48faf6f8f;hp=c5bc219a392e35db1d823a61df8dc3b927e28c88;hpb=d072b64415abd87ca07e34eea00546774823f322;p=libs%2Fgl.git diff --git a/scripts/extgen.py b/scripts/extgen.py index c5bc219a..e6edd42b 100755 --- a/scripts/extgen.py +++ b/scripts/extgen.py @@ -31,7 +31,10 @@ if sys.argv[i].startswith("gl"): i += 1 target_ext = sys.argv[i] +backport_ext = None +deprecated_version = None out_base = None +ignore_things = [] if target_ext.endswith(".glext"): fn = target_ext target_ext = None @@ -44,8 +47,15 @@ if target_ext.endswith(".glext"): elif parts[0]=="core_version": if parts[1]==target_api: core_version = parts[2] + elif parts[0]=="deprecated": + if parts[1]==target_api: + deprecated_version = parts[2] elif parts[0]=="secondary": secondary.append(parts[1]) + elif parts[0]=="backport": + backport_ext = parts[1] + elif parts[0]=="ignore": + ignore_things.append(parts[1]) if i+11: + core_version_candidates.sort(reverse=True) + if core_version_candidates[1][0]+1>=core_version_candidates[0][0]: + ver0 = core_version_candidates[0][1] + ver1 = core_version_candidates[1][1] + print "Warning: multiple likely core version candidates: %d.%d %d.%d"%(ver0[0], ver0[1], ver1[0], ver1[1]) + core_version = core_version_candidates[0][1] + +if not deprecated_version: + deprecated_version = min_deprecated_version + +if backport_ext: + if backport_ext=="none": + backport_ext = None + else: + backport_ext = extensions[backport_ext] + + if backport_ext not in backport_ext_candidates: + print "Warning: explicitly specified backport extension %s does not look like a backport extension" +elif backport_ext_candidates: + if len(backport_ext_candidates)>1: + print "Warning: multiple backport extension candidates: %s"%(" ".join(e.name for e in backport_ext_candidates)) + + for e in backport_ext_candidates: + if e.base_name==target_ext.base_name: + backport_ext = e + + if not backport_ext and len(backport_ext_candidates)==1: + print "Warning: potential backport extension has mismatched name: %s"%backport_ext_candidates[0].name for f in funcs: f.typedef = "FPtr_%s"%f.name @@ -386,7 +451,7 @@ namespace GL { if funcs or enums: if funcs: for f in funcs: - out.write("typedef %s (*%s)(%s);\n"%(f.return_type, f.typedef, ", ".join(f.params))) + out.write("typedef %s (APIENTRY *%s)(%s);\n"%(f.return_type, f.typedef, ", ".join(f.params))) out.write("\n") if enums: @@ -430,10 +495,16 @@ out.write("#include \"%s.h\"\n"%target_ext.name.lower()) if funcs: out.write(""" #ifdef __APPLE__ -#define GET_PROC_ADDRESS(x) ::x +#define GET_PROC_ADDRESS(x) &::x #else #define GET_PROC_ADDRESS(x) get_proc_address(#x) #endif + +#ifdef WIN32 +#define GET_PROC_ADDRESS_1_1(x) &::x +#else +#define GET_PROC_ADDRESS_1_1(x) GET_PROC_ADDRESS(x) +#endif """) out.write(""" namespace Msp { @@ -446,23 +517,43 @@ for f in funcs: out.write("\nExtension::SupportLevel init_%s()\n{\n"%target_ext.name.lower()) if core_version: - out.write("\tif(is_version_at_least(%d, %d)"%tuple(core_version)) + out.write("\tif(") + if deprecated_version and backport_ext: + out.write("(") + out.write("is_version_at_least(%d, %d)"%tuple(core_version)) + if deprecated_version: + out.write(" && (get_gl_profile()!=CORE_PROFILE || !is_version_at_least(%d, %d))"%tuple(deprecated_version)) + if backport_ext: + out.write(")") if backport_ext: out.write(" || is_supported(\"GL_%s\")"%backport_ext.name) out.write(")\n\t{\n") for f in funcs: if target_api in f.supported_apis: - out.write("\t\t%s = reinterpret_cast<%s>(GET_PROC_ADDRESS(%s));\n"%(f.name, f.typedef, f.name)) + gpa_suffix = "" + if f.version is not None and f.version<=[1, 1]: + gpa_suffix = "_1_1" + out.write("\t\t%s = reinterpret_cast<%s>(GET_PROC_ADDRESS%s(%s));\n"%(f.name, f.typedef, gpa_suffix, f.name)) out.write("\t\treturn Extension::CORE;\n") out.write("\t}\n") if source_ext and source_ext!=backport_ext: out.write("\tif(is_supported(\"GL_%s\"))\n\t{\n"%(source_ext.name)) for f in funcs: - s = f if f.sources: - s = f.sources[0] - if target_api in s.supported_apis: - out.write("\t\t%s = reinterpret_cast<%s>(GET_PROC_ADDRESS(%s));\n"%(f.name, f.typedef, s.name)) + src = None + for s in f.sources: + if s.name.endswith(source_ext.ext_type): + src = s + break + if not src: + src = f.sources[0] + else: + src = f + + if target_api in src.supported_apis: + if not src.name.endswith(source_ext.ext_type): + print "Warning: %s does not match extension type %s"%(src.name, source_ext.ext_type) + out.write("\t\t%s = reinterpret_cast<%s>(GET_PROC_ADDRESS(%s));\n"%(f.name, f.typedef, src.name)) out.write("\t\treturn Extension::EXTENSION;\n") out.write("\t}\n") out.write("\treturn Extension::UNSUPPORTED;\n")