3 # (C) Copyright IBM Corporation 2004, 2005
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:
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
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
26 # Ian Romanick <idr@us.ibm.com>
28 import gl_XML
, glX_XML
, glX_proto_common
, license
32 class glx_doc_item_factory(glX_proto_common
.glx_proto_item_factory
):
33 """Factory to create GLX protocol documentation oriented objects derived from glItem."""
35 def create_item(self
, name
, element
, context
):
36 if name
== "parameter":
37 return glx_doc_parameter(element
, context
)
39 return glX_proto_common
.glx_proto_item_factory
.create_item(self
, name
, element
, context
)
42 class glx_doc_parameter(gl_XML
.gl_parameter
):
43 def packet_type(self
, type_dict
):
44 """Get the type string for the packet header
46 GLX protocol documentation uses type names like CARD32,
47 FLOAT64, LISTofCARD8, and ENUM. This function converts the
48 type of the parameter to one of these names."""
54 t_name
= self
.get_base_type_string()
55 if not type_dict
.has_key( t_name
):
58 type_name
= type_dict
[ t_name
]
60 return "%s%s" % (list_of
, type_name
)
63 def packet_size(self
):
68 b_prod
= self
.p_type
.size
70 if not self
.count_parameter_list
and self
.counter
:
72 elif self
.count_parameter_list
and not self
.counter
or self
.is_output
:
74 elif self
.count_parameter_list
and self
.counter
:
77 raise RuntimeError("Parameter '%s' to function '%s' has size 0." % (self
.name
, self
.context
.name
))
79 ss
= "%s*%s" % (a_prod
, b_prod
)
88 class PrintGlxProtoText(gl_XML
.gl_print_base
):
90 gl_XML
.gl_print_base
.__init
__(self
)
94 def printHeader(self
):
98 def body_size(self
, f
):
99 # At some point, refactor this function and
100 # glXFunction::command_payload_length.
106 for p
in f
.parameterIterateGlxSend():
107 [s
, pad
] = p
.packet_size()
111 size_str
+= "%s%s" % (plus
, s
)
117 return [size
, size_str
, pad_str
]
120 def print_render_header(self
, f
):
121 [size
, size_str
, pad_str
] = self
.body_size(f
)
125 s
= "%u" % ((size
+ 3) & ~
3)
127 s
= "%u+%s+%s" % (size
, size_str
, pad_str
)
129 s
= "%u+%s" % (size
, size_str
)
131 print ' 2 %-15s rendering command length' % (s
)
132 print ' 2 %-4u rendering command opcode' % (f
.glx_rop
)
136 def print_single_header(self
, f
):
137 [size
, size_str
, pad_str
] = self
.body_size(f
)
138 size
= ((size
+ 3) / 4) + 2;
140 if f
.glx_vendorpriv
!= 0:
143 print ' 1 CARD8 opcode (X assigned)'
144 print ' 1 %-4u GLX opcode (%s)' % (f
.opcode_real_value(), f
.opcode_real_name())
149 s
= "%u+((%s+%s)/4)" % (size
, size_str
, pad_str
)
151 s
= "%u+((%s)/4)" % (size
, size_str
)
153 print ' 2 %-15s request length' % (s
)
155 if f
.glx_vendorpriv
!= 0:
156 print ' 4 %-4u vendor specific opcode' % (f
.opcode_value())
158 print ' 4 GLX_CONTEXT_TAG context tag'
163 def print_reply(self
, f
):
167 print ' 2 CARD16 sequence number'
170 print ' 4 0 reply length'
171 elif f
.reply_always_array
:
172 print ' 4 m reply length'
174 print ' 4 m reply length, m = (n == 1 ? 0 : n)'
178 for x
in f
.parameterIterateOutputs():
184 if f
.return_type
!= 'void':
185 print ' 4 %-15s return value' % (f
.return_type
)
196 if not f
.reply_always_array
:
198 print ' if (n = 1) this follows:'
200 print ' 4 CARD32 %s' % (output
.name
)
201 print ' %-2u unused' % (unused
- 4)
203 print ' otherwise this follows:'
206 print ' %-2u unused' % (unused
)
208 [s
, pad
] = output
.packet_size()
209 print ' %-8s %-15s %s' % (s
, output
.packet_type( self
.type_map
), output
.name
)
213 bytes
= 4 - (bytes
& 3)
214 print ' %-8u %-15s unused' % (bytes
, "")
216 print ' %-8s %-15s unused, %s=pad(%s)' % (pad
, "", pad
, s
)
218 print ' %-2u unused' % (unused
)
221 def print_body(self
, f
):
222 for p
in f
.parameterIterateGlxSend():
223 [s
, pad
] = p
.packet_size()
224 print ' %-8s %-15s %s' % (s
, p
.packet_type( self
.type_map
), p
.name
)
228 bytes
= 4 - (bytes
& 3)
229 print ' %-8u %-15s unused' % (bytes
, "")
231 print ' %-8s %-15s unused, %s=pad(%s)' % (pad
, "", pad
, s
)
233 def printBody(self
, api
):
235 for t
in api
.typeIterate():
236 self
.type_map
[ "GL" + t
.name
] = t
.glx_name
239 # At some point this should be expanded to support pixel
240 # functions, but I'm not going to lose any sleep over it now.
242 for f
in api
.functionIterateByOffset():
243 if f
.client_handcode
or f
.server_handcode
or f
.vectorequiv
or len(f
.get_images()):
248 print ' %s' % (f
.name
)
249 self
.print_render_header(f
)
250 elif f
.glx_sop
or f
.glx_vendorpriv
:
251 print ' %s' % (f
.name
)
252 self
.print_single_header(f
)
265 if __name__
== '__main__':
266 file_name
= "gl_API.xml"
269 (args
, trail
) = getopt
.getopt(sys
.argv
[1:], "f:")
273 for (arg
,val
) in args
:
277 api
= gl_XML
.parse_GL_API( file_name
, glx_doc_item_factory() )
279 printer
= PrintGlxProtoText()