class glXEnum(gl_XML.glEnum):
def __init__(self, context, name, attrs):
gl_XML.glEnum.__init__(self, context, name, attrs)
- self.glx_functions = []
+
def startElement(self, name, attrs):
if name == "size":
return
+
def variable_length_parameter(self):
for param in self.fn_parameters:
if param.is_variable_length_array():
return None
- def command_payload_length(self):
- size = 0
+ def offset_of_first_parameter(self):
+ """Get the offset of the first parameter in the command.
+
+ Gets the offset of the first function parameter in the GLX
+ command packet. This byte offset is measured from the end
+ of the Render / RenderLarge header. The offset for all non-
+ pixel commends is zero. The offset for pixel commands depends
+ on the number of dimensions of the pixel data."""
if self.image:
[dim, junk, junk, junk, junk] = self.dimensions()
-
+
# The base size is the size of the pixel pack info
# header used by images with the specified number
# of dimensions.
if dim <= 2:
- size = 20
+ return 20
elif dim <= 4:
- size = 36
+ return 36
else:
raise RuntimeError('Invalid number of dimensions %u for parameter "%s" in function "%s".' % (dim, self.image.name, self.name))
+ else:
+ return 0
- if self.image.img_null_flag:
- size += 4
- if self.image.img_pad_dimensions:
- size += 4 * (dim & 1)
-
- # If the image has offset parameters, like
- # TexSubImage1D or TexSubImage3D, they need to
- # be padded out as well.
+ def command_fixed_length(self):
+ """Return the length, in bytes as an integer, of the
+ fixed-size portion of the command."""
- if self.image.img_xoff:
- size += 4 * (dim & 1)
-
+ size = self.offset_of_first_parameter()
+
+ for p in gl_XML.glFunction.parameterIterator(self):
+ if not p.is_output:
+ size += p.size()
+ if self.pad_after(p):
+ size += 4
+
+ if self.image and self.image.img_null_flag:
+ size += 4
+
+ return size
+
+
+ def command_variable_length(self):
+ """Return the length, as a string, of the variable-sized
+ portion of the command."""
-
size_string = ""
for p in gl_XML.glFunction.parameterIterator(self):
- if p.is_output: continue
- temp = p.size_string()
- try:
- s = int(temp)
- size += s
- except Exception,e:
- size_string = size_string + " + __GLX_PAD(%s)" % (temp)
+ if (not p.is_output) and (p.size() == 0):
+ size_string = size_string + " + __GLX_PAD(%s)" % (p.size_string())
+
+ return size_string
- return [size, size_string]
def command_length(self):
- [size, size_string] = self.command_payload_length()
+ size = self.command_fixed_length()
if self.glx_rop != 0:
size += 4
size = ((size + 3) & ~3)
- return "%u%s" % (size, size_string)
+ return "%u%s" % (size, self.command_variable_length())
def opcode_real_value(self):
indent += " "
[dim, width, height, depth, extent] = pixel_func.dimensions()
-
- if dim < 3:
- adjust = 20 + 4
- else:
- adjust = 36 + 4
-
+ adjust = pixel_func.offset_of_first_parameter() + 4
print '%s emit_header(gc->pc, opcode, cmdlen);' % (indent)
offset = self.pixel_emit_args(pixel_func, "gc->pc", indent, adjust, dim, 0)
- [s, junk] = pixel_func.command_payload_length()
+ s = pixel_func.command_fixed_length()
pixHeaderPtr = "gc->pc + 4"
pcPtr = "gc->pc + %u" % (s + 4)
indent += " "
[dim, width, height, depth, extent] = f.dimensions()
-
- if dim < 3:
- adjust = 20 + 4
- else:
- adjust = 36 + 4
-
+ adjust = f.offset_of_first_parameter() + 4
print '%s emit_header(gc->pc, %s, cmdlen);' % (indent, f.opcode_real_name())
offset = self.pixel_emit_args(f, "gc->pc", indent, adjust, dim, 0)
- [s, junk] = f.command_payload_length()
+ s = f.command_fixed_length()
pixHeaderPtr = "gc->pc + 4"
pcPtr = "gc->pc + %u" % (s + 4)
if f.variable_length_parameter() == None and len(f.fn_parameters) == 1:
p = f.fn_parameters[0]
if p.is_pointer:
- [cmdlen, size_string] = f.command_payload_length()
+ cmdlen = f.command_fixed_length()
if cmdlen in self.generic_sizes:
self.common_func_print_just_header(f)
print ' generic_%u_byte( %s, %s );' % (cmdlen, f.opcode_real_name(), p.name)