1bf215546Sopenharmony_cicopyright = ''' 2bf215546Sopenharmony_ci/* 3bf215546Sopenharmony_ci * Copyright 2009 VMware, Inc. 4bf215546Sopenharmony_ci * All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 8bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 9bf215546Sopenharmony_ci * on the rights to use, copy, modify, merge, publish, distribute, sub 10bf215546Sopenharmony_ci * license, and/or sell copies of the Software, and to permit persons to whom 11bf215546Sopenharmony_ci * the Software is furnished to do so, subject to the following conditions: 12bf215546Sopenharmony_ci * 13bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 14bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 15bf215546Sopenharmony_ci * Software. 16bf215546Sopenharmony_ci * 17bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 20bf215546Sopenharmony_ci * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 21bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 22bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 23bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE. 24bf215546Sopenharmony_ci */ 25bf215546Sopenharmony_ci''' 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ciGENERATE, UBYTE, USHORT, UINT = 'generate', 'ubyte', 'ushort', 'uint' 28bf215546Sopenharmony_ciFIRST, LAST = 'first', 'last' 29bf215546Sopenharmony_ciPRDISABLE, PRENABLE = 'prdisable', 'prenable' 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_ciINTYPES = (GENERATE, UBYTE, USHORT, UINT) 32bf215546Sopenharmony_ciOUTTYPES = (USHORT, UINT) 33bf215546Sopenharmony_ciPVS=(FIRST, LAST) 34bf215546Sopenharmony_ciPRS=(PRDISABLE, PRENABLE) 35bf215546Sopenharmony_ciPRIMS=('points', 36bf215546Sopenharmony_ci 'lines', 37bf215546Sopenharmony_ci 'linestrip', 38bf215546Sopenharmony_ci 'lineloop', 39bf215546Sopenharmony_ci 'tris', 40bf215546Sopenharmony_ci 'trifan', 41bf215546Sopenharmony_ci 'tristrip', 42bf215546Sopenharmony_ci 'quads', 43bf215546Sopenharmony_ci 'quadstrip', 44bf215546Sopenharmony_ci 'polygon', 45bf215546Sopenharmony_ci 'linesadj', 46bf215546Sopenharmony_ci 'linestripadj', 47bf215546Sopenharmony_ci 'trisadj', 48bf215546Sopenharmony_ci 'tristripadj') 49bf215546Sopenharmony_ci 50bf215546Sopenharmony_ciLONGPRIMS=('PIPE_PRIM_POINTS', 51bf215546Sopenharmony_ci 'PIPE_PRIM_LINES', 52bf215546Sopenharmony_ci 'PIPE_PRIM_LINE_STRIP', 53bf215546Sopenharmony_ci 'PIPE_PRIM_LINE_LOOP', 54bf215546Sopenharmony_ci 'PIPE_PRIM_TRIANGLES', 55bf215546Sopenharmony_ci 'PIPE_PRIM_TRIANGLE_FAN', 56bf215546Sopenharmony_ci 'PIPE_PRIM_TRIANGLE_STRIP', 57bf215546Sopenharmony_ci 'PIPE_PRIM_QUADS', 58bf215546Sopenharmony_ci 'PIPE_PRIM_QUAD_STRIP', 59bf215546Sopenharmony_ci 'PIPE_PRIM_POLYGON', 60bf215546Sopenharmony_ci 'PIPE_PRIM_LINES_ADJACENCY', 61bf215546Sopenharmony_ci 'PIPE_PRIM_LINE_STRIP_ADJACENCY', 62bf215546Sopenharmony_ci 'PIPE_PRIM_TRIANGLES_ADJACENCY', 63bf215546Sopenharmony_ci 'PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY') 64bf215546Sopenharmony_ci 65bf215546Sopenharmony_cilongprim = dict(zip(PRIMS, LONGPRIMS)) 66bf215546Sopenharmony_ciintype_idx = dict(ubyte='IN_UBYTE', ushort='IN_USHORT', uint='IN_UINT') 67bf215546Sopenharmony_ciouttype_idx = dict(ushort='OUT_USHORT', uint='OUT_UINT') 68bf215546Sopenharmony_cipv_idx = dict(first='PV_FIRST', last='PV_LAST') 69bf215546Sopenharmony_cipr_idx = dict(prdisable='PR_DISABLE', prenable='PR_ENABLE') 70bf215546Sopenharmony_ci 71bf215546Sopenharmony_cidef prolog(): 72bf215546Sopenharmony_ci print('''/* File automatically generated by u_indices_gen.py */''') 73bf215546Sopenharmony_ci print(copyright) 74bf215546Sopenharmony_ci print(r''' 75bf215546Sopenharmony_ci 76bf215546Sopenharmony_ci/** 77bf215546Sopenharmony_ci * @file 78bf215546Sopenharmony_ci * Functions to translate and generate index lists 79bf215546Sopenharmony_ci */ 80bf215546Sopenharmony_ci 81bf215546Sopenharmony_ci#include "indices/u_indices_priv.h" 82bf215546Sopenharmony_ci#include "util/u_debug.h" 83bf215546Sopenharmony_ci#include "util/u_memory.h" 84bf215546Sopenharmony_ci 85bf215546Sopenharmony_ci#include "c99_compat.h" 86bf215546Sopenharmony_ci 87bf215546Sopenharmony_cistatic unsigned out_size_idx( unsigned index_size ) 88bf215546Sopenharmony_ci{ 89bf215546Sopenharmony_ci switch (index_size) { 90bf215546Sopenharmony_ci case 4: return OUT_UINT; 91bf215546Sopenharmony_ci case 2: return OUT_USHORT; 92bf215546Sopenharmony_ci default: assert(0); return OUT_USHORT; 93bf215546Sopenharmony_ci } 94bf215546Sopenharmony_ci} 95bf215546Sopenharmony_ci 96bf215546Sopenharmony_cistatic unsigned in_size_idx( unsigned index_size ) 97bf215546Sopenharmony_ci{ 98bf215546Sopenharmony_ci switch (index_size) { 99bf215546Sopenharmony_ci case 4: return IN_UINT; 100bf215546Sopenharmony_ci case 2: return IN_USHORT; 101bf215546Sopenharmony_ci case 1: return IN_UBYTE; 102bf215546Sopenharmony_ci default: assert(0); return IN_UBYTE; 103bf215546Sopenharmony_ci } 104bf215546Sopenharmony_ci} 105bf215546Sopenharmony_ci 106bf215546Sopenharmony_ci 107bf215546Sopenharmony_cistatic u_translate_func translate[IN_COUNT][OUT_COUNT][PV_COUNT][PV_COUNT][PR_COUNT][PRIM_COUNT]; 108bf215546Sopenharmony_cistatic u_generate_func generate[OUT_COUNT][PV_COUNT][PV_COUNT][PRIM_COUNT]; 109bf215546Sopenharmony_ci 110bf215546Sopenharmony_ci 111bf215546Sopenharmony_ci''') 112bf215546Sopenharmony_ci 113bf215546Sopenharmony_cidef vert( intype, outtype, v0 ): 114bf215546Sopenharmony_ci if intype == GENERATE: 115bf215546Sopenharmony_ci return '(' + outtype + ')(' + v0 + ')' 116bf215546Sopenharmony_ci else: 117bf215546Sopenharmony_ci return '(' + outtype + ')in[' + v0 + ']' 118bf215546Sopenharmony_ci 119bf215546Sopenharmony_cidef point( intype, outtype, ptr, v0 ): 120bf215546Sopenharmony_ci print(' (' + ptr + ')[0] = ' + vert( intype, outtype, v0 ) + ';') 121bf215546Sopenharmony_ci 122bf215546Sopenharmony_cidef line( intype, outtype, ptr, v0, v1 ): 123bf215546Sopenharmony_ci print(' (' + ptr + ')[0] = ' + vert( intype, outtype, v0 ) + ';') 124bf215546Sopenharmony_ci print(' (' + ptr + ')[1] = ' + vert( intype, outtype, v1 ) + ';') 125bf215546Sopenharmony_ci 126bf215546Sopenharmony_cidef tri( intype, outtype, ptr, v0, v1, v2 ): 127bf215546Sopenharmony_ci print(' (' + ptr + ')[0] = ' + vert( intype, outtype, v0 ) + ';') 128bf215546Sopenharmony_ci print(' (' + ptr + ')[1] = ' + vert( intype, outtype, v1 ) + ';') 129bf215546Sopenharmony_ci print(' (' + ptr + ')[2] = ' + vert( intype, outtype, v2 ) + ';') 130bf215546Sopenharmony_ci 131bf215546Sopenharmony_cidef lineadj( intype, outtype, ptr, v0, v1, v2, v3 ): 132bf215546Sopenharmony_ci print(' (' + ptr + ')[0] = ' + vert( intype, outtype, v0 ) + ';') 133bf215546Sopenharmony_ci print(' (' + ptr + ')[1] = ' + vert( intype, outtype, v1 ) + ';') 134bf215546Sopenharmony_ci print(' (' + ptr + ')[2] = ' + vert( intype, outtype, v2 ) + ';') 135bf215546Sopenharmony_ci print(' (' + ptr + ')[3] = ' + vert( intype, outtype, v3 ) + ';') 136bf215546Sopenharmony_ci 137bf215546Sopenharmony_cidef triadj( intype, outtype, ptr, v0, v1, v2, v3, v4, v5 ): 138bf215546Sopenharmony_ci print(' (' + ptr + ')[0] = ' + vert( intype, outtype, v0 ) + ';') 139bf215546Sopenharmony_ci print(' (' + ptr + ')[1] = ' + vert( intype, outtype, v1 ) + ';') 140bf215546Sopenharmony_ci print(' (' + ptr + ')[2] = ' + vert( intype, outtype, v2 ) + ';') 141bf215546Sopenharmony_ci print(' (' + ptr + ')[3] = ' + vert( intype, outtype, v3 ) + ';') 142bf215546Sopenharmony_ci print(' (' + ptr + ')[4] = ' + vert( intype, outtype, v4 ) + ';') 143bf215546Sopenharmony_ci print(' (' + ptr + ')[5] = ' + vert( intype, outtype, v5 ) + ';') 144bf215546Sopenharmony_ci 145bf215546Sopenharmony_cidef do_point( intype, outtype, ptr, v0 ): 146bf215546Sopenharmony_ci point( intype, outtype, ptr, v0 ) 147bf215546Sopenharmony_ci 148bf215546Sopenharmony_cidef do_line( intype, outtype, ptr, v0, v1, inpv, outpv ): 149bf215546Sopenharmony_ci if inpv == outpv: 150bf215546Sopenharmony_ci line( intype, outtype, ptr, v0, v1 ) 151bf215546Sopenharmony_ci else: 152bf215546Sopenharmony_ci line( intype, outtype, ptr, v1, v0 ) 153bf215546Sopenharmony_ci 154bf215546Sopenharmony_cidef do_tri( intype, outtype, ptr, v0, v1, v2, inpv, outpv ): 155bf215546Sopenharmony_ci if inpv == outpv: 156bf215546Sopenharmony_ci tri( intype, outtype, ptr, v0, v1, v2 ) 157bf215546Sopenharmony_ci else: 158bf215546Sopenharmony_ci if inpv == FIRST: 159bf215546Sopenharmony_ci tri( intype, outtype, ptr, v1, v2, v0 ) 160bf215546Sopenharmony_ci else: 161bf215546Sopenharmony_ci tri( intype, outtype, ptr, v2, v0, v1 ) 162bf215546Sopenharmony_ci 163bf215546Sopenharmony_cidef do_quad( intype, outtype, ptr, v0, v1, v2, v3, inpv, outpv ): 164bf215546Sopenharmony_ci if inpv == LAST: 165bf215546Sopenharmony_ci do_tri( intype, outtype, ptr+'+0', v0, v1, v3, inpv, outpv ); 166bf215546Sopenharmony_ci do_tri( intype, outtype, ptr+'+3', v1, v2, v3, inpv, outpv ); 167bf215546Sopenharmony_ci else: 168bf215546Sopenharmony_ci do_tri( intype, outtype, ptr+'+0', v0, v1, v2, inpv, outpv ); 169bf215546Sopenharmony_ci do_tri( intype, outtype, ptr+'+3', v0, v2, v3, inpv, outpv ); 170bf215546Sopenharmony_ci 171bf215546Sopenharmony_cidef do_lineadj( intype, outtype, ptr, v0, v1, v2, v3, inpv, outpv ): 172bf215546Sopenharmony_ci if inpv == outpv: 173bf215546Sopenharmony_ci lineadj( intype, outtype, ptr, v0, v1, v2, v3 ) 174bf215546Sopenharmony_ci else: 175bf215546Sopenharmony_ci lineadj( intype, outtype, ptr, v3, v2, v1, v0 ) 176bf215546Sopenharmony_ci 177bf215546Sopenharmony_cidef do_triadj( intype, outtype, ptr, v0, v1, v2, v3, v4, v5, inpv, outpv ): 178bf215546Sopenharmony_ci if inpv == outpv: 179bf215546Sopenharmony_ci triadj( intype, outtype, ptr, v0, v1, v2, v3, v4, v5 ) 180bf215546Sopenharmony_ci else: 181bf215546Sopenharmony_ci triadj( intype, outtype, ptr, v4, v5, v0, v1, v2, v3 ) 182bf215546Sopenharmony_ci 183bf215546Sopenharmony_cidef name(intype, outtype, inpv, outpv, pr, prim): 184bf215546Sopenharmony_ci if intype == GENERATE: 185bf215546Sopenharmony_ci return 'generate_' + prim + '_' + outtype + '_' + inpv + '2' + outpv 186bf215546Sopenharmony_ci else: 187bf215546Sopenharmony_ci return 'translate_' + prim + '_' + intype + '2' + outtype + '_' + inpv + '2' + outpv + '_' + pr 188bf215546Sopenharmony_ci 189bf215546Sopenharmony_cidef preamble(intype, outtype, inpv, outpv, pr, prim): 190bf215546Sopenharmony_ci print('static void ' + name( intype, outtype, inpv, outpv, pr, prim ) + '(') 191bf215546Sopenharmony_ci if intype != GENERATE: 192bf215546Sopenharmony_ci print(' const void * restrict _in,') 193bf215546Sopenharmony_ci print(' unsigned start,') 194bf215546Sopenharmony_ci if intype != GENERATE: 195bf215546Sopenharmony_ci print(' unsigned in_nr,') 196bf215546Sopenharmony_ci print(' unsigned out_nr,') 197bf215546Sopenharmony_ci if intype != GENERATE: 198bf215546Sopenharmony_ci print(' unsigned restart_index,') 199bf215546Sopenharmony_ci print(' void * restrict _out )') 200bf215546Sopenharmony_ci print('{') 201bf215546Sopenharmony_ci if intype != GENERATE: 202bf215546Sopenharmony_ci print(' const ' + intype + '* restrict in = (const ' + intype + '* restrict)_in;') 203bf215546Sopenharmony_ci print(' ' + outtype + ' * restrict out = (' + outtype + '* restrict)_out;') 204bf215546Sopenharmony_ci print(' unsigned i, j;') 205bf215546Sopenharmony_ci print(' (void)j;') 206bf215546Sopenharmony_ci 207bf215546Sopenharmony_cidef postamble(): 208bf215546Sopenharmony_ci print('}') 209bf215546Sopenharmony_ci 210bf215546Sopenharmony_cidef prim_restart(in_verts, out_verts, out_prims, close_func = None): 211bf215546Sopenharmony_ci print('restart:') 212bf215546Sopenharmony_ci print(' if (i + ' + str(in_verts) + ' > in_nr) {') 213bf215546Sopenharmony_ci for i in range(out_prims): 214bf215546Sopenharmony_ci for j in range(out_verts): 215bf215546Sopenharmony_ci print(' (out+j+' + str(out_verts * i) + ')[' + str(j) + '] = restart_index;') 216bf215546Sopenharmony_ci print(' continue;') 217bf215546Sopenharmony_ci print(' }') 218bf215546Sopenharmony_ci for i in range(in_verts): 219bf215546Sopenharmony_ci print(' if (in[i + ' + str(i) + '] == restart_index) {') 220bf215546Sopenharmony_ci print(' i += ' + str(i + 1) + ';') 221bf215546Sopenharmony_ci 222bf215546Sopenharmony_ci if close_func is not None: 223bf215546Sopenharmony_ci close_func(i) 224bf215546Sopenharmony_ci 225bf215546Sopenharmony_ci print(' goto restart;') 226bf215546Sopenharmony_ci print(' }') 227bf215546Sopenharmony_ci 228bf215546Sopenharmony_cidef points(intype, outtype, inpv, outpv, pr): 229bf215546Sopenharmony_ci preamble(intype, outtype, inpv, outpv, pr, prim='points') 230bf215546Sopenharmony_ci print(' for (i = start, j = 0; j < out_nr; j++, i++) { ') 231bf215546Sopenharmony_ci do_point( intype, outtype, 'out+j', 'i' ); 232bf215546Sopenharmony_ci print(' }') 233bf215546Sopenharmony_ci postamble() 234bf215546Sopenharmony_ci 235bf215546Sopenharmony_cidef lines(intype, outtype, inpv, outpv, pr): 236bf215546Sopenharmony_ci preamble(intype, outtype, inpv, outpv, pr, prim='lines') 237bf215546Sopenharmony_ci print(' for (i = start, j = 0; j < out_nr; j+=2, i+=2) { ') 238bf215546Sopenharmony_ci do_line( intype, outtype, 'out+j', 'i', 'i+1', inpv, outpv ); 239bf215546Sopenharmony_ci print(' }') 240bf215546Sopenharmony_ci postamble() 241bf215546Sopenharmony_ci 242bf215546Sopenharmony_cidef linestrip(intype, outtype, inpv, outpv, pr): 243bf215546Sopenharmony_ci preamble(intype, outtype, inpv, outpv, pr, prim='linestrip') 244bf215546Sopenharmony_ci print(' for (i = start, j = 0; j < out_nr; j+=2, i++) { ') 245bf215546Sopenharmony_ci do_line( intype, outtype, 'out+j', 'i', 'i+1', inpv, outpv ); 246bf215546Sopenharmony_ci print(' }') 247bf215546Sopenharmony_ci postamble() 248bf215546Sopenharmony_ci 249bf215546Sopenharmony_cidef lineloop(intype, outtype, inpv, outpv, pr): 250bf215546Sopenharmony_ci preamble(intype, outtype, inpv, outpv, pr, prim='lineloop') 251bf215546Sopenharmony_ci print(' unsigned end = start;') 252bf215546Sopenharmony_ci print(' for (i = start, j = 0; j < out_nr - 2; j+=2, i++) { ') 253bf215546Sopenharmony_ci if pr == PRENABLE: 254bf215546Sopenharmony_ci def close_func(index): 255bf215546Sopenharmony_ci do_line( intype, outtype, 'out+j', 'end', 'start', inpv, outpv ) 256bf215546Sopenharmony_ci print(' start = i;') 257bf215546Sopenharmony_ci print(' end = start;') 258bf215546Sopenharmony_ci print(' j += 2;') 259bf215546Sopenharmony_ci 260bf215546Sopenharmony_ci prim_restart(2, 2, 1, close_func) 261bf215546Sopenharmony_ci 262bf215546Sopenharmony_ci do_line( intype, outtype, 'out+j', 'i', 'i+1', inpv, outpv ); 263bf215546Sopenharmony_ci print(' end = i+1;') 264bf215546Sopenharmony_ci print(' }') 265bf215546Sopenharmony_ci do_line( intype, outtype, 'out+j', 'end', 'start', inpv, outpv ); 266bf215546Sopenharmony_ci postamble() 267bf215546Sopenharmony_ci 268bf215546Sopenharmony_cidef tris(intype, outtype, inpv, outpv, pr): 269bf215546Sopenharmony_ci preamble(intype, outtype, inpv, outpv, pr, prim='tris') 270bf215546Sopenharmony_ci print(' for (i = start, j = 0; j < out_nr; j+=3, i+=3) { ') 271bf215546Sopenharmony_ci do_tri( intype, outtype, 'out+j', 'i', 'i+1', 'i+2', inpv, outpv ); 272bf215546Sopenharmony_ci print(' }') 273bf215546Sopenharmony_ci postamble() 274bf215546Sopenharmony_ci 275bf215546Sopenharmony_ci 276bf215546Sopenharmony_cidef tristrip(intype, outtype, inpv, outpv, pr): 277bf215546Sopenharmony_ci preamble(intype, outtype, inpv, outpv, pr, prim='tristrip') 278bf215546Sopenharmony_ci print(' for (i = start, j = 0; j < out_nr; j+=3, i++) { ') 279bf215546Sopenharmony_ci if inpv == FIRST: 280bf215546Sopenharmony_ci do_tri( intype, outtype, 'out+j', 'i', 'i+1+(i&1)', 'i+2-(i&1)', inpv, outpv ); 281bf215546Sopenharmony_ci else: 282bf215546Sopenharmony_ci do_tri( intype, outtype, 'out+j', 'i+(i&1)', 'i+1-(i&1)', 'i+2', inpv, outpv ); 283bf215546Sopenharmony_ci print(' }') 284bf215546Sopenharmony_ci postamble() 285bf215546Sopenharmony_ci 286bf215546Sopenharmony_ci 287bf215546Sopenharmony_cidef trifan(intype, outtype, inpv, outpv, pr): 288bf215546Sopenharmony_ci preamble(intype, outtype, inpv, outpv, pr, prim='trifan') 289bf215546Sopenharmony_ci print(' for (i = start, j = 0; j < out_nr; j+=3, i++) { ') 290bf215546Sopenharmony_ci 291bf215546Sopenharmony_ci if pr == PRENABLE: 292bf215546Sopenharmony_ci def close_func(index): 293bf215546Sopenharmony_ci print(' start = i;') 294bf215546Sopenharmony_ci prim_restart(3, 3, 1, close_func) 295bf215546Sopenharmony_ci 296bf215546Sopenharmony_ci if inpv == FIRST: 297bf215546Sopenharmony_ci do_tri( intype, outtype, 'out+j', 'i+1', 'i+2', 'start', inpv, outpv ); 298bf215546Sopenharmony_ci else: 299bf215546Sopenharmony_ci do_tri( intype, outtype, 'out+j', 'start', 'i+1', 'i+2', inpv, outpv ); 300bf215546Sopenharmony_ci 301bf215546Sopenharmony_ci print(' }') 302bf215546Sopenharmony_ci postamble() 303bf215546Sopenharmony_ci 304bf215546Sopenharmony_ci 305bf215546Sopenharmony_ci 306bf215546Sopenharmony_cidef polygon(intype, outtype, inpv, outpv, pr): 307bf215546Sopenharmony_ci preamble(intype, outtype, inpv, outpv, pr, prim='polygon') 308bf215546Sopenharmony_ci print(' for (i = start, j = 0; j < out_nr; j+=3, i++) { ') 309bf215546Sopenharmony_ci if pr == PRENABLE: 310bf215546Sopenharmony_ci def close_func(index): 311bf215546Sopenharmony_ci print(' start = i;') 312bf215546Sopenharmony_ci prim_restart(3, 3, 1, close_func) 313bf215546Sopenharmony_ci 314bf215546Sopenharmony_ci if inpv == FIRST: 315bf215546Sopenharmony_ci do_tri( intype, outtype, 'out+j', 'start', 'i+1', 'i+2', inpv, outpv ); 316bf215546Sopenharmony_ci else: 317bf215546Sopenharmony_ci do_tri( intype, outtype, 'out+j', 'i+1', 'i+2', 'start', inpv, outpv ); 318bf215546Sopenharmony_ci print(' }') 319bf215546Sopenharmony_ci postamble() 320bf215546Sopenharmony_ci 321bf215546Sopenharmony_ci 322bf215546Sopenharmony_cidef quads(intype, outtype, inpv, outpv, pr): 323bf215546Sopenharmony_ci preamble(intype, outtype, inpv, outpv, pr, prim='quads') 324bf215546Sopenharmony_ci print(' for (i = start, j = 0; j < out_nr; j+=6, i+=4) { ') 325bf215546Sopenharmony_ci if pr == PRENABLE: 326bf215546Sopenharmony_ci prim_restart(4, 3, 2) 327bf215546Sopenharmony_ci 328bf215546Sopenharmony_ci do_quad( intype, outtype, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3', inpv, outpv ); 329bf215546Sopenharmony_ci print(' }') 330bf215546Sopenharmony_ci postamble() 331bf215546Sopenharmony_ci 332bf215546Sopenharmony_ci 333bf215546Sopenharmony_cidef quadstrip(intype, outtype, inpv, outpv, pr): 334bf215546Sopenharmony_ci preamble(intype, outtype, inpv, outpv, pr, prim='quadstrip') 335bf215546Sopenharmony_ci print(' for (i = start, j = 0; j < out_nr; j+=6, i+=2) { ') 336bf215546Sopenharmony_ci if pr == PRENABLE: 337bf215546Sopenharmony_ci prim_restart(4, 3, 2) 338bf215546Sopenharmony_ci 339bf215546Sopenharmony_ci if inpv == LAST: 340bf215546Sopenharmony_ci do_quad( intype, outtype, 'out+j', 'i+2', 'i+0', 'i+1', 'i+3', inpv, outpv ); 341bf215546Sopenharmony_ci else: 342bf215546Sopenharmony_ci do_quad( intype, outtype, 'out+j', 'i+0', 'i+1', 'i+3', 'i+2', inpv, outpv ); 343bf215546Sopenharmony_ci print(' }') 344bf215546Sopenharmony_ci postamble() 345bf215546Sopenharmony_ci 346bf215546Sopenharmony_ci 347bf215546Sopenharmony_cidef linesadj(intype, outtype, inpv, outpv, pr): 348bf215546Sopenharmony_ci preamble(intype, outtype, inpv, outpv, pr, prim='linesadj') 349bf215546Sopenharmony_ci print(' for (i = start, j = 0; j < out_nr; j+=4, i+=4) { ') 350bf215546Sopenharmony_ci do_lineadj( intype, outtype, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3', inpv, outpv ) 351bf215546Sopenharmony_ci print(' }') 352bf215546Sopenharmony_ci postamble() 353bf215546Sopenharmony_ci 354bf215546Sopenharmony_ci 355bf215546Sopenharmony_cidef linestripadj(intype, outtype, inpv, outpv, pr): 356bf215546Sopenharmony_ci preamble(intype, outtype, inpv, outpv, pr, prim='linestripadj') 357bf215546Sopenharmony_ci print(' for (i = start, j = 0; j < out_nr; j+=4, i++) {') 358bf215546Sopenharmony_ci do_lineadj( intype, outtype, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3', inpv, outpv ) 359bf215546Sopenharmony_ci print(' }') 360bf215546Sopenharmony_ci postamble() 361bf215546Sopenharmony_ci 362bf215546Sopenharmony_ci 363bf215546Sopenharmony_cidef trisadj(intype, outtype, inpv, outpv, pr): 364bf215546Sopenharmony_ci preamble(intype, outtype, inpv, outpv, pr, prim='trisadj') 365bf215546Sopenharmony_ci print(' for (i = start, j = 0; j < out_nr; j+=6, i+=6) { ') 366bf215546Sopenharmony_ci do_triadj( intype, outtype, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3', 367bf215546Sopenharmony_ci 'i+4', 'i+5', inpv, outpv ) 368bf215546Sopenharmony_ci print(' }') 369bf215546Sopenharmony_ci postamble() 370bf215546Sopenharmony_ci 371bf215546Sopenharmony_ci 372bf215546Sopenharmony_cidef tristripadj(intype, outtype, inpv, outpv, pr): 373bf215546Sopenharmony_ci preamble(intype, outtype, inpv, outpv, pr, prim='tristripadj') 374bf215546Sopenharmony_ci print(' for (i = start, j = 0; j < out_nr; i+=2, j+=6) { ') 375bf215546Sopenharmony_ci print(' if (i % 4 == 0) {') 376bf215546Sopenharmony_ci print(' /* even triangle */') 377bf215546Sopenharmony_ci do_triadj( intype, outtype, 'out+j', 378bf215546Sopenharmony_ci 'i+0', 'i+1', 'i+2', 'i+3', 'i+4', 'i+5', inpv, outpv ) 379bf215546Sopenharmony_ci print(' } else {') 380bf215546Sopenharmony_ci print(' /* odd triangle */') 381bf215546Sopenharmony_ci do_triadj( intype, outtype, 'out+j', 382bf215546Sopenharmony_ci 'i+2', 'i-2', 'i+0', 'i+3', 'i+4', 'i+6', inpv, outpv ) 383bf215546Sopenharmony_ci print(' }') 384bf215546Sopenharmony_ci print(' }') 385bf215546Sopenharmony_ci postamble() 386bf215546Sopenharmony_ci 387bf215546Sopenharmony_ci 388bf215546Sopenharmony_cidef emit_funcs(): 389bf215546Sopenharmony_ci for intype in INTYPES: 390bf215546Sopenharmony_ci for outtype in OUTTYPES: 391bf215546Sopenharmony_ci for inpv in (FIRST, LAST): 392bf215546Sopenharmony_ci for outpv in (FIRST, LAST): 393bf215546Sopenharmony_ci for pr in (PRDISABLE, PRENABLE): 394bf215546Sopenharmony_ci if pr == PRENABLE and intype == GENERATE: 395bf215546Sopenharmony_ci continue 396bf215546Sopenharmony_ci points(intype, outtype, inpv, outpv, pr) 397bf215546Sopenharmony_ci lines(intype, outtype, inpv, outpv, pr) 398bf215546Sopenharmony_ci linestrip(intype, outtype, inpv, outpv, pr) 399bf215546Sopenharmony_ci lineloop(intype, outtype, inpv, outpv, pr) 400bf215546Sopenharmony_ci tris(intype, outtype, inpv, outpv, pr) 401bf215546Sopenharmony_ci tristrip(intype, outtype, inpv, outpv, pr) 402bf215546Sopenharmony_ci trifan(intype, outtype, inpv, outpv, pr) 403bf215546Sopenharmony_ci quads(intype, outtype, inpv, outpv, pr) 404bf215546Sopenharmony_ci quadstrip(intype, outtype, inpv, outpv, pr) 405bf215546Sopenharmony_ci polygon(intype, outtype, inpv, outpv, pr) 406bf215546Sopenharmony_ci linesadj(intype, outtype, inpv, outpv, pr) 407bf215546Sopenharmony_ci linestripadj(intype, outtype, inpv, outpv, pr) 408bf215546Sopenharmony_ci trisadj(intype, outtype, inpv, outpv, pr) 409bf215546Sopenharmony_ci tristripadj(intype, outtype, inpv, outpv, pr) 410bf215546Sopenharmony_ci 411bf215546Sopenharmony_cidef init(intype, outtype, inpv, outpv, pr, prim): 412bf215546Sopenharmony_ci if intype == GENERATE: 413bf215546Sopenharmony_ci print ('generate[' + 414bf215546Sopenharmony_ci outtype_idx[outtype] + 415bf215546Sopenharmony_ci '][' + pv_idx[inpv] + 416bf215546Sopenharmony_ci '][' + pv_idx[outpv] + 417bf215546Sopenharmony_ci '][' + longprim[prim] + 418bf215546Sopenharmony_ci '] = ' + name( intype, outtype, inpv, outpv, pr, prim ) + ';') 419bf215546Sopenharmony_ci else: 420bf215546Sopenharmony_ci print ('translate[' + 421bf215546Sopenharmony_ci intype_idx[intype] + 422bf215546Sopenharmony_ci '][' + outtype_idx[outtype] + 423bf215546Sopenharmony_ci '][' + pv_idx[inpv] + 424bf215546Sopenharmony_ci '][' + pv_idx[outpv] + 425bf215546Sopenharmony_ci '][' + pr_idx[pr] + 426bf215546Sopenharmony_ci '][' + longprim[prim] + 427bf215546Sopenharmony_ci '] = ' + name( intype, outtype, inpv, outpv, pr, prim ) + ';') 428bf215546Sopenharmony_ci 429bf215546Sopenharmony_ci 430bf215546Sopenharmony_cidef emit_all_inits(): 431bf215546Sopenharmony_ci for intype in INTYPES: 432bf215546Sopenharmony_ci for outtype in OUTTYPES: 433bf215546Sopenharmony_ci for inpv in PVS: 434bf215546Sopenharmony_ci for outpv in PVS: 435bf215546Sopenharmony_ci for pr in PRS: 436bf215546Sopenharmony_ci for prim in PRIMS: 437bf215546Sopenharmony_ci init(intype, outtype, inpv, outpv, pr, prim) 438bf215546Sopenharmony_ci 439bf215546Sopenharmony_cidef emit_init(): 440bf215546Sopenharmony_ci print('void u_index_init( void )') 441bf215546Sopenharmony_ci print('{') 442bf215546Sopenharmony_ci print(' static int firsttime = 1;') 443bf215546Sopenharmony_ci print(' if (!firsttime) return;') 444bf215546Sopenharmony_ci print(' firsttime = 0;') 445bf215546Sopenharmony_ci emit_all_inits() 446bf215546Sopenharmony_ci print('}') 447bf215546Sopenharmony_ci 448bf215546Sopenharmony_ci 449bf215546Sopenharmony_ci 450bf215546Sopenharmony_ci 451bf215546Sopenharmony_cidef epilog(): 452bf215546Sopenharmony_ci print('#include "indices/u_indices.c"') 453bf215546Sopenharmony_ci 454bf215546Sopenharmony_ci 455bf215546Sopenharmony_cidef main(): 456bf215546Sopenharmony_ci prolog() 457bf215546Sopenharmony_ci emit_funcs() 458bf215546Sopenharmony_ci emit_init() 459bf215546Sopenharmony_ci epilog() 460bf215546Sopenharmony_ci 461bf215546Sopenharmony_ci 462bf215546Sopenharmony_ciif __name__ == '__main__': 463bf215546Sopenharmony_ci main() 464