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 imap, chain
27 def getMangledName (funcName):
28 assert funcName[:2] == "gl"
29 return "glw" + funcName[2:]
31 def commandAliasDefinition (command):
32 return "#define\t%s\t%s" % (command.name, getMangledName(command.name))
34 def commandWrapperDeclaration (command):
35 return "%s\t%s\t(%s);" % (
37 getMangledName(command.name),
38 ", ".join([param.declaration for param in command.params]))
40 def genWrapperHeader (iface):
41 defines = imap(commandAliasDefinition, iface.commands)
42 prototypes = imap(commandWrapperDeclaration, iface.commands)
43 src = indentLines(chain(defines, prototypes))
44 writeInlFile(os.path.join(OPENGL_INC_DIR, "glwApi.inl"), src)
46 def getDefaultReturn (command):
47 if command.name == "glGetError":
48 return "GL_INVALID_OPERATION"
50 assert command.type != 'void'
51 return "(%s)0" % command.type
53 def commandWrapperDefinition (command):
55 {returnType} {mangledName} ({paramDecls})
57 const glw::Functions* gl = glw::getCurrentThreadFunctions();
59 return{defaultReturn};
60 {maybeReturn}gl->{memberName}({arguments});
62 return template.format(
63 returnType = command.type,
64 mangledName = getMangledName(command.name),
65 paramDecls = commandParams(command),
66 defaultReturn = " " + getDefaultReturn(command) if command.type != 'void' else "",
67 maybeReturn = "return " if command.type != 'void' else "",
68 memberName = getFunctionMemberName(command.name),
69 arguments = commandArgs(command))
71 def genWrapperImplementation (iface):
72 genCommandList(iface, commandWrapperDefinition, OPENGL_INC_DIR, "glwImpl.inl")
74 def genWrapper (iface):
75 genWrapperHeader(iface)
76 genWrapperImplementation(iface)
78 if __name__ == "__main__":
79 genWrapper(getHybridInterface())