GENERATE, UBYTE, USHORT, UINT = 'generate', 'ubyte', 'ushort', 'uint'
FIRST, LAST = 'first', 'last'
+PRDISABLE, PRENABLE = 'prdisable', 'prenable'
INTYPES = (GENERATE, UBYTE, USHORT, UINT)
OUTTYPES = (USHORT, UINT)
PVS=(FIRST, LAST)
+PRS=(PRDISABLE, PRENABLE)
PRIMS=('points',
'lines',
'linestrip',
intype_idx = dict(ubyte='IN_UBYTE', ushort='IN_USHORT', uint='IN_UINT')
outtype_idx = dict(ushort='OUT_USHORT', uint='OUT_UINT')
pv_idx = dict(first='PV_FIRST', last='PV_LAST')
-
+pr_idx = dict(prdisable='PR_DISABLE', prenable='PR_ENABLE')
def prolog():
print '''/* File automatically generated by indices.py */'''
}
-static u_translate_func translate[IN_COUNT][OUT_COUNT][PV_COUNT][PV_COUNT][PRIM_COUNT];
+static u_translate_func translate[IN_COUNT][OUT_COUNT][PV_COUNT][PV_COUNT][PR_COUNT][PRIM_COUNT];
static u_generate_func generate[OUT_COUNT][PV_COUNT][PV_COUNT][PRIM_COUNT];
do_tri( intype, outtype, ptr+'+0', v0, v1, v3, inpv, outpv );
do_tri( intype, outtype, ptr+'+3', v1, v2, v3, inpv, outpv );
-def name(intype, outtype, inpv, outpv, prim):
+def name(intype, outtype, inpv, outpv, pr, prim):
if intype == GENERATE:
return 'generate_' + prim + '_' + outtype + '_' + inpv + '2' + outpv
else:
- return 'translate_' + prim + '_' + intype + '2' + outtype + '_' + inpv + '2' + outpv
+ return 'translate_' + prim + '_' + intype + '2' + outtype + '_' + inpv + '2' + outpv + '_' + pr
-def preamble(intype, outtype, inpv, outpv, prim):
- print 'static void ' + name( intype, outtype, inpv, outpv, prim ) + '('
+def preamble(intype, outtype, inpv, outpv, pr, prim):
+ print 'static void ' + name( intype, outtype, inpv, outpv, pr, prim ) + '('
if intype != GENERATE:
print ' const void * _in,'
print ' unsigned start,'
- print ' unsigned nr,'
+ if intype != GENERATE:
+ print ' unsigned in_nr,'
+ print ' unsigned out_nr,'
+ if intype != GENERATE:
+ print ' unsigned restart_index,'
print ' void *_out )'
print '{'
if intype != GENERATE:
print '}'
-def points(intype, outtype, inpv, outpv):
- preamble(intype, outtype, inpv, outpv, prim='points')
- print ' for (i = start; i < (nr+start); i++) { '
+def points(intype, outtype, inpv, outpv, pr):
+ preamble(intype, outtype, inpv, outpv, pr, prim='points')
+ print ' for (i = start; i < (out_nr+start); i++) { '
do_point( intype, outtype, 'out+i', 'i' );
print ' }'
postamble()
-def lines(intype, outtype, inpv, outpv):
- preamble(intype, outtype, inpv, outpv, prim='lines')
- print ' for (i = start; i < (nr+start); i+=2) { '
+def lines(intype, outtype, inpv, outpv, pr):
+ preamble(intype, outtype, inpv, outpv, pr, prim='lines')
+ print ' for (i = start; i < (out_nr+start); i+=2) { '
do_line( intype, outtype, 'out+i', 'i', 'i+1', inpv, outpv );
print ' }'
postamble()
-def linestrip(intype, outtype, inpv, outpv):
- preamble(intype, outtype, inpv, outpv, prim='linestrip')
- print ' for (i = start, j = 0; j < nr; j+=2, i++) { '
+def linestrip(intype, outtype, inpv, outpv, pr):
+ preamble(intype, outtype, inpv, outpv, pr, prim='linestrip')
+ print ' for (i = start, j = 0; j < out_nr; j+=2, i++) { '
do_line( intype, outtype, 'out+j', 'i', 'i+1', inpv, outpv );
print ' }'
postamble()
-def lineloop(intype, outtype, inpv, outpv):
- preamble(intype, outtype, inpv, outpv, prim='lineloop')
- print ' for (i = start, j = 0; j < nr - 2; j+=2, i++) { '
+def lineloop(intype, outtype, inpv, outpv, pr):
+ preamble(intype, outtype, inpv, outpv, pr, prim='lineloop')
+ print ' for (i = start, j = 0; j < out_nr - 2; j+=2, i++) { '
do_line( intype, outtype, 'out+j', 'i', 'i+1', inpv, outpv );
print ' }'
do_line( intype, outtype, 'out+j', 'i', 'start', inpv, outpv );
postamble()
-def tris(intype, outtype, inpv, outpv):
- preamble(intype, outtype, inpv, outpv, prim='tris')
- print ' for (i = start; i < (nr+start); i+=3) { '
+def tris(intype, outtype, inpv, outpv, pr):
+ preamble(intype, outtype, inpv, outpv, pr, prim='tris')
+ print ' for (i = start; i < (out_nr+start); i+=3) { '
do_tri( intype, outtype, 'out+i', 'i', 'i+1', 'i+2', inpv, outpv );
print ' }'
postamble()
-def tristrip(intype, outtype, inpv, outpv):
- preamble(intype, outtype, inpv, outpv, prim='tristrip')
- print ' for (i = start, j = 0; j < nr; j+=3, i++) { '
+def tristrip(intype, outtype, inpv, outpv, pr):
+ preamble(intype, outtype, inpv, outpv, pr, prim='tristrip')
+ print ' for (i = start, j = 0; j < out_nr; j+=3, i++) { '
if inpv == FIRST:
do_tri( intype, outtype, 'out+j', 'i', 'i+1+(i&1)', 'i+2-(i&1)', inpv, outpv );
else:
postamble()
-def trifan(intype, outtype, inpv, outpv):
- preamble(intype, outtype, inpv, outpv, prim='trifan')
- print ' for (i = start, j = 0; j < nr; j+=3, i++) { '
+def trifan(intype, outtype, inpv, outpv, pr):
+ preamble(intype, outtype, inpv, outpv, pr, prim='trifan')
+ print ' for (i = start, j = 0; j < out_nr; j+=3, i++) { '
do_tri( intype, outtype, 'out+j', 'start', 'i+1', 'i+2', inpv, outpv );
print ' }'
postamble()
-def polygon(intype, outtype, inpv, outpv):
- preamble(intype, outtype, inpv, outpv, prim='polygon')
- print ' for (i = start, j = 0; j < nr; j+=3, i++) { '
+def polygon(intype, outtype, inpv, outpv, pr):
+ preamble(intype, outtype, inpv, outpv, pr, prim='polygon')
+ print ' for (i = start, j = 0; j < out_nr; j+=3, i++) { '
+ if pr == PRENABLE:
+ print 'restart:'
+ print ' if (i + 3 > in_nr) {'
+ print ' (out+j+0)[0] = restart_index;'
+ print ' (out+j+0)[1] = restart_index;'
+ print ' (out+j+0)[2] = restart_index;'
+ print ' continue;'
+ print ' }'
+ print ' if (in[i + 0] == restart_index) {'
+ print ' i += 1;'
+ print ' start = i;'
+ print ' goto restart;'
+ print ' }'
+ print ' if (in[i + 1] == restart_index) {'
+ print ' i += 2;'
+ print ' start = i;'
+ print ' goto restart;'
+ print ' }'
+ print ' if (in[i + 2] == restart_index) {'
+ print ' i += 3;'
+ print ' start = i;'
+ print ' goto restart;'
+ print ' }'
+
if inpv == FIRST:
do_tri( intype, outtype, 'out+j', 'start', 'i+1', 'i+2', inpv, outpv );
else:
postamble()
-def quads(intype, outtype, inpv, outpv):
- preamble(intype, outtype, inpv, outpv, prim='quads')
- print ' for (i = start, j = 0; j < nr; j+=6, i+=4) { '
+def quads(intype, outtype, inpv, outpv, pr):
+ preamble(intype, outtype, inpv, outpv, pr, prim='quads')
+ print ' for (i = start, j = 0; j < out_nr; j+=6, i+=4) { '
+ if pr == PRENABLE:
+ print 'restart:'
+ print ' if (i + 4 > in_nr) {'
+ print ' (out+j+0)[0] = restart_index;'
+ print ' (out+j+0)[1] = restart_index;'
+ print ' (out+j+0)[2] = restart_index;'
+ print ' (out+j+3)[0] = restart_index;'
+ print ' (out+j+3)[1] = restart_index;'
+ print ' (out+j+3)[2] = restart_index;'
+ print ' continue;'
+ print ' }'
+ print ' if (in[i + 0] == restart_index) {'
+ print ' i += 1;'
+ print ' goto restart;'
+ print ' }'
+ print ' if (in[i + 1] == restart_index) {'
+ print ' i += 2;'
+ print ' goto restart;'
+ print ' }'
+ print ' if (in[i + 2] == restart_index) {'
+ print ' i += 3;'
+ print ' goto restart;'
+ print ' }'
+ print ' if (in[i + 3] == restart_index) {'
+ print ' i += 4;'
+ print ' goto restart;'
+ print ' }'
+
do_quad( intype, outtype, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3', inpv, outpv );
print ' }'
postamble()
-def quadstrip(intype, outtype, inpv, outpv):
- preamble(intype, outtype, inpv, outpv, prim='quadstrip')
- print ' for (i = start, j = 0; j < nr; j+=6, i+=2) { '
+def quadstrip(intype, outtype, inpv, outpv, pr):
+ preamble(intype, outtype, inpv, outpv, pr, prim='quadstrip')
+ print ' for (i = start, j = 0; j < out_nr; j+=6, i+=2) { '
+ if pr == PRENABLE:
+ print 'restart:'
+ print ' if (i + 4 > in_nr) {'
+ print ' (out+j+0)[0] = restart_index;'
+ print ' (out+j+0)[1] = restart_index;'
+ print ' (out+j+0)[2] = restart_index;'
+ print ' (out+j+3)[0] = restart_index;'
+ print ' (out+j+3)[1] = restart_index;'
+ print ' (out+j+3)[2] = restart_index;'
+ print ' continue;'
+ print ' }'
+ print ' if (in[i + 0] == restart_index) {'
+ print ' i += 1;'
+ print ' goto restart;'
+ print ' }'
+ print ' if (in[i + 1] == restart_index) {'
+ print ' i += 2;'
+ print ' goto restart;'
+ print ' }'
+ print ' if (in[i + 2] == restart_index) {'
+ print ' i += 3;'
+ print ' goto restart;'
+ print ' }'
+ print ' if (in[i + 3] == restart_index) {'
+ print ' i += 4;'
+ print ' goto restart;'
+ print ' }'
do_quad( intype, outtype, 'out+j', 'i+2', 'i+0', 'i+1', 'i+3', inpv, outpv );
print ' }'
postamble()
for outtype in OUTTYPES:
for inpv in (FIRST, LAST):
for outpv in (FIRST, LAST):
- points(intype, outtype, inpv, outpv)
- lines(intype, outtype, inpv, outpv)
- linestrip(intype, outtype, inpv, outpv)
- lineloop(intype, outtype, inpv, outpv)
- tris(intype, outtype, inpv, outpv)
- tristrip(intype, outtype, inpv, outpv)
- trifan(intype, outtype, inpv, outpv)
- quads(intype, outtype, inpv, outpv)
- quadstrip(intype, outtype, inpv, outpv)
- polygon(intype, outtype, inpv, outpv)
-
-def init(intype, outtype, inpv, outpv, prim):
+ for pr in (PRDISABLE, PRENABLE):
+ if pr == PRENABLE and intype == GENERATE:
+ continue
+ points(intype, outtype, inpv, outpv, pr)
+ lines(intype, outtype, inpv, outpv, pr)
+ linestrip(intype, outtype, inpv, outpv, pr)
+ lineloop(intype, outtype, inpv, outpv, pr)
+ tris(intype, outtype, inpv, outpv, pr)
+ tristrip(intype, outtype, inpv, outpv, pr)
+ trifan(intype, outtype, inpv, outpv, pr)
+ quads(intype, outtype, inpv, outpv, pr)
+ quadstrip(intype, outtype, inpv, outpv, pr)
+ polygon(intype, outtype, inpv, outpv, pr)
+
+def init(intype, outtype, inpv, outpv, pr, prim):
if intype == GENERATE:
print ('generate[' +
outtype_idx[outtype] +
'][' + pv_idx[inpv] +
'][' + pv_idx[outpv] +
'][' + longprim[prim] +
- '] = ' + name( intype, outtype, inpv, outpv, prim ) + ';')
+ '] = ' + name( intype, outtype, inpv, outpv, pr, prim ) + ';')
else:
print ('translate[' +
intype_idx[intype] +
'][' + outtype_idx[outtype] +
'][' + pv_idx[inpv] +
- '][' + pv_idx[outpv] +
+ '][' + pv_idx[outpv] +
+ '][' + pr_idx[pr] +
'][' + longprim[prim] +
- '] = ' + name( intype, outtype, inpv, outpv, prim ) + ';')
+ '] = ' + name( intype, outtype, inpv, outpv, pr, prim ) + ';')
def emit_all_inits():
for outtype in OUTTYPES:
for inpv in PVS:
for outpv in PVS:
- for prim in PRIMS:
- init(intype, outtype, inpv, outpv, prim)
+ for pr in PRS:
+ for prim in PRIMS:
+ init(intype, outtype, inpv, outpv, pr, prim)
def emit_init():
print 'void u_index_init( void )'