draw: Implement index bias.

This commit is contained in:
José Fonseca 2010-04-19 18:14:04 +02:00
parent 857c7c7ca2
commit 2197fac47c
8 changed files with 65 additions and 46 deletions

View file

@ -427,12 +427,14 @@ void draw_set_render( struct draw_context *draw,
void
draw_set_mapped_element_buffer_range( struct draw_context *draw,
unsigned eltSize,
int eltBias,
unsigned min_index,
unsigned max_index,
const void *elements )
{
draw->pt.user.elts = elements;
draw->pt.user.eltSize = eltSize;
draw->pt.user.eltBias = eltBias;
draw->pt.user.min_index = min_index;
draw->pt.user.max_index = max_index;
}
@ -441,10 +443,12 @@ draw_set_mapped_element_buffer_range( struct draw_context *draw,
void
draw_set_mapped_element_buffer( struct draw_context *draw,
unsigned eltSize,
int eltBias,
const void *elements )
{
draw->pt.user.elts = elements;
draw->pt.user.eltSize = eltSize;
draw->pt.user.eltBias = eltBias;
draw->pt.user.min_index = 0;
draw->pt.user.max_index = 0xffffffff;
}

View file

@ -139,12 +139,14 @@ void draw_set_vertex_elements(struct draw_context *draw,
void
draw_set_mapped_element_buffer_range( struct draw_context *draw,
unsigned eltSize,
int eltBias,
unsigned min_index,
unsigned max_index,
const void *elements );
void draw_set_mapped_element_buffer( struct draw_context *draw,
unsigned eltSize,
int eltBias,
const void *elements );
void draw_set_mapped_vertex_buffer(struct draw_context *draw,

View file

@ -148,6 +148,7 @@ struct draw_context
const void *elts;
/** bytes per index (0, 1, 2 or 4) */
unsigned eltSize;
int eltBias;
unsigned min_index;
unsigned max_index;

View file

@ -111,6 +111,7 @@ draw_pt_arrays(struct draw_context *draw,
frontend->run(frontend,
draw_pt_elt_func(draw),
draw_pt_elt_ptr(draw, start),
draw->pt.user.eltBias,
count);
frontend->finish( frontend );
@ -222,8 +223,11 @@ draw_print_arrays(struct draw_context *draw, uint prim, int start, uint count)
break;
default:
assert(0);
return;
}
debug_printf("Element[%u + %u] -> Vertex %u:\n", start, i, ii);
ii += draw->pt.user.eltBias;
debug_printf("Element[%u + %u] + %i -> Vertex %u:\n", start, i,
draw->pt.user.eltBias, ii);
}
else {
/* non-indexed arrays */

View file

@ -67,6 +67,7 @@ struct draw_pt_front_end {
void (*run)( struct draw_pt_front_end *,
pt_elt_func elt_func,
const void *elt_ptr,
int elt_bias,
unsigned count );
void (*finish)( struct draw_pt_front_end * );

View file

@ -6,6 +6,7 @@ static unsigned trim( unsigned count, unsigned first, unsigned incr )
static void FUNC(struct draw_pt_front_end *frontend,
pt_elt_func get_elt,
const void *elts,
int elt_bias,
unsigned count)
{
struct varray_frontend *varray = (struct varray_frontend *)frontend;
@ -14,6 +15,8 @@ static void FUNC(struct draw_pt_front_end *frontend,
unsigned j;
unsigned first, incr;
assert(elt_bias == 0);
draw_pt_split_prim(varray->input_prim, &first, &incr);
/* Sanitize primitive length:

View file

@ -329,6 +329,7 @@ static INLINE void
vcache_check_run( struct draw_pt_front_end *frontend,
pt_elt_func get_elt,
const void *elts,
int elt_bias,
unsigned draw_count )
{
struct vcache_frontend *vcache = (struct vcache_frontend *)frontend;
@ -362,8 +363,9 @@ vcache_check_run( struct draw_pt_front_end *frontend,
}
if (min_index == 0 &&
index_size == 2)
if (elt_bias <= 0 &&
min_index == (unsigned)-elt_bias &&
index_size == 2)
{
transformed_elts = (const ushort *)elts;
}
@ -373,7 +375,8 @@ vcache_check_run( struct draw_pt_front_end *frontend,
if (!storage)
goto fail;
if (min_index == 0) {
if (elt_bias <= 0 &&
min_index == (unsigned)-elt_bias) {
switch(index_size) {
case 1:
translate_ubyte_elts( (const ubyte *)elts,
@ -404,21 +407,21 @@ vcache_check_run( struct draw_pt_front_end *frontend,
case 1:
rebase_ubyte_elts( (const ubyte *)elts,
draw_count,
0 - (int)min_index,
elt_bias - (int)min_index,
storage );
break;
case 2:
rebase_ushort_elts( (const ushort *)elts,
draw_count,
0 - (int)min_index,
elt_bias - (int)min_index,
storage );
break;
case 4:
rebase_uint_elts( (const uint *)elts,
draw_count,
0 - (int)min_index,
elt_bias - (int)min_index,
storage );
break;
@ -447,7 +450,7 @@ vcache_check_run( struct draw_pt_front_end *frontend,
fetch_count, draw_count);
fail:
vcache_run( frontend, get_elt, elts, draw_count );
vcache_run( frontend, get_elt, elts, elt_bias, draw_count );
}

View file

@ -3,6 +3,7 @@
static void FUNC( struct draw_pt_front_end *frontend,
pt_elt_func get_elt,
const void *elts,
int elt_bias,
unsigned count )
{
struct vcache_frontend *vcache = (struct vcache_frontend *)frontend;
@ -20,7 +21,7 @@ static void FUNC( struct draw_pt_front_end *frontend,
case PIPE_PRIM_POINTS:
for (i = 0; i < count; i ++) {
POINT( vcache,
get_elt(elts, i + 0) );
get_elt(elts, i + 0) + elt_bias );
}
break;
@ -28,8 +29,8 @@ static void FUNC( struct draw_pt_front_end *frontend,
for (i = 0; i+1 < count; i += 2) {
LINE( vcache,
DRAW_PIPE_RESET_STIPPLE,
get_elt(elts, i + 0),
get_elt(elts, i + 1));
get_elt(elts, i + 0) + elt_bias,
get_elt(elts, i + 1) + elt_bias);
}
break;
@ -40,14 +41,14 @@ static void FUNC( struct draw_pt_front_end *frontend,
for (i = 1; i < count; i++, flags = 0) {
LINE( vcache,
flags,
get_elt(elts, i - 1),
get_elt(elts, i ));
get_elt(elts, i - 1) + elt_bias,
get_elt(elts, i ) + elt_bias);
}
LINE( vcache,
flags,
get_elt(elts, i - 1),
get_elt(elts, 0 ));
get_elt(elts, i - 1) + elt_bias,
get_elt(elts, 0 ) + elt_bias);
}
break;
@ -56,8 +57,8 @@ static void FUNC( struct draw_pt_front_end *frontend,
for (i = 1; i < count; i++, flags = 0) {
LINE( vcache,
flags,
get_elt(elts, i - 1),
get_elt(elts, i ));
get_elt(elts, i - 1) + elt_bias,
get_elt(elts, i ) + elt_bias);
}
break;
@ -65,9 +66,9 @@ static void FUNC( struct draw_pt_front_end *frontend,
for (i = 0; i+2 < count; i += 3) {
TRIANGLE( vcache,
DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL,
get_elt(elts, i + 0),
get_elt(elts, i + 1),
get_elt(elts, i + 2 ));
get_elt(elts, i + 0) + elt_bias,
get_elt(elts, i + 1) + elt_bias,
get_elt(elts, i + 2 ) + elt_bias);
}
break;
@ -76,18 +77,18 @@ static void FUNC( struct draw_pt_front_end *frontend,
for (i = 0; i+2 < count; i++) {
TRIANGLE( vcache,
DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL,
get_elt(elts, i + 0),
get_elt(elts, i + 1 + (i&1)),
get_elt(elts, i + 2 - (i&1)));
get_elt(elts, i + 0) + elt_bias,
get_elt(elts, i + 1 + (i&1) + elt_bias),
get_elt(elts, i + 2 - (i&1) + elt_bias));
}
}
else {
for (i = 0; i+2 < count; i++) {
TRIANGLE( vcache,
DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL,
get_elt(elts, i + 0 + (i&1)),
get_elt(elts, i + 1 - (i&1)),
get_elt(elts, i + 2 ));
get_elt(elts, i + 0 + (i&1) + elt_bias),
get_elt(elts, i + 1 - (i&1) + elt_bias),
get_elt(elts, i + 2 ) + elt_bias);
}
}
break;
@ -98,18 +99,18 @@ static void FUNC( struct draw_pt_front_end *frontend,
for (i = 0; i+2 < count; i++) {
TRIANGLE( vcache,
DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL,
get_elt(elts, i + 1),
get_elt(elts, i + 2),
get_elt(elts, 0 ));
get_elt(elts, i + 1) + elt_bias,
get_elt(elts, i + 2) + elt_bias,
get_elt(elts, 0 ) + elt_bias);
}
}
else {
for (i = 0; i+2 < count; i++) {
TRIANGLE( vcache,
DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL,
get_elt(elts, 0),
get_elt(elts, i + 1),
get_elt(elts, i + 2 ));
get_elt(elts, 0) + elt_bias,
get_elt(elts, i + 1) + elt_bias,
get_elt(elts, i + 2 ) + elt_bias);
}
}
}
@ -119,20 +120,20 @@ static void FUNC( struct draw_pt_front_end *frontend,
case PIPE_PRIM_QUADS:
for (i = 0; i+3 < count; i += 4) {
QUAD( vcache,
get_elt(elts, i + 0),
get_elt(elts, i + 1),
get_elt(elts, i + 2),
get_elt(elts, i + 3) );
get_elt(elts, i + 0) + elt_bias,
get_elt(elts, i + 1) + elt_bias,
get_elt(elts, i + 2) + elt_bias,
get_elt(elts, i + 3) + elt_bias );
}
break;
case PIPE_PRIM_QUAD_STRIP:
for (i = 0; i+3 < count; i += 2) {
QUAD( vcache,
get_elt(elts, i + 2),
get_elt(elts, i + 0),
get_elt(elts, i + 1),
get_elt(elts, i + 3) );
get_elt(elts, i + 2) + elt_bias,
get_elt(elts, i + 0) + elt_bias,
get_elt(elts, i + 1) + elt_bias,
get_elt(elts, i + 3) + elt_bias );
}
break;
@ -165,16 +166,16 @@ static void FUNC( struct draw_pt_front_end *frontend,
if (flatfirst) {
TRIANGLE( vcache,
flags,
get_elt(elts, 0),
get_elt(elts, i + 1),
get_elt(elts, i + 2) );
get_elt(elts, 0) + elt_bias,
get_elt(elts, i + 1) + elt_bias,
get_elt(elts, i + 2) + elt_bias );
}
else {
TRIANGLE( vcache,
flags,
get_elt(elts, i + 1),
get_elt(elts, i + 2),
get_elt(elts, 0));
get_elt(elts, i + 1) + elt_bias,
get_elt(elts, i + 2) + elt_bias,
get_elt(elts, 0) + elt_bias);
}
}
}