4 * Copyright 2009 VMware, Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * on the rights to use, copy, modify, merge, publish, distribute, sub
11 * license, and/or sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
28 GENERATE
, UBYTE
, USHORT
, UINT
= 'generate', 'ubyte', 'ushort', 'uint'
29 FIRST
, LAST
= 'first', 'last'
31 INTYPES
= (GENERATE
, UBYTE
, USHORT
, UINT
)
32 OUTTYPES
= (USHORT
, UINT
)
40 LONGPRIMS
=('PIPE_PRIM_TRIANGLES',
41 'PIPE_PRIM_TRIANGLE_FAN',
42 'PIPE_PRIM_TRIANGLE_STRIP',
44 'PIPE_PRIM_QUAD_STRIP',
47 longprim
= dict(zip(PRIMS
, LONGPRIMS
))
48 intype_idx
= dict(ubyte
='IN_UBYTE', ushort
='IN_USHORT', uint
='IN_UINT')
49 outtype_idx
= dict(ushort
='OUT_USHORT', uint
='OUT_UINT')
53 print '''/* File automatically generated by u_unfilled_gen.py */'''
59 * Functions to translate and generate index lists
62 #include "indices/u_indices.h"
63 #include "indices/u_indices_priv.h"
64 #include "pipe/p_compiler.h"
65 #include "util/u_debug.h"
66 #include "pipe/p_defines.h"
67 #include "util/u_memory.h"
70 static unsigned out_size_idx( unsigned index_size )
73 case 4: return OUT_UINT;
74 case 2: return OUT_USHORT;
75 default: assert(0); return OUT_USHORT;
79 static unsigned in_size_idx( unsigned index_size )
82 case 4: return IN_UINT;
83 case 2: return IN_USHORT;
84 case 1: return IN_UBYTE;
85 default: assert(0); return IN_UBYTE;
90 static u_generate_func generate_line[OUT_COUNT][PRIM_COUNT];
91 static u_translate_func translate_line[IN_COUNT][OUT_COUNT][PRIM_COUNT];
95 def vert( intype
, outtype
, v0
):
96 if intype
== GENERATE
:
97 return '(' + outtype
+ ')(' + v0
+ ')'
99 return '(' + outtype
+ ')in[' + v0
+ ']'
101 def line( intype
, outtype
, ptr
, v0
, v1
):
102 print ' debug_printf(" line %d %d\\n", (int)' + v0
+ ', (int)' + v1
+ ');'
103 print ' (' + ptr
+ ')[0] = ' + vert( intype
, outtype
, v0
) + ';'
104 print ' (' + ptr
+ ')[1] = ' + vert( intype
, outtype
, v1
) + ';'
106 # XXX: have the opportunity here to avoid over-drawing shared lines in
107 # tristrips, fans, etc, by integrating this into the calling functions
108 # and only emitting each line at most once.
110 def do_tri( intype
, outtype
, ptr
, v0
, v1
, v2
):
111 line( intype
, outtype
, ptr
, v0
, v1
)
112 line( intype
, outtype
, ptr
+ '+2', v1
, v2
)
113 line( intype
, outtype
, ptr
+ '+4', v2
, v0
)
115 def do_quad( intype
, outtype
, ptr
, v0
, v1
, v2
, v3
):
116 line( intype
, outtype
, ptr
, v0
, v1
)
117 line( intype
, outtype
, ptr
+ '+2', v1
, v2
)
118 line( intype
, outtype
, ptr
+ '+4', v2
, v3
)
119 line( intype
, outtype
, ptr
+ '+6', v3
, v0
)
121 def name(intype
, outtype
, prim
):
122 if intype
== GENERATE
:
123 return 'generate_' + prim
+ '_' + outtype
125 return 'translate_' + prim
+ '_' + intype
+ '2' + outtype
127 def preamble(intype
, outtype
, prim
):
128 print 'static void ' + name( intype
, outtype
, prim
) + '('
129 if intype
!= GENERATE
:
130 print ' const void * _in,'
131 print ' unsigned nr,'
132 print ' void *_out )'
134 if intype
!= GENERATE
:
135 print ' const ' + intype
+ '*in = (const ' + intype
+ '*)_in;'
136 print ' ' + outtype
+ ' *out = (' + outtype
+ '*)_out;'
137 print ' unsigned i, j;'
144 def tris(intype
, outtype
):
145 preamble(intype
, outtype
, prim
='tris')
146 print ' for (j = i = 0; j < nr; j+=6, i+=3) { '
147 do_tri( intype
, outtype
, 'out+j', 'i', 'i+1', 'i+2' );
152 def tristrip(intype
, outtype
):
153 preamble(intype
, outtype
, prim
='tristrip')
154 print ' for (j = i = 0; j < nr; j+=6, i++) { '
155 do_tri( intype
, outtype
, 'out+j', 'i', 'i+1/*+(i&1)*/', 'i+2/*-(i&1)*/' );
160 def trifan(intype
, outtype
):
161 preamble(intype
, outtype
, prim
='trifan')
162 print ' for (j = i = 0; j < nr; j+=6, i++) { '
163 do_tri( intype
, outtype
, 'out+j', '0', 'i+1', 'i+2' );
169 def polygon(intype
, outtype
):
170 preamble(intype
, outtype
, prim
='polygon')
171 print ' for (j = i = 0; j < nr; j+=6, i++) { '
172 do_tri( intype
, outtype
, 'out+j', '0', 'i+1', 'i+2' );
177 def quads(intype
, outtype
):
178 preamble(intype
, outtype
, prim
='quads')
179 print ' for (j = i = 0; j < nr; j+=8, i+=4) { '
180 do_quad( intype
, outtype
, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3' );
185 def quadstrip(intype
, outtype
):
186 preamble(intype
, outtype
, prim
='quadstrip')
187 print ' for (j = i = 0; j < nr; j+=8, i+=2) { '
188 do_quad( intype
, outtype
, 'out+j', 'i+2', 'i+0', 'i+1', 'i+3' );
194 for intype
in INTYPES
:
195 for outtype
in OUTTYPES
:
196 tris(intype
, outtype
)
197 tristrip(intype
, outtype
)
198 trifan(intype
, outtype
)
199 quads(intype
, outtype
)
200 quadstrip(intype
, outtype
)
201 polygon(intype
, outtype
)
203 def init(intype
, outtype
, prim
):
204 if intype
== GENERATE
:
205 print ('generate_line[' +
206 outtype_idx
[outtype
] +
207 '][' + longprim
[prim
] +
208 '] = ' + name( intype
, outtype
, prim
) + ';')
210 print ('translate_line[' +
212 '][' + outtype_idx
[outtype
] +
213 '][' + longprim
[prim
] +
214 '] = ' + name( intype
, outtype
, prim
) + ';')
217 def emit_all_inits():
218 for intype
in INTYPES
:
219 for outtype
in OUTTYPES
:
221 init(intype
, outtype
, prim
)
224 print 'void u_unfilled_init( void )'
226 print ' static int firsttime = 1;'
227 print ' if (!firsttime) return;'
228 print ' firsttime = 0;'
236 print '#include "indices/u_unfilled_indices.c"'
246 if __name__
== '__main__':