Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1901 serge 1
#!/usr/bin/python2
2
 
3
# (C) Copyright IBM Corporation 2004
4
# All Rights Reserved.
5
#
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:
12
#
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
15
# Software.
16
#
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
23
# IN THE SOFTWARE.
24
#
25
# Authors:
26
#    Ian Romanick 
27
 
28
import gl_XML
29
import license
30
import sys, getopt
31
 
32
class PrintGlTable(gl_XML.gl_print_base):
33
	def __init__(self, es=False):
34
		gl_XML.gl_print_base.__init__(self)
35
 
36
		self.es = es
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
		return
43
 
44
 
45
	def printBody(self, api):
46
		for f in api.functionIterateByOffset():
47
			arg_string = f.get_parameter_string()
48
			print '   %s (GLAPIENTRYP %s)(%s); /* %d */' % (f.return_type, f.name, arg_string, f.offset)
49
 
50
 
51
	def printRealHeader(self):
52
		print '#ifndef GLAPIENTRYP'
53
		print '# ifndef GLAPIENTRY'
54
		print '#  define GLAPIENTRY'
55
		print '# endif'
56
		print ''
57
		print '# define GLAPIENTRYP GLAPIENTRY *'
58
		print '#endif'
59
		print ''
60
		print ''
61
		print 'struct _glapi_table'
62
		print '{'
63
		return
64
 
65
 
66
	def printRealFooter(self):
67
		print '};'
68
		return
69
 
70
 
71
class PrintRemapTable(gl_XML.gl_print_base):
72
	def __init__(self, es=False):
73
		gl_XML.gl_print_base.__init__(self)
74
 
75
		self.es = es
76
		self.header_tag = '_GLAPI_DISPATCH_H_'
77
		self.name = "gl_table.py (from Mesa)"
78
		self.license = license.bsd_license_template % ("(C) Copyright IBM Corporation 2005", "IBM")
79
		return
80
 
81
 
82
	def printRealHeader(self):
83
		print """
84
/* this file should not be included directly in mesa */
85
 
86
/**
87
 * \\file glapidispatch.h
88
 * Macros for handling GL dispatch tables.
89
 *
90
 * For each known GL function, there are 3 macros in this file.  The first
91
 * macro is named CALL_FuncName and is used to call that GL function using
92
 * the specified dispatch table.  The other 2 macros, called GET_FuncName
93
 * can SET_FuncName, are used to get and set the dispatch pointer for the
94
 * named function in the specified dispatch table.
95
 */
96
"""
97
 
98
		return
99
 
100
	def printBody(self, api):
101
		print '#define CALL_by_offset(disp, cast, offset, parameters) \\'
102
		print '    (*(cast (GET_by_offset(disp, offset)))) parameters'
103
		print '#define GET_by_offset(disp, offset) \\'
104
		print '    (offset >= 0) ? (((_glapi_proc *)(disp))[offset]) : NULL'
105
		print '#define SET_by_offset(disp, offset, fn) \\'
106
		print '    do { \\'
107
		print '        if ( (offset) < 0 ) { \\'
108
		print '            /* fprintf( stderr, "[%s:%u] SET_by_offset(%p, %d, %s)!\\n", */ \\'
109
		print '            /*         __func__, __LINE__, disp, offset, # fn); */ \\'
110
		print '            /* abort(); */ \\'
111
		print '        } \\'
112
		print '        else { \\'
113
		print '            ( (_glapi_proc *) (disp) )[offset] = (_glapi_proc) fn; \\'
114
		print '        } \\'
115
		print '    } while(0)'
116
		print ''
117
 
118
		functions = []
119
		abi_functions = []
120
		alias_functions = []
121
		count = 0
122
		for f in api.functionIterateByOffset():
123
			if not f.is_abi():
124
				functions.append( [f, count] )
125
				count += 1
126
			else:
127
				abi_functions.append( [f, -1] )
128
 
129
			if self.es:
130
				# remember functions with aliases
131
				if len(f.entry_points) > 1:
