]>
Commit | Line | Data |
---|---|---|
bd3239d2 MF |
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 | struct gl_framebuffer { | |
21 | struct gl_renderbuffer *_ColorDrawBuffers[8]; | |
22 | }; | |
23 | struct gl_context { | |
24 | struct gl_framebuffer *DrawBuffer; | |
25 | }; | |
26 | typedef struct { | |
27 | float attrib[30][4]; | |
28 | } SWvertex; | |
29 | typedef struct sw_span { | |
30 | int x, y; | |
31 | unsigned int end; | |
32 | float attrStepX[30][4]; | |
33 | int intTex[2], intTexStep[2]; | |
34 | } SWspan; | |
35 | static void simple_textured_triangle(const SWvertex * v1) | |
36 | { | |
37 | struct gl_context *ctx; | |
38 | const SWvertex *v0; | |
39 | const SWvertex *v2; | |
40 | typedef struct { | |
41 | float dx; | |
42 | float dy; | |
43 | int fsx; | |
44 | int fx0; | |
45 | int lines; | |
46 | } EdgeT; | |
47 | EdgeT eMaj; | |
48 | EdgeT eTop; | |
49 | EdgeT eBot; | |
50 | float oneOverArea; | |
51 | const SWvertex *vMin; | |
52 | const SWvertex *vMid; | |
53 | const SWvertex *vMax; | |
54 | const int snapMask = ~127; | |
55 | int vMin_fx; | |
56 | int vMin_fy; | |
57 | int vMid_fx; | |
58 | int vMid_fy; | |
59 | int vMax_fx; | |
60 | int vMax_fy; | |
61 | SWspan span; | |
62 | const int fy0 = | |
63 | (((int) | |
64 | ((((v0->attrib[0][1] - 0) * (float)2048) >= | |
65 | 0) ? (((v0->attrib[0][1] - 0) * (float)2048) + | |
66 | 0) : (((v0->attrib[0][1] - 0) * (float)2048) - | |
67 | 0)))); | |
68 | const int fy1 = | |
69 | (((int) | |
70 | ((((v1->attrib[0][1] - 0) * (float)2048) >= | |
71 | 0.0F) ? (((v1->attrib[0][1] - 0) * (float)2048) + | |
72 | 0) : (((v1->attrib[0][1] - 0) * (float)2048) - | |
73 | 0)))); | |
74 | const int fy2 = | |
75 | (((int) | |
76 | ((((v2->attrib[0][1] - 0) * (float)2048) >= | |
77 | 0.0F) ? (((v2->attrib[0][1] - 0) * (float)2048) + | |
78 | 0) : (((v2->attrib[0][1] - 0) * (float)2048) - | |
79 | 0)))); | |
80 | if (fy1 <= fy2) | |
81 | { | |
82 | vMin = v0; | |
83 | vMax = v1; | |
84 | vMin_fy = fy0; | |
85 | } | |
86 | vMin_fx = | |
87 | (((int) | |
88 | ((((vMin->attrib[0][0] + 0.5F) * (float)2048) >= | |
89 | 0.0F) ? (((vMin->attrib[0][0] + 0.5F) * (float)2048) + | |
90 | 0.5F) : (((vMin->attrib[0][0] + 0.5F) * (float)2048) - | |
91 | 0.5F)))) & snapMask; | |
92 | vMid_fx = | |
93 | (((int) | |
94 | ((((vMid->attrib[0][0] + 0.5F) * (float)2048) >= | |
95 | 0.0F) ? (((vMid->attrib[0][0] + 0.5F) * (float)2048) + | |
96 | 0.5F) : (((vMid->attrib[0][0] + 0.5F) * (float)2048) - | |
97 | 0.5F)))) & snapMask; | |
98 | eMaj.dx = ((vMax_fx - vMin_fx) * (1.0F / (float)2048)); | |
99 | eMaj.dy = ((vMax_fy - vMin_fy) * (1.0F / (float)2048)); | |
100 | eTop.dx = ((vMax_fx - vMid_fx) * (1.0F / (float)2048)); | |
101 | eBot.dy = ((vMid_fy - vMin_fy) * (1.0F / (float)2048)); | |
102 | const float area = eMaj.dx * eBot.dy - eBot.dx * eMaj.dy; | |
103 | if (IS_INF_OR_NAN(area)) | |
104 | return; | |
105 | oneOverArea = 1.0F / area; | |
106 | eBot.fx0 = vMin_fx; | |
107 | int scan_from_left_to_right; | |
108 | struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0]; | |
109 | const struct gl_texture_image *texImg; | |
110 | const float twidth; | |
111 | const int twidth_log2; | |
112 | const unsigned char *texture = texImg->Data; | |
113 | const int smask = texImg->Width; | |
114 | const int tmask = texImg->Height; | |
115 | float eMaj_ds = (vMax->attrib[4][0] - vMin->attrib[4][0]) * twidth; | |
116 | float eBot_ds; | |
117 | span.attrStepX[4][0] = | |
118 | oneOverArea * (eMaj_ds * eBot.dy - eMaj.dy * eBot_ds); | |
119 | span.intTexStep[0] = | |
120 | (((int) | |
121 | ((((span.attrStepX[4][0]) * (float)2048) >= | |
122 | 0.0F) ? (((span.attrStepX[4][0]) * (float)2048) + | |
123 | 0.5F) : (((span.attrStepX[4][0]) * (float)2048) - | |
124 | 0.5F)))); | |
125 | int subTriangle; | |
126 | int fxLeftEdge = 0; | |
127 | int fxRightEdge = 0; | |
128 | int sLeft = 0; | |
129 | for (subTriangle = 0; subTriangle <= 1; subTriangle++) { | |
130 | EdgeT *eRight; | |
131 | int lines; | |
132 | if (subTriangle == 0) { | |
133 | if (scan_from_left_to_right) { | |
134 | eRight = &eBot; | |
135 | lines = eRight->lines; | |
136 | } else { | |
137 | eRight = &eMaj; | |
138 | } | |
139 | } else { | |
140 | if (scan_from_left_to_right) { | |
141 | eRight = &eTop; | |
142 | } | |
143 | fxRightEdge = eRight->fsx - 1; | |
144 | } | |
145 | while (lines > 0) { | |
146 | const int right = fxRightEdge >> 11; | |
147 | span.x = fxLeftEdge >> 11; | |
148 | if (right <= span.x) | |
149 | span.end = 0; | |
150 | else | |
151 | span.end = right - span.x; | |
152 | span.intTex[0] = sLeft; | |
153 | if (span.end > 0 && span.y >= 0) { | |
154 | unsigned int i; | |
155 | unsigned char rgb[16384][3]; | |
156 | for (i = 0; i < span.end; i++) { | |
157 | int s = | |
158 | ((span.intTex[0]) >> 11) & smask; | |
159 | int t = | |
160 | ((span.intTex[1]) >> 11) & tmask; | |
161 | int pos = (t << twidth_log2) + s; | |
162 | rgb[i][0] = texture[pos + 2]; | |
163 | span.intTex[0] += span.intTexStep[0]; | |
164 | } | |
165 | rb->PutRowRGB(rgb); | |
166 | } | |
167 | } | |
168 | } | |
169 | } | |
170 | ||
171 | void *foo() | |
172 | { | |
173 | return simple_textured_triangle; | |
174 | } |