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>
34 class glXDocItemFactory(glX_XML
.glXItemFactory
):
35 """Factory to create GLX protocol documentation oriented objects derived from glItem."""
37 def create(self
, context
, name
, attrs
):
39 return glXDocParameter(context
, name
, attrs
)
41 return glX_XML
.glXItemFactory
.create(self
, context
, name
, attrs
)
43 class glXDocParameter(gl_XML
.glParameter
):
44 def __init__(self
, context
, name
, attrs
):
46 gl_XML
.glParameter
.__init
__(self
, context
, name
, attrs
);
49 def packet_type(self
):
50 """Get the type string for the packet header
52 GLX protocol documentation uses type names like CARD32,
53 FLOAT64, LISTofCARD8, and ENUM. This function converts the
54 type of the parameter to one of these names."""
60 if self
.p_type
.glx_name
== "":
63 type_name
= self
.p_type
.glx_name
65 return "%s%s" % (list_of
, type_name
)
67 def packet_size(self
):
72 b_prod
= self
.p_type
.size
74 if not self
.count_parameter_list
and self
.counter
:
76 elif self
.count_parameter_list
and not self
.counter
or self
.is_output
:
78 elif self
.count_parameter_list
and self
.counter
:
81 raise RuntimeError("Parameter '%s' to function '%s' has size 0." % (self
.name
, self
.context
.name
))
83 ss
= "%s*%s" % (a_prod
, b_prod
)
92 class PrintGlxProtoText(glX_XML
.GlxProto
):
94 glX_XML
.GlxProto
.__init
__(self
)
95 self
.factory
= glXDocItemFactory()
96 self
.last_category
= ""
99 def printHeader(self
):
102 def body_size(self
, f
):
103 # At some point, refactor this function and
104 # glXFunction::command_payload_length.
110 for p
in f
.parameterIterator(1, 2):
111 [s
, pad
] = p
.packet_size()
115 size_str
+= "%s%s" % (plus
, s
)
121 return [size
, size_str
, pad_str
]
123 def print_render_header(self
, f
):
124 [size
, size_str
, pad_str
] = self
.body_size(f
)
128 s
= "%u" % ((size
+ 3) & ~
3)
130 s
= "%u+%s+%s" % (size
, size_str
, pad_str
)
132 s
= "%u+%s" % (size
, size_str
)
134 print ' 2 %-15s rendering command length' % (s
)
135 print ' 2 %-4u rendering command opcode' % (f
.glx_rop
)
139 def print_single_header(self
, f
):
140 [size
, size_str
, pad_str
] = self
.body_size(f
)
141 size
= ((size
+ 3) / 4) + 2;
143 if f
.glx_vendorpriv
!= 0:
146 print ' 1 CARD8 opcode (X assigned)'
147 print ' 1 %-4u GLX opcode (%s)' % (f
.opcode_real_value(), f
.opcode_real_name())
152 s
= "%u+((%s+%s)/4)" % (size
, size_str
, pad_str
)
154 s
= "%u+((%s)/4)" % (size
, size_str
)
156 print ' 2 %-15s request length' % (s
)
158 if f
.glx_vendorpriv
!= 0:
159 print ' 4 %-4u vendor specific opcode' % (f
.opcode_value())
161 print ' 4 GLX_CONTEXT_TAG context tag'
165 def print_reply(self
, f
):
169 print ' 2 CARD16 sequence number'
172 print ' 4 0 reply length'
173 elif f
.reply_always_array
:
174 print ' 4 m reply length'
176 print ' 4 m reply length, m = (n == 1 ? 0 : n)'
180 if f
.fn_return_type
!= 'void':
181 print ' 4 %-15s return value' % (f
.fn_return_type
)
183 elif f
.output
!= None:
192 if not f
.reply_always_array
:
194 print ' if (n = 1) this follows:'
196 print ' 4 CARD32 %s' % (f
.output
.name
)
197 print ' %-2u unused' % (unused
- 4)
199 print ' otherwise this follows:'
202 print ' %-2u unused' % (unused
)
204 [s
, pad
] = p
.packet_size()
205 print ' %-8s %-15s %s' % (s
, p
.packet_type(), p
.name
)
209 bytes
= 4 - (bytes
& 3)
210 print ' %-8u %-15s unused' % (bytes
, "")
212 print ' %-8s %-15s unused, %s=pad(%s)' % (pad
, "", pad
, s
)
214 print ' %-2u unused' % (unused
)
217 def print_body(self
, f
):
218 for p
in f
.parameterIterator(1, 2):
219 [s
, pad
] = p
.packet_size()
220 print ' %-8s %-15s %s' % (s
, p
.packet_type(), p
.name
)
224 bytes
= 4 - (bytes
& 3)
225 print ' %-8u %-15s unused' % (bytes
, "")
227 print ' %-8s %-15s unused, %s=pad(%s)' % (pad
, "", pad
, s
)
229 def printFunction(self
, f
):
230 # At some point this should be expanded to support pixel
231 # functions, but I'm not going to lose any sleep over it now.
233 if f
.client_handcode
or f
.server_handcode
or f
.vectorequiv
or f
.image
:
236 print ' %s' % (f
.name
)
239 self
.print_render_header(f
)
241 self
.print_single_header(f
)
252 if __name__
== '__main__':
253 file_name
= "gl_API.xml"
256 (args
, trail
) = getopt
.getopt(sys
.argv
[1:], "f:")
260 for (arg
,val
) in args
:
264 dh
= PrintGlxProtoText()
265 gl_XML
.parse_GL_API( dh
, file_name
)