]> git.wh0rd.org - ICEs.git/blob - 394889/s_triangle.i.7
more
[ICEs.git] / 394889 / s_triangle.i.7
1 typedef union {
2 float f;
3 int i;
4 } fi_type;
5 static __inline__
6 int IS_INF_OR_NAN(float x)
7 {
8 fi_type tmp;
9 tmp.f = x;
10 return !(int)((unsigned int)((tmp.i & 0x7fffffff) - 0x7f800000) >> 31);
11 }
12
13 typedef enum {
14 MESA_FORMAT_RGBA8888, MESA_FORMAT_RGB888,
15 } gl_format;
16 typedef enum {
17 FRAG_ATTRIB_WPOS = 0, FRAG_ATTRIB_COL0 = 1, FRAG_ATTRIB_COL1 =
18 2, FRAG_ATTRIB_FOGC = 3, FRAG_ATTRIB_TEX0 = 4, FRAG_ATTRIB_TEX1 =
19 5, FRAG_ATTRIB_TEX2 = 6, FRAG_ATTRIB_TEX3 = 7, FRAG_ATTRIB_TEX4 =
20 8, FRAG_ATTRIB_TEX5 = 9, FRAG_ATTRIB_TEX6 = 10, FRAG_ATTRIB_TEX7 =
21 11, FRAG_ATTRIB_FACE = 12, FRAG_ATTRIB_PNTC = 13, FRAG_ATTRIB_VAR0 =
22 14, FRAG_ATTRIB_MAX = (FRAG_ATTRIB_VAR0 + 16)
23 } gl_frag_result;
24 struct gl_config {
25 int depthBits;
26 };
27 struct gl_lightmodel {
28 unsigned int ColorControl;
29 };
30 struct gl_depthbuffer_attrib {
31 unsigned int Func;
32 unsigned char Mask;
33 };
34 struct gl_hint_attrib {
35 unsigned int PerspectiveCorrection;
36 };
37 struct gl_light_attrib {
38 struct gl_lightmodel Model;
39 };
40 struct gl_polygon_attrib {
41 unsigned char StippleFlag;
42 };
43 typedef enum {
44 TEXTURE_BUFFER_INDEX, TEXTURE_2D_ARRAY_INDEX, TEXTURE_1D_ARRAY_INDEX,
45 TEXTURE_CUBE_INDEX, TEXTURE_3D_INDEX, TEXTURE_RECT_INDEX,
46 TEXTURE_2D_INDEX, TEXTURE_1D_INDEX, NUM_TEXTURE_TARGETS
47 } gl_texture_index;
48 struct gl_texture_image {
49 unsigned int Border;
50 unsigned int Width;
51 unsigned int Height;
52 unsigned int WidthLog2;
53 unsigned char _IsPowerOfTwo;
54 unsigned int RowStride;
55 void *Data;
56 };
57 typedef enum {
58 MAX_FACES = 6
59 } gl_face_index;
60 struct gl_sampler_object {
61 unsigned int WrapS;
62 unsigned int WrapT;
63 };
64 struct gl_texture_object {
65 struct gl_sampler_object Sampler;
66 int BaseLevel;
67 unsigned int _Swizzle;
68 struct gl_texture_image *Image[MAX_FACES][15];
69 };
70 struct gl_texture_unit {
71 unsigned int _ReallyEnabled;
72 unsigned int EnvMode;
73 struct gl_texture_object *CurrentTex[NUM_TEXTURE_TARGETS];
74 };
75 struct gl_texture_attrib {
76 struct gl_texture_unit Unit[(16 + 16)];
77 unsigned int _EnabledUnits;
78 unsigned int _EnabledCoordUnits;
79 };
80 struct gl_fragment_program_state {
81 struct gl_fragment_program *_Current;
82 };
83 struct gl_ati_fragment_shader_state {
84 unsigned char _Enabled;
85 };
86 struct gl_renderbuffer {
87 void (*PutRowRGB) (struct gl_context * ctx, struct gl_renderbuffer * rb,
88 unsigned int count, int x, int y, const void *values);
89 };
90 struct gl_framebuffer {
91 struct gl_config Visual;
92 struct gl_renderbuffer *_ColorDrawBuffers[8];
93 };
94 struct gl_context {
95 struct gl_framebuffer *DrawBuffer;
96 struct gl_depthbuffer_attrib Depth;
97 struct gl_hint_attrib Hint;
98 struct gl_light_attrib Light;
99 struct gl_polygon_attrib Polygon;
100 struct gl_texture_attrib Texture;
101 struct gl_fragment_program_state FragmentProgram;
102 struct gl_ati_fragment_shader_state ATIFragmentShader;
103 unsigned int RenderMode;
104 };
105 typedef struct {
106 float attrib[FRAG_ATTRIB_MAX][4];
107 } SWvertex;
108 typedef struct sw_span {
109 int x, y;
110 unsigned int end;
111 float attrStepX[FRAG_ATTRIB_MAX][4];
112 int intTex[2], intTexStep[2];
113 } SWspan;
114 typedef void (*swrast_tri_func) (struct gl_context * ctx, const SWvertex *,
115 const SWvertex *, const SWvertex *);
116 typedef struct {
117 unsigned int _RasterMask;
118 unsigned char _FogEnabled;
119 swrast_tri_func Triangle;
120 } SWcontext;
121 static void simple_textured_triangle(struct gl_context *ctx,
122 const SWvertex * v0, const SWvertex * v1,
123 const SWvertex * v2)
124 {
125 typedef struct {
126 float dx;
127 float dy;
128 int fsx;
129 int fx0;
130 int lines;
131 } EdgeT;
132 EdgeT eMaj;
133 EdgeT eTop;
134 EdgeT eBot;
135 float oneOverArea;
136 const SWvertex *vMin;
137 const SWvertex *vMid;
138 const SWvertex *vMax;
139 const int snapMask = ~(((1 << 11) / (1 << 4)) - 1);
140 int vMin_fx;
141 int vMin_fy;
142 int vMid_fx;
143 int vMid_fy;
144 int vMax_fx;
145 int vMax_fy;
146 SWspan span;
147 const int fy0 =
148 (((int)
149 ((((v0->attrib[FRAG_ATTRIB_WPOS][1] -
150 0.5F) * ((float)(1 << 11))) >=
151 0.0F) ? (((v0->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) *
152 ((float)(1 << 11))) +
153 0.5F)
154 : (((v0->attrib[FRAG_ATTRIB_WPOS][1] -
155 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
156 const int fy1 =
157 (((int)
158 ((((v1->attrib[FRAG_ATTRIB_WPOS][1] -
159 0.5F) * ((float)(1 << 11))) >=
160 0.0F) ? (((v1->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) *
161 ((float)(1 << 11))) +
162 0.5F)
163 : (((v1->attrib[FRAG_ATTRIB_WPOS][1] -
164 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
165 const int fy2 =
166 (((int)
167 ((((v2->attrib[FRAG_ATTRIB_WPOS][1] -
168 0.5F) * ((float)(1 << 11))) >=
169 0.0F) ? (((v2->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) *
170 ((float)(1 << 11))) +
171 0.5F)
172 : (((v2->attrib[FRAG_ATTRIB_WPOS][1] -
173 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
174 if (fy0 <= fy1) {
175 if (fy1 <= fy2) {
176 vMin = v0;
177 vMax = v1;
178 vMin_fy = fy0;
179 }
180 }
181 vMin_fx =
182 (((int)
183 ((((vMin->attrib[FRAG_ATTRIB_WPOS][0] +
184 0.5F) * ((float)(1 << 11))) >=
185 0.0F) ? (((vMin->attrib[FRAG_ATTRIB_WPOS][0] + 0.5F) *
186 ((float)(1 << 11))) +
187 0.5F)
188 : (((vMin->attrib[FRAG_ATTRIB_WPOS][0] +
189 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
190 vMid_fx =
191 (((int)
192 ((((vMid->attrib[FRAG_ATTRIB_WPOS][0] +
193 0.5F) * ((float)(1 << 11))) >=
194 0.0F) ? (((vMid->attrib[FRAG_ATTRIB_WPOS][0] + 0.5F) *
195 ((float)(1 << 11))) +
196 0.5F)
197 : (((vMid->attrib[FRAG_ATTRIB_WPOS][0] +
198 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
199 eMaj.dx = ((vMax_fx - vMin_fx) * (1.0F / ((float)(1 << 11))));
200 eMaj.dy = ((vMax_fy - vMin_fy) * (1.0F / ((float)(1 << 11))));
201 eTop.dx = ((vMax_fx - vMid_fx) * (1.0F / ((float)(1 << 11))));
202 eBot.dy = ((vMid_fy - vMin_fy) * (1.0F / ((float)(1 << 11))));
203 const float area = eMaj.dx * eBot.dy - eBot.dx * eMaj.dy;
204 if (IS_INF_OR_NAN(area) || area == 0.0F)
205 return;
206 oneOverArea = 1.0F / area;
207 if (eBot.lines > 0) {
208 eBot.fx0 = vMin_fx;
209 }
210 int scan_from_left_to_right;
211 struct gl_renderbuffer *rb =
212 ctx->DrawBuffer->_ColorDrawBuffers[0];
213 const struct gl_texture_object *obj =
214 ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];
215 const struct gl_texture_image *texImg =
216 obj->Image[0][obj->BaseLevel];
217 const float twidth = (float) texImg->Width;
218 const int twidth_log2 = texImg->WidthLog2;
219 const unsigned char *texture = (const unsigned char *)texImg->Data;
220 const int smask = texImg->Width - 1;
221 const int tmask = texImg->Height - 1;
222 if (!rb || !texture) {
223 return;
224 }
225 float eMaj_ds =
226 (vMax->attrib[FRAG_ATTRIB_TEX0][0] -
227 vMin->attrib[FRAG_ATTRIB_TEX0][0]) * twidth;
228 float eBot_ds =
229 (vMid->attrib[FRAG_ATTRIB_TEX0][0] -
230 vMin->attrib[FRAG_ATTRIB_TEX0][0]) * twidth;
231 span.attrStepX[FRAG_ATTRIB_TEX0][0] =
232 oneOverArea * (eMaj_ds * eBot.dy -
233 eMaj.dy * eBot_ds);
234 span.intTexStep[0] =
235 (((int)
236 ((((span.attrStepX[FRAG_ATTRIB_TEX0][0]) *
237 ((float)(1 << 11))) >=
238 0.0F) ? (((span.attrStepX[FRAG_ATTRIB_TEX0][0])
239 * ((float)(1 << 11))) +
240 0.5F)
241 : (((span.attrStepX[FRAG_ATTRIB_TEX0][0]) *
242 ((float)(1 << 11))) - 0.5F))));
243 int subTriangle;
244 int fxLeftEdge = 0;
245 int fxRightEdge = 0;
246 int sLeft = 0;
247 for (subTriangle = 0; subTriangle <= 1; subTriangle++) {
248 EdgeT *eRight;
249 int lines;
250 if (subTriangle == 0) {
251 if (scan_from_left_to_right) {
252 eRight = &eBot;
253 lines = eRight->lines;
254 } else {
255 eRight = &eMaj;
256 }
257 } else {
258 if (scan_from_left_to_right) {
259 eRight = &eTop;
260 }
261 fxRightEdge = eRight->fsx - 1;
262 }
263 while (lines > 0) {
264 const int right= fxRightEdge >> 11;
265 span.x = fxLeftEdge >> 11;
266 if (right <= span.x)
267 span.end = 0;
268 else
269 span.end = right - span.x;
270 span.intTex[0] = sLeft;
271 if (span.end > 0 && span.y >= 0) {
272 unsigned int i;
273 unsigned char rgb[16384][3];
274 for (i = 0;
275 i < span.end;
276 i++) {
277 int s =
278 ((span.
279 intTex[0])
280 >> 11) &
281 smask;
282 int t =
283 ((span.
284 intTex[1])
285 >> 11) &
286 tmask;
287 int pos =
288 (t <<
289 twidth_log2)
290 + s;
291 rgb[i][0] =
292 texture[pos
293 +
294 2];
295 span.
296 intTex[0] +=
297 span.
298 intTexStep
299 [0];
300 }
301 rb->PutRowRGB(ctx, rb,
302 span.end,
303 span.x,
304 span.y,
305 rgb);
306 }
307 }
308 }
309 }
310
311 void _swrast_choose_triangle(struct gl_context *ctx)
312 {
313 SWcontext *swrast = SWRAST_CONTEXT(ctx);
314 if (ctx->RenderMode == 0x1C00) {
315 if (ctx->Texture._EnabledCoordUnits
316 || ctx->FragmentProgram._Current
317 || ctx->ATIFragmentShader._Enabled
318 || _mesa_need_secondary_color(ctx) || swrast->_FogEnabled) {
319 const struct gl_texture_object *texObj2D;
320 const struct gl_texture_image *texImg;
321 unsigned int minFilter;
322 unsigned int magFilter;
323 unsigned int envMode;
324 gl_format format;
325 if (ctx->Texture._EnabledCoordUnits == 0x1
326 && !ctx->FragmentProgram._Current
327 && !ctx->ATIFragmentShader._Enabled
328 && ctx->Texture._EnabledUnits == 0x1
329 && ctx->Texture.Unit[0]._ReallyEnabled ==
330 (1 << TEXTURE_2D_INDEX)
331 && texObj2D->Sampler.WrapS == 0x2901
332 && texObj2D->Sampler.WrapT == 0x2901
333 && texObj2D->_Swizzle ==
334 (((0) << 0) | ((1) << 3) | ((2) << 6) | ((3) << 9))
335 && texImg->_IsPowerOfTwo && texImg->Border == 0
336 && texImg->Width == texImg->RowStride
337 && (format == MESA_FORMAT_RGB888
338 || format == MESA_FORMAT_RGBA8888)
339 && minFilter == magFilter
340 && ctx->Light.Model.ColorControl == 0x81F9
341 && !swrast->_FogEnabled
342 && ctx->Texture.Unit[0].EnvMode != 0x8570
343 && ctx->Texture.Unit[0].EnvMode != 0x8503) {
344 if (ctx->Hint.PerspectiveCorrection == 0x1101) {
345 if (minFilter == 0x2600
346 && format == MESA_FORMAT_RGB888
347 && (envMode == 0x1E01
348 || envMode == 0x2101)
349 &&
350 ((swrast->_RasterMask ==
351 (0x004 | 0x1000)
352 && ctx->Depth.Func == 0x0201
353 && ctx->Depth.Mask == 0x1)
354 || swrast->_RasterMask == 0x1000)
355 && ctx->Polygon.StippleFlag == 0x0
356 && ctx->DrawBuffer->Visual.
357 depthBits <= 16) {
358 if (swrast->_RasterMask ==
359 (0x004 | 0x1000)) {
360 swrast->Triangle =
361 simple_textured_triangle;
362 }
363 }
364 }
365 }
366 }
367 }
368 }