• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
23import os
24from src_util import *
25from itertools import imap, chain
26
27def getMangledName (funcName):
28	assert funcName[:2] == "gl"
29	return "glw" + funcName[2:]
30
31def commandAliasDefinition (command):
32	return "#define\t%s\t%s" % (command.name, getMangledName(command.name))
33
34def commandWrapperDeclaration (command):
35	return "%s\t%s\t(%s);" % (
36		command.type,
37		getMangledName(command.name),
38		", ".join([param.declaration for param in command.params]))
39
40def 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)
45
46def getDefaultReturn (command):
47	if command.name == "glGetError":
48		return "GL_INVALID_OPERATION"
49	else:
50		assert command.type != 'void'
51		return "(%s)0" % command.type
52
53def commandWrapperDefinition (command):
54	template = """
55{returnType} {mangledName} ({paramDecls})
56{{
57	const glw::Functions* gl = glw::getCurrentThreadFunctions();
58	if (!gl)
59		return{defaultReturn};
60	{maybeReturn}gl->{memberName}({arguments});
61}}"""
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))
70
71def genWrapperImplementation (iface):
72	genCommandList(iface, commandWrapperDefinition, OPENGL_INC_DIR, "glwImpl.inl")
73
74def genWrapper (iface):
75	genWrapperHeader(iface)
76	genWrapperImplementation(iface)
77
78if __name__ == "__main__":
79	genWrapper(getHybridInterface())
80