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