blob: e48955e34e7a44c8c3e551755bfd1b606ce783aa [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 Romanick73b4c1b2005-04-14 23:00:34 +0000362 self.ignore = gl_XML.is_attr_true( attrs, 'ignore' )
363 self.can_be_large = gl_XML.is_attr_true( attrs, 'large' )
364 self.glx_doubles_in_order = gl_XML.is_attr_true( attrs, 'doubles_in_order' )
365 self.reply_always_array = gl_XML.is_attr_true( attrs, 'always_array' )
366 self.dimensions_in_reply = gl_XML.is_attr_true( attrs, 'dimensions_in_reply' )
Ian Romanick74764062004-12-03 20:31:59 +0000367 else:
368 gl_XML.glFunction.startElement(self, name, attrs)
369
370
Ian Romanick7f958e92005-01-24 20:08:28 +0000371 def endElement(self, name):
372 if name == "function":
373 # Mark any function that does not have GLX protocol
374 # defined as "ignore". This prevents bad things from
375 # happening when people add new functions to the GL
376 # API XML without adding any GLX section.
377 #
378 # This will also mark functions that don't have a
379 # dispatch offset at ignored.
380
Ian Romanickfdb05272005-01-28 17:30:25 +0000381 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 +0000382 #if not self.ignore:
383 # if self.fn_offset == -1:
384 # print '/* %s ignored becuase no offset assigned. */' % (self.name)
385 # else:
386 # print '/* %s ignored becuase no GLX opcode assigned. */' % (self.name)
387
388 self.ignore = 1
389
390 return gl_XML.glFunction.endElement(self, name)
391
392
Ian Romanick74764062004-12-03 20:31:59 +0000393 def append(self, tag_name, p):
394 gl_XML.glFunction.append(self, tag_name, p)
395
396 if p.is_variable_length_array():
397 p.order = 2;
398 elif not self.glx_doubles_in_order and p.p_type.size == 8:
399 p.order = 0;
400
Ian Romanick74764062004-12-03 20:31:59 +0000401 if p.is_counter:
402 self.counter = p.name
403
404 if p.is_output:
405 self.output = p
406
407 return
408
Ian Romanick0246b2a2005-01-24 20:59:32 +0000409
Ian Romanick74764062004-12-03 20:31:59 +0000410 def variable_length_parameter(self):
Ian Romanick6af6a692005-03-17 20:56:13 +0000411 if len(self.variable_length_parameters):
412 return self.variable_length_parameters[0]
413
Ian Romanick74764062004-12-03 20:31:59 +0000414 return None
415
416
Ian Romanick54584df2005-01-28 18:20:43 +0000417 def output_parameter(self):
418 for param in self.fn_parameters:
419 if param.is_output:
420 return param
421
422 return None
423
424
Ian Romanick0246b2a2005-01-24 20:59:32 +0000425 def offset_of_first_parameter(self):
426 """Get the offset of the first parameter in the command.
427
428 Gets the offset of the first function parameter in the GLX
429 command packet. This byte offset is measured from the end
430 of the Render / RenderLarge header. The offset for all non-
431 pixel commends is zero. The offset for pixel commands depends
432 on the number of dimensions of the pixel data."""
Ian Romanick5f1f2292005-01-07 02:39:09 +0000433
Ian Romanickd8634242005-02-09 03:11:23 +0000434 if self.image and not self.image.is_output:
Ian Romanick5f1f2292005-01-07 02:39:09 +0000435 [dim, junk, junk, junk, junk] = self.dimensions()
Ian Romanick0246b2a2005-01-24 20:59:32 +0000436
Ian Romanick5f1f2292005-01-07 02:39:09 +0000437 # The base size is the size of the pixel pack info
438 # header used by images with the specified number
439 # of dimensions.
440
441 if dim <= 2:
Ian Romanick0246b2a2005-01-24 20:59:32 +0000442 return 20
Ian Romanick5f1f2292005-01-07 02:39:09 +0000443 elif dim <= 4:
Ian Romanick0246b2a2005-01-24 20:59:32 +0000444 return 36
Ian Romanick5f1f2292005-01-07 02:39:09 +0000445 else:
446 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 +0000447 else:
448 return 0
Ian Romanick5f1f2292005-01-07 02:39:09 +0000449
Ian Romanick5f1f2292005-01-07 02:39:09 +0000450
Ian Romanick0246b2a2005-01-24 20:59:32 +0000451 def command_fixed_length(self):
452 """Return the length, in bytes as an integer, of the
453 fixed-size portion of the command."""
Ian Romanick5f1f2292005-01-07 02:39:09 +0000454
Ian Romanick0246b2a2005-01-24 20:59:32 +0000455 size = self.offset_of_first_parameter()
Ian Romanick5f1f2292005-01-07 02:39:09 +0000456
Ian Romanick0246b2a2005-01-24 20:59:32 +0000457 for p in gl_XML.glFunction.parameterIterator(self):
Ian Romanickd8634242005-02-09 03:11:23 +0000458 if not p.is_output and p.name != self.img_reset:
Ian Romanick0246b2a2005-01-24 20:59:32 +0000459 size += p.size()
460 if self.pad_after(p):
461 size += 4
462
Ian Romanickd8634242005-02-09 03:11:23 +0000463 if self.image and (self.image.img_null_flag or self.image.is_output):
Ian Romanick0246b2a2005-01-24 20:59:32 +0000464 size += 4
465
466 return size
467
468
469 def command_variable_length(self):
470 """Return the length, as a string, of the variable-sized
471 portion of the command."""
472
Ian Romanick74764062004-12-03 20:31:59 +0000473 size_string = ""
Ian Romanick1d270842004-12-21 21:26:36 +0000474 for p in gl_XML.glFunction.parameterIterator(self):
Ian Romanick0246b2a2005-01-24 20:59:32 +0000475 if (not p.is_output) and (p.size() == 0):
476 size_string = size_string + " + __GLX_PAD(%s)" % (p.size_string())
Ian Romanick74764062004-12-03 20:31:59 +0000477
Ian Romanick0246b2a2005-01-24 20:59:32 +0000478 return size_string
479
Ian Romanick74764062004-12-03 20:31:59 +0000480
481 def command_length(self):
Ian Romanick0246b2a2005-01-24 20:59:32 +0000482 size = self.command_fixed_length()
Ian Romanick74764062004-12-03 20:31:59 +0000483
484 if self.glx_rop != 0:
485 size += 4
486
487 size = ((size + 3) & ~3)
Ian Romanick0246b2a2005-01-24 20:59:32 +0000488 return "%u%s" % (size, self.command_variable_length())
Ian Romanick74764062004-12-03 20:31:59 +0000489
490
491 def opcode_real_value(self):
Ian Romanick1d270842004-12-21 21:26:36 +0000492 """Get the true numeric value of the GLX opcode
493
494 Behaves similarly to opcode_value, except for
495 X_GLXVendorPrivate and X_GLXVendorPrivateWithReply commands.
496 In these cases the value for the GLX opcode field (i.e.,
497 16 for X_GLXVendorPrivate or 17 for
498 X_GLXVendorPrivateWithReply) is returned. For other 'single'
499 commands, the opcode for the command (e.g., 101 for
500 X_GLsop_NewList) is returned."""
501
Ian Romanick74764062004-12-03 20:31:59 +0000502 if self.glx_vendorpriv != 0:
503 if self.needs_reply():
504 return 17
505 else:
506 return 16
507 else:
508 return self.opcode_value()
509
510 def opcode_value(self):
Ian Romanick1d270842004-12-21 21:26:36 +0000511 """Get the unique protocol opcode for the glXFunction"""
512
Ian Romanick74764062004-12-03 20:31:59 +0000513 if self.glx_rop != 0:
514 return self.glx_rop
515 elif self.glx_sop != 0:
516 return self.glx_sop
517 elif self.glx_vendorpriv != 0:
518 return self.glx_vendorpriv
519 else:
520 return -1
521
522 def opcode_rop_basename(self):
Ian Romanick1d270842004-12-21 21:26:36 +0000523 """Return either the name to be used for GLX protocol enum.
524
525 Returns either the name of the function or the name of the
526 name of the equivalent vector (e.g., glVertex3fv for
527 glVertex3f) function."""
528
Ian Romanick74764062004-12-03 20:31:59 +0000529 if self.vectorequiv == None:
530 return self.name
531 else:
532 return self.vectorequiv
533
534 def opcode_name(self):
Ian Romanick1d270842004-12-21 21:26:36 +0000535 """Get the unique protocol enum name for the glXFunction"""
536
Ian Romanick74764062004-12-03 20:31:59 +0000537 if self.glx_rop != 0:
538 return "X_GLrop_%s" % (self.opcode_rop_basename())
539 elif self.glx_sop != 0:
540 return "X_GLsop_%s" % (self.name)
541 elif self.glx_vendorpriv != 0:
542 return "X_GLvop_%s" % (self.name)
543 else:
Ian Romanick3fec8c22005-02-02 00:54:45 +0000544 raise RuntimeError('Function "%s" has no opcode.' % (self.name))
545
Ian Romanick74764062004-12-03 20:31:59 +0000546
547 def opcode_real_name(self):
Ian Romanick1d270842004-12-21 21:26:36 +0000548 """Get the true protocol enum name for the GLX opcode
549
550 Behaves similarly to opcode_name, except for
551 X_GLXVendorPrivate and X_GLXVendorPrivateWithReply commands.
552 In these cases the string 'X_GLXVendorPrivate' or
553 'X_GLXVendorPrivateWithReply' is returned. For other
554 single or render commands 'X_GLsop' or 'X_GLrop' plus the
555 name of the function returned."""
556
Ian Romanick74764062004-12-03 20:31:59 +0000557 if self.glx_vendorpriv != 0:
558 if self.needs_reply():
559 return "X_GLXVendorPrivateWithReply"
560 else:
561 return "X_GLXVendorPrivate"
562 else:
563 return self.opcode_name()
564
565
566 def return_string(self):
567 if self.fn_return_type != 'void':
568 return "return retval;"
569 else:
570 return "return;"
571
572
573 def needs_reply(self):
574 return self.fn_return_type != 'void' or self.output != None
575
576
Ian Romanick5f1f2292005-01-07 02:39:09 +0000577 def dimensions(self):
578 """Determine the dimensions of an image.
579
580 Returns a tuple representing the number of dimensions and the
581 string name of each of the dimensions of an image, If the
582 function is not a pixel function, the number of dimensions
583 will be zero."""
584
585 if not self.image:
586 return [0, "0", "0", "0", "0"]
587 else:
588 dim = 1
589 w = self.image.width
590
591 if self.image.height:
592 dim = 2
593 h = self.image.height
594 else:
595 h = "1"
596
597 if self.image.depth:
598 dim = 3
599 d = self.image.depth
600 else:
601 d = "1"
602
603 if self.image.extent:
604 dim = 4
605 e = self.image.extent
606 else:
607 e = "1"
608
609 return [dim, w, h, d, e]
610
611
612 def pad_after(self, p):
613 """Returns the name of the field inserted after the
614 specified field to pad out the command header."""
615
616 if self.image and self.image.img_pad_dimensions:
617 if not self.image.height:
618 if p.name == self.image.width:
619 return "height"
620 elif p.name == self.image.img_xoff:
621 return "yoffset"
622 elif not self.image.extent:
623 if p.name == self.image.depth:
624 # Should this be "size4d"?
625 return "extent"
626 elif p.name == self.image.img_zoff:
627 return "woffset"
628 return None
629
Ian Romanick3fec8c22005-02-02 00:54:45 +0000630
631class glXFunctionIterator(gl_XML.glFunctionIterator):
632 """Class to iterate over a list of glXFunctions"""
633
634 def __init__(self, context):
635 self.context = context
636 self.keys = context.functions.keys()
637 self.keys.sort()
638
639 for self.index in range(0, len(self.keys)):
640 if self.keys[ self.index ] >= 0: break
641
642 return
643
644
645 def next(self):
646 if self.index == len(self.keys):
647 raise StopIteration
648
649 f = self.context.functions[ self.keys[ self.index ] ]
650 self.index += 1
651
652 if f.ignore:
653 return self.next()
654 else:
655 return f
656
657
Ian Romanick74764062004-12-03 20:31:59 +0000658class GlxProto(gl_XML.FilterGLAPISpecBase):
659 name = "glX_proto_send.py (from Mesa)"
660
661 def __init__(self):
662 gl_XML.FilterGLAPISpecBase.__init__(self)
663 self.factory = glXItemFactory()
664 self.glx_enum_functions = {}
665
666
667 def endElement(self, name):
668 if name == 'OpenGLAPI':
669 # Once all the parsing is done, we have to go back and
670 # fix-up some cross references between different
671 # functions.
672
673 for k in self.functions:
674 f = self.functions[k]
675 if f.vectorequiv != None:
676 equiv = self.find_function(f.vectorequiv)
677 if equiv != None:
678 f.glx_doubles_in_order = equiv.glx_doubles_in_order
679 f.glx_rop = equiv.glx_rop
680 else:
681 raise RuntimeError("Could not find the vector equiv. function %s for %s!" % (f.name, f.vectorequiv))
682 else:
683 gl_XML.FilterGLAPISpecBase.endElement(self, name)
684 return
Ian Romanickba09c192005-02-01 00:13:04 +0000685
686
687 def createEnumFunction(self, n):
688 return glXEnumFunction(n, self)
Ian Romanick3fec8c22005-02-02 00:54:45 +0000689
690
691 def functionIterator(self):
692 return glXFunctionIterator(self)
693
694
695 def size_call(self, func):
696 """Create C code to calculate 'compsize'.
697
698 Creates code to calculate 'compsize'. If the function does
699 not need 'compsize' to be calculated, None will be
700 returned."""
701
702 if not func.image and not func.count_parameter_list:
703 return None
704
705 if not func.image:
706 parameters = string.join( func.count_parameter_list, "," )
707 compsize = "__gl%s_size(%s)" % (func.name, parameters)
708 else:
709 [dim, w, h, d, junk] = func.dimensions()
710
711 compsize = '__glImageSize(%s, %s, %s, %s, %s, %s)' % (w, h, d, func.image.img_format, func.image.img_type, func.image.img_target)
712 if not func.image.img_send_null:
713 compsize = '(%s != NULL) ? %s : 0' % (func.image.name, compsize)
714
715 return compsize