]>
Commit | Line | Data |
---|---|---|
bd3239d2 MF |
1 | static __inline__ int IS_INF_OR_NAN(float x) |
2 | { | |
3 | union { | |
4 | float f; | |
5 | int i; | |
6 | } tmp; | |
7 | tmp.f = x; | |
8 | return tmp.i; | |
9 | } | |
10 | ||
11 | typedef struct { | |
12 | float **attrib; | |
13 | } SWvertex; | |
14 | typedef struct sw_span { | |
15 | int x; | |
16 | int y; | |
17 | int end; | |
18 | float attrStepX[30][4]; | |
19 | int intTex[2]; | |
20 | int intTexStep[2]; | |
21 | } SWspan; | |
22 | static void simple_textured_triangle( SWvertex * v1) | |
23 | { | |
24 | SWvertex *v0; | |
25 | SWvertex *v2; | |
26 | typedef struct { | |
27 | float dx; | |
28 | float dy; | |
29 | int fsx; | |
30 | int fx0; | |
31 | int lines; | |
32 | } EdgeT; | |
33 | EdgeT eMaj; | |
34 | EdgeT eTop; | |
35 | EdgeT eBot; | |
36 | float oneOverArea; | |
37 | SWvertex *vMin; | |
38 | SWvertex *vMid; | |
39 | SWvertex *vMax; | |
40 | int vMin_fx; | |
41 | int vMin_fy; | |
42 | int vMid_fx; | |
43 | int vMid_fy; | |
44 | int vMax_fx; | |
45 | int vMax_fy; | |
46 | SWspan span; | |
47 | int fy0 = v0->attrib[0][1]; | |
48 | int fy1 = v1->attrib[0][1]; | |
49 | int fy2 = v2->attrib[0][1]; | |
50 | if (fy1 <= fy2) { | |
51 | vMin = v0; | |
52 | vMax = v1; | |
53 | vMin_fy = fy0; | |
54 | } | |
55 | vMin_fx = vMin->attrib[0][0]; | |
56 | vMid_fx = (int) | |
57 | (vMid->attrib[4][0] ? | |
58 | ((vMid->attrib[4][0] * (float)2048) + 0.5F) : | |
59 | ((vMid->attrib[4][0] * (float)2048) - 0.5F)); | |
60 | eMaj.dx = (vMax_fx - vMin_fx) * (1.0F / (float)2048); | |
61 | eMaj.dy = (vMax_fy - vMin_fy) * (1.0F / (float)2048); | |
62 | eTop.dx = (vMax_fx - vMid_fx) * (1.0F / (float)2048); | |
63 | eBot.dy = (vMid_fy - vMin_fy) * (1.0F / (float)2048); | |
64 | float area = eMaj.dx * eBot.dy - eBot.dx * eMaj.dy; | |
65 | if (IS_INF_OR_NAN(area)) | |
66 | return; | |
67 | oneOverArea = 1.0F / area; | |
68 | eBot.fx0 = vMin_fx; | |
69 | int scan_from_left_to_right; | |
70 | void (*PutRowRGB)(); | |
71 | char *texture; | |
72 | float eMaj_ds = (vMax->attrib[4][0] - vMin->attrib[4][0]); | |
73 | float eBot_ds; | |
74 | span.attrStepX[4][0] = | |
75 | oneOverArea * (eMaj_ds * eBot.dy - eMaj.dy * eBot_ds); | |
76 | span.intTexStep[0] = | |
77 | (int) | |
78 | ((span.attrStepX[4][0] >= | |
79 | 0.0F) ? span.attrStepX[4][0] : | |
80 | (span.attrStepX[4][0] * (float)2048) - 0.5F); | |
81 | int subTriangle; | |
82 | int fxRightEdge = 0; | |
83 | for (subTriangle = 0; subTriangle <= 1; subTriangle++) { | |
84 | EdgeT *eRight; | |
85 | int lines; | |
86 | if (subTriangle == 0) { | |
87 | if (scan_from_left_to_right) { | |
88 | eRight = &eBot; | |
89 | lines = eRight->lines; | |
90 | } else { | |
91 | eRight = &eMaj; | |
92 | } | |
93 | } else { | |
94 | if (scan_from_left_to_right) { | |
95 | eRight = &eTop; | |
96 | } | |
97 | fxRightEdge = eRight->fsx; | |
98 | } | |
99 | while (lines > 0) { | |
100 | span.x = 0; | |
101 | if (fxRightEdge <= span.x) | |
102 | span.end = 0; | |
103 | else | |
104 | span.end = fxRightEdge - span.x; | |
105 | span.intTex[0] = 0; | |
106 | if (span.end > 0 && span.y >= 0) { | |
107 | int i; | |
108 | char *rgb; | |
109 | for (i = 0; i < span.end; i++) { | |
110 | rgb[i] = texture[span.intTex[0]]; | |
111 | span.intTex[0] += span.intTexStep[0]; | |
112 | } | |
113 | PutRowRGB(rgb); | |
114 | } | |
115 | } | |
116 | } | |
117 | } | |
118 | ||
119 | void *foo() | |
120 | { | |
121 | return simple_textured_triangle; | |
122 | } |