3 # (C) Copyright IBM Corporation 2004
5 # Copyright (c) 2014 Intel Corporation
7 # Permission is hereby granted, free of charge, to any person obtaining a
8 # copy of this software and associated documentation files (the "Software"),
9 # to deal in the Software without restriction, including without limitation
10 # on the rights to use, copy, modify, merge, publish, distribute, sub
11 # license, and/or sell copies of the Software, and to permit persons to whom
12 # the Software is furnished to do so, subject to the following conditions:
14 # The above copyright notice and this permission notice (including the next
15 # paragraph) shall be included in all copies or substantial portions of the
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 # IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 # Ian Romanick <idr@us.ibm.com>
35 class PrintGlTable(gl_XML
.gl_print_base
):
36 def __init__(self
, es
=False):
37 gl_XML
.gl_print_base
.__init
__(self
)
40 self
.header_tag
= '_GLAPI_TABLE_H_'
41 self
.name
= "gl_table.py (from Mesa)"
42 self
.license
= license
.bsd_license_template
% ( \
43 """Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
44 (C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM")
45 self
.ifdef_emitted
= False
48 def printBody(self
, api
):
49 for f
in api
.functionIterateByOffset():
50 if not f
.is_abi() and not self
.ifdef_emitted
:
51 print '#if !defined HAVE_SHARED_GLAPI'
52 self
.ifdef_emitted
= True
53 arg_string
= f
.get_parameter_string()
54 print ' %s (GLAPIENTRYP %s)(%s); /* %d */' % (
55 f
.return_type
, f
.name
, arg_string
, f
.offset
)
57 print '#endif /* !defined HAVE_SHARED_GLAPI */'
59 def printRealHeader(self
):
60 print '#ifndef GLAPIENTRYP'
61 print '# ifndef GLAPIENTRY'
62 print '# define GLAPIENTRY'
65 print '# define GLAPIENTRYP GLAPIENTRY *'
69 print 'struct _glapi_table'
73 def printRealFooter(self
):
78 class PrintRemapTable(gl_XML
.gl_print_base
):
79 def __init__(self
, es
=False):
80 gl_XML
.gl_print_base
.__init
__(self
)
83 self
.header_tag
= '_DISPATCH_H_'
84 self
.name
= "gl_table.py (from Mesa)"
85 self
.license
= license
.bsd_license_template
% (
86 "(C) Copyright IBM Corporation 2005", "IBM")
90 def printRealHeader(self
):
93 * \\file main/dispatch.h
94 * Macros for handling GL dispatch tables.
96 * For each known GL function, there are 3 macros in this file. The first
97 * macro is named CALL_FuncName and is used to call that GL function using
98 * the specified dispatch table. The other 2 macros, called GET_FuncName
99 * can SET_FuncName, are used to get and set the dispatch pointer for the
100 * named function in the specified dispatch table.
106 def printBody(self
, api
):
107 print '#define CALL_by_offset(disp, cast, offset, parameters) \\'
108 print ' (*(cast (GET_by_offset(disp, offset)))) parameters'
109 print '#define GET_by_offset(disp, offset) \\'
110 print ' (offset >= 0) ? (((_glapi_proc *)(disp))[offset]) : NULL'
111 print '#define SET_by_offset(disp, offset, fn) \\'
113 print ' if ( (offset) < 0 ) { \\'
114 print ' /* fprintf( stderr, "[%s:%u] SET_by_offset(%p, %d, %s)!\\n", */ \\'
115 print ' /* __func__, __LINE__, disp, offset, # fn); */ \\'
116 print ' /* abort(); */ \\'
119 print ' ( (_glapi_proc *) (disp) )[offset] = (_glapi_proc) fn; \\'
128 for f
in api
.functionIterateByOffset():
130 functions
.append([f
, count
])
133 abi_functions
.append([f
, -1])
136 # remember functions with aliases
137 if len(f
.entry_points
) > 1:
138 alias_functions
.append(f
)
140 print '/* total number of offsets below */'
141 print '#define _gloffset_COUNT %d' % (len(abi_functions
+ functions
))
144 for f
, index
in abi_functions
:
145 print '#define _gloffset_%s %d' % (f
.name
, f
.offset
)
148 remap_table
= "esLocalRemapTable"
150 print '#define %s_size %u' % (remap_table
, count
)
151 print 'static int %s[ %s_size ];' % (remap_table
, remap_table
)
154 remap_table
= "driDispatchRemapTable"
156 print '#define %s_size %u' % (remap_table
, count
)
157 print 'extern int %s[ %s_size ];' % (remap_table
, remap_table
)
160 for f
, index
in functions
:
161 print '#define %s_remap_index %u' % (f
.name
, index
)
165 for f
, index
in functions
:
166 print '#define _gloffset_%s %s[%s_remap_index]' % (f
.name
, remap_table
, f
.name
)
170 for f
, index
in abi_functions
+ functions
:
171 arg_string
= gl_XML
.create_parameter_string(f
.parameters
, 0)
173 print 'typedef %s (GLAPIENTRYP _glptr_%s)(%s);' % (f
.return_type
, f
.name
, arg_string
)
174 print '#define CALL_%s(disp, parameters) \\' % (f
.name
)
175 print ' (* GET_%s(disp)) parameters' % (f
.name
)
176 print 'static inline _glptr_%s GET_%s(struct _glapi_table *disp) {' % (f
.name
, f
.name
)
177 print ' return (_glptr_%s) (GET_by_offset(disp, _gloffset_%s));' % (f
.name
, f
.name
)
180 print 'static inline void SET_%s(struct _glapi_table *disp, %s (GLAPIENTRYP fn)(%s)) {' % (f
.name
, f
.return_type
, arg_string
)
181 print ' SET_by_offset(disp, _gloffset_%s, fn);' % (f
.name
)
187 print '/* define aliases for compatibility */'
188 for f
in alias_functions
:
189 for name
in f
.entry_points
:
191 print '#define CALL_%s(disp, parameters) CALL_%s(disp, parameters)' % (name
, f
.name
)
192 print '#define GET_%s(disp) GET_%s(disp)' % (name
, f
.name
)
193 print '#define SET_%s(disp, fn) SET_%s(disp, fn)' % (name
, f
.name
)
196 for f
in alias_functions
:
197 for name
in f
.entry_points
:
199 print '#define %s_remap_index %s_remap_index' % (name
, f
.name
)
206 """Parse arguments and return a namespace."""
207 parser
= argparse
.ArgumentParser()
208 parser
.add_argument('-f', '--filename',
209 default
='gl_API.xml',
210 metavar
="input_file_name",
212 help="Path to an XML description of OpenGL API.")
213 parser
.add_argument('-m', '--mode',
214 choices
=['table', 'remap_table'],
217 help="Generate either a table or a remap_table")
218 parser
.add_argument('-c', '--es-version',
219 choices
=[None, 'es1', 'es2'],
223 help="filter functions for es")
224 return parser
.parse_args()
231 api
= gl_XML
.parse_GL_API(args
.file_name
)
233 if args
.mode
== "table":
234 printer
= PrintGlTable(args
.es
)
235 elif args
.mode
== "remap_table":
236 printer
= PrintRemapTable(args
.es
)
238 if args
.es
is not None:
239 api
.filter_functions_by_api(args
.es
)
244 if __name__
== '__main__':