3 # $Id: glapitemp.py,v 1.2 2001/12/14 03:17:00 brianp Exp $
5 # Mesa 3-D graphics library
8 # Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
10 # Permission is hereby granted, free of charge, to any person obtaining a
11 # copy of this software and associated documentation files (the "Software"),
12 # to deal in the Software without restriction, including without limitation
13 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 # and/or sell copies of the Software, and to permit persons to whom the
15 # Software is furnished to do so, subject to the following conditions:
17 # The above copyright notice and this permission notice shall be included
18 # in all copies or substantial portions of the Software.
20 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 # BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
24 # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 # Generate the glapitemp.h file.
31 # gloffsets.py >glapitemp.h
34 # The apispec file must be in the current directory.
43 /* DO NOT EDIT! This file is generated by the glapitemp.py script. */
46 * This file is a template which generates the OpenGL API entry point
47 * functions. It should be included by a .c file which first defines
48 * the following macros:
49 * KEYWORD1 - usually nothing, but might be __declspec(dllexport) on Win32
50 * KEYWORD2 - usually nothing, but might be __stdcall on Win32
51 * NAME(n) - builds the final function name (usually add "gl" prefix)
52 * DISPATCH(func, args, msg) - code to do dispatch of named function.
53 * msg is a printf-style debug message.
54 * RETURN_DISPATCH(func, args, msg) - code to do dispatch with a return value
56 * Here's an example which generates the usual OpenGL functions:
59 * #define NAME(func) gl##func
60 * #define DISPATCH(func, args, msg) \\
61 * struct _glapi_table *dispatch = CurrentDispatch; \\
62 * (*dispatch->func) args
63 * #define RETURN DISPATCH(func, args, msg) \\
64 * struct _glapi_table *dispatch = CurrentDispatch; \\
65 * return (*dispatch->func) args
79 #error NAME must be defined
83 #error DISPATCH must be defined
86 #ifndef RETURN_DISPATCH
87 #error RETURN_DISPATCH must be defined
90 extern void gl__unused413(void); /* silence warning */
102 #undef RETURN_DISPATCH
103 #undef DISPATCH_TABLE_NAME
104 #undef UNUSED_TABLE_NAME
110 def MakeParamList(nameList
):
114 for name
in nameList
:
115 result
= result
+ name
117 result
= result
+ ', '
123 def MakePrintfString(funcName
, argTypeList
, argNameList
):
124 result
= '(F, "gl%s(' % (funcName
)
129 for argType
in argTypeList
:
131 if argType
== 'GLenum':
132 result
= result
+ '0x%x'
133 elif argType
in ['GLfloat', 'GLdouble', 'GLclampf', 'GLclampd']:
134 result
= result
+ '%f'
135 elif argType
in ['GLbyte', 'GLubyte', 'GLshort', 'GLushort', 'GLint', 'GLuint', 'GLboolean']:
136 result
= result
+ '%d'
138 result
= result
+ '%p'
141 result
= result
+ ', '
145 result
= result
+ ');\\n"'
150 result
= result
+ ', '
151 for pname
in argNameList
:
153 result
= result
+ '(void *) '
154 result
= result
+ pname
156 result
= result
+ ', '
158 result
= result
+ ')'
167 def FindOffset(funcName
):
168 for (name
, alias
, offset
) in records
:
176 def EmitFunction(name
, returnType
, argTypeList
, argNameList
, alias
, offset
):
177 argList
= apiparser
.MakeArgList(argTypeList
, argNameList
)
178 parms
= MakeParamList(argNameList
)
179 printString
= MakePrintfString(name
, argTypeList
, argNameList
)
185 offset
= FindOffset(dispatchName
)
187 print 'KEYWORD1 %s KEYWORD2 NAME(%s)(%s)' % (returnType
, name
, argList
)
189 if returnType
== 'void':
190 print ' DISPATCH(%s, (%s), %s);' % (dispatchName
, parms
, printString
)
192 print ' RETURN_DISPATCH(%s, (%s), %s);' % (dispatchName
, parms
, printString
)
195 records
.append((name
, dispatchName
, offset
))
196 if not emittedFuncs
.has_key(offset
):
197 emittedFuncs
[offset
] = name
199 aliasedFuncs
.append(name
)
201 print '/* No dispatch for %s() */' % (name
)
205 def PrintInitDispatch():
209 * This is how a dispatch table can be initialized with all the functions
210 * we generated above.
212 #ifdef DISPATCH_TABLE_NAME
215 #error TABLE_ENTRY must be defined
218 void *DISPATCH_TABLE_NAME[] = {"""
219 keys
= emittedFuncs
.keys()
222 print ' TABLE_ENTRY(%s),' % (emittedFuncs
[k
])
224 print ' /* A whole bunch of no-op functions. These might be called'
225 print ' * when someone tries to call a dynamically-registered'
226 print ' * extension function without a current rendering context.'
228 for i
in range(1, 100):
229 print ' TABLE_ENTRY(Unused),'
232 print '#endif /* DISPATCH_TABLE_NAME */'
238 def PrintAliasedTable():
241 * This is just used to silence compiler warnings.
242 * We list the functions which aren't otherwise used.
244 #ifdef UNUSED_TABLE_NAME
245 void *UNUSED_TABLE_NAME[] = {"""
246 for alias
in aliasedFuncs
:
247 print ' TABLE_ENTRY(%s),' % (alias
)
250 print '#endif /*UNUSED_TABLE_NAME*/'
257 apiparser
.ProcessSpecFile("APIspec", EmitFunction
)