am bc4cbda8: (-s ours) am 246b7d91: DO NOT MERGE Fix setjmp warning in qpTestLog...
[platform/upstream/VK-GL-CTS.git] / scripts / opengl / gen_wrapper.py
1 # -*- coding: utf-8 -*-
2
3 import os
4 from src_util import *
5 from itertools import imap, chain
6
7 def getMangledName (funcName):
8         assert funcName[:2] == "gl"
9         return "glw" + funcName[2:]
10
11 def commandAliasDefinition (command):
12         return "#define\t%s\t%s" % (command.name, getMangledName(command.name))
13
14 def commandWrapperDeclaration (command):
15         return "%s\t%s\t(%s);" % (
16                 command.type,
17                 getMangledName(command.name),
18                 ", ".join([param.declaration for param in command.params]))
19
20 def genWrapperHeader (iface):
21         defines = imap(commandAliasDefinition, iface.commands)
22         prototypes = imap(commandWrapperDeclaration, iface.commands)
23         src = indentLines(chain(defines, prototypes))
24         writeInlFile(os.path.join(OPENGL_INC_DIR, "glwApi.inl"), src)
25
26 def getDefaultReturn (command):
27         if command.name == "glGetError":
28                 return "GL_INVALID_OPERATION"
29         else:
30                 assert command.type != 'void'
31                 return "(%s)0" % command.type
32
33 def commandWrapperDefinition (command):
34         template = """
35 {returnType} {mangledName} ({paramDecls})
36 {{
37         const glw::Functions* gl = glw::getCurrentThreadFunctions();
38         if (!gl)
39                 return{defaultReturn};
40         {maybeReturn}gl->{memberName}({arguments});
41 }}"""
42         return template.format(
43                 returnType              = command.type,
44                 mangledName             = getMangledName(command.name),
45                 paramDecls              = commandParams(command),
46                 defaultReturn   = " " + getDefaultReturn(command) if command.type != 'void' else "",
47                 maybeReturn             = "return " if command.type != 'void' else "",
48                 memberName              = getFunctionMemberName(command.name),
49                 arguments               = commandArgs(command))
50
51 def genWrapperImplementation (iface):
52         genCommandList(iface, commandWrapperDefinition, OPENGL_INC_DIR, "glwImpl.inl")
53
54 def genWrapper (iface):
55         genWrapperHeader(iface)
56         genWrapperImplementation(iface)
57
58 if __name__ == "__main__":
59         genWrapper(getHybridInterface())