blob: 3e749790d81eec8e3cf41ec4a431168031314f47 [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
128 # Determine if there is some mask M, such that M = (2^N) - 1,
129 # that will generate unique values for all of the enums.
130
131 mask = 0
132 for i in [1, 2, 3, 4, 5, 6, 7, 8]:
133 mask = (1 << i) - 1
134
135 fail = 0;
136 for a in self.enums:
137 for b in self.enums:
138 if a != b:
139 if (a & mask) == (b & mask):
140 fail = 1;
141
142 if not fail:
143 break;
144 else:
145 mask = 0
146
147 if (mask != 0) and (mask < (2 * count)):
148 masked_enums = {}
149 masked_count = {}
150
151 for i in range(0, mask + 1):
152 masked_enums[i] = "0";
153 masked_count[i] = 0;
154
155 for c in self.count:
156 for e in self.count[c]:
157 i = e & mask
158 masked_enums[i] = '0x%04x /* %s */' % (e, self.enums[e][0])
159 masked_count[i] = c
160
161
162 print ' static const GLushort a[%u] = {' % (mask + 1)
163 for e in masked_enums:
164 print ' %s, ' % (masked_enums[e])
165 print ' };'
166
167 print ' static const GLubyte b[%u] = {' % (mask + 1)
168 for c in masked_count:
169 print ' %u, ' % (masked_count[c])
170 print ' };'
171
172 print ' const unsigned idx = (e & 0x%02xU);' % (mask)
173 print ''
174 print ' return (e == a[idx]) ? (GLint) b[idx] : 0;'
175 return 1;
176 else:
177 return 0;
178
179 def PrintUsingSwitch(self):
180 """Emit the body of the __gl*_size function using a
181 switch-statement."""
182
183 print ' switch( e ) {'
184
185 for c in self.count:
186 for e in self.count[c]:
187 first = 1
188
189 # There may be multiple enums with the same
190 # value. This happens has extensions are
191 # promoted from vendor-specific or EXT to
192 # ARB and to the core. Emit the first one as
193 # a case label, and emit the others as
194 # commented-out case labels.
195
196 for j in self.enums[e]:
197 if first:
198 print ' case %s:' % (j)
199 first = 0
200 else:
201 print '/* case %s:*/' % (j)
202
203 print ' return %u;' % (c)
204
205 print ' default: return 0;'
206 print ' }'
207
208
209 def Print(self, name):
210 print 'INTERNAL PURE FASTCALL GLint'
211 print '__gl%s_size( GLenum e )' % (name)
212 print '{'
213
214 if not self.PrintUsingTable():
215 self.PrintUsingSwitch()
216
217 print '}'
218 print ''
219
220
221
222class glXEnum(gl_XML.glEnum):
223 def __init__(self, context, name, attrs):
224 gl_XML.glEnum.__init__(self, context, name, attrs)
Ian Romanick0246b2a2005-01-24 20:59:32 +0000225
Ian Romanick74764062004-12-03 20:31:59 +0000226
227 def startElement(self, name, attrs):
228 if name == "size":
Ian Romanick85f0fa32005-01-25 01:20:11 +0000229 [n, c, mode] = self.process_attributes(attrs)
Ian Romanick5ff2b942005-01-24 21:29:13 +0000230
Ian Romanick74764062004-12-03 20:31:59 +0000231 if not self.context.glx_enum_functions.has_key( n ):
Ian Romanickba09c192005-02-01 00:13:04 +0000232 f = self.context.createEnumFunction( n )
Ian Romanick5aa6dc322005-01-27 01:08:48 +0000233 f.set_mode( mode )
Ian Romanick74764062004-12-03 20:31:59 +0000234 self.context.glx_enum_functions[ f.name ] = f
235
Ian Romanick74764062004-12-03 20:31:59 +0000236 self.context.glx_enum_functions[ n ].append( c, self.value, self.name )
237 else:
238 gl_XML.glEnum.startElement(self, context, name, attrs)
239 return
240
241
242class glXParameter(gl_XML.glParameter):
243 def __init__(self, context, name, attrs):
244 self.order = 1;
245 gl_XML.glParameter.__init__(self, context, name, attrs);
246
247
Ian Romanick1d270842004-12-21 21:26:36 +0000248class glXParameterIterator:
249 """Class to iterate over a list of glXParameters.
250
251 Objects of this class are returned by the parameterIterator method of
252 the glXFunction class. They are used to iterate over the list of
253 parameters to the function."""
254
255 def __init__(self, data, skip_output, max_order):
256 self.data = data
257 self.index = 0
258 self.order = 0
259 self.skip_output = skip_output
260 self.max_order = max_order
261
262 def __iter__(self):
263 return self
264
265 def next(self):
266 if len( self.data ) == 0:
267 raise StopIteration
268
269 while 1:
270 if self.index == len( self.data ):
271 if self.order == self.max_order:
272 raise StopIteration
273 else:
274 self.order += 1
275 self.index = 0
276
277 i = self.index
278 self.index += 1
279
280 if self.data[i].order == self.order and not (self.data[i].is_output and self.skip_output):
281 return self.data[i]
282
283
Ian Romanick74764062004-12-03 20:31:59 +0000284class glXFunction(gl_XML.glFunction):
285 glx_rop = 0
286 glx_sop = 0
287 glx_vendorpriv = 0
288
289 # If this is set to true, it means that GLdouble parameters should be
290 # written to the GLX protocol packet in the order they appear in the
291 # prototype. This is different from the "classic" ordering. In the
292 # classic ordering GLdoubles are written to the protocol packet first,
293 # followed by non-doubles. NV_vertex_program was the first extension
294 # to break with this tradition.
295
296 glx_doubles_in_order = 0
297
298 vectorequiv = None
Ian Romanick74764062004-12-03 20:31:59 +0000299 can_be_large = 0
300
301 def __init__(self, context, name, attrs):
302 self.vectorequiv = attrs.get('vectorequiv', None)
Ian Romanick74764062004-12-03 20:31:59 +0000303 self.counter = None
304 self.output = None
305 self.can_be_large = 0
306 self.reply_always_array = 0
307
Ian Romanickfdb05272005-01-28 17:30:25 +0000308 self.server_handcode = 0
309 self.client_handcode = 0
310 self.ignore = 0
311
Ian Romanick74764062004-12-03 20:31:59 +0000312 gl_XML.glFunction.__init__(self, context, name, attrs)
313 return
314
Ian Romanick1d270842004-12-21 21:26:36 +0000315
316 def parameterIterator(self, skip_output, max_order):
317 return glXParameterIterator(self.fn_parameters, skip_output, max_order)
318
319
Ian Romanick74764062004-12-03 20:31:59 +0000320 def startElement(self, name, attrs):
321 """Process elements within a function that are specific to GLX."""
322
323 if name == "glx":
324 self.glx_rop = int(attrs.get('rop', "0"))
325 self.glx_sop = int(attrs.get('sop', "0"))
326 self.glx_vendorpriv = int(attrs.get('vendorpriv', "0"))
327
Ian Romanickfdb05272005-01-28 17:30:25 +0000328 # The 'handcode' attribute can be one of 'true',
329 # 'false', 'client', or 'server'.
330
331 handcode = attrs.get('handcode', "false")
332 if handcode == "false":
333 self.server_handcode = 0
334 self.client_handcode = 0
335 elif handcode == "true":
336 self.server_handcode = 1
337 self.client_handcode = 1
338 elif handcode == "client":
339 self.server_handcode = 0
340 self.client_handcode = 1
341 elif handcode == "server":
342 self.server_handcode = 1
343 self.client_handcode = 0
Ian Romanick74764062004-12-03 20:31:59 +0000344 else:
Ian Romanickfdb05272005-01-28 17:30:25 +0000345 raise RuntimeError('Invalid handcode mode "%s" in function "%s".' % (handcode, self.name))
346
Ian Romanick74764062004-12-03 20:31:59 +0000347
348 if attrs.get('ignore', "false") == "true":
349 self.ignore = 1
350 else:
351 self.ignore = 0
352
353 if attrs.get('large', "false") == "true":
354 self.can_be_large = 1
355 else:
356 self.can_be_large = 0
357
358 if attrs.get('doubles_in_order', "false") == "true":
359 self.glx_doubles_in_order = 1
360 else:
361 self.glx_doubles_in_order = 0
362
363 if attrs.get('always_array', "false") == "true":
364 self.reply_always_array = 1
365 else:
366 self.reply_always_array = 0
367
368 else:
369 gl_XML.glFunction.startElement(self, name, attrs)
370
371
Ian Romanick7f958e92005-01-24 20:08:28 +0000372 def endElement(self, name):
373 if name == "function":
374 # Mark any function that does not have GLX protocol
375 # defined as "ignore". This prevents bad things from
376 # happening when people add new functions to the GL
377 # API XML without adding any GLX section.
378 #
379 # This will also mark functions that don't have a
380 # dispatch offset at ignored.
381
Ian Romanickfdb05272005-01-28 17:30:25 +0000382 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 +0000383 #if not self.ignore:
384 # if self.fn_offset == -1:
385 # print '/* %s ignored becuase no offset assigned. */' % (self.name)
386 # else:
387 # print '/* %s ignored becuase no GLX opcode assigned. */' % (self.name)
388
389 self.ignore = 1
390
391 return gl_XML.glFunction.endElement(self, name)
392
393
Ian Romanick74764062004-12-03 20:31:59 +0000394 def append(self, tag_name, p):
395 gl_XML.glFunction.append(self, tag_name, p)
396
397 if p.is_variable_length_array():
398 p.order = 2;
399 elif not self.glx_doubles_in_order and p.p_type.size == 8:
400 p.order = 0;
401
Ian Romanick74764062004-12-03 20:31:59 +0000402 if p.is_counter:
403 self.counter = p.name
404
405 if p.is_output:
406 self.output = p
407
408 return
409
Ian Romanick0246b2a2005-01-24 20:59:32 +0000410
Ian Romanick74764062004-12-03 20:31:59 +0000411 def variable_length_parameter(self):
412 for param in self.fn_parameters:
413 if param.is_variable_length_array():
414 return param
415
416 return None
417
418
Ian Romanick54584df2005-01-28 18:20:43 +0000419 def output_parameter(self):
420 for param in self.fn_parameters:
421 if param.is_output:
422 return param
423
424 return None
425
426
Ian Romanick0246b2a2005-01-24 20:59:32 +0000427 def offset_of_first_parameter(self):
428 """Get the offset of the first parameter in the command.
429
430 Gets the offset of the first function parameter in the GLX
431 command packet. This byte offset is measured from the end
432 of the Render / RenderLarge header. The offset for all non-
433 pixel commends is zero. The offset for pixel commands depends
434 on the number of dimensions of the pixel data."""
Ian Romanick5f1f2292005-01-07 02:39:09 +0000435
436 if self.image:
437 [dim, junk, junk, junk, junk] = self.dimensions()
Ian Romanick0246b2a2005-01-24 20:59:32 +0000438
Ian Romanick5f1f2292005-01-07 02:39:09 +0000439 # The base size is the size of the pixel pack info
440 # header used by images with the specified number
441 # of dimensions.
442
443 if dim <= 2:
Ian Romanick0246b2a2005-01-24 20:59:32 +0000444 return 20
Ian Romanick5f1f2292005-01-07 02:39:09 +0000445 elif dim <= 4:
Ian Romanick0246b2a2005-01-24 20:59:32 +0000446 return 36
Ian Romanick5f1f2292005-01-07 02:39:09 +0000447 else:
448 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 +0000449 else:
450 return 0
Ian Romanick5f1f2292005-01-07 02:39:09 +0000451
Ian Romanick5f1f2292005-01-07 02:39:09 +0000452
Ian Romanick0246b2a2005-01-24 20:59:32 +0000453 def command_fixed_length(self):
454 """Return the length, in bytes as an integer, of the
455 fixed-size portion of the command."""
Ian Romanick5f1f2292005-01-07 02:39:09 +0000456
Ian Romanick0246b2a2005-01-24 20:59:32 +0000457 size = self.offset_of_first_parameter()
Ian Romanick5f1f2292005-01-07 02:39:09 +0000458
Ian Romanick0246b2a2005-01-24 20:59:32 +0000459 for p in gl_XML.glFunction.parameterIterator(self):
460 if not p.is_output:
461 size += p.size()
462 if self.pad_after(p):
463 size += 4
464
465 if self.image and self.image.img_null_flag:
466 size += 4
467
468 return size
469
470
471 def command_variable_length(self):
472 """Return the length, as a string, of the variable-sized
473 portion of the command."""
474
Ian Romanick74764062004-12-03 20:31:59 +0000475 size_string = ""
Ian Romanick1d270842004-12-21 21:26:36 +0000476 for p in gl_XML.glFunction.parameterIterator(self):
Ian Romanick0246b2a2005-01-24 20:59:32 +0000477 if (not p.is_output) and (p.size() == 0):
478 size_string = size_string + " + __GLX_PAD(%s)" % (p.size_string())
Ian Romanick74764062004-12-03 20:31:59 +0000479
Ian Romanick0246b2a2005-01-24 20:59:32 +0000480 return size_string
481
Ian Romanick74764062004-12-03 20:31:59 +0000482
483 def command_length(self):
Ian Romanick0246b2a2005-01-24 20:59:32 +0000484 size = self.command_fixed_length()
Ian Romanick74764062004-12-03 20:31:59 +0000485
486 if self.glx_rop != 0:
487 size += 4
488
489 size = ((size + 3) & ~3)
Ian Romanick0246b2a2005-01-24 20:59:32 +0000490 return "%u%s" % (size, self.command_variable_length())
Ian Romanick74764062004-12-03 20:31:59 +0000491
492
493 def opcode_real_value(self):
Ian Romanick1d270842004-12-21 21:26:36 +0000494 """Get the true numeric value of the GLX opcode
495
496 Behaves similarly to opcode_value, except for
497 X_GLXVendorPrivate and X_GLXVendorPrivateWithReply commands.
498 In these cases the value for the GLX opcode field (i.e.,
499 16 for X_GLXVendorPrivate or 17 for
500 X_GLXVendorPrivateWithReply) is returned. For other 'single'
501 commands, the opcode for the command (e.g., 101 for
502 X_GLsop_NewList) is returned."""
503
Ian Romanick74764062004-12-03 20:31:59 +0000504 if self.glx_vendorpriv != 0:
505 if self.needs_reply():
506 return 17
507 else:
508 return 16
509 else:
510 return self.opcode_value()
511
512 def opcode_value(self):
Ian Romanick1d270842004-12-21 21:26:36 +0000513 """Get the unique protocol opcode for the glXFunction"""
514
Ian Romanick74764062004-12-03 20:31:59 +0000515 if self.glx_rop != 0:
516 return self.glx_rop
517 elif self.glx_sop != 0:
518 return self.glx_sop
519 elif self.glx_vendorpriv != 0:
520 return self.glx_vendorpriv
521 else:
522 return -1
523
524 def opcode_rop_basename(self):
Ian Romanick1d270842004-12-21 21:26:36 +0000525 """Return either the name to be used for GLX protocol enum.
526
527 Returns either the name of the function or the name of the
528 name of the equivalent vector (e.g., glVertex3fv for
529 glVertex3f) function."""
530
Ian Romanick74764062004-12-03 20:31:59 +0000531 if self.vectorequiv == None:
532 return self.name
533 else:
534 return self.vectorequiv
535
536 def opcode_name(self):
Ian Romanick1d270842004-12-21 21:26:36 +0000537 """Get the unique protocol enum name for the glXFunction"""
538
Ian Romanick74764062004-12-03 20:31:59 +0000539 if self.glx_rop != 0:
540 return "X_GLrop_%s" % (self.opcode_rop_basename())
541 elif self.glx_sop != 0:
542 return "X_GLsop_%s" % (self.name)
543 elif self.glx_vendorpriv != 0:
544 return "X_GLvop_%s" % (self.name)
545 else:
Ian Romanick3fec8c22005-02-02 00:54:45 +0000546 raise RuntimeError('Function "%s" has no opcode.' % (self.name))
547
Ian Romanick74764062004-12-03 20:31:59 +0000548
549 def opcode_real_name(self):
Ian Romanick1d270842004-12-21 21:26:36 +0000550 """Get the true protocol enum name for the GLX opcode
551
552 Behaves similarly to opcode_name, except for
553 X_GLXVendorPrivate and X_GLXVendorPrivateWithReply commands.
554 In these cases the string 'X_GLXVendorPrivate' or
555 'X_GLXVendorPrivateWithReply' is returned. For other
556 single or render commands 'X_GLsop' or 'X_GLrop' plus the
557 name of the function returned."""
558
Ian Romanick74764062004-12-03 20:31:59 +0000559 if self.glx_vendorpriv != 0:
560 if self.needs_reply():
561 return "X_GLXVendorPrivateWithReply"
562 else:
563 return "X_GLXVendorPrivate"
564 else:
565 return self.opcode_name()
566
567
568 def return_string(self):
569 if self.fn_return_type != 'void':
570 return "return retval;"
571 else:
572 return "return;"
573
574
575 def needs_reply(self):
576 return self.fn_return_type != 'void' or self.output != None
577
578
Ian Romanick5f1f2292005-01-07 02:39:09 +0000579 def dimensions(self):
580 """Determine the dimensions of an image.
581
582 Returns a tuple representing the number of dimensions and the
583 string name of each of the dimensions of an image, If the
584 function is not a pixel function, the number of dimensions
585 will be zero."""
586
587 if not self.image:
588 return [0, "0", "0", "0", "0"]
589 else:
590 dim = 1
591 w = self.image.width
592
593 if self.image.height:
594 dim = 2
595 h = self.image.height
596 else:
597 h = "1"
598
599 if self.image.depth:
600 dim = 3
601 d = self.image.depth
602 else:
603 d = "1"
604
605 if self.image.extent:
606 dim = 4
607 e = self.image.extent
608 else:
609 e = "1"
610
611 return [dim, w, h, d, e]
612
613
614 def pad_after(self, p):
615 """Returns the name of the field inserted after the
616 specified field to pad out the command header."""
617
618 if self.image and self.image.img_pad_dimensions:
619 if not self.image.height:
620 if p.name == self.image.width:
621 return "height"
622 elif p.name == self.image.img_xoff:
623 return "yoffset"
624 elif not self.image.extent:
625 if p.name == self.image.depth:
626 # Should this be "size4d"?
627 return "extent"
628 elif p.name == self.image.img_zoff:
629 return "woffset"
630 return None
631
Ian Romanick3fec8c22005-02-02 00:54:45 +0000632
633class glXFunctionIterator(gl_XML.glFunctionIterator):
634 """Class to iterate over a list of glXFunctions"""
635
636 def __init__(self, context):
637 self.context = context
638 self.keys = context.functions.keys()
639 self.keys.sort()
640
641 for self.index in range(0, len(self.keys)):
642 if self.keys[ self.index ] >= 0: break
643
644 return
645
646
647 def next(self):
648 if self.index == len(self.keys):
649 raise StopIteration
650
651 f = self.context.functions[ self.keys[ self.index ] ]
652 self.index += 1
653
654 if f.ignore:
655 return self.next()
656 else:
657 return f
658
659
Ian Romanick74764062004-12-03 20:31:59 +0000660class GlxProto(gl_XML.FilterGLAPISpecBase):
661 name = "glX_proto_send.py (from Mesa)"
662
663 def __init__(self):
664 gl_XML.FilterGLAPISpecBase.__init__(self)
665 self.factory = glXItemFactory()
666 self.glx_enum_functions = {}
667
668
669 def endElement(self, name):
670 if name == 'OpenGLAPI':
671 # Once all the parsing is done, we have to go back and
672 # fix-up some cross references between different
673 # functions.
674
675 for k in self.functions:
676 f = self.functions[k]
677 if f.vectorequiv != None:
678 equiv = self.find_function(f.vectorequiv)
679 if equiv != None:
680 f.glx_doubles_in_order = equiv.glx_doubles_in_order
681 f.glx_rop = equiv.glx_rop
682 else:
683 raise RuntimeError("Could not find the vector equiv. function %s for %s!" % (f.name, f.vectorequiv))
684 else:
685 gl_XML.FilterGLAPISpecBase.endElement(self, name)
686 return
Ian Romanickba09c192005-02-01 00:13:04 +0000687
688
689 def createEnumFunction(self, n):
690 return glXEnumFunction(n, self)
Ian Romanick3fec8c22005-02-02 00:54:45 +0000691
692
693 def functionIterator(self):
694 return glXFunctionIterator(self)
695
696
697 def size_call(self, func):
698 """Create C code to calculate 'compsize'.
699
700 Creates code to calculate 'compsize'. If the function does
701 not need 'compsize' to be calculated, None will be
702 returned."""
703
704 if not func.image and not func.count_parameter_list:
705 return None
706
707 if not func.image:
708 parameters = string.join( func.count_parameter_list, "," )
709 compsize = "__gl%s_size(%s)" % (func.name, parameters)
710 else:
711 [dim, w, h, d, junk] = func.dimensions()
712
713 compsize = '__glImageSize(%s, %s, %s, %s, %s, %s)' % (w, h, d, func.image.img_format, func.image.img_type, func.image.img_target)
714 if not func.image.img_send_null:
715 compsize = '(%s != NULL) ? %s : 0' % (func.image.name, compsize)
716
717 return compsize