--- /dev/null
+typedef union {
+ float f;
+ int i;
+} fi_type;
+static __inline__ int IS_INF_OR_NAN(float x)
+{
+ fi_type tmp;
+ tmp.f = x;
+ return !(int)((unsigned int)((tmp.i & 0x7fffffff) - 0x7f800000) >> 31);
+}
+
+struct gl_texture_image {
+ unsigned int Width;
+ unsigned int Height;
+ void *Data;
+};
+struct gl_renderbuffer {
+ void (*PutRowRGB) ();
+};
+typedef struct {
+ float attrib[30][4];
+} SWvertex;
+typedef struct sw_span {
+ int x; int y;
+ unsigned int end;
+ float attrStepX[30][4];
+ int intTex[2]; int intTexStep[2];
+} SWspan;
+static void simple_textured_triangle(const SWvertex * v1)
+{
+ const SWvertex *v0;
+ const SWvertex *v2;
+ typedef struct {
+ float dx;
+ float dy;
+ int fsx;
+ int fx0;
+ int lines;
+ } EdgeT;
+ EdgeT eMaj;
+ EdgeT eTop;
+ EdgeT eBot;
+ float oneOverArea;
+ const SWvertex *vMin;
+ const SWvertex *vMid;
+ const SWvertex *vMax;
+ int vMin_fx;
+ int vMin_fy;
+ int vMid_fx;
+ int vMid_fy;
+ int vMax_fx;
+ int vMax_fy;
+ SWspan span;
+ const int fy0 = v0->attrib[0][1];
+ const int fy1 = v1->attrib[0][1];
+ const int fy2 = v2->attrib[0][1];
+ if (fy1 <= fy2)
+{
+ vMin = v0;
+ vMax = v1;
+ vMin_fy = fy0;
+ }
+ vMin_fx = vMin->attrib[0][0];
+ vMid_fx =
+ (((int)
+ ((vMid->attrib[0][0] >=
+ 0) ? ((vMid->attrib[0][0] * (float)2048
+) +
+ 0.5F) : (((vMid->attrib[0][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));
+ const 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;
+ struct gl_renderbuffer *rb;
+ const struct gl_texture_image *texImg;
+ const float twidth;
+ const int twidth_log2;
+ const unsigned char *texture = texImg->Data;
+ const int smask = texImg->Width;
+ const int tmask = texImg->Height;
+ float eMaj_ds = (vMax->attrib[4][0] - vMin->attrib[4][0]) * twidth;
+ float eBot_ds;
+ span.attrStepX[4][0] =
+ oneOverArea * (eMaj_ds * eBot.dy - eMaj.dy * eBot_ds);
+ span.intTexStep[0] =
+ (((int)
+ ((((span.attrStepX[4][0]) * (float)2048) >=
+ 0.0F) ? (((span.attrStepX[4][0]) * (float)2048) +
+ 0.5F) : (((span.attrStepX[4][0]) * (float)2048) -
+ 0.5F))));
+ int subTriangle;
+ int fxLeftEdge = 0;
+ int fxRightEdge = 0;
+ int sLeft = 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) {
+ const int right = fxRightEdge ;
+ span.x = 0;
+ if (right <= span.x)
+ span.end = 0;
+ else
+ span.end = right - span.x;
+ span.intTex[0] = 0;
+ if (span.end > 0 && span.y >= 0) {
+ unsigned int i;
+ unsigned char rgb[16384][3];
+ for (i = 0; i < span.end; i++)
+{
+ int s = span.intTex[0];
+ int t = span.intTex[1];
+ int pos = (t << twidth_log2) + s;
+ rgb[i][0] = texture[pos ];
+ span.intTex[0] += span.intTexStep[0];
+ }
+ rb->PutRowRGB(rgb);
+ }
+ }
+ }
+}
+
+void *foo()
+{
+ return simple_textured_triangle;
+}