3 # $Id: glapitemp.py,v 1.4 2002/01/15 19:04:53 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 GLAPI void GLAPIENTRY 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 Contains(haystack
, needle
):
124 if string
.find(haystack
, needle
) >= 0:
131 def MakePrintfString(funcName
, argTypeList
, argNameList
):
132 result
= '(F, "gl%s(' % (funcName
)
138 for argType
in argTypeList
:
141 if argType
== 'GLenum':
142 result
= result
+ '0x%x'
143 elif argType
in ['GLfloat', 'GLdouble', 'GLclampf', 'GLclampd']:
144 result
= result
+ '%f'
145 elif argType
in ['GLbyte', 'GLubyte', 'GLshort', 'GLushort', 'GLint', 'GLuint', 'GLboolean', 'GLsizei']:
146 result
= result
+ '%d'
148 result
= result
+ '%p'
150 if argType
[0:13] == 'const GLfloat' or argType
[0:14] == 'const GLdouble':
151 if Contains(funcName
, '2fv') or Contains(funcName
, '2dv'):
152 result
= result
+ ' /* %g, %g */'
154 elif Contains(funcName
, '3fv') or Contains(funcName
, '3dv'):
155 result
= result
+ ' /* %g, %g, %g */'
157 elif Contains(funcName
, '4fv') or Contains(funcName
, '4dv'):
158 result
= result
+ ' /* %g, %g, %g, %g */'
162 result
= result
+ ', '
166 result
= result
+ ');\\n"'
171 result
= result
+ ', '
172 for pname
in argNameList
:
174 result
= result
+ '(void *) '
175 result
= result
+ pname
177 result
= result
+ ', ' + pname
+ '[0], ' + pname
+ '[1]'
179 result
= result
+ ', ' + pname
+ '[0], ' + pname
+ '[1], ' + pname
+ '[2]'
181 result
= result
+ ', ' + pname
+ '[0], ' + pname
+ '[1], ' + pname
+ '[2], ' + pname
+ '[3]'
183 result
= result
+ ', '
185 result
= result
+ ')'
194 def FindOffset(funcName
):
195 for (name
, alias
, offset
) in records
:
203 def EmitFunction(name
, returnType
, argTypeList
, argNameList
, alias
, offset
):
204 argList
= apiparser
.MakeArgList(argTypeList
, argNameList
)
205 parms
= MakeParamList(argNameList
)
206 printString
= MakePrintfString(name
, argTypeList
, argNameList
)
212 offset
= FindOffset(dispatchName
)
214 print 'KEYWORD1 %s KEYWORD2 NAME(%s)(%s)' % (returnType
, name
, argList
)
216 if returnType
== 'void':
217 print ' DISPATCH(%s, (%s), %s);' % (dispatchName
, parms
, printString
)
219 print ' RETURN_DISPATCH(%s, (%s), %s);' % (dispatchName
, parms
, printString
)
222 records
.append((name
, dispatchName
, offset
))
223 if not emittedFuncs
.has_key(offset
):
224 emittedFuncs
[offset
] = name
226 aliasedFuncs
.append(name
)
228 print '/* No dispatch for %s() */' % (name
)
232 def PrintInitDispatch():
236 * This is how a dispatch table can be initialized with all the functions
237 * we generated above.
239 #ifdef DISPATCH_TABLE_NAME
242 #error TABLE_ENTRY must be defined
245 void *DISPATCH_TABLE_NAME[] = {"""
246 keys
= emittedFuncs
.keys()
249 print ' TABLE_ENTRY(%s),' % (emittedFuncs
[k
])
251 print ' /* A whole bunch of no-op functions. These might be called'
252 print ' * when someone tries to call a dynamically-registered'
253 print ' * extension function without a current rendering context.'
255 for i
in range(1, 100):
256 print ' TABLE_ENTRY(Unused),'
259 print '#endif /* DISPATCH_TABLE_NAME */'
265 def PrintAliasedTable():
268 * This is just used to silence compiler warnings.
269 * We list the functions which aren't otherwise used.
271 #ifdef UNUSED_TABLE_NAME
272 void *UNUSED_TABLE_NAME[] = {"""
273 for alias
in aliasedFuncs
:
274 print ' TABLE_ENTRY(%s),' % (alias
)
277 print '#endif /*UNUSED_TABLE_NAME*/'
284 apiparser
.ProcessSpecFile("APIspec", EmitFunction
)