am ed1f0c93: (-s ours) am 45fe81cf: am 3cc483b1: DO NOT MERGE: Remove broken record_v...
[platform/upstream/VK-GL-CTS.git] / scripts / egl / proc_address_tests.py
1 # -*- coding: utf-8 -*-
2
3 import os
4 import string
5
6 from common import *
7 from opengl.src_util import getGLRegistry
8 from itertools import chain
9
10 import khr_util.registry
11 from khr_util.format import indentLines
12
13 def toCamelCase (extName):
14         return "".join([x.title() for x in extName.split("_")])
15
16 def makeStringList (name, strings):
17         yield ""
18         yield "static const char* s_%s[] =" % name
19         yield "{"
20
21         for entry in strings:
22                 yield "\t\"%s\"," % (entry)
23
24         yield "};"
25
26 def makeFunctionList (name, iface):
27         return makeStringList(name, [command.name for command in iface.commands])
28
29 def makeExtensionList (extensions):
30         for name, iface in extensions:
31                 for line in makeFunctionList(name, iface):
32                         yield line
33
34         yield ""
35         yield "static const struct"
36         yield "{"
37         yield "\tconst char*\t\t\tname;"
38         yield "\tconst int\t\t\tnumFunctions;"
39         yield "\tconst char* const*\tfunctions;"
40         yield "} s_extensions[] ="
41         yield "{"
42
43         entries = []
44         for name, iface in extensions:
45                 entries.append("\t{ \"%s\",\tDE_LENGTH_OF_ARRAY(s_%s),\ts_%s\t}," % (name, name, name))
46
47         for line in indentLines(entries):
48                 yield line
49
50         yield "};"
51
52 def getExtensionList (registry, api):
53         exts = []
54
55         for extension in registry.extensions:
56                 if not khr_util.registry.extensionSupports(extension, api):
57                         continue
58
59                 spec = khr_util.registry.InterfaceSpec()
60                 spec.addExtension(extension, api)
61                 iface = khr_util.registry.createInterface(registry, spec, api)
62
63                 if len(iface.commands) == 0:
64                         continue
65
66                 exts.append((khr_util.registry.getExtensionName(extension),
67                                          iface))
68
69         return exts
70
71 def uniqueExtensions (extensions):
72         res = []
73         seen = set()
74
75         for name, iface in extensions:
76                 if not name in seen:
77                         res.append((name, iface))
78                         seen.add(name)
79
80         return res
81
82 def getInterfaceExactVersion (registry, api, version):
83         spec = khr_util.registry.InterfaceSpec()
84
85         def check (v): return v == version
86
87         for feature in registry.getFeatures(api, check):
88                 spec.addFeature(feature, api)
89
90         return khr_util.registry.createInterface(registry, spec, api)
91
92 def gen ():
93         eglRegistry             = getEGLRegistry()
94         eglCoreIface    = getInterface(eglRegistry, 'egl', '1.4')
95         eglExtensions   = getExtensionList(eglRegistry, 'egl')
96
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')
104
105         allExtensions   = eglExtensions + uniqueExtensions(gles1Extensions + gles2Extensions)
106
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)))