From 9b6abe4206bda1ae87ae273295fe8e1988bdd674 Mon Sep 17 00:00:00 2001 From: Roland Scheidegger Date: Thu, 30 Mar 2023 18:31:52 +0200 Subject: [PATCH] llvmpipe: minor cleanups in line rendering code Use float constants, some code deduplication, no functional change. Reviewed-by: Brian Paul Part-of: --- src/gallium/drivers/llvmpipe/lp_setup_line.c | 83 +++++++++++++--------------- 1 file changed, 38 insertions(+), 45 deletions(-) diff --git a/src/gallium/drivers/llvmpipe/lp_setup_line.c b/src/gallium/drivers/llvmpipe/lp_setup_line.c index efbc339..2710f94 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup_line.c +++ b/src/gallium/drivers/llvmpipe/lp_setup_line.c @@ -357,6 +357,7 @@ try_setup_line(struct lp_setup_context *setup, float x_offset = 0, y_offset=0; float x_offset_end = 0, y_offset_end = 0; + /* FIXME: not taking into account setup->pixel_offset here is wrong. */ float x1diff = v1[0][0] - floorf(v1[0][0]) - 0.5f; float y1diff = v1[0][1] - floorf(v1[0][1]) - 0.5f; float x2diff = v2[0][0] - floorf(v2[0][0]) - 0.5f; @@ -369,18 +370,18 @@ try_setup_line(struct lp_setup_context *setup, bool draw_end; if (fabsf(dx) >= fabsf(dy)) { - float dydx = dy / dx; + const float dydx = dy / dx; /* X-MAJOR LINE */ - if (y2diff == -0.5 && dy < 0) { - y2diff = 0.5; + if (y2diff == -0.5f && dy < 0.0f) { + y2diff = 0.5f; } /* - * Diamond exit rule test for starting point - */ - if (fabsf(x1diff) + fabsf(y1diff) < 0.5) { + * Diamond exit rule test for starting point + */ + if (fabsf(x1diff) + fabsf(y1diff) < 0.5f) { draw_start = true; } else if (sign(x1diff) == sign(-dx)) { draw_start = false; @@ -389,13 +390,13 @@ try_setup_line(struct lp_setup_context *setup, } else { /* do intersection test */ float yintersect = fracf(v1[0][1]) + x1diff * dydx; - draw_start = (yintersect < 1.0 && yintersect > 0.0); + draw_start = (yintersect < 1.0f && yintersect > 0.0f); } /* - * Diamond exit rule test for ending point - */ - if (fabsf(x2diff) + fabsf(y2diff) < 0.5) { + * Diamond exit rule test for ending point + */ + if (fabsf(x2diff) + fabsf(y2diff) < 0.5f) { draw_end = false; } else if (sign(x2diff) != sign(-dx)) { draw_end = false; @@ -404,43 +405,41 @@ try_setup_line(struct lp_setup_context *setup, } else { /* do intersection test */ float yintersect = fracf(v2[0][1]) + x2diff * dydx; - draw_end = (yintersect < 1.0 && yintersect > 0.0); + draw_end = (yintersect < 1.0f && yintersect > 0.0f); } - /* Are we already drawing start/end? - */ + /* Are we already drawing start/end? */ bool will_draw_start = sign(-x1diff) != sign(dx); bool will_draw_end = (sign(x2diff) == sign(-dx)) || x2diff==0; /* interpolate using the preferred wide-lines formula */ - info.dx *= 1 + dydx * dydx; - info.dy = 0; + info.dx *= 1.0f + dydx * dydx; + info.dy = 0.0f; - if (dx < 0) { + if (dx < 0.0f) { /* if v2 is to the right of v1, swap pointers */ const float (*temp)[4] = v1; v1 = v2; v2 = temp; dx = -dx; - dy = -dy; /* Otherwise shift planes appropriately */ if (will_draw_start != draw_start) { - x_offset_end = -x1diff - 0.5; + x_offset_end = -x1diff - 0.5f; y_offset_end = x_offset_end * dydx; } if (will_draw_end != draw_end) { - x_offset = -x2diff - 0.5; + x_offset = -x2diff - 0.5f; y_offset = x_offset * dydx; } } else { /* Otherwise shift planes appropriately */ if (will_draw_start != draw_start) { - x_offset = -x1diff + 0.5; + x_offset = -x1diff + 0.5f; y_offset = x_offset * dydx; } if (will_draw_end != draw_end) { - x_offset_end = -x2diff + 0.5; + x_offset_end = -x2diff + 0.5f; y_offset_end = x_offset_end * dydx; } } @@ -459,19 +458,15 @@ try_setup_line(struct lp_setup_context *setup, const float dxdy = dx / dy; /* Y-MAJOR LINE */ - x1diff = v1[0][0] - floorf(v1[0][0]) - 0.5f; - y1diff = v1[0][1] - floorf(v1[0][1]) - 0.5f; - x2diff = v2[0][0] - floorf(v2[0][0]) - 0.5f; - y2diff = v2[0][1] - floorf(v2[0][1]) - 0.5f; - if (x2diff == -0.5 && dx < 0) { - x2diff = 0.5; + if (x2diff == -0.5f && dx < 0.0f) { + x2diff = 0.5f; } /* - * Diamond exit rule test for starting point - */ - if (fabsf(x1diff) + fabsf(y1diff) < 0.5) { + * Diamond exit rule test for starting point + */ + if (fabsf(x1diff) + fabsf(y1diff) < 0.5f) { draw_start = true; } else if (sign(-y1diff) == sign(dy)) { draw_start = false; @@ -480,13 +475,13 @@ try_setup_line(struct lp_setup_context *setup, } else { /* do intersection test */ float xintersect = fracf(v1[0][0]) + y1diff * dxdy; - draw_start = (xintersect < 1.0 && xintersect > 0.0); + draw_start = (xintersect < 1.0f && xintersect > 0.0f); } /* - * Diamond exit rule test for ending point - */ - if (fabsf(x2diff) + fabsf(y2diff) < 0.5) { + * Diamond exit rule test for ending point + */ + if (fabsf(x2diff) + fabsf(y2diff) < 0.5f) { draw_end = false; } else if (sign(-y2diff) != sign(dy)) { draw_end = false; @@ -495,43 +490,41 @@ try_setup_line(struct lp_setup_context *setup, } else { /* do intersection test */ float xintersect = fracf(v2[0][0]) + y2diff * dxdy; - draw_end = (xintersect < 1.0 && xintersect >= 0.0); + draw_end = (xintersect < 1.0f && xintersect >= 0.0f); } - /* Are we already drawing start/end? - */ + /* Are we already drawing start/end? */ bool will_draw_start = sign(y1diff) == sign(dy); bool will_draw_end = (sign(-y2diff) == sign(dy)) || y2diff==0; /* interpolate using the preferred wide-lines formula */ - info.dx = 0; - info.dy *= 1 + dxdy * dxdy; + info.dx = 0.0f; + info.dy *= 1.0f + dxdy * dxdy; - if (dy > 0) { + if (dy > 0.0f) { /* if v2 is on top of v1, swap pointers */ const float (*temp)[4] = v1; v1 = v2; v2 = temp; - dx = -dx; dy = -dy; /* Otherwise shift planes appropriately */ if (will_draw_start != draw_start) { - y_offset_end = -y1diff + 0.5; + y_offset_end = -y1diff + 0.5f; x_offset_end = y_offset_end * dxdy; } if (will_draw_end != draw_end) { - y_offset = -y2diff + 0.5; + y_offset = -y2diff + 0.5f; x_offset = y_offset * dxdy; } } else { /* Otherwise shift planes appropriately */ if (will_draw_start != draw_start) { - y_offset = -y1diff - 0.5; + y_offset = -y1diff - 0.5f; x_offset = y_offset * dxdy; } if (will_draw_end != draw_end) { - y_offset_end = -y2diff - 0.5; + y_offset_end = -y2diff - 0.5f; x_offset_end = y_offset_end * dxdy; } } -- 2.7.4