e25971a698c3e4430ac90d55590b5b66ac074588
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
):
37 gl_XML
.gl_print_base
.__init
__(self
)
39 self
.header_tag
= '_GLAPI_TABLE_H_'
40 self
.name
= "gl_table.py (from Mesa)"
41 self
.license
= license
.bsd_license_template
% ( \
42 """Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
43 (C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM")
44 self
.ifdef_emitted
= False
47 def printBody(self
, api
):
48 for f
in api
.functionIterateByOffset():
49 if not f
.is_abi() and not self
.ifdef_emitted
:
50 print '#if !defined HAVE_SHARED_GLAPI'
51 self
.ifdef_emitted
= True
52 arg_string
= f
.get_parameter_string()
53 print ' %s (GLAPIENTRYP %s)(%s); /* %d */' % (
54 f
.return_type
, f
.name
, arg_string
, f
.offset
)
56 print '#endif /* !defined HAVE_SHARED_GLAPI */'
58 def printRealHeader(self
):
59 print '#ifndef GLAPIENTRYP'
60 print '# ifndef GLAPIENTRY'
61 print '# define GLAPIENTRY'
64 print '# define GLAPIENTRYP GLAPIENTRY *'
68 print 'struct _glapi_table'
72 def printRealFooter(self
):
77 class PrintRemapTable(gl_XML
.gl_print_base
):
79 gl_XML
.gl_print_base
.__init
__(self
)
81 self
.header_tag
= '_DISPATCH_H_'
82 self
.name
= "gl_table.py (from Mesa)"
83 self
.license
= license
.bsd_license_template
% (
84 "(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.
104 def printBody(self
, api
):
105 print '#define CALL_by_offset(disp, cast, offset, parameters) \\'
106 print ' (*(cast (GET_by_offset(disp, offset)))) parameters'
107 print '#define GET_by_offset(disp, offset) \\'
108 print ' (offset >= 0) ? (((_glapi_proc *)(disp))[offset]) : NULL'
109 print '#define SET_by_offset(disp, offset, fn) \\'
111 print ' if ( (offset) < 0 ) { \\'
112 print ' /* fprintf( stderr, "[%s:%u] SET_by_offset(%p, %d, %s)!\\n", */ \\'
113 print ' /* __func__, __LINE__, disp, offset, # fn); */ \\'
114 print ' /* abort(); */ \\'
117 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])
132 print '/* total number of offsets below */'
133 print '#define _gloffset_COUNT %d' % (len(abi_functions
+ functions
))
136 for f
, index
in abi_functions
:
137 print '#define _gloffset_%s %d' % (f
.name
, f
.offset
)
139 remap_table
= "driDispatchRemapTable"
141 print '#define %s_size %u' % (remap_table
, count
)
142 print 'extern int %s[ %s_size ];' % (remap_table
, remap_table
)
145 for f
, index
in functions
:
146 print '#define %s_remap_index %u' % (f
.name
, index
)
150 for f
, index
in functions
:
151 print '#define _gloffset_%s %s[%s_remap_index]' % (f
.name
, remap_table
, f
.name
)
155 for f
, index
in abi_functions
+ functions
:
156 arg_string
= gl_XML
.create_parameter_string(f
.parameters
, 0)
158 print 'typedef %s (GLAPIENTRYP _glptr_%s)(%s);' % (f
.return_type
, f
.name
, arg_string
)
159 print '#define CALL_%s(disp, parameters) \\' % (f
.name
)
160 print ' (* GET_%s(disp)) parameters' % (f
.name
)
161 print 'static inline _glptr_%s GET_%s(struct _glapi_table *disp) {' % (f
.name
, f
.name
)
162 print ' return (_glptr_%s) (GET_by_offset(disp, _gloffset_%s));' % (f
.name
, f
.name
)
165 print 'static inline void SET_%s(struct _glapi_table *disp, %s (GLAPIENTRYP fn)(%s)) {' % (f
.name
, f
.return_type
, arg_string
)
166 print ' SET_by_offset(disp, _gloffset_%s, fn);' % (f
.name
)
174 """Parse arguments and return a namespace."""
175 parser
= argparse
.ArgumentParser()
176 parser
.add_argument('-f', '--filename',
177 default
='gl_API.xml',
178 metavar
="input_file_name",
180 help="Path to an XML description of OpenGL API.")
181 parser
.add_argument('-m', '--mode',
182 choices
=['table', 'remap_table'],
185 help="Generate either a table or a remap_table")
186 return parser
.parse_args()
193 api
= gl_XML
.parse_GL_API(args
.file_name
)
195 if args
.mode
== "table":
196 printer
= PrintGlTable()
197 elif args
.mode
== "remap_table":
198 printer
= PrintRemapTable()
203 if __name__
== '__main__':