azrp_line() with clipping added

This commit is contained in:
Sylvain PILLOT 2023-05-10 07:58:20 +02:00
parent 5907c27706
commit b8b9064e9b
1 changed files with 3 additions and 2 deletions

View File

@ -62,13 +62,14 @@ void azrp_line(int xA, int yA, int xB, int yB, int color)
int ymax = azrp_height;
//step 1 line are fully out of the screen
if ((xA<xmin && xB<xmin) || (xA>xmax && xB>xmax) || (yA<ymin && yB<ymin) || (yA>ymax && yB>ymax)) {
if ((xA<xmin && xB<xmin) || (xA>xmax && xB>xmax) || (yA<ymin && yB<ymin) || (yA>ymax && yB>ymax)) {
prof_leave(azrp_perf_cmdgen);
return;
}
int x1, x2, y1, y2;
// step 1.5 - specific to Azur fragment approach
// we swap to always start with the point on top as the fragment are updated from top to bottom
// (x1,y1) is the most top point and (x2,y2) is the most bottom point (rankig as per y values only
if (yA <= yB) {
@ -87,6 +88,7 @@ void azrp_line(int xA, int yA, int xB, int yB, int color)
x[0] = x1; x[1] = x2;
y[0] = y1; y[1] = y2;
for(int i=0; i<2; i++) {
if (x[i] < xmin) {
x[i] = xmin; y[i] = ((y2-y1) * (xmin-x1)) / (x2-x1) + y1;
@ -133,7 +135,6 @@ void azrp_line(int xA, int yA, int xB, int yB, int color)
cmd.i = 0;
cmd.cumul = (cmd.dx >= cmd.dy) ? cmd.dx >> 1 : cmd.dy >> 1;
exit:
azrp_queue_command(&cmd, sizeof cmd, frag_first, frag_count);
prof_leave(azrp_perf_cmdgen);
}