1 # -*- coding: utf-8 -*-
5 from itertools import imap, chain
7 def getMangledName (funcName):
8 assert funcName[:2] == "gl"
9 return "glw" + funcName[2:]
11 def commandAliasDefinition (command):
12 return "#define\t%s\t%s" % (command.name, getMangledName(command.name))
14 def commandWrapperDeclaration (command):
15 return "%s\t%s\t(%s);" % (
17 getMangledName(command.name),
18 ", ".join([param.declaration for param in command.params]))
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)
26 def getDefaultReturn (command):
27 if command.name == "glGetError":
28 return "GL_INVALID_OPERATION"
30 assert command.type != 'void'
31 return "(%s)0" % command.type
33 def commandWrapperDefinition (command):
35 {returnType} {mangledName} ({paramDecls})
37 const glw::Functions* gl = glw::getCurrentThreadFunctions();
39 return{defaultReturn};
40 {maybeReturn}gl->{memberName}({arguments});
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))
51 def genWrapperImplementation (iface):
52 genCommandList(iface, commandWrapperDefinition, OPENGL_INC_DIR, "glwImpl.inl")
54 def genWrapper (iface):
55 genWrapperHeader(iface)
56 genWrapperImplementation(iface)
58 if __name__ == "__main__":
59 genWrapper(getHybridInterface())