Pyry Haulos | a017863 | 2014-11-21 14:56:21 -0800 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | |
Jarkko Pöyry | 3c77ed4 | 2015-01-06 12:54:34 -0800 | [diff] [blame] | 3 | #------------------------------------------------------------------------- |
| 4 | # drawElements Quality Program utilities |
| 5 | # -------------------------------------- |
| 6 | # |
| 7 | # Copyright 2015 The Android Open Source Project |
| 8 | # |
| 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 |
| 12 | # |
| 13 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | # |
| 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. |
| 20 | # |
| 21 | #------------------------------------------------------------------------- |
| 22 | |
Pyry Haulos | a017863 | 2014-11-21 14:56:21 -0800 | [diff] [blame] | 23 | import os |
| 24 | import string |
| 25 | |
| 26 | from common import * |
| 27 | from opengl.src_util import getGLRegistry |
| 28 | from itertools import chain |
| 29 | |
| 30 | import khr_util.registry |
| 31 | from khr_util.format import indentLines |
| 32 | |
| 33 | def toCamelCase (extName): |
| 34 | return "".join([x.title() for x in extName.split("_")]) |
| 35 | |
| 36 | def makeStringList (name, strings): |
| 37 | yield "" |
| 38 | yield "static const char* s_%s[] =" % name |
| 39 | yield "{" |
| 40 | |
| 41 | for entry in strings: |
| 42 | yield "\t\"%s\"," % (entry) |
| 43 | |
| 44 | yield "};" |
| 45 | |
| 46 | def makeFunctionList (name, iface): |
| 47 | return makeStringList(name, [command.name for command in iface.commands]) |
| 48 | |
| 49 | def makeExtensionList (extensions): |
| 50 | for name, iface in extensions: |
| 51 | for line in makeFunctionList(name, iface): |
| 52 | yield line |
| 53 | |
| 54 | yield "" |
| 55 | yield "static const struct" |
| 56 | yield "{" |
| 57 | yield "\tconst char*\t\t\tname;" |
| 58 | yield "\tconst int\t\t\tnumFunctions;" |
| 59 | yield "\tconst char* const*\tfunctions;" |
| 60 | yield "} s_extensions[] =" |
| 61 | yield "{" |
| 62 | |
| 63 | entries = [] |
| 64 | for name, iface in extensions: |
| 65 | entries.append("\t{ \"%s\",\tDE_LENGTH_OF_ARRAY(s_%s),\ts_%s\t}," % (name, name, name)) |
| 66 | |
| 67 | for line in indentLines(entries): |
| 68 | yield line |
| 69 | |
| 70 | yield "};" |
| 71 | |
| 72 | def getExtensionList (registry, api): |
| 73 | exts = [] |
| 74 | |
| 75 | for extension in registry.extensions: |
| 76 | if not khr_util.registry.extensionSupports(extension, api): |
| 77 | continue |
| 78 | |
| 79 | spec = khr_util.registry.InterfaceSpec() |
| 80 | spec.addExtension(extension, api) |
| 81 | iface = khr_util.registry.createInterface(registry, spec, api) |
| 82 | |
| 83 | if len(iface.commands) == 0: |
| 84 | continue |
| 85 | |
| 86 | exts.append((khr_util.registry.getExtensionName(extension), |
| 87 | iface)) |
| 88 | |
| 89 | return exts |
| 90 | |
| 91 | def uniqueExtensions (extensions): |
| 92 | res = [] |
| 93 | seen = set() |
| 94 | |
| 95 | for name, iface in extensions: |
| 96 | if not name in seen: |
| 97 | res.append((name, iface)) |
| 98 | seen.add(name) |
| 99 | |
| 100 | return res |
| 101 | |
| 102 | def getInterfaceExactVersion (registry, api, version): |
| 103 | spec = khr_util.registry.InterfaceSpec() |
| 104 | |
| 105 | def check (v): return v == version |
| 106 | |
| 107 | for feature in registry.getFeatures(api, check): |
| 108 | spec.addFeature(feature, api) |
| 109 | |
| 110 | return khr_util.registry.createInterface(registry, spec, api) |
| 111 | |
| 112 | def gen (): |
| 113 | eglRegistry = getEGLRegistry() |
| 114 | eglCoreIface = getInterface(eglRegistry, 'egl', '1.4') |
| 115 | eglExtensions = getExtensionList(eglRegistry, 'egl') |
| 116 | |
| 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') |
| 124 | |
| 125 | allExtensions = eglExtensions + uniqueExtensions(gles1Extensions + gles2Extensions) |
| 126 | |
| 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))) |