Speed up triangle rasterisation

This commit is contained in:
Phil Bennett 2010-01-20 09:47:04 +00:00
parent 093637cc29
commit f6f342c06b
2 changed files with 38 additions and 13 deletions

View File

@ -52,7 +52,7 @@ struct _micro3d_state
} mc68901; } mc68901;
UINT16 *shared_ram; UINT16 *shared_ram;
running_device *duart68681; running_device *duart68681;
UINT8 m68681_tx0; UINT8 m68681_tx0;
/* Sound */ /* Sound */
@ -78,7 +78,7 @@ struct _micro3d_state
/* 2D video */ /* 2D video */
UINT16 *micro3d_sprite_vram; UINT16 *micro3d_sprite_vram;
UINT16 creg; UINT16 creg;
UINT16 xfer3dk; UINT16 xfer3dk;
/* 3D pipeline */ /* 3D pipeline */

View File

@ -511,6 +511,8 @@ static void draw_triangles(micro3d_state *state, UINT32 attr)
int i; int i;
int triangles = 0; int triangles = 0;
int vertices = state->fifo_idx / 3; int vertices = state->fifo_idx / 3;
int min_y = 0x3ff;
int max_y = 0;
/* This satisifes the burst write test */ /* This satisifes the burst write test */
if (vertices == 0) if (vertices == 0)
@ -568,11 +570,12 @@ static void draw_triangles(micro3d_state *state, UINT32 attr)
clip_vertices = clip_triangle(state, vclip_list, vclip_list, clip_vertices, CLIP_Y_MIN); clip_vertices = clip_triangle(state, vclip_list, vclip_list, clip_vertices, CLIP_Y_MIN);
/* Rasterise */ /* Rasterise */
for (k = 2; k < clip_vertices; ++k) if (clip_vertices >= 3)
{ {
micro3d_vtx a = vclip_list[0]; micro3d_vtx a = vclip_list[0];
micro3d_vtx b = vclip_list[k - 1]; micro3d_vtx b = vclip_list[1];
micro3d_vtx c = vclip_list[k];
triangles = TRUE;
a.x += state->x_mid; a.x += state->x_mid;
a.y += state->y_mid; a.y += state->y_mid;
@ -580,19 +583,41 @@ static void draw_triangles(micro3d_state *state, UINT32 attr)
b.x += state->x_mid; b.x += state->x_mid;
b.y += state->y_mid; b.y += state->y_mid;
c.x += state->x_mid; /* Keep track of the y-extents so we don't have to scan every line later */
c.y += state->y_mid; if (a.y < min_y)
min_y = a.y;
if (a.y > max_y)
max_y = a.y;
/* TODO: Don't draw lines twice */ if (b.y < min_y)
min_y = b.y;
if (b.y > max_y)
max_y = b.y;
/* Draw the first line of the triangle/fan */
draw_line(state, a.x, a.y, b.x, b.y); draw_line(state, a.x, a.y, b.x, b.y);
draw_line(state, b.x, b.y, c.x, c.y);
draw_line(state, a.x, a.y, c.x, c.y); for (k = 2; k < clip_vertices; ++k)
triangles = TRUE; {
micro3d_vtx c = vclip_list[k];
c.x += state->x_mid;
c.y += state->y_mid;
if (c.y < min_y)
min_y = c.y;
if (c.y > max_y)
max_y = c.y;
draw_line(state, b.x, b.y, c.x, c.y);
draw_line(state, a.x, a.y, c.x, c.y);
b = c;
}
} }
} }
if (triangles) if (triangles == TRUE)
rasterise_spans(state, 0, 399, attr); rasterise_spans(state, min_y, max_y, attr);
} }