blob: 4c16a68cb6b29da9a41f9e5b4718f1e735f4a950 [file] [log] [blame]
Ian Romanick74764062004-12-03 20:31:59 +00001#!/usr/bin/python2
2
Ian Romanick5f1f2292005-01-07 02:39:09 +00003# (C) Copyright IBM Corporation 2004, 2005
Ian Romanick74764062004-12-03 20:31:59 +00004# 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 <idr@us.ibm.com>
27
28from xml.sax import saxutils
29from xml.sax import make_parser
30from xml.sax.handler import feature_namespaces
31
32import gl_XML
33import license
Ian Romanick3fec8c22005-02-02 00:54:45 +000034import sys, getopt, string
Ian Romanick74764062004-12-03 20:31:59 +000035
36
Ian Romanick74764062004-12-03 20:31:59 +000037class glXItemFactory(gl_XML.glItemFactory):
38 """Factory to create GLX protocol oriented objects derived from glItem."""
39
40 def create(self, context, name, attrs):
41 if name == "function":
42 return glXFunction(context, name, attrs)
43 elif name == "enum":
44 return glXEnum(context, name, attrs)
45 elif name == "param":
46 return glXParameter(context, name, attrs)
47 else:
48 return gl_XML.glItemFactory.create(self, context, name, attrs)
49
50class glXEnumFunction:
Ian Romanickba09c192005-02-01 00:13:04 +000051 def __init__(self, name, context):
Ian Romanick74764062004-12-03 20:31:59 +000052 self.name = name
Ian Romanickba09c192005-02-01 00:13:04 +000053 self.context = context
Ian Romanick5aa6dc322005-01-27 01:08:48 +000054 self.mode = 0
55 self.sig = None
56
Ian Romanick74764062004-12-03 20:31:59 +000057 # "enums" is a set of lists. The element in the set is the
58 # value of the enum. The list is the list of names for that
59 # value. For example, [0x8126] = {"POINT_SIZE_MIN",
60 # "POINT_SIZE_MIN_ARB", "POINT_SIZE_MIN_EXT",
61 # "POINT_SIZE_MIN_SGIS"}.
62
63 self.enums = {}
64
65 # "count" is indexed by count values. Each element of count
66 # is a list of index to "enums" that have that number of
67 # associated data elements. For example, [4] =
68 # {GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_EMISSION,
69 # GL_AMBIENT_AND_DIFFUSE} (the enum names are used here,
70 # but the actual hexadecimal values would be in the array).
71
72 self.count = {}
73
74
75 def append(self, count, value, name):
76 if self.enums.has_key( value ):
77 self.enums[value].append(name)
78 else:
79 if not self.count.has_key(count):
80 self.count[count] = []
81
82 self.enums[value] = []
83 self.enums[value].append(name)
84 self.count[count].append(value)
85
86
87 def signature( self ):
Ian Romanick5aa6dc322005-01-27 01:08:48 +000088 if self.sig == None:
89 self.sig = ""
90 for i in self.count:
Ian Romanick82e22f52005-01-27 19:39:16 +000091 self.count[i].sort()
Ian Romanick5aa6dc322005-01-27 01:08:48 +000092 for e in self.count[i]:
93 self.sig += "%04x,%u," % (e, i)
Ian Romanick74764062004-12-03 20:31:59 +000094
Ian Romanick5aa6dc322005-01-27 01:08:48 +000095 return self.sig
96
97
98 def set_mode( self, mode ):
99 """Mark an enum-function as a 'set' function."""
100
101 self.mode = mode
102
103
104 def is_set( self ):
105 return self.mode
Ian Romanick74764062004-12-03 20:31:59 +0000106
107
108 def PrintUsingTable(self):
109 """Emit the body of the __gl*_size function using a pair
110 of look-up tables and a mask. The mask is calculated such
111 that (e & mask) is unique for all the valid values of e for
112 this function. The result of (e & mask) is used as an index
113 into the first look-up table. If it matches e, then the
114 same entry of the second table is returned. Otherwise zero
115 is returned.
116
117 It seems like this should cause better code to be generated.
118 However, on x86 at least, the resulting .o file is about 20%
119 larger then the switch-statment version. I am leaving this
120 code in because the results may be different on other
121 platforms (e.g., PowerPC or x86-64)."""
122
123 return 0
124 count = 0
125 for a in self.enums:
126 count += 1
127
Ian Romanick80a939c2005-03-17 21:48:37 +0000128 if self.count.has_key(-1):
129 return 0
130
Ian Romanick74764062004-12-03 20:31:59 +0000131 # Determine if there is some mask M, such that M = (2^N) - 1,
132 # that will generate unique values for all of the enums.
133
134 mask = 0
135 for i in [1, 2, 3, 4, 5, 6, 7, 8]:
136 mask = (1 << i) - 1
137
138 fail = 0;
139 for a in self.enums:
140 for b in self.enums:
141 if a != b:
142 if (a & mask) == (b & mask):
143 fail = 1;
144
145 if not fail:
146 break;
147 else:
148 mask = 0
149
150 if (mask != 0) and (mask < (2 * count)):
151 masked_enums = {}
152 masked_count = {}
153
154 for i in range(0, mask + 1):
155 masked_enums[i] = "0";
156 masked_count[i] = 0;
157
158 for c in self.count:
159 for e in self.count[c]:
160 i = e & mask
161 masked_enums[i] = '0x%04x /* %s */' % (e, self.enums[e][0])
162 masked_count[i] = c
163
164
165 print ' static const GLushort a[%u] = {' % (mask + 1)
166 for e in masked_enums:
167 print ' %s, ' % (masked_enums[e])
168 print ' };'
169
170 print ' static const GLubyte b[%u] = {' % (mask + 1)
171 for c in masked_count:
172 print ' %u, ' % (masked_count[c])
173 print ' };'
174
175 print ' const unsigned idx = (e & 0x%02xU);' % (mask)
176 print ''
177 print ' return (e == a[idx]) ? (GLint) b[idx] : 0;'
178 return 1;
179 else:
180 return 0;
181
Ian Romanick80a939c2005-03-17 21:48:37 +0000182 def PrintUsingSwitch(self, name):
Ian Romanick74764062004-12-03 20:31:59 +0000183 """Emit the body of the __gl*_size function using a
184 switch-statement."""
185
186 print ' switch( e ) {'
187
188 for c in self.count:
189 for e in self.count[c]:
190 first = 1
191
192 # There may be multiple enums with the same
193 # value. This happens has extensions are
194 # promoted from vendor-specific or EXT to
195 # ARB and to the core. Emit the first one as
196 # a case label, and emit the others as
197 # commented-out case labels.
198
199 for j in self.enums[e]:
200 if first:
201 print ' case %s:' % (j)
202 first = 0
203 else:
204 print '/* case %s:*/' % (j)
205
Ian Romanick80a939c2005-03-17 21:48:37 +0000206 if c == -1:
207 print ' return __gl%s_variable_size( e );' % (name)
208 else:
209 print ' return %u;' % (c)
Ian Romanick74764062004-12-03 20:31:59 +0000210
211 print ' default: return 0;'
212 print ' }'
213
214
215 def Print(self, name):
216 print 'INTERNAL PURE FASTCALL GLint'
217 print '__gl%s_size( GLenum e )' % (name)
218 print '{'
219
220 if not self.PrintUsingTable():
Ian Romanick80a939c2005-03-17 21:48:37 +0000221 self.PrintUsingSwitch(name)
Ian Romanick74764062004-12-03 20:31:59 +0000222
223 print '}'
224 print ''
225
226
227
228class glXEnum(gl_XML.glEnum):
229 def __init__(self, context, name, attrs):
230 gl_XML.glEnum.__init__(self, context, name, attrs)
Ian Romanick0246b2a2005-01-24 20:59:32 +0000231
Ian Romanick74764062004-12-03 20:31:59 +0000232
233 def startElement(self, name, attrs):
234 if name == "size":
Ian Romanick80a939c2005-03-17 21:48:37 +0000235 [temp_n, c, mode] = self.process_attributes(attrs)
Ian Romanick5ff2b942005-01-24 21:29:13 +0000236
Ian Romanick80a939c2005-03-17 21:48:37 +0000237 if temp_n == "Get":
238 names = ["GetIntegerv", "GetBooleanv", "GetFloatv", "GetDoublev" ]
239 else:
240 names = [ temp_n ]
Ian Romanick74764062004-12-03 20:31:59 +0000241
Ian Romanick80a939c2005-03-17 21:48:37 +0000242 for n in names:
243 if not self.context.glx_enum_functions.has_key( n ):
244 f = self.context.createEnumFunction( n )
245 f.set_mode( mode )
246 self.context.glx_enum_functions[ f.name ] = f
247
248 self.context.glx_enum_functions[ n ].append( c, self.value, self.name )
Ian Romanick74764062004-12-03 20:31:59 +0000249 else:
250 gl_XML.glEnum.startElement(self, context, name, attrs)
251 return
252
253
254class glXParameter(gl_XML.glParameter):
255 def __init__(self, context, name, attrs):
256 self.order = 1;
257 gl_XML.glParameter.__init__(self, context, name, attrs);
258
259
Ian Romanick1d270842004-12-21 21:26:36 +0000260class glXParameterIterator:
261 """Class to iterate over a list of glXParameters.
262
263 Objects of this class are returned by the parameterIterator method of
264 the glXFunction class. They are used to iterate over the list of
265 parameters to the function."""
266
267 def __init__(self, data, skip_output, max_order):
268 self.data = data
269 self.index = 0
270 self.order = 0
271 self.skip_output = skip_output
272 self.max_order = max_order
273
274 def __iter__(self):
275 return self
276
277 def next(self):
278 if len( self.data ) == 0:
279 raise StopIteration
280
281 while 1:
282 if self.index == len( self.data ):
283 if self.order == self.max_order:
284 raise StopIteration
285 else:
286 self.order += 1
287 self.index = 0
288
289 i = self.index
290 self.index += 1
291
292 if self.data[i].order == self.order and not (self.data[i].is_output and self.skip_output):
293 return self.data[i]
294
295
Ian Romanick74764062004-12-03 20:31:59 +0000296class glXFunction(gl_XML.glFunction):
297 glx_rop = 0
298 glx_sop = 0
299 glx_vendorpriv = 0
300
301 # If this is set to true, it means that GLdouble parameters should be
302 # written to the GLX protocol packet in the order they appear in the
303 # prototype. This is different from the "classic" ordering. In the
304 # classic ordering GLdoubles are written to the protocol packet first,
305 # followed by non-doubles. NV_vertex_program was the first extension
306 # to break with this tradition.
307
308 glx_doubles_in_order = 0
309
310 vectorequiv = None
Ian Romanick74764062004-12-03 20:31:59 +0000311 can_be_large = 0
312
313 def __init__(self, context, name, attrs):
314 self.vectorequiv = attrs.get('vectorequiv', None)
Ian Romanick74764062004-12-03 20:31:59 +0000315 self.counter = None
316 self.output = None
317 self.can_be_large = 0
318 self.reply_always_array = 0
Ian Romanickd8634242005-02-09 03:11:23 +0000319 self.dimensions_in_reply = 0
320 self.img_reset = None
Ian Romanick74764062004-12-03 20:31:59 +0000321
Ian Romanickfdb05272005-01-28 17:30:25 +0000322 self.server_handcode = 0
323 self.client_handcode = 0
324 self.ignore = 0
325
Ian Romanick74764062004-12-03 20:31:59 +0000326 gl_XML.glFunction.__init__(self, context, name, attrs)
327 return
328
Ian Romanick1d270842004-12-21 21:26:36 +0000329
330 def parameterIterator(self, skip_output, max_order):
331 return glXParameterIterator(self.fn_parameters, skip_output, max_order)
332
333
Ian Romanick74764062004-12-03 20:31:59 +0000334 def startElement(self, name, attrs):
335 """Process elements within a function that are specific to GLX."""
336
337 if name == "glx":
338 self.glx_rop = int(attrs.get('rop', "0"))
339 self.glx_sop = int(attrs.get('sop', "0"))
340 self.glx_vendorpriv = int(attrs.get('vendorpriv', "0"))
Ian Romanickd8634242005-02-09 03:11:23 +0000341 self.img_reset = attrs.get('img_reset', None)
Ian Romanick74764062004-12-03 20:31:59 +0000342
Ian Romanickfdb05272005-01-28 17:30:25 +0000343 # The 'handcode' attribute can be one of 'true',
344 # 'false', 'client', or 'server'.
345
346 handcode = attrs.get('handcode', "false")
347 if handcode == "false":
348 self.server_handcode = 0
349 self.client_handcode = 0
350 elif handcode == "true":
351 self.server_handcode = 1
352 self.client_handcode = 1
353 elif handcode == "client":
354 self.server_handcode = 0
355 self.client_handcode = 1
356 elif handcode == "server":
357 self.server_handcode = 1
358 self.client_handcode = 0
Ian Romanick74764062004-12-03 20:31:59 +0000359 else:
Ian Romanickfdb05272005-01-28 17:30:25 +0000360 raise RuntimeError('Invalid handcode mode "%s" in function "%s".' % (handcode, self.name))
361
Ian Romanick74764062004-12-03 20:31:59 +0000362
363 if attrs.get('ignore', "false") == "true":
364 self.ignore = 1
365 else:
366 self.ignore = 0
367
368 if attrs.get('large', "false") == "true":
369 self.can_be_large = 1
370 else:
371 self.can_be_large = 0
372
373 if attrs.get('doubles_in_order', "false") == "true":
374 self.glx_doubles_in_order = 1
375 else:
376 self.glx_doubles_in_order = 0
377
378 if attrs.get('always_array', "false") == "true":
379 self.reply_always_array = 1
380 else:
381 self.reply_always_array = 0
382
Ian Romanickd8634242005-02-09 03:11:23 +0000383 if attrs.get('dimensions_in_reply', "false") == "true":
384 self.dimensions_in_reply = 1
385 else:
386 self.dimensions_in_reply = 0
Ian Romanick74764062004-12-03 20:31:59 +0000387 else:
388 gl_XML.glFunction.startElement(self, name, attrs)
389
390
Ian Romanick7f958e92005-01-24 20:08:28 +0000391 def endElement(self, name):
392 if name == "function":
393 # Mark any function that does not have GLX protocol
394 # defined as "ignore". This prevents bad things from
395 # happening when people add new functions to the GL
396 # API XML without adding any GLX section.
397 #
398 # This will also mark functions that don't have a
399 # dispatch offset at ignored.
400
Ian Romanickfdb05272005-01-28 17:30:25 +0000401 if (self.fn_offset == -1 and not self.fn_alias) or not (self.client_handcode or self.server_handcode or self.glx_rop or self.glx_sop or self.glx_vendorpriv or self.vectorequiv or self.fn_alias):
Ian Romanick7f958e92005-01-24 20:08:28 +0000402 #if not self.ignore:
403 # if self.fn_offset == -1:
404 # print '/* %s ignored becuase no offset assigned. */' % (self.name)
405 # else:
406 # print '/* %s ignored becuase no GLX opcode assigned. */' % (self.name)
407
408 self.ignore = 1
409
410 return gl_XML.glFunction.endElement(self, name)
411
412
Ian Romanick74764062004-12-03 20:31:59 +0000413 def append(self, tag_name, p):
414 gl_XML.glFunction.append(self, tag_name, p)
415
416 if p.is_variable_length_array():
417 p.order = 2;
418 elif not self.glx_doubles_in_order and p.p_type.size == 8:
419 p.order = 0;
420
Ian Romanick74764062004-12-03 20:31:59 +0000421 if p.is_counter:
422 self.counter = p.name
423
424 if p.is_output:
425 self.output = p
426
427 return
428
Ian Romanick0246b2a2005-01-24 20:59:32 +0000429
Ian Romanick74764062004-12-03 20:31:59 +0000430 def variable_length_parameter(self):
Ian Romanick6af6a692005-03-17 20:56:13 +0000431 if len(self.variable_length_parameters):
432 return self.variable_length_parameters[0]
433
Ian Romanick74764062004-12-03 20:31:59 +0000434 return None
435
436
Ian Romanick54584df2005-01-28 18:20:43 +0000437 def output_parameter(self):
438 for param in self.fn_parameters:
439 if param.is_output:
440 return param
441
442 return None
443
444
Ian Romanick0246b2a2005-01-24 20:59:32 +0000445 def offset_of_first_parameter(self):
446 """Get the offset of the first parameter in the command.
447
448 Gets the offset of the first function parameter in the GLX
449 command packet. This byte offset is measured from the end
450 of the Render / RenderLarge header. The offset for all non-
451 pixel commends is zero. The offset for pixel commands depends
452 on the number of dimensions of the pixel data."""
Ian Romanick5f1f2292005-01-07 02:39:09 +0000453
Ian Romanickd8634242005-02-09 03:11:23 +0000454 if self.image and not self.image.is_output:
Ian Romanick5f1f2292005-01-07 02:39:09 +0000455 [dim, junk, junk, junk, junk] = self.dimensions()
Ian Romanick0246b2a2005-01-24 20:59:32 +0000456
Ian Romanick5f1f2292005-01-07 02:39:09 +0000457 # The base size is the size of the pixel pack info
458 # header used by images with the specified number
459 # of dimensions.
460
461 if dim <= 2:
Ian Romanick0246b2a2005-01-24 20:59:32 +0000462 return 20
Ian Romanick5f1f2292005-01-07 02:39:09 +0000463 elif dim <= 4:
Ian Romanick0246b2a2005-01-24 20:59:32 +0000464 return 36
Ian Romanick5f1f2292005-01-07 02:39:09 +0000465 else:
466 raise RuntimeError('Invalid number of dimensions %u for parameter "%s" in function "%s".' % (dim, self.image.name, self.name))
Ian Romanick0246b2a2005-01-24 20:59:32 +0000467 else:
468 return 0
Ian Romanick5f1f2292005-01-07 02:39:09 +0000469
Ian Romanick5f1f2292005-01-07 02:39:09 +0000470
Ian Romanick0246b2a2005-01-24 20:59:32 +0000471 def command_fixed_length(self):
472 """Return the length, in bytes as an integer, of the
473 fixed-size portion of the command."""
Ian Romanick5f1f2292005-01-07 02:39:09 +0000474
Ian Romanick0246b2a2005-01-24 20:59:32 +0000475 size = self.offset_of_first_parameter()
Ian Romanick5f1f2292005-01-07 02:39:09 +0000476
Ian Romanick0246b2a2005-01-24 20:59:32 +0000477 for p in gl_XML.glFunction.parameterIterator(self):
Ian Romanickd8634242005-02-09 03:11:23 +0000478 if not p.is_output and p.name != self.img_reset:
Ian Romanick0246b2a2005-01-24 20:59:32 +0000479 size += p.size()
480 if self.pad_after(p):
481 size += 4
482
Ian Romanickd8634242005-02-09 03:11:23 +0000483 if self.image and (self.image.img_null_flag or self.image.is_output):
Ian Romanick0246b2a2005-01-24 20:59:32 +0000484 size += 4
485
486 return size
487
488
489 def command_variable_length(self):
490 """Return the length, as a string, of the variable-sized
491 portion of the command."""
492
Ian Romanick74764062004-12-03 20:31:59 +0000493 size_string = ""
Ian Romanick1d270842004-12-21 21:26:36 +0000494 for p in gl_XML.glFunction.parameterIterator(self):
Ian Romanick0246b2a2005-01-24 20:59:32 +0000495 if (not p.is_output) and (p.size() == 0):
496 size_string = size_string + " + __GLX_PAD(%s)" % (p.size_string())
Ian Romanick74764062004-12-03 20:31:59 +0000497
Ian Romanick0246b2a2005-01-24 20:59:32 +0000498 return size_string
499
Ian Romanick74764062004-12-03 20:31:59 +0000500
501 def command_length(self):
Ian Romanick0246b2a2005-01-24 20:59:32 +0000502 size = self.command_fixed_length()
Ian Romanick74764062004-12-03 20:31:59 +0000503
504 if self.glx_rop != 0:
505 size += 4
506
507 size = ((size + 3) & ~3)
Ian Romanick0246b2a2005-01-24 20:59:32 +0000508 return "%u%s" % (size, self.command_variable_length())
Ian Romanick74764062004-12-03 20:31:59 +0000509
510
511 def opcode_real_value(self):
Ian Romanick1d270842004-12-21 21:26:36 +0000512 """Get the true numeric value of the GLX opcode
513
514 Behaves similarly to opcode_value, except for
515 X_GLXVendorPrivate and X_GLXVendorPrivateWithReply commands.
516 In these cases the value for the GLX opcode field (i.e.,
517 16 for X_GLXVendorPrivate or 17 for
518 X_GLXVendorPrivateWithReply) is returned. For other 'single'
519 commands, the opcode for the command (e.g., 101 for
520 X_GLsop_NewList) is returned."""
521
Ian Romanick74764062004-12-03 20:31:59 +0000522 if self.glx_vendorpriv != 0:
523 if self.needs_reply():
524 return 17
525 else:
526 return 16
527 else:
528 return self.opcode_value()
529
530 def opcode_value(self):
Ian Romanick1d270842004-12-21 21:26:36 +0000531 """Get the unique protocol opcode for the glXFunction"""
532
Ian Romanick74764062004-12-03 20:31:59 +0000533 if self.glx_rop != 0:
534 return self.glx_rop
535 elif self.glx_sop != 0:
536 return self.glx_sop
537 elif self.glx_vendorpriv != 0:
538 return self.glx_vendorpriv
539 else:
540 return -1
541
542 def opcode_rop_basename(self):
Ian Romanick1d270842004-12-21 21:26:36 +0000543 """Return either the name to be used for GLX protocol enum.
544
545 Returns either the name of the function or the name of the
546 name of the equivalent vector (e.g., glVertex3fv for
547 glVertex3f) function."""
548
Ian Romanick74764062004-12-03 20:31:59 +0000549 if self.vectorequiv == None:
550 return self.name
551 else:
552 return self.vectorequiv
553
554 def opcode_name(self):
Ian Romanick1d270842004-12-21 21:26:36 +0000555 """Get the unique protocol enum name for the glXFunction"""
556
Ian Romanick74764062004-12-03 20:31:59 +0000557 if self.glx_rop != 0:
558 return "X_GLrop_%s" % (self.opcode_rop_basename())
559 elif self.glx_sop != 0:
560 return "X_GLsop_%s" % (self.name)
561 elif self.glx_vendorpriv != 0:
562 return "X_GLvop_%s" % (self.name)
563 else:
Ian Romanick3fec8c22005-02-02 00:54:45 +0000564 raise RuntimeError('Function "%s" has no opcode.' % (self.name))
565
Ian Romanick74764062004-12-03 20:31:59 +0000566
567 def opcode_real_name(self):
Ian Romanick1d270842004-12-21 21:26:36 +0000568 """Get the true protocol enum name for the GLX opcode
569
570 Behaves similarly to opcode_name, except for
571 X_GLXVendorPrivate and X_GLXVendorPrivateWithReply commands.
572 In these cases the string 'X_GLXVendorPrivate' or
573 'X_GLXVendorPrivateWithReply' is returned. For other
574 single or render commands 'X_GLsop' or 'X_GLrop' plus the
575 name of the function returned."""
576
Ian Romanick74764062004-12-03 20:31:59 +0000577 if self.glx_vendorpriv != 0:
578 if self.needs_reply():
579 return "X_GLXVendorPrivateWithReply"
580 else:
581 return "X_GLXVendorPrivate"
582 else:
583 return self.opcode_name()
584
585
586 def return_string(self):
587 if self.fn_return_type != 'void':
588 return "return retval;"
589 else:
590 return "return;"
591
592
593 def needs_reply(self):
594 return self.fn_return_type != 'void' or self.output != None
595
596
Ian Romanick5f1f2292005-01-07 02:39:09 +0000597 def dimensions(self):
598 """Determine the dimensions of an image.
599
600 Returns a tuple representing the number of dimensions and the
601 string name of each of the dimensions of an image, If the
602 function is not a pixel function, the number of dimensions
603 will be zero."""
604
605 if not self.image:
606 return [0, "0", "0", "0", "0"]
607 else:
608 dim = 1
609 w = self.image.width
610
611 if self.image.height:
612 dim = 2
613 h = self.image.height
614 else:
615 h = "1"
616
617 if self.image.depth:
618 dim = 3
619 d = self.image.depth
620 else:
621 d = "1"
622
623 if self.image.extent:
624 dim = 4
625 e = self.image.extent
626 else:
627 e = "1"
628
629 return [dim, w, h, d, e]
630
631
632 def pad_after(self, p):
633 """Returns the name of the field inserted after the
634 specified field to pad out the command header."""
635
636 if self.image and self.image.img_pad_dimensions:
637 if not self.image.height:
638 if p.name == self.image.width:
639 return "height"
640 elif p.name == self.image.img_xoff:
641 return "yoffset"
642 elif not self.image.extent:
643 if p.name == self.image.depth:
644 # Should this be "size4d"?
645 return "extent"
646 elif p.name == self.image.img_zoff:
647 return "woffset"
648 return None
649
Ian Romanick3fec8c22005-02-02 00:54:45 +0000650
651class glXFunctionIterator(gl_XML.glFunctionIterator):
652 """Class to iterate over a list of glXFunctions"""
653
654 def __init__(self, context):
655 self.context = context
656 self.keys = context.functions.keys()
657 self.keys.sort()
658
659 for self.index in range(0, len(self.keys)):
660 if self.keys[ self.index ] >= 0: break
661
662 return
663
664
665 def next(self):
666 if self.index == len(self.keys):
667 raise StopIteration
668
669 f = self.context.functions[ self.keys[ self.index ] ]
670 self.index += 1
671
672 if f.ignore:
673 return self.next()
674 else:
675 return f
676
677
Ian Romanick74764062004-12-03 20:31:59 +0000678class GlxProto(gl_XML.FilterGLAPISpecBase):
679 name = "glX_proto_send.py (from Mesa)"
680
681 def __init__(self):
682 gl_XML.FilterGLAPISpecBase.__init__(self)
683 self.factory = glXItemFactory()
684 self.glx_enum_functions = {}
685
686
687 def endElement(self, name):
688 if name == 'OpenGLAPI':
689 # Once all the parsing is done, we have to go back and
690 # fix-up some cross references between different
691 # functions.
692
693 for k in self.functions:
694 f = self.functions[k]
695 if f.vectorequiv != None:
696 equiv = self.find_function(f.vectorequiv)
697 if equiv != None:
698 f.glx_doubles_in_order = equiv.glx_doubles_in_order
699 f.glx_rop = equiv.glx_rop
700 else:
701 raise RuntimeError("Could not find the vector equiv. function %s for %s!" % (f.name, f.vectorequiv))
702 else:
703 gl_XML.FilterGLAPISpecBase.endElement(self, name)
704 return
Ian Romanickba09c192005-02-01 00:13:04 +0000705
706
707 def createEnumFunction(self, n):
708 return glXEnumFunction(n, self)
Ian Romanick3fec8c22005-02-02 00:54:45 +0000709
710
711 def functionIterator(self):
712 return glXFunctionIterator(self)
713
714
715 def size_call(self, func):
716 """Create C code to calculate 'compsize'.
717
718 Creates code to calculate 'compsize'. If the function does
719 not need 'compsize' to be calculated, None will be
720 returned."""
721
722 if not func.image and not func.count_parameter_list:
723 return None
724
725 if not func.image:
726 parameters = string.join( func.count_parameter_list, "," )
727 compsize = "__gl%s_size(%s)" % (func.name, parameters)
728 else:
729 [dim, w, h, d, junk] = func.dimensions()
730
731 compsize = '__glImageSize(%s, %s, %s, %s, %s, %s)' % (w, h, d, func.image.img_format, func.image.img_type, func.image.img_target)
732 if not func.image.img_send_null:
733 compsize = '(%s != NULL) ? %s : 0' % (func.image.name, compsize)
734
735 return compsize