4780d98383a1186fd7600056a7d1d151ea9a98ce
3 * Copyright 2009 VMware, Inc.
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 * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 * USE OR OTHER DEALINGS IN THE SOFTWARE.
27 GENERATE
, UBYTE
, USHORT
, UINT
= 'generate', 'ubyte', 'ushort', 'uint'
28 FIRST
, LAST
= 'first', 'last'
30 INTYPES
= (GENERATE
, UBYTE
, USHORT
, UINT
)
31 OUTTYPES
= (USHORT
, UINT
)
41 LONGPRIMS
=('PIPE_PRIM_TRIANGLES',
42 'PIPE_PRIM_TRIANGLE_FAN',
43 'PIPE_PRIM_TRIANGLE_STRIP',
45 'PIPE_PRIM_QUAD_STRIP',
47 'PIPE_PRIM_TRIANGLES_ADJACENCY',
48 'PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY')
50 longprim
= dict(zip(PRIMS
, LONGPRIMS
))
51 intype_idx
= dict(ubyte
='IN_UBYTE', ushort
='IN_USHORT', uint
='IN_UINT')
52 outtype_idx
= dict(ushort
='OUT_USHORT', uint
='OUT_UINT')
56 print '''/* File automatically generated by u_unfilled_gen.py */'''
62 * Functions to translate and generate index lists
65 #include "indices/u_indices.h"
66 #include "indices/u_indices_priv.h"
67 #include "pipe/p_compiler.h"
68 #include "util/u_debug.h"
69 #include "pipe/p_defines.h"
70 #include "util/u_memory.h"
73 static unsigned out_size_idx( unsigned index_size )
76 case 4: return OUT_UINT;
77 case 2: return OUT_USHORT;
78 default: assert(0); return OUT_USHORT;
82 static unsigned in_size_idx( unsigned index_size )
85 case 4: return IN_UINT;
86 case 2: return IN_USHORT;
87 case 1: return IN_UBYTE;
88 default: assert(0); return IN_UBYTE;
93 static u_generate_func generate_line[OUT_COUNT][PRIM_COUNT];
94 static u_translate_func translate_line[IN_COUNT][OUT_COUNT][PRIM_COUNT];
98 def vert( intype
, outtype
, v0
):
99 if intype
== GENERATE
:
100 return '(' + outtype
+ ')(' + v0
+ ')'
102 return '(' + outtype
+ ')in[' + v0
+ ']'
104 def line( intype
, outtype
, ptr
, v0
, v1
):
105 print ' (' + ptr
+ ')[0] = ' + vert( intype
, outtype
, v0
) + ';'
106 print ' (' + ptr
+ ')[1] = ' + vert( intype
, outtype
, v1
) + ';'
108 # XXX: have the opportunity here to avoid over-drawing shared lines in
109 # tristrips, fans, etc, by integrating this into the calling functions
110 # and only emitting each line at most once.
112 def do_tri( intype
, outtype
, ptr
, v0
, v1
, v2
):
113 line( intype
, outtype
, ptr
, v0
, v1
)
114 line( intype
, outtype
, ptr
+ '+2', v1
, v2
)
115 line( intype
, outtype
, ptr
+ '+4', v2
, v0
)
117 def do_quad( intype
, outtype
, ptr
, v0
, v1
, v2
, v3
):
118 line( intype
, outtype
, ptr
, v0
, v1
)
119 line( intype
, outtype
, ptr
+ '+2', v1
, v2
)
120 line( intype
, outtype
, ptr
+ '+4', v2
, v3
)
121 line( intype
, outtype
, ptr
+ '+6', v3
, v0
)
123 def name(intype
, outtype
, prim
):
124 if intype
== GENERATE
:
125 return 'generate_' + prim
+ '_' + outtype
127 return 'translate_' + prim
+ '_' + intype
+ '2' + outtype
129 def preamble(intype
, outtype
, prim
):
130 print 'static void ' + name( intype
, outtype
, prim
) + '('
131 if intype
!= GENERATE
:
132 print ' const void * _in,'
133 print ' unsigned start,'
134 if intype
!= GENERATE
:
135 print ' unsigned in_nr,'
136 print ' unsigned out_nr,'
137 if intype
!= GENERATE
:
138 print ' unsigned restart_index,'
139 print ' void *_out )'
141 if intype
!= GENERATE
:
142 print ' const ' + intype
+ '*in = (const ' + intype
+ '*)_in;'
143 print ' ' + outtype
+ ' *out = (' + outtype
+ '*)_out;'
144 print ' unsigned i, j;'
151 def tris(intype
, outtype
):
152 preamble(intype
, outtype
, prim
='tris')
153 print ' for (i = start, j = 0; j < out_nr; j+=6, i+=3) { '
154 do_tri( intype
, outtype
, 'out+j', 'i', 'i+1', 'i+2' );
159 def tristrip(intype
, outtype
):
160 preamble(intype
, outtype
, prim
='tristrip')
161 print ' for (i = start, j = 0; j < out_nr; j+=6, i++) { '
162 do_tri( intype
, outtype
, 'out+j', 'i', 'i+1/*+(i&1)*/', 'i+2/*-(i&1)*/' );
167 def trifan(intype
, outtype
):
168 preamble(intype
, outtype
, prim
='trifan')
169 print ' for (i = start, j = 0; j < out_nr; j+=6, i++) { '
170 do_tri( intype
, outtype
, 'out+j', '0', 'i+1', 'i+2' );
176 def polygon(intype
, outtype
):
177 preamble(intype
, outtype
, prim
='polygon')
178 print ' for (i = start, j = 0; j < out_nr; j+=2, i++) { '
179 line( intype
, outtype
, 'out+j', 'i', '(i+1)%(out_nr/2)' )
184 def quads(intype
, outtype
):
185 preamble(intype
, outtype
, prim
='quads')
186 print ' for (i = start, j = 0; j < out_nr; j+=8, i+=4) { '
187 do_quad( intype
, outtype
, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3' );
192 def quadstrip(intype
, outtype
):
193 preamble(intype
, outtype
, prim
='quadstrip')
194 print ' for (i = start, j = 0; j < out_nr; j+=8, i+=2) { '
195 do_quad( intype
, outtype
, 'out+j', 'i+2', 'i+0', 'i+1', 'i+3' );
200 def trisadj(intype
, outtype
):
201 preamble(intype
, outtype
, prim
='trisadj')
202 print ' for (i = start, j = 0; j < out_nr; j+=6, i+=6) { '
203 do_tri( intype
, outtype
, 'out+j', 'i', 'i+2', 'i+4' );
208 def tristripadj(intype
, outtype
):
209 preamble(intype
, outtype
, prim
='tristripadj')
210 print ' for (i = start, j = 0; j < out_nr; j+=6, i+=2) { '
211 do_tri( intype
, outtype
, 'out+j', 'i', 'i+2', 'i+4' );
217 for intype
in INTYPES
:
218 for outtype
in OUTTYPES
:
219 tris(intype
, outtype
)
220 tristrip(intype
, outtype
)
221 trifan(intype
, outtype
)
222 quads(intype
, outtype
)
223 quadstrip(intype
, outtype
)
224 polygon(intype
, outtype
)
225 trisadj(intype
, outtype
)
226 tristripadj(intype
, outtype
)
228 def init(intype
, outtype
, prim
):
229 if intype
== GENERATE
:
230 print ('generate_line[' +
231 outtype_idx
[outtype
] +
232 '][' + longprim
[prim
] +
233 '] = ' + name( intype
, outtype
, prim
) + ';')
235 print ('translate_line[' +
237 '][' + outtype_idx
[outtype
] +
238 '][' + longprim
[prim
] +
239 '] = ' + name( intype
, outtype
, prim
) + ';')
242 def emit_all_inits():
243 for intype
in INTYPES
:
244 for outtype
in OUTTYPES
:
246 init(intype
, outtype
, prim
)
249 print 'void u_unfilled_init( void )'
251 print ' static int firsttime = 1;'
252 print ' if (!firsttime) return;'
253 print ' firsttime = 0;'
261 print '#include "indices/u_unfilled_indices.c"'
271 if __name__
== '__main__':