From: Mikko Rasa Date: Wed, 15 Oct 2014 15:54:16 +0000 (+0300) Subject: Enhance the extension generator to support different APIs X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=67538c60b8baa6816b8ae2d343ae62d881e6c58d;p=libs%2Fgl.git Enhance the extension generator to support different APIs --- diff --git a/extensions/arb_fragment_shader.glext b/extensions/arb_fragment_shader.glext index ac02f71f..30961f56 100644 --- a/extensions/arb_fragment_shader.glext +++ b/extensions/arb_fragment_shader.glext @@ -1,2 +1,2 @@ extension ARB_fragment_shader -core_version 2.0 +core_version gl 2.0 diff --git a/extensions/arb_pixel_buffer_object.glext b/extensions/arb_pixel_buffer_object.glext index c11586d8..b36e7f12 100644 --- a/extensions/arb_pixel_buffer_object.glext +++ b/extensions/arb_pixel_buffer_object.glext @@ -1,2 +1,2 @@ extension ARB_pixel_buffer_object -core_version 2.1 +core_version gl 2.1 diff --git a/extensions/arb_texture_cube_map.glext b/extensions/arb_texture_cube_map.glext index 16a6a929..88745307 100644 --- a/extensions/arb_texture_cube_map.glext +++ b/extensions/arb_texture_cube_map.glext @@ -1,2 +1,2 @@ extension ARB_texture_cube_map -core_version 1.3 +core_version gl 1.3 diff --git a/extensions/arb_texture_float.glext b/extensions/arb_texture_float.glext index bb379fdf..24f42c2f 100644 --- a/extensions/arb_texture_float.glext +++ b/extensions/arb_texture_float.glext @@ -1,2 +1,2 @@ extension ARB_texture_float -core_version 3.0 +core_version gl 3.0 diff --git a/extensions/arb_uniform_buffer_object.glext b/extensions/arb_uniform_buffer_object.glext index c6b1b443..8e0e9310 100644 --- a/extensions/arb_uniform_buffer_object.glext +++ b/extensions/arb_uniform_buffer_object.glext @@ -1,2 +1,2 @@ extension ARB_uniform_buffer_object -core_version 3.0 +core_version gl 3.0 diff --git a/extensions/ext_bgra.glext b/extensions/ext_bgra.glext index b449b888..2ba56750 100644 --- a/extensions/ext_bgra.glext +++ b/extensions/ext_bgra.glext @@ -1,2 +1,2 @@ extension EXT_bgra -core_version 1.2 +core_version gl 1.2 diff --git a/extensions/ext_blend_subtract.glext b/extensions/ext_blend_subtract.glext index 312119da..0e89f4d2 100644 --- a/extensions/ext_blend_subtract.glext +++ b/extensions/ext_blend_subtract.glext @@ -1,2 +1,2 @@ extension EXT_blend_subtract -core_version 1.2 +core_version gl 1.2 diff --git a/scripts/extgen.py b/scripts/extgen.py index c8f87c3b..fbb66815 100755 --- a/scripts/extgen.py +++ b/scripts/extgen.py @@ -10,8 +10,8 @@ import itertools if len(sys.argv)<2: print """Usage: - extgen.py [] [ ...] - extgen.py [] + extgen.py [api] [] [ ...] + extgen.py [api] [] Reads gl.xml and generates files to use . Any promoted functions are exposed with their promoted names. If extensions are given, @@ -23,7 +23,14 @@ absent, the extension's lowercased name is used. Anything after the last dot in is removed and replaced with cpp and h.""" sys.exit(0) -target_ext = sys.argv[1] +target_api = "gl" + +i = 1 +if sys.argv[i].startswith("gl"): + target_api = sys.argv[i] + i += 1 + +target_ext = sys.argv[i] out_base = None if target_ext.endswith(".glext"): fn = target_ext @@ -35,13 +42,14 @@ if target_ext.endswith(".glext"): if parts[0]=="extension": target_ext = parts[1] elif parts[0]=="core_version": - core_version = parts[1] + if parts[1]==target_api: + core_version = parts[2] elif parts[0]=="secondary": secondary.append(parts[1]) - if len(sys.argv)>=3: - out_base = os.path.splitext(sys.argv[2])[0] + if i+1 @@ -276,24 +358,37 @@ namespace GL { if funcs or enums: if funcs: - out.write("#if defined(__APPLE__) || !defined(GL_%s)\n"%target_ext) for f in funcs: out.write("typedef %s (*%s)(%s);\n"%(f.return_type, f.typedef, ", ".join(f.params))) - out.write("#endif\n\n") + out.write("\n") if enums: - if core_version: - out.write("#ifndef GL_VERSION_%s\n"%"_".join(map(str, core_version))) - else: - out.write("#ifndef GL_%s\n"%target_ext) + api_prefix = "GL" + if target_api=="gles2": + api_prefix = "GL_ES" + + enums_by_category = {} for e in enums: - out.write("#define %s 0x%04X\n"%(e.name, e.value)) - out.write("#endif\n\n") + cat = None + if e.version: + cat = api_prefix+"_VERSION_"+"_".join(map(str, e.version)) + elif e.extension: + cat = "GL_"+e.extension.name + enums_by_category.setdefault(cat, []).append(e) + + for cat in sorted(enums_by_category.keys()): + if cat: + out.write("#ifndef %s\n"%cat) + for e in enums_by_category[cat]: + out.write("#define %s 0x%04X\n"%(e.name, e.value)) + if cat: + out.write("#endif\n") + out.write("\n") for f in funcs: out.write("extern %s %s;\n"%(f.typedef, f.name)) -out.write("extern Extension %s;\n"%target_ext) +out.write("extern Extension %s;\n"%target_ext.name) out.write(""" } // namespace GL @@ -303,7 +398,7 @@ out.write(""" """) out = file(out_base+".cpp", "w") -out.write("#include \"%s.h\"\n"%target_ext.lower()) +out.write("#include \"%s.h\"\n"%target_ext.name.lower()) if funcs: out.write(""" @@ -322,33 +417,31 @@ namespace GL { for f in funcs: out.write("%s %s = 0;\n"%(f.typedef, f.name)) -out.write("\nExtension::SupportLevel init_%s()\n{\n"%target_ext.lower()) -out.write("#ifdef GL_%s\n"%target_ext) +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)) if backport_ext: - out.write(" || is_supported(\"GL_%s\")"%backport_ext) + out.write(" || is_supported(\"GL_%s\")"%backport_ext.name) out.write(")\n\t{\n") - if funcs: - for f in funcs: + for f in funcs: + if f.version or 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)) out.write("\t\treturn Extension::CORE;\n") out.write("\t}\n") -if target_ext!=backport_ext: - out.write("\tif(is_supported(\"GL_%s\"))\n\t{\n"%(target_ext)) - if funcs: - for f in funcs: - n = f.name - if f.source: - n = f.source.name - out.write("\t\t%s = reinterpret_cast<%s>(GET_PROC_ADDRESS(%s));\n"%(f.name, f.typedef, 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 s.version or 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)) out.write("\t\treturn Extension::EXTENSION;\n") out.write("\t}\n") -out.write("#endif\n") out.write("\treturn Extension::UNSUPPORTED;\n") out.write("}\n") -out.write("\nExtension %s(\"GL_%s\", init_%s);\n"%(target_ext, target_ext, target_ext.lower())) +out.write("\nExtension %s(\"GL_%s\", init_%s);\n"%(target_ext.name, target_ext.name, target_ext.name.lower())) out.write(""" } // namespace GL