3 # $Id: glapitemp.py,v 1.6 2004/06/29 19:08:20 idr 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
80 #error DISPATCH must be defined
83 #ifndef RETURN_DISPATCH
84 #error RETURN_DISPATCH must be defined
87 GLAPI void GLAPIENTRY gl__unused413(void); /* silence warning */
99 #undef RETURN_DISPATCH
100 #undef DISPATCH_TABLE_NAME
101 #undef UNUSED_TABLE_NAME
107 def MakeParamList(nameList
):
111 for name
in nameList
:
112 result
= result
+ name
114 result
= result
+ ', '
120 def Contains(haystack
, needle
):
121 if string
.find(haystack
, needle
) >= 0:
128 def MakePrintfString(funcName
, argTypeList
, argNameList
):
129 result
= '(F, "gl%s(' % (funcName
)
135 for argType
in argTypeList
:
138 if argType
== 'GLenum':
139 result
= result
+ '0x%x'
140 elif argType
in ['GLfloat', 'GLdouble', 'GLclampf', 'GLclampd']:
141 result
= result
+ '%f'
142 elif argType
in ['GLbyte', 'GLubyte', 'GLshort', 'GLushort', 'GLint', 'GLuint', 'GLboolean', 'GLsizei']:
143 result
= result
+ '%d'
145 result
= result
+ '%p'
147 if argType
[0:13] == 'const GLfloat' or argType
[0:14] == 'const GLdouble':
148 if Contains(funcName
, '2fv') or Contains(funcName
, '2dv'):
149 result
= result
+ ' /* %g, %g */'
151 elif Contains(funcName
, '3fv') or Contains(funcName
, '3dv'):
152 result
= result
+ ' /* %g, %g, %g */'
154 elif Contains(funcName
, '4fv') or Contains(funcName
, '4dv'):
155 result
= result
+ ' /* %g, %g, %g, %g */'
159 result
= result
+ ', '
163 result
= result
+ ');\\n"'
168 result
= result
+ ', '
169 for pname
in argNameList
:
171 result
= result
+ '(const void *) '
172 result
= result
+ pname
174 result
= result
+ ', ' + pname
+ '[0], ' + pname
+ '[1]'
176 result
= result
+ ', ' + pname
+ '[0], ' + pname
+ '[1], ' + pname
+ '[2]'
178 result
= result
+ ', ' + pname
+ '[0], ' + pname
+ '[1], ' + pname
+ '[2], ' + pname
+ '[3]'
180 result
= result
+ ', '
182 result
= result
+ ')'
191 def FindOffset(funcName
):
192 for (name
, alias
, offset
) in records
:
200 def EmitFunction(name
, returnType
, argTypeList
, argNameList
, alias
, offset
):
201 argList
= apiparser
.MakeArgList(argTypeList
, argNameList
)
202 parms
= MakeParamList(argNameList
)
203 printString
= MakePrintfString(name
, argTypeList
, argNameList
)
209 offset
= FindOffset(dispatchName
)
211 print 'KEYWORD1 %s KEYWORD2 NAME(%s)(%s)' % (returnType
, name
, argList
)
213 if returnType
== 'void':
214 print ' DISPATCH(%s, (%s), %s);' % (dispatchName
, parms
, printString
)
216 print ' RETURN_DISPATCH(%s, (%s), %s);' % (dispatchName
, parms
, printString
)
219 records
.append((name
, dispatchName
, offset
))
220 if not emittedFuncs
.has_key(offset
):
221 emittedFuncs
[offset
] = name
223 aliasedFuncs
.append(name
)
225 print '/* No dispatch for %s() */' % (name
)
229 def PrintInitDispatch():
231 #endif /* defined( NAME ) */
234 * This is how a dispatch table can be initialized with all the functions
235 * we generated above.
237 #ifdef DISPATCH_TABLE_NAME
240 #error TABLE_ENTRY must be defined
243 void *DISPATCH_TABLE_NAME[] = {"""
244 keys
= emittedFuncs
.keys()
247 print ' TABLE_ENTRY(%s),' % (emittedFuncs
[k
])
249 print ' /* A whole bunch of no-op functions. These might be called'
250 print ' * when someone tries to call a dynamically-registered'
251 print ' * extension function without a current rendering context.'
253 for i
in range(1, 100):
254 print ' TABLE_ENTRY(Unused),'
257 print '#endif /* DISPATCH_TABLE_NAME */'
263 def PrintAliasedTable():
266 * This is just used to silence compiler warnings.
267 * We list the functions which aren't otherwise used.
269 #ifdef UNUSED_TABLE_NAME
270 void *UNUSED_TABLE_NAME[] = {"""
271 for alias
in aliasedFuncs
:
272 print ' TABLE_ENTRY(%s),' % (alias
)
275 print '#endif /*UNUSED_TABLE_NAME*/'
282 apiparser
.ProcessSpecFile("APIspec", EmitFunction
)