1 # -*- coding: utf-8 -*-
3 #-------------------------------------------------------------------------
4 # drawElements Quality Program utilities
5 # --------------------------------------
7 # Copyright 2015 The Android Open Source Project
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
21 #-------------------------------------------------------------------------
27 from opengl.src_util import getGLRegistry
28 from itertools import chain
30 import khr_util.registry
31 from khr_util.format import indentLines
33 def toCamelCase (extName):
34 return "".join([x.title() for x in extName.split("_")])
36 def makeStringList (name, strings):
38 yield "static const char* s_%s[] =" % name
42 yield "\t\"%s\"," % (entry)
46 def makeFunctionList (name, iface):
47 return makeStringList(name, [command.name for command in iface.commands])
49 def makeExtensionList (extensions):
50 for name, iface in extensions:
51 for line in makeFunctionList(name, iface):
55 yield "static const struct"
57 yield "\tconst char*\t\t\tname;"
58 yield "\tconst int\t\t\tnumFunctions;"
59 yield "\tconst char* const*\tfunctions;"
60 yield "} s_extensions[] ="
64 for name, iface in extensions:
65 entries.append("\t{ \"%s\",\tDE_LENGTH_OF_ARRAY(s_%s),\ts_%s\t}," % (name, name, name))
67 for line in indentLines(entries):
72 def getExtensionList (registry, api):
75 for extension in registry.extensions:
76 if not khr_util.registry.extensionSupports(extension, api):
79 spec = khr_util.registry.InterfaceSpec()
80 spec.addExtension(extension, api)
81 iface = khr_util.registry.createInterface(registry, spec, api)
83 if len(iface.commands) == 0:
86 exts.append((khr_util.registry.getExtensionName(extension),
91 def uniqueExtensions (extensions):
95 for name, iface in extensions:
97 res.append((name, iface))
102 def getInterfaceExactVersion (registry, api, version):
103 spec = khr_util.registry.InterfaceSpec()
105 def check (v): return v == version
107 for feature in registry.getFeatures(api, check):
108 spec.addFeature(feature, api)
110 return khr_util.registry.createInterface(registry, spec, api)
113 eglRegistry = getEGLRegistry()
114 eglCoreIface = getInterface(eglRegistry, 'egl', '1.4')
115 eglExtensions = getExtensionList(eglRegistry, 'egl')
117 glRegistry = getGLRegistry()
118 gles1Extensions = getExtensionList(glRegistry, 'gles1')
119 gles2Extensions = getExtensionList(glRegistry, 'gles2')
120 gles10CoreIface = getInterface(glRegistry, 'gles1', '1.0')
121 gles20CoreIface = getInterface(glRegistry, 'gles2', '2.0')
122 gles30CoreIface = getInterfaceExactVersion(glRegistry, 'gles2', '3.0')
123 # gles31CoreIface = getInterfaceExactVersion(glRegistry, 'gles2', '3.1')
125 allExtensions = eglExtensions + uniqueExtensions(gles1Extensions + gles2Extensions)
127 writeInlFile(os.path.normpath(os.path.join(SCRIPTS_DIR, "..", "..", "modules", "egl", "teglGetProcAddressTests.inl")),
128 chain(makeFunctionList ("EGL14", eglCoreIface),
129 makeFunctionList ("GLES10", gles10CoreIface),
130 makeFunctionList ("GLES20", gles20CoreIface),
131 makeFunctionList ("GLES30", gles30CoreIface),
132 # makeFunctionList ("GLES31", gles31CoreIface),
133 makeExtensionList (allExtensions)))