]> git.wh0rd.org - ICEs.git/blob - 394889/s_triangle.i.14
more
[ICEs.git] / 394889 / s_triangle.i.14
1 typedef union {
2 float f;
3 int i;
4 } fi_type;
5 static __inline__ int IS_INF_OR_NAN(float x)
6 {
7 fi_type tmp;
8 tmp.f = x;
9 return !(int)((unsigned int)((tmp.i & 0x7fffffff) - 0x7f800000) >> 31);
10 }
11
12 struct gl_texture_image {
13 unsigned int Width;
14 unsigned int Height;
15 void *Data;
16 };
17 struct gl_renderbuffer {
18 void (*PutRowRGB) ();
19 };
20 typedef struct {
21 float attrib[30][4];
22 } SWvertex;
23 typedef struct sw_span {
24 int x; int y;
25 unsigned int end;
26 float attrStepX[30][4];
27 int intTex[2]; int intTexStep[2];
28 } SWspan;
29 static void simple_textured_triangle(const SWvertex * v1)
30 {
31 const SWvertex *v0;
32 const SWvertex *v2;
33 typedef struct {
34 float dx;
35 float dy;
36 int fsx;
37 int fx0;
38 int lines;
39 } EdgeT;
40 EdgeT eMaj;
41 EdgeT eTop;
42 EdgeT eBot;
43 float oneOverArea;
44 const SWvertex *vMin;
45 const SWvertex *vMid;
46 const SWvertex *vMax;
47 int vMin_fx;
48 int vMin_fy;
49 int vMid_fx;
50 int vMid_fy;
51 int vMax_fx;
52 int vMax_fy;
53 SWspan span;
54 const int fy0 = v0->attrib[0][1];
55 const int fy1 = v1->attrib[0][1];
56 const int fy2 = v2->attrib[0][1];
57 if (fy1 <= fy2)
58 {
59 vMin = v0;
60 vMax = v1;
61 vMin_fy = fy0;
62 }
63 vMin_fx = vMin->attrib[0][0];
64 vMid_fx =
65 (((int)
66 ((vMid->attrib[0][0] >=
67 0) ? ((vMid->attrib[0][0] * (float)2048
68 ) +
69 0.5F) : (((vMid->attrib[0][0]) * (float)2048) -
70 0.5F))));
71 eMaj.dx = ((vMax_fx - vMin_fx) * (1.0F / (float)2048));
72 eMaj.dy = ((vMax_fy - vMin_fy) * (1.0F / (float)2048));
73 eTop.dx = ((vMax_fx - vMid_fx) * (1.0F / (float)2048));
74 eBot.dy = ((vMid_fy - vMin_fy) * (1.0F / (float)2048));
75 const float area = eMaj.dx * eBot.dy - eBot.dx * eMaj.dy;
76 if (IS_INF_OR_NAN(area))
77 return;
78 oneOverArea = 1.0F / area;
79 eBot.fx0 = vMin_fx;
80 int scan_from_left_to_right;
81 struct gl_renderbuffer *rb;
82 const struct gl_texture_image *texImg;
83 const float twidth;
84 const int twidth_log2;
85 const unsigned char *texture = texImg->Data;
86 const int smask = texImg->Width;
87 const int tmask = texImg->Height;
88 float eMaj_ds = (vMax->attrib[4][0] - vMin->attrib[4][0]) * twidth;
89 float eBot_ds;
90 span.attrStepX[4][0] =
91 oneOverArea * (eMaj_ds * eBot.dy - eMaj.dy * eBot_ds);
92 span.intTexStep[0] =
93 (((int)
94 ((((span.attrStepX[4][0]) * (float)2048) >=
95 0.0F) ? (((span.attrStepX[4][0]) * (float)2048) +
96 0.5F) : (((span.attrStepX[4][0]) * (float)2048) -
97 0.5F))));
98 int subTriangle;
99 int fxLeftEdge = 0;
100 int fxRightEdge = 0;
101 int sLeft = 0;
102 for (subTriangle = 0; subTriangle <= 1; subTriangle++) {
103 EdgeT *eRight;
104 int lines;
105 if (subTriangle == 0) {
106 if (scan_from_left_to_right) {
107 eRight = &eBot;
108 lines = eRight->lines;
109 } else {
110 eRight = &eMaj;
111 }
112 } else {
113 if (scan_from_left_to_right) {
114 eRight = &eTop;
115 }
116 fxRightEdge = eRight->fsx ;
117 }
118 while (lines > 0) {
119 const int right = fxRightEdge ;
120 span.x = 0;
121 if (right <= span.x)
122 span.end = 0;
123 else
124 span.end = right - span.x;
125 span.intTex[0] = 0;
126 if (span.end > 0 && span.y >= 0) {
127 unsigned int i;
128 unsigned char rgb[16384][3];
129 for (i = 0; i < span.end; i++)
130 {
131 int s = span.intTex[0];
132 int t = span.intTex[1];
133 int pos = (t << twidth_log2) + s;
134 rgb[i][0] = texture[pos ];
135 span.intTex[0] += span.intTexStep[0];
136 }
137 rb->PutRowRGB(rgb);
138 }
139 }
140 }
141 }
142
143 void *foo()
144 {
145 return simple_textured_triangle;
146 }