Commit 28f3f8d4 authored by Rob Clark's avatar Rob Clark

gallium/auxiliary/indices: add start param

Add 'start' parameter to generator/translator.
Signed-off-by: default avatarRob Clark <robclark@freedesktop.org>
Reviewed-by: Brian Paul's avatarBrian Paul <brianp@vmware.com>
parent 5127436a
......@@ -26,17 +26,19 @@
#include "u_indices_priv.h"
static void translate_memcpy_ushort( const void *in,
unsigned start,
unsigned nr,
void *out )
{
memcpy(out, in, nr*sizeof(short));
memcpy(out, &((short *)in)[start], nr*sizeof(short));
}
static void translate_memcpy_uint( const void *in,
unsigned start,
unsigned nr,
void *out )
{
memcpy(out, in, nr*sizeof(int));
memcpy(out, &((int *)in)[start], nr*sizeof(int));
}
......
......@@ -31,11 +31,30 @@
#define PV_LAST 1
#define PV_COUNT 2
/**
* Index translator function (for glDrawElements() case)
*
* \param in the input index buffer
* \param start the index of the first vertex (pipe_draw_info::start)
* \param nr the number of vertices (pipe_draw_info::count)
* \param out output buffer big enough or nr vertices (of
* @out_index_size bytes each)
*/
typedef void (*u_translate_func)( const void *in,
unsigned start,
unsigned nr,
void *out );
typedef void (*u_generate_func)( unsigned nr,
/**
* Index generator function (for glDrawArrays() case)
*
* \param start the index of the first vertex (pipe_draw_info::start)
* \param nr the number of vertices (pipe_draw_info::count)
* \param out output buffer big enough or nr vertices (of
* @out_index_size bytes each)
*/
typedef void (*u_generate_func)( unsigned start,
unsigned nr,
void *out );
......
......@@ -153,6 +153,7 @@ def preamble(intype, outtype, inpv, outpv, prim):
print 'static void ' + name( intype, outtype, inpv, outpv, prim ) + '('
if intype != GENERATE:
print ' const void * _in,'
print ' unsigned start,'
print ' unsigned nr,'
print ' void *_out )'
print '{'
......@@ -168,28 +169,28 @@ def postamble():
def points(intype, outtype, inpv, outpv):
preamble(intype, outtype, inpv, outpv, prim='points')
print ' for (i = 0; i < nr; i++) { '
print ' for (i = start; i < (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 = 0; i < nr; i+=2) { '
print ' for (i = start; i < (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 (j = i = 0; j < nr; j+=2, i++) { '
print ' for (i = start, j = 0; j < 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 (j = i = 0; j < nr - 2; j+=2, i++) { '
print ' for (i = start, j = 0; j < nr - 2; j+=2, i++) { '
do_line( intype, outtype, 'out+j', 'i', 'i+1', inpv, outpv );
print ' }'
do_line( intype, outtype, 'out+j', 'i', '0', inpv, outpv );
......@@ -197,7 +198,7 @@ def lineloop(intype, outtype, inpv, outpv):
def tris(intype, outtype, inpv, outpv):
preamble(intype, outtype, inpv, outpv, prim='tris')
print ' for (i = 0; i < nr; i+=3) { '
print ' for (i = start; i < (nr+start); i+=3) { '
do_tri( intype, outtype, 'out+i', 'i', 'i+1', 'i+2', inpv, outpv );
print ' }'
postamble()
......@@ -205,7 +206,7 @@ def tris(intype, outtype, inpv, outpv):
def tristrip(intype, outtype, inpv, outpv):
preamble(intype, outtype, inpv, outpv, prim='tristrip')
print ' for (j = i = 0; j < nr; j+=3, i++) { '
print ' for (i = start, j = 0; j < 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:
......@@ -216,7 +217,7 @@ def tristrip(intype, outtype, inpv, outpv):
def trifan(intype, outtype, inpv, outpv):
preamble(intype, outtype, inpv, outpv, prim='trifan')
print ' for (j = i = 0; j < nr; j+=3, i++) { '
print ' for (i = start, j = 0; j < nr; j+=3, i++) { '
do_tri( intype, outtype, 'out+j', '0', 'i+1', 'i+2', inpv, outpv );
print ' }'
postamble()
......@@ -225,7 +226,7 @@ def trifan(intype, outtype, inpv, outpv):
def polygon(intype, outtype, inpv, outpv):
preamble(intype, outtype, inpv, outpv, prim='polygon')
print ' for (j = i = 0; j < nr; j+=3, i++) { '
print ' for (i = start, j = 0; j < nr; j+=3, i++) { '
if inpv == FIRST:
do_tri( intype, outtype, 'out+j', '0', 'i+1', 'i+2', inpv, outpv );
else:
......@@ -236,7 +237,7 @@ def polygon(intype, outtype, inpv, outpv):
def quads(intype, outtype, inpv, outpv):
preamble(intype, outtype, inpv, outpv, prim='quads')
print ' for (j = i = 0; j < nr; j+=6, i+=4) { '
print ' for (i = start, j = 0; j < nr; j+=6, i+=4) { '
do_quad( intype, outtype, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3', inpv, outpv );
print ' }'
postamble()
......@@ -244,7 +245,7 @@ def quads(intype, outtype, inpv, outpv):
def quadstrip(intype, outtype, inpv, outpv):
preamble(intype, outtype, inpv, outpv, prim='quadstrip')
print ' for (j = i = 0; j < nr; j+=6, i+=2) { '
print ' for (i = start, j = 0; j < nr; j+=6, i+=2) { '
do_quad( intype, outtype, 'out+j', 'i+2', 'i+0', 'i+1', 'i+3', inpv, outpv );
print ' }'
postamble()
......
......@@ -127,6 +127,7 @@ def preamble(intype, outtype, prim):
print 'static void ' + name( intype, outtype, prim ) + '('
if intype != GENERATE:
print ' const void * _in,'
print ' unsigned start,'
print ' unsigned nr,'
print ' void *_out )'
print '{'
......@@ -142,7 +143,7 @@ def postamble():
def tris(intype, outtype):
preamble(intype, outtype, prim='tris')
print ' for (j = i = 0; j < nr; j+=6, i+=3) { '
print ' for (i = start, j = 0; j < nr; j+=6, i+=3) { '
do_tri( intype, outtype, 'out+j', 'i', 'i+1', 'i+2' );
print ' }'
postamble()
......@@ -150,7 +151,7 @@ def tris(intype, outtype):
def tristrip(intype, outtype):
preamble(intype, outtype, prim='tristrip')
print ' for (j = i = 0; j < nr; j+=6, i++) { '
print ' for (i = start, j = 0; j < nr; j+=6, i++) { '
do_tri( intype, outtype, 'out+j', 'i', 'i+1/*+(i&1)*/', 'i+2/*-(i&1)*/' );
print ' }'
postamble()
......@@ -158,7 +159,7 @@ def tristrip(intype, outtype):
def trifan(intype, outtype):
preamble(intype, outtype, prim='trifan')
print ' for (j = i = 0; j < nr; j+=6, i++) { '
print ' for (i = start, j = 0; j < nr; j+=6, i++) { '
do_tri( intype, outtype, 'out+j', '0', 'i+1', 'i+2' );
print ' }'
postamble()
......@@ -167,7 +168,7 @@ def trifan(intype, outtype):
def polygon(intype, outtype):
preamble(intype, outtype, prim='polygon')
print ' for (j = i = 0; j < nr; j+=2, i++) { '
print ' for (i = start, j = 0; j < nr; j+=2, i++) { '
line( intype, outtype, 'out+j', 'i', '(i+1)%(nr/2)' )
print ' }'
postamble()
......@@ -175,7 +176,7 @@ def polygon(intype, outtype):
def quads(intype, outtype):
preamble(intype, outtype, prim='quads')
print ' for (j = i = 0; j < nr; j+=8, i+=4) { '
print ' for (i = start, j = 0; j < nr; j+=8, i+=4) { '
do_quad( intype, outtype, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3' );
print ' }'
postamble()
......@@ -183,7 +184,7 @@ def quads(intype, outtype):
def quadstrip(intype, outtype):
preamble(intype, outtype, prim='quadstrip')
print ' for (j = i = 0; j < nr; j+=8, i+=2) { '
print ' for (i = start, j = 0; j < nr; j+=8, i+=2) { '
do_quad( intype, outtype, 'out+j', 'i+2', 'i+0', 'i+1', 'i+3' );
print ' }'
postamble()
......
......@@ -27,6 +27,7 @@
static void translate_ubyte_ushort( const void *in,
unsigned start,
unsigned nr,
void *out )
{
......@@ -34,40 +35,44 @@ static void translate_ubyte_ushort( const void *in,
ushort *out_us = (ushort *)out;
unsigned i;
for (i = 0; i < nr; i++)
out_us[i] = (ushort) in_ub[i];
out_us[i] = (ushort) in_ub[i+start];
}
static void translate_memcpy_ushort( const void *in,
unsigned start,
unsigned nr,
void *out )
{
memcpy(out, in, nr*sizeof(short));
memcpy(out, &((short *)in)[start], nr*sizeof(short));
}
static void translate_memcpy_uint( const void *in,
unsigned start,
unsigned nr,
void *out )
{
memcpy(out, in, nr*sizeof(int));
memcpy(out, &((int *)in)[start], nr*sizeof(int));
}
static void generate_linear_ushort( unsigned nr,
static void generate_linear_ushort( unsigned start,
unsigned nr,
void *out )
{
ushort *out_us = (ushort *)out;
unsigned i;
for (i = 0; i < nr; i++)
out_us[i] = (ushort) i;
out_us[i] = (ushort)(i + start);
}
static void generate_linear_uint( unsigned nr,
static void generate_linear_uint( unsigned start,
unsigned nr,
void *out )
{
unsigned *out_ui = (unsigned *)out;
unsigned i;
for (i = 0; i < nr; i++)
out_ui[i] = i;
out_ui[i] = i + start;
}
......
......@@ -58,7 +58,7 @@ generate_indices(struct svga_hwtnl *hwtnl,
if (dst_map == NULL)
goto fail;
generate(nr, dst_map);
generate(0, nr, dst_map);
pipe_buffer_unmap(pipe, transfer);
......
......@@ -61,7 +61,7 @@ translate_indices(struct svga_hwtnl *hwtnl, struct pipe_resource *src,
if (dst_map == NULL)
goto fail;
translate((const char *) src_map + offset, nr, dst_map);
translate((const char *) src_map + offset, 0, nr, dst_map);
pipe_buffer_unmap(pipe, src_transfer);
pipe_buffer_unmap(pipe, dst_transfer);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment