1 from __future__
import print_function
5 * Copyright 2009 VMware, Inc.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * on the rights to use, copy, modify, merge, publish, distribute, sub
12 * license, and/or sell copies of the Software, and to permit persons to whom
13 * the Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
22 * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
23 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25 * USE OR OTHER DEALINGS IN THE SOFTWARE.
29 GENERATE
, UBYTE
, USHORT
, UINT
= 'generate', 'ubyte', 'ushort', 'uint'
30 FIRST
, LAST
= 'first', 'last'
32 INTYPES
= (GENERATE
, UBYTE
, USHORT
, UINT
)
33 OUTTYPES
= (USHORT
, UINT
)
43 LONGPRIMS
=('PIPE_PRIM_TRIANGLES',
44 'PIPE_PRIM_TRIANGLE_FAN',
45 'PIPE_PRIM_TRIANGLE_STRIP',
47 'PIPE_PRIM_QUAD_STRIP',
49 'PIPE_PRIM_TRIANGLES_ADJACENCY',
50 'PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY')
52 longprim
= dict(zip(PRIMS
, LONGPRIMS
))
53 intype_idx
= dict(ubyte
='IN_UBYTE', ushort
='IN_USHORT', uint
='IN_UINT')
54 outtype_idx
= dict(ushort
='OUT_USHORT', uint
='OUT_UINT')
58 print('''/* File automatically generated by u_unfilled_gen.py */''')
64 * Functions to translate and generate index lists
67 #include "indices/u_indices.h"
68 #include "indices/u_indices_priv.h"
69 #include "pipe/p_compiler.h"
70 #include "util/u_debug.h"
71 #include "pipe/p_defines.h"
72 #include "util/u_memory.h"
75 static unsigned out_size_idx( unsigned index_size )
78 case 4: return OUT_UINT;
79 case 2: return OUT_USHORT;
80 default: assert(0); return OUT_USHORT;
84 static unsigned in_size_idx( unsigned index_size )
87 case 4: return IN_UINT;
88 case 2: return IN_USHORT;
89 case 1: return IN_UBYTE;
90 default: assert(0); return IN_UBYTE;
95 static u_generate_func generate_line[OUT_COUNT][PRIM_COUNT];
96 static u_translate_func translate_line[IN_COUNT][OUT_COUNT][PRIM_COUNT];
100 def vert( intype
, outtype
, v0
):
101 if intype
== GENERATE
:
102 return '(' + outtype
+ ')(' + v0
+ ')'
104 return '(' + outtype
+ ')in[' + v0
+ ']'
106 def line( intype
, outtype
, ptr
, v0
, v1
):
107 print(' (' + ptr
+ ')[0] = ' + vert( intype
, outtype
, v0
) + ';')
108 print(' (' + ptr
+ ')[1] = ' + vert( intype
, outtype
, v1
) + ';')
110 # XXX: have the opportunity here to avoid over-drawing shared lines in
111 # tristrips, fans, etc, by integrating this into the calling functions
112 # and only emitting each line at most once.
114 def do_tri( intype
, outtype
, ptr
, v0
, v1
, v2
):
115 line( intype
, outtype
, ptr
, v0
, v1
)
116 line( intype
, outtype
, ptr
+ '+2', v1
, v2
)
117 line( intype
, outtype
, ptr
+ '+4', v2
, v0
)
119 def do_quad( intype
, outtype
, ptr
, v0
, v1
, v2
, v3
):
120 line( intype
, outtype
, ptr
, v0
, v1
)
121 line( intype
, outtype
, ptr
+ '+2', v1
, v2
)
122 line( intype
, outtype
, ptr
+ '+4', v2
, v3
)
123 line( intype
, outtype
, ptr
+ '+6', v3
, v0
)
125 def name(intype
, outtype
, prim
):
126 if intype
== GENERATE
:
127 return 'generate_' + prim
+ '_' + outtype
129 return 'translate_' + prim
+ '_' + intype
+ '2' + outtype
131 def preamble(intype
, outtype
, prim
):
132 print('static void ' + name( intype
, outtype
, prim
) + '(')
133 if intype
!= GENERATE
:
134 print(' const void * _in,')
135 print(' unsigned start,')
136 if intype
!= GENERATE
:
137 print(' unsigned in_nr,')
138 print(' unsigned out_nr,')
139 if intype
!= GENERATE
:
140 print(' unsigned restart_index,')
141 print(' void *_out )')
143 if intype
!= GENERATE
:
144 print(' const ' + intype
+ '*in = (const ' + intype
+ '*)_in;')
145 print(' ' + outtype
+ ' *out = (' + outtype
+ '*)_out;')
146 print(' unsigned i, j;')
153 def tris(intype
, outtype
):
154 preamble(intype
, outtype
, prim
='tris')
155 print(' for (i = start, j = 0; j < out_nr; j+=6, i+=3) { ')
156 do_tri( intype
, outtype
, 'out+j', 'i', 'i+1', 'i+2' );
161 def tristrip(intype
, outtype
):
162 preamble(intype
, outtype
, prim
='tristrip')
163 print(' for (i = start, j = 0; j < out_nr; j+=6, i++) { ')
164 do_tri( intype
, outtype
, 'out+j', 'i', 'i+1/*+(i&1)*/', 'i+2/*-(i&1)*/' );
169 def trifan(intype
, outtype
):
170 preamble(intype
, outtype
, prim
='trifan')
171 print(' for (i = start, j = 0; j < out_nr; j+=6, i++) { ')
172 do_tri( intype
, outtype
, 'out+j', '0', 'i+1', 'i+2' );
178 def polygon(intype
, outtype
):
179 preamble(intype
, outtype
, prim
='polygon')
180 print(' for (i = start, j = 0; j < out_nr; j+=2, i++) { ')
181 line( intype
, outtype
, 'out+j', 'i', '(i+1)%(out_nr/2)' )
186 def quads(intype
, outtype
):
187 preamble(intype
, outtype
, prim
='quads')
188 print(' for (i = start, j = 0; j < out_nr; j+=8, i+=4) { ')
189 do_quad( intype
, outtype
, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3' );
194 def quadstrip(intype
, outtype
):
195 preamble(intype
, outtype
, prim
='quadstrip')
196 print(' for (i = start, j = 0; j < out_nr; j+=8, i+=2) { ')
197 do_quad( intype
, outtype
, 'out+j', 'i+2', 'i+0', 'i+1', 'i+3' );
202 def trisadj(intype
, outtype
):
203 preamble(intype
, outtype
, prim
='trisadj')
204 print(' for (i = start, j = 0; j < out_nr; j+=6, i+=6) { ')
205 do_tri( intype
, outtype
, 'out+j', 'i', 'i+2', 'i+4' );
210 def tristripadj(intype
, outtype
):
211 preamble(intype
, outtype
, prim
='tristripadj')
212 print(' for (i = start, j = 0; j < out_nr; j+=6, i+=2) { ')
213 do_tri( intype
, outtype
, 'out+j', 'i', 'i+2', 'i+4' );
219 for intype
in INTYPES
:
220 for outtype
in OUTTYPES
:
221 tris(intype
, outtype
)
222 tristrip(intype
, outtype
)
223 trifan(intype
, outtype
)
224 quads(intype
, outtype
)
225 quadstrip(intype
, outtype
)
226 polygon(intype
, outtype
)
227 trisadj(intype
, outtype
)
228 tristripadj(intype
, outtype
)
230 def init(intype
, outtype
, prim
):
231 if intype
== GENERATE
:
232 print(('generate_line[' +
233 outtype_idx
[outtype
] +
234 '][' + longprim
[prim
] +
235 '] = ' + name( intype
, outtype
, prim
) + ';'))
237 print(('translate_line[' +
239 '][' + outtype_idx
[outtype
] +
240 '][' + longprim
[prim
] +
241 '] = ' + name( intype
, outtype
, prim
) + ';'))
244 def emit_all_inits():
245 for intype
in INTYPES
:
246 for outtype
in OUTTYPES
:
248 init(intype
, outtype
, prim
)
251 print('void u_unfilled_init( void )')
253 print(' static int firsttime = 1;')
254 print(' if (!firsttime) return;')
255 print(' firsttime = 0;')
263 print('#include "indices/u_unfilled_indices.c"')
273 if __name__
== '__main__':