b210c704a74af388f8083d2957d68e6d4c0bdb83
3 # (C) Copyright IBM Corporation 2004
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>
28 from xml
.sax
import saxutils
29 from xml
.sax
import make_parser
30 from xml
.sax
.handler
import feature_namespaces
36 class PrintGlOffsets(gl_XML
.FilterGLAPISpecBase
):
37 name
= "gl_apitemp.py (from Mesa)"
40 gl_XML
.FilterGLAPISpecBase
.__init
__(self
)
41 self
.license
= license
.bsd_license_template
% ( \
42 """Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
43 (C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM")
45 def printFunction(self
, f
):
56 cast
= "(const void *) "
57 elif p
.p_type_string
== 'GLenum':
59 elif p
.p_type_string
in ['GLfloat', 'GLdouble', 'GLclampf', 'GLclampd']:
64 t_string
= t_string
+ comma
+ t
65 p_string
= p_string
+ comma
+ p
.name
66 o_string
= o_string
+ comma
+ cast
+ p
.name
70 if f
.fn_return_type
!= 'void':
71 dispatch
= "RETURN_DISPATCH"
75 print 'KEYWORD1 %s KEYWORD2 NAME(%s)(%s)' \
76 % (f
.fn_return_type
, f
.name
, f
.get_parameter_string())
79 print ' %s(%s, (), (F, "gl%s();\\n"));' \
80 % (dispatch
, f
.real_name
, f
.name
)
82 print ' %s(%s, (%s), (F, "gl%s(%s);\\n", %s));' \
83 % (dispatch
, f
.real_name
, p_string
, f
.name
, t_string
, o_string
)
88 def printRealHeader(self
):
91 * This file is a template which generates the OpenGL API entry point
92 * functions. It should be included by a .c file which first defines
93 * the following macros:
94 * KEYWORD1 - usually nothing, but might be __declspec(dllexport) on Win32
95 * KEYWORD2 - usually nothing, but might be __stdcall on Win32
96 * NAME(n) - builds the final function name (usually add "gl" prefix)
97 * DISPATCH(func, args, msg) - code to do dispatch of named function.
98 * msg is a printf-style debug message.
99 * RETURN_DISPATCH(func, args, msg) - code to do dispatch with a return value
101 * Here is an example which generates the usual OpenGL functions:
104 * #define NAME(func) gl##func
105 * #define DISPATCH(func, args, msg) \\
106 * struct _glapi_table *dispatch = CurrentDispatch; \\
107 * (*dispatch->func) args
108 * #define RETURN DISPATCH(func, args, msg) \\
109 * struct _glapi_table *dispatch = CurrentDispatch; \\
110 * return (*dispatch->func) args
124 #error NAME must be defined
128 #error DISPATCH must be defined
131 #ifndef RETURN_DISPATCH
132 #error RETURN_DISPATCH must be defined
135 GLAPI void GLAPIENTRY gl__unused413(void); /* silence warning */
141 def printInitDispatch(self
):
145 * This is how a dispatch table can be initialized with all the functions
146 * we generated above.
148 #ifdef DISPATCH_TABLE_NAME
151 #error TABLE_ENTRY must be defined
154 static void * DISPATCH_TABLE_NAME[] = {"""
155 keys
= self
.functions
.keys()
160 print ' TABLE_ENTRY(%s),' % (self
.functions
[k
].name
)
162 print ' /* A whole bunch of no-op functions. These might be called'
163 print ' * when someone tries to call a dynamically-registered'
164 print ' * extension function without a current rendering context.'
166 for i
in range(1, 100):
167 print ' TABLE_ENTRY(Unused),'
170 print '#endif /* DISPATCH_TABLE_NAME */'
174 def printAliasedTable(self
):
177 * This is just used to silence compiler warnings.
178 * We list the functions which are not otherwise used.
180 #ifdef UNUSED_TABLE_NAME
181 static const void * const UNUSED_TABLE_NAME[] = {"""
183 keys
= self
.functions
.keys()
187 f
= self
.functions
[k
]
189 print ' TABLE_ENTRY(%s),' % (f
.name
)
192 print '#endif /*UNUSED_TABLE_NAME*/'
196 def printRealFooter(self
):
197 self
.printInitDispatch()
198 self
.printAliasedTable()
204 #undef RETURN_DISPATCH
205 #undef DISPATCH_TABLE_NAME
206 #undef UNUSED_TABLE_NAME
212 print "Usage: %s [-f input_file_name]" % sys
.argv
[0]
215 if __name__
== '__main__':
216 file_name
= "gl_API.xml"
219 (args
, trail
) = getopt
.getopt(sys
.argv
[1:], "f:")
223 for (arg
,val
) in args
:
227 dh
= PrintGlOffsets()
229 parser
= make_parser()
230 parser
.setFeature(feature_namespaces
, 0)
231 parser
.setContentHandler(dh
)