1 # -*- coding: utf-8 -*-
7 from opengl.src_util import getGLRegistry
8 from itertools import chain
10 import khr_util.registry
11 from khr_util.format import indentLines
13 def toCamelCase (extName):
14 return "".join([x.title() for x in extName.split("_")])
16 def makeStringList (name, strings):
18 yield "static const char* s_%s[] =" % name
22 yield "\t\"%s\"," % (entry)
26 def makeFunctionList (name, iface):
27 return makeStringList(name, [command.name for command in iface.commands])
29 def makeExtensionList (extensions):
30 for name, iface in extensions:
31 for line in makeFunctionList(name, iface):
35 yield "static const struct"
37 yield "\tconst char*\t\t\tname;"
38 yield "\tconst int\t\t\tnumFunctions;"
39 yield "\tconst char* const*\tfunctions;"
40 yield "} s_extensions[] ="
44 for name, iface in extensions:
45 entries.append("\t{ \"%s\",\tDE_LENGTH_OF_ARRAY(s_%s),\ts_%s\t}," % (name, name, name))
47 for line in indentLines(entries):
52 def getExtensionList (registry, api):
55 for extension in registry.extensions:
56 if not khr_util.registry.extensionSupports(extension, api):
59 spec = khr_util.registry.InterfaceSpec()
60 spec.addExtension(extension, api)
61 iface = khr_util.registry.createInterface(registry, spec, api)
63 if len(iface.commands) == 0:
66 exts.append((khr_util.registry.getExtensionName(extension),
71 def uniqueExtensions (extensions):
75 for name, iface in extensions:
77 res.append((name, iface))
82 def getInterfaceExactVersion (registry, api, version):
83 spec = khr_util.registry.InterfaceSpec()
85 def check (v): return v == version
87 for feature in registry.getFeatures(api, check):
88 spec.addFeature(feature, api)
90 return khr_util.registry.createInterface(registry, spec, api)
93 eglRegistry = getEGLRegistry()
94 eglCoreIface = getInterface(eglRegistry, 'egl', '1.4')
95 eglExtensions = getExtensionList(eglRegistry, 'egl')
97 glRegistry = getGLRegistry()
98 gles1Extensions = getExtensionList(glRegistry, 'gles1')
99 gles2Extensions = getExtensionList(glRegistry, 'gles2')
100 gles10CoreIface = getInterface(glRegistry, 'gles1', '1.0')
101 gles20CoreIface = getInterface(glRegistry, 'gles2', '2.0')
102 gles30CoreIface = getInterfaceExactVersion(glRegistry, 'gles2', '3.0')
103 # gles31CoreIface = getInterfaceExactVersion(glRegistry, 'gles2', '3.1')
105 allExtensions = eglExtensions + uniqueExtensions(gles1Extensions + gles2Extensions)
107 writeInlFile(os.path.normpath(os.path.join(SCRIPTS_DIR, "..", "..", "modules", "egl", "teglGetProcAddressTests.inl")),
108 chain(makeFunctionList ("EGL14", eglCoreIface),
109 makeFunctionList ("GLES10", gles10CoreIface),
110 makeFunctionList ("GLES20", gles20CoreIface),
111 makeFunctionList ("GLES30", gles30CoreIface),
112 # makeFunctionList ("GLES31", gles31CoreIface),
113 makeExtensionList (allExtensions)))