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>
32 class PrintGlTable(gl_XML
.gl_print_base
):
33 def __init__(self
, es
=False):
34 gl_XML
.gl_print_base
.__init
__(self
)
37 self
.header_tag
= '_GLAPI_TABLE_H_'
38 self
.name
= "gl_table.py (from Mesa)"
39 self
.license
= license
.bsd_license_template
% ( \
40 """Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
41 (C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM")
42 self
.ifdef_emitted
= False;
46 def printBody(self
, api
):
47 for f
in api
.functionIterateByOffset():
48 if not f
.is_abi() and not self
.ifdef_emitted
:
49 print '#if !defined HAVE_SHARED_GLAPI'
50 self
.ifdef_emitted
= True
51 arg_string
= f
.get_parameter_string()
52 print ' %s (GLAPIENTRYP %s)(%s); /* %d */' % (f
.return_type
, f
.name
, arg_string
, f
.offset
)
54 print '#endif /* !defined HAVE_SHARED_GLAPI */'
57 def printRealHeader(self
):
58 print '#ifndef GLAPIENTRYP'
59 print '# ifndef GLAPIENTRY'
60 print '# define GLAPIENTRY'
63 print '# define GLAPIENTRYP GLAPIENTRY *'
67 print 'struct _glapi_table'
72 def printRealFooter(self
):
77 class PrintRemapTable(gl_XML
.gl_print_base
):
78 def __init__(self
, es
=False):
79 gl_XML
.gl_print_base
.__init
__(self
)
82 self
.header_tag
= '_DISPATCH_H_'
83 self
.name
= "gl_table.py (from Mesa)"
84 self
.license
= license
.bsd_license_template
% ("(C) Copyright IBM Corporation 2005", "IBM")
88 def printRealHeader(self
):
91 * \\file main/dispatch.h
92 * Macros for handling GL dispatch tables.
94 * For each known GL function, there are 3 macros in this file. The first
95 * macro is named CALL_FuncName and is used to call that GL function using
96 * the specified dispatch table. The other 2 macros, called GET_FuncName
97 * can SET_FuncName, are used to get and set the dispatch pointer for the
98 * named function in the specified dispatch table.
103 def printBody(self
, api
):
104 print '#define CALL_by_offset(disp, cast, offset, parameters) \\'
105 print ' (*(cast (GET_by_offset(disp, offset)))) parameters'
106 print '#define GET_by_offset(disp, offset) \\'
107 print ' (offset >= 0) ? (((_glapi_proc *)(disp))[offset]) : NULL'
108 print '#define SET_by_offset(disp, offset, fn) \\'
110 print ' if ( (offset) < 0 ) { \\'
111 print ' /* fprintf( stderr, "[%s:%u] SET_by_offset(%p, %d, %s)!\\n", */ \\'
112 print ' /* __func__, __LINE__, disp, offset, # fn); */ \\'
113 print ' /* abort(); */ \\'
116 print ' ( (_glapi_proc *) (disp) )[offset] = (_glapi_proc) fn; \\'
125 for f
in api
.functionIterateByOffset():
127 functions
.append( [f
, count
] )
130 abi_functions
.append( [f
, -1] )
133 # remember functions with aliases
134 if len(f
.entry_points
) > 1:
135 alias_functions
.append(f
)
137 print '/* total number of offsets below */'
138 print '#define _gloffset_COUNT %d' % (len(abi_functions
+ functions
))
141 for f
, index
in abi_functions
:
142 print '#define _gloffset_%s %d' % (f
.name
, f
.offset
)
145 remap_table
= "esLocalRemapTable"
147 print '#define %s_size %u' % (remap_table
, count
)
148 print 'static int %s[ %s_size ];' % (remap_table
, remap_table
)
151 remap_table
= "driDispatchRemapTable"
153 print '#define %s_size %u' % (remap_table
, count
)
154 print 'extern int %s[ %s_size ];' % (remap_table
, remap_table
)
157 for f
, index
in functions
:
158 print '#define %s_remap_index %u' % (f
.name
, index
)
162 for f
, index
in functions
:
163 print '#define _gloffset_%s %s[%s_remap_index]' % (f
.name
, remap_table
, f
.name
)
167 for f
, index
in abi_functions
+ functions
:
168 arg_string
= gl_XML
.create_parameter_string( f
.parameters
, 0 )
170 print 'typedef %s (GLAPIENTRYP _glptr_%s)(%s);' % (f
.return_type
, f
.name
, arg_string
)
171 print '#define CALL_%s(disp, parameters) \\' % (f
.name
)
172 print ' (* GET_%s(disp)) parameters' % (f
.name
)
173 print 'static inline _glptr_%s GET_%s(struct _glapi_table *disp) {' % (f
.name
, f
.name
)
174 print ' return (_glptr_%s) (GET_by_offset(disp, _gloffset_%s));' % (f
.name
, f
.name
)
177 print 'static inline void SET_%s(struct _glapi_table *disp, %s (GLAPIENTRYP fn)(%s)) {' % (f
.name
, f
.return_type
, arg_string
)
178 print ' SET_by_offset(disp, _gloffset_%s, fn);' % (f
.name
)
184 print '/* define aliases for compatibility */'
185 for f
in alias_functions
:
186 for name
in f
.entry_points
:
188 print '#define CALL_%s(disp, parameters) CALL_%s(disp, parameters)' % (name
, f
.name
)
189 print '#define GET_%s(disp) GET_%s(disp)' % (name
, f
.name
)
190 print '#define SET_%s(disp, fn) SET_%s(disp, fn)' % (name
, f
.name
)
193 for f
in alias_functions
:
194 for name
in f
.entry_points
:
196 print '#define %s_remap_index %s_remap_index' % (name
, f
.name
)
203 print "Usage: %s [-f input_file_name] [-m mode] [-c ver]" % sys
.argv
[0]
204 print " -m mode Mode can be 'table' or 'remap_table'."
205 print " -c ver Version can be 'es1' or 'es2'."
208 if __name__
== '__main__':
209 file_name
= "gl_API.xml"
212 (args
, trail
) = getopt
.getopt(sys
.argv
[1:], "f:m:c:")
218 for (arg
,val
) in args
:
227 printer
= PrintGlTable(es
)
228 elif mode
== "remap_table":
229 printer
= PrintRemapTable(es
)
233 api
= gl_XML
.parse_GL_API( file_name
)
236 api
.filter_functions_by_api(es
)