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