132
					alias_functions.append(f)
133
 
134
		print '/* total number of offsets below */'
135
		print '#define _gloffset_COUNT %d' % (len(abi_functions + functions))
136
		print ''
137
 
138
		for f, index in abi_functions:
139
			print '#define _gloffset_%s %d' % (f.name, f.offset)
140
 
141
		print ''
142
		print '#if !defined(_GLAPI_USE_REMAP_TABLE)'
143
		print ''
144
 
145
		for f, index in functions:
146
			print '#define _gloffset_%s %d' % (f.name, f.offset)
147
 
148
		print ''
149
		print '#else /* !_GLAPI_USE_REMAP_TABLE */'
150
		print ''
151
 
152
		print '#define driDispatchRemapTable_size %u' % (count)
153
		print 'extern int driDispatchRemapTable[ driDispatchRemapTable_size ];'
154
		print ''
155
 
156
		for f, index in functions:
157
			print '#define %s_remap_index %u' % (f.name, index)
158
 
159
		print ''
160
 
161
		for f, index in functions:
162
			print '#define _gloffset_%s driDispatchRemapTable[%s_remap_index]' % (f.name, f.name)
163
 
164
		print ''
165
		print '#endif /* _GLAPI_USE_REMAP_TABLE */'
166
		print ''
167
 
168
		for f, index in abi_functions + functions:
169
			arg_string = gl_XML.create_parameter_string( f.parameters, 0 )
170
			cast = '%s (GLAPIENTRYP)(%s)' % (f.return_type, arg_string)
171
 
172
			print '#define CALL_%s(disp, parameters) CALL_by_offset(disp, (%s), _gloffset_%s, parameters)' % (f.name, cast, f.name)
173
			print '#define GET_%s(disp) GET_by_offset(disp, _gloffset_%s)' % (f.name, f.name)
174
			print '#define SET_%s(disp, fn) SET_by_offset(disp, _gloffset_%s, fn)' % (f.name, f.name)
175
 
176
		if alias_functions:
177
			print ''
178
			print '/* define aliases for compatibility */'
179
			for f in alias_functions:
180
				for name in f.entry_points:
181
					if name != f.name:
182
						print '#define CALL_%s(disp, parameters) CALL_%s(disp, parameters)' % (name, f.name)
183
						print '#define GET_%s(disp) GET_%s(disp)' % (name, f.name)
184
						print '#define SET_%s(disp, fn) SET_%s(disp, fn)' % (name, f.name)
185
			print ''
186
 
187
			print '#if defined(_GLAPI_USE_REMAP_TABLE)'
188
			for f in alias_functions:
189
				for name in f.entry_points:
190
					if name != f.name:
191
						print '#define %s_remap_index %s_remap_index' % (name, f.name)
192
			print '#endif /* defined(_GLAPI_USE_REMAP_TABLE) */'
193
			print ''
194
 
195
		return
196
 
197
 
198
def show_usage():
199
	print "Usage: %s [-f input_file_name] [-m mode] [-c]" % sys.argv[0]
200
	print "    -m mode   Mode can be 'table' or 'remap_table'."
201
	print "    -c        Enable compatibility with OpenGL ES."
202
	sys.exit(1)
203
 
204
if __name__ == '__main__':
205
	file_name = "gl_API.xml"
206
 
207
	try:
208
		(args, trail) = getopt.getopt(sys.argv[1:], "f:m:c")
209
	except Exception,e:
210
		show_usage()
211
 
212
	mode = "table"
213
	es = False
214
	for (arg,val) in args:
215
		if arg == "-f":
216
			file_name = val
217
		elif arg == "-m":
218
			mode = val
219
		elif arg == "-c":
220
			es = True
221
 
222
	if mode == "table":
223
		printer = PrintGlTable(es)
224
	elif mode == "remap_table":
225
		printer = PrintRemapTable(es)
226
	else:
227
		show_usage()
228
 
229
	api = gl_XML.parse_GL_API( file_name )
230
 
231
	printer.Print( api )