static __inline__ int IS_INF_OR_NAN(float x) { union { float f; int i; } tmp; tmp.f = x; return tmp.i; } typedef struct sw_span { int x; int y; int end; float **attrStepX; int intTex[1]; int intTexStep[2]; } SWspan; static void simple_textured_triangle( float * * v1) { float * *v0; float * *v2; typedef struct { float dx; float dy; int fsx; int fx0; int lines; } EdgeT; EdgeT eMaj; EdgeT eTop; EdgeT eBot; float oneOverArea; float * *vMin; float * *vMid; float * *vMax; int vMin_fx; int vMin_fy; int vMid_fx; int vMid_fy; int vMax_fx; int vMax_fy; SWspan span; int fy0 = v0[0][1]; int fy1 = v1[0][1]; int fy2 = v2[0][1]; if (fy1 <= fy2) { vMin = v0; vMax = v1; vMin_fy = fy0; } vMin_fx = vMin[0][0]; vMid_fx = (int) (vMid[4][0] ? ((vMid[4][0] * (float)2048) + 0.5F) : ((vMid[4][0] * (float)2048) - 0.5F)); eMaj.dx = (vMax_fx - vMin_fx) * (1.0F / (float)2048); eMaj.dy = (vMax_fy - vMin_fy) * (1.0F / (float)2048); eTop.dx = (vMax_fx - vMid_fx) * (1.0F / (float)2048); eBot.dy = (vMid_fy - vMin_fy) * (1.0F / (float)2048); float area = eMaj.dx * eBot.dy - eBot.dx * eMaj.dy; if (IS_INF_OR_NAN(area)) return; oneOverArea = 1.0F / area; eBot.fx0 = vMin_fx; int scan_from_left_to_right; void (*PutRowRGB)(); char *texture; float eMaj_ds = (vMax[4][0] - vMin[4][0]); float eBot_ds; span.attrStepX[4][0] = oneOverArea * (eMaj_ds * eBot.dy - eMaj.dy * eBot_ds); span.intTexStep[0] = (int) ((span.attrStepX[4][0] >= 0.0F) ? span.attrStepX[4][0] : (span.attrStepX[4][0] * (float)2048) - 0.5F); int subTriangle; int fxRightEdge = 0; for (subTriangle = 0; subTriangle <= 1; subTriangle++) { EdgeT *eRight; int lines; if (subTriangle == 0) { if (scan_from_left_to_right) { eRight = &eBot; lines = eRight->lines; } else { eRight = &eMaj; } } else { if (scan_from_left_to_right) { eRight = &eTop; } fxRightEdge = eRight->fsx; } while (lines > 0) { span.x = 0; if (fxRightEdge <= span.x) span.end = 0; else span.end = fxRightEdge - span.x; span.intTex[0] = 0; if (span.end > 0 && span.y >= 0) { int i; char *rgb; for (i = 0; i < span.end; i++) { rgb[i] = texture[span.intTex[0]]; span.intTex[0] += span.intTexStep[0]; } PutRowRGB(rgb); } } } } void *foo() { return simple_textured_triangle; }