cb87dbd62b0b65ece619cd646a2f7b5b827f4f75
3 # (C) Copyright IBM Corporation 2004, 2005
6 # Permission is hereby granted, free of charge, to any person obtaining a
7 # copy of this software and associated documentation files (the "Software"),
8 # to deal in the Software without restriction, including without limitation
9 # on the rights to use, copy, modify, merge, publish, distribute, sub
10 # license, and/or sell copies of the Software, and to permit persons to whom
11 # the Software is furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice (including the next
14 # paragraph) shall be included in all copies or substantial portions of the
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 # IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 # Ian Romanick <idr@us.ibm.com>
32 class PrintGlOffsets(gl_XML
.gl_print_base
):
34 gl_XML
.gl_print_base
.__init
__(self
)
36 self
.name
= "gl_apitemp.py (from Mesa)"
37 self
.license
= license
.bsd_license_template
% ( \
38 """Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
39 (C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM")
41 self
.undef_list
.append( "KEYWORD1" )
42 self
.undef_list
.append( "KEYWORD1_ALT" )
43 self
.undef_list
.append( "KEYWORD2" )
44 self
.undef_list
.append( "NAME" )
45 self
.undef_list
.append( "DISPATCH" )
46 self
.undef_list
.append( "RETURN_DISPATCH" )
47 self
.undef_list
.append( "DISPATCH_TABLE_NAME" )
48 self
.undef_list
.append( "UNUSED_TABLE_NAME" )
49 self
.undef_list
.append( "TABLE_ENTRY" )
52 def printFunction(self
, f
, name
):
58 if f
.is_static_entry_point(name
):
61 keyword
= "KEYWORD1_ALT"
63 n
= f
.static_name(name
)
65 for p
in f
.parameterIterator():
67 cast
= "(const void *) "
71 t_string
= t_string
+ comma
+ p
.format_string()
72 p_string
= p_string
+ comma
+ p
.name
73 o_string
= o_string
+ comma
+ cast
+ p
.name
77 if f
.return_type
!= 'void':
78 dispatch
= "RETURN_DISPATCH"
82 if not f
.is_static_entry_point(name
):
83 print '%s %s KEYWORD2 NAME(%s)(%s);' % (keyword
, f
.return_type
, n
, f
.get_parameter_string(name
))
86 print '%s %s KEYWORD2 NAME(%s)(%s)' % (keyword
, f
.return_type
, n
, f
.get_parameter_string(name
))
89 print ' %s(%s, (), (F, "gl%s();\\n"));' \
90 % (dispatch
, f
.name
, name
)
92 print ' %s(%s, (%s), (F, "gl%s(%s);\\n", %s));' \
93 % (dispatch
, f
.name
, p_string
, name
, t_string
, o_string
)
98 def printRealHeader(self
):
100 self
.printVisibility( "HIDDEN", "hidden" )
103 * This file is a template which generates the OpenGL API entry point
104 * functions. It should be included by a .c file which first defines
105 * the following macros:
106 * KEYWORD1 - usually nothing, but might be __declspec(dllexport) on Win32
107 * KEYWORD2 - usually nothing, but might be __stdcall on Win32
108 * NAME(n) - builds the final function name (usually add "gl" prefix)
109 * DISPATCH(func, args, msg) - code to do dispatch of named function.
110 * msg is a printf-style debug message.
111 * RETURN_DISPATCH(func, args, msg) - code to do dispatch with a return value
113 * Here is an example which generates the usual OpenGL functions:
116 * #define NAME(func) gl##func
117 * #define DISPATCH(func, args, msg) \\
118 * struct _glapi_table *dispatch = CurrentDispatch; \\
119 * (*dispatch->func) args
120 * #define RETURN DISPATCH(func, args, msg) \\
121 * struct _glapi_table *dispatch = CurrentDispatch; \\
122 * return (*dispatch->func) args
133 #define KEYWORD1_ALT HIDDEN
141 #error DISPATCH must be defined
144 #ifndef RETURN_DISPATCH
145 #error RETURN_DISPATCH must be defined
153 def printInitDispatch(self
, api
):
155 #endif /* defined( NAME ) */
158 * This is how a dispatch table can be initialized with all the functions
159 * we generated above.
161 #ifdef DISPATCH_TABLE_NAME
164 #error TABLE_ENTRY must be defined
167 static _glapi_proc DISPATCH_TABLE_NAME[] = {"""
168 for f
in api
.functionIterateByOffset():
169 print ' TABLE_ENTRY(%s),' % (f
.dispatch_name())
171 print ' /* A whole bunch of no-op functions. These might be called'
172 print ' * when someone tries to call a dynamically-registered'
173 print ' * extension function without a current rendering context.'
175 for i
in range(1, 100):
176 print ' TABLE_ENTRY(Unused),'
179 print '#endif /* DISPATCH_TABLE_NAME */'
184 def printAliasedTable(self
, api
):
187 * This is just used to silence compiler warnings.
188 * We list the functions which are not otherwise used.
190 #ifdef UNUSED_TABLE_NAME
191 static _glapi_proc UNUSED_TABLE_NAME[] = {"""
193 for f
in api
.functionIterateByOffset():
194 for n
in f
.entry_points
:
196 if f
.is_static_entry_point(n
):
197 print ' TABLE_ENTRY(%s),' % (n
)
200 print '#endif /*UNUSED_TABLE_NAME*/'
205 def printBody(self
, api
):
206 for func
in api
.functionIterateByOffset():
208 for n
in func
.entry_points
:
209 if func
.is_static_entry_point(n
):
210 self
.printFunction(func
, n
)
212 self
.printFunction(func
, n
)
215 self
.printInitDispatch(api
)
216 self
.printAliasedTable(api
)
221 print "Usage: %s [-f input_file_name]" % sys
.argv
[0]
224 if __name__
== '__main__':
225 file_name
= "gl_API.xml"
228 (args
, trail
) = getopt
.getopt(sys
.argv
[1:], "f:")
232 for (arg
,val
) in args
:
236 api
= gl_XML
.parse_GL_API( file_name
)
238 printer
= PrintGlOffsets()