Add CTS_ARB_gl_spirv test implementation
[platform/upstream/VK-GL-CTS.git] / scripts / opengl / gen_ext_init.py
1 # -*- coding: utf-8 -*-
2
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
23 from src_util import *
24
25 def getExtensionCommands (registry, iface, api, extension):
26         commands = []
27
28         # Build interface with just the single extension and no core APIs.
29         # Aliases will not be set in this iface so we will use it only for
30         # slicing the complete (hybrid) iface.
31         extIface = getInterface(registry, api, version=False, profile='core', extensionNames=[extension])
32         if not extIface.commands:
33                 return commands
34
35         cmdMap = {}
36         for command in iface.commands:
37                 cmdMap[command.name] = command
38
39         for extCommand in extIface.commands:
40                 assert extCommand.name in cmdMap
41                 commands.append(cmdMap[extCommand.name])
42
43         return commands
44
45 def genExtensions (registry, iface, api):
46         for extName in EXTENSIONS:
47                 extCommands = getExtensionCommands(registry, iface, api, extName)
48                 if len(extCommands) == 0:
49                         continue # Not applicable for this api
50
51                 yield ""
52                 yield "if (de::contains(extSet, \"%s\"))" % extName
53                 yield "{"
54
55                 def genInit (command):
56                         ifaceName = command.alias.name if command.alias else command.name
57                         return "gl->%s\t= (%s)\tloader->get(\"%s\");" % (
58                                 getFunctionMemberName(ifaceName),
59                                 getFunctionTypeName(ifaceName),
60                                 command.name)
61
62                 for line in indentLines(genInit(command) for command in extCommands):
63                         yield "\t" + line
64
65                 yield "}"
66
67 def genExtInit (registry, iface):
68         nonStrippedIface = getHybridInterface(stripAliasedExtCommands = False)
69
70         writeInlFile(os.path.join(OPENGL_INC_DIR, "glwInitExtES.inl"), genExtensions(registry, nonStrippedIface, 'gles2'))
71         writeInlFile(os.path.join(OPENGL_INC_DIR, "glwInitExtGL.inl"), genExtensions(registry, nonStrippedIface, 'gl'))
72
73 if __name__ == '__main__':
74         genExtInit(getGLRegistry(), getHybridInterface())