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 #-------------------------------------------------------------------------
24 from src_util import *
25 from itertools import chain
28 from itertools import imap
32 def getMangledName (funcName):
33 assert funcName[:2] == "gl"
34 return "glw" + funcName[2:]
36 def commandAliasDefinition (command):
37 return "#define\t%s\t%s" % (command.name, getMangledName(command.name))
39 def commandWrapperDeclaration (command):
40 return "%s\t%s\t(%s);" % (
42 getMangledName(command.name),
43 ", ".join([param.declaration for param in command.params]))
45 def genWrapperHeader (iface):
46 defines = imap(commandAliasDefinition, iface.commands)
47 prototypes = imap(commandWrapperDeclaration, iface.commands)
48 src = indentLines(chain(defines, prototypes))
49 writeInlFile(os.path.join(OPENGL_INC_DIR, "glwApi.inl"), src)
51 def getDefaultReturn (command):
52 if command.name == "glGetError":
53 return "GL_INVALID_OPERATION"
55 assert command.type != 'void'
56 return "(%s)0" % command.type
58 def commandWrapperDefinition (command):
60 {returnType} {mangledName} ({paramDecls})
62 const glw::Functions* gl = glw::getCurrentThreadFunctions();
64 return{defaultReturn};
65 {maybeReturn}gl->{memberName}({arguments});
67 return template.format(
68 returnType = command.type,
69 mangledName = getMangledName(command.name),
70 paramDecls = commandParams(command),
71 defaultReturn = " " + getDefaultReturn(command) if command.type != 'void' else "",
72 maybeReturn = "return " if command.type != 'void' else "",
73 memberName = getFunctionMemberName(command.name),
74 arguments = commandArgs(command))
76 def genWrapperImplementation (iface):
77 genCommandList(iface, commandWrapperDefinition, OPENGL_INC_DIR, "glwImpl.inl")
79 def genWrapper (iface):
80 genWrapperHeader(iface)
81 genWrapperImplementation(iface)
83 if __name__ == "__main__":
84 genWrapper(getHybridInterface())