]> git.wh0rd.org - ICEs.git/blob - 394889/s_triangle.i.2
more
[ICEs.git] / 394889 / s_triangle.i.2
1 typedef unsigned int GLenum;
2 typedef unsigned char GLboolean;
3 typedef unsigned int GLbitfield;
4 typedef void GLvoid;
5 typedef int GLint;
6 typedef unsigned char GLubyte;
7 typedef unsigned int GLuint;
8 typedef float GLfloat;
9 typedef int GLfixed;
10 typedef union {
11 GLfloat f;
12 GLint i;
13 } fi_type;
14 static __inline__ int IS_INF_OR_NAN(float x)
15 {
16 fi_type tmp;
17 tmp.f = x;
18 return !(int)((unsigned int)((tmp.i & 0x7fffffff) - 0x7f800000) >> 31);
19 }
20
21 typedef enum {
22 MESA_FORMAT_NONE =
23 0, MESA_FORMAT_RGBA8888, MESA_FORMAT_RGBA8888_REV,
24 MESA_FORMAT_ARGB8888, MESA_FORMAT_ARGB8888_REV,
25 MESA_FORMAT_XRGB8888, MESA_FORMAT_XRGB8888_REV, MESA_FORMAT_RGB888,
26 MESA_FORMAT_BGR888, MESA_FORMAT_RGB565, MESA_FORMAT_RGB565_REV,
27 MESA_FORMAT_ARGB4444, MESA_FORMAT_ARGB4444_REV,
28 MESA_FORMAT_RGBA5551, MESA_FORMAT_ARGB1555,
29 MESA_FORMAT_ARGB1555_REV, MESA_FORMAT_AL44, MESA_FORMAT_AL88,
30 MESA_FORMAT_AL88_REV, MESA_FORMAT_AL1616, MESA_FORMAT_AL1616_REV,
31 MESA_FORMAT_RGB332, MESA_FORMAT_A8, MESA_FORMAT_A16, MESA_FORMAT_L8,
32 MESA_FORMAT_L16, MESA_FORMAT_I8, MESA_FORMAT_I16, MESA_FORMAT_CI8,
33 MESA_FORMAT_YCBCR, MESA_FORMAT_YCBCR_REV, MESA_FORMAT_R8,
34 MESA_FORMAT_RG88, MESA_FORMAT_RG88_REV, MESA_FORMAT_R16,
35 MESA_FORMAT_RG1616, MESA_FORMAT_RG1616_REV, MESA_FORMAT_ARGB2101010,
36 MESA_FORMAT_Z24_S8, MESA_FORMAT_S8_Z24, MESA_FORMAT_Z16,
37 MESA_FORMAT_X8_Z24, MESA_FORMAT_Z24_X8, MESA_FORMAT_Z32,
38 MESA_FORMAT_S8, MESA_FORMAT_SRGB8, MESA_FORMAT_SRGBA8,
39 MESA_FORMAT_SARGB8, MESA_FORMAT_SL8, MESA_FORMAT_SLA8,
40 MESA_FORMAT_SRGB_DXT1, MESA_FORMAT_SRGBA_DXT1,
41 MESA_FORMAT_SRGBA_DXT3, MESA_FORMAT_SRGBA_DXT5,
42 MESA_FORMAT_RGB_FXT1, MESA_FORMAT_RGBA_FXT1, MESA_FORMAT_RGB_DXT1,
43 MESA_FORMAT_RGBA_DXT1, MESA_FORMAT_RGBA_DXT3, MESA_FORMAT_RGBA_DXT5,
44 MESA_FORMAT_RGBA_FLOAT32, MESA_FORMAT_RGBA_FLOAT16,
45 MESA_FORMAT_RGB_FLOAT32, MESA_FORMAT_RGB_FLOAT16,
46 MESA_FORMAT_ALPHA_FLOAT32, MESA_FORMAT_ALPHA_FLOAT16,
47 MESA_FORMAT_LUMINANCE_FLOAT32, MESA_FORMAT_LUMINANCE_FLOAT16,
48 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,
49 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16, MESA_FORMAT_INTENSITY_FLOAT32,
50 MESA_FORMAT_INTENSITY_FLOAT16, MESA_FORMAT_R_FLOAT32,
51 MESA_FORMAT_R_FLOAT16, MESA_FORMAT_RG_FLOAT32,
52 MESA_FORMAT_RG_FLOAT16, MESA_FORMAT_RGBA_INT8,
53 MESA_FORMAT_RGBA_INT16, MESA_FORMAT_RGBA_INT32,
54 MESA_FORMAT_RGBA_UINT8, MESA_FORMAT_RGBA_UINT16,
55 MESA_FORMAT_RGBA_UINT32, MESA_FORMAT_DUDV8, MESA_FORMAT_SIGNED_R8,
56 MESA_FORMAT_SIGNED_RG88_REV, MESA_FORMAT_SIGNED_RGBX8888,
57 MESA_FORMAT_SIGNED_RGBA8888, MESA_FORMAT_SIGNED_RGBA8888_REV,
58 MESA_FORMAT_SIGNED_R16, MESA_FORMAT_SIGNED_GR1616,
59 MESA_FORMAT_SIGNED_RGB_16, MESA_FORMAT_SIGNED_RGBA_16,
60 MESA_FORMAT_RGBA_16, MESA_FORMAT_RED_RGTC1,
61 MESA_FORMAT_SIGNED_RED_RGTC1, MESA_FORMAT_RG_RGTC2,
62 MESA_FORMAT_SIGNED_RG_RGTC2, MESA_FORMAT_L_LATC1,
63 MESA_FORMAT_SIGNED_L_LATC1, MESA_FORMAT_LA_LATC2,
64 MESA_FORMAT_SIGNED_LA_LATC2, MESA_FORMAT_SIGNED_A8,
65 MESA_FORMAT_SIGNED_L8, MESA_FORMAT_SIGNED_AL88,
66 MESA_FORMAT_SIGNED_I8, MESA_FORMAT_SIGNED_A16,
67 MESA_FORMAT_SIGNED_L16, MESA_FORMAT_SIGNED_AL1616,
68 MESA_FORMAT_SIGNED_I16, MESA_FORMAT_RGB9_E5_FLOAT,
69 MESA_FORMAT_R11_G11_B10_FLOAT, MESA_FORMAT_COUNT
70 } gl_format;
71 typedef enum {
72 FRAG_ATTRIB_WPOS = 0, FRAG_ATTRIB_COL0 = 1, FRAG_ATTRIB_COL1 =
73 2, FRAG_ATTRIB_FOGC = 3, FRAG_ATTRIB_TEX0 = 4, FRAG_ATTRIB_TEX1 =
74 5, FRAG_ATTRIB_TEX2 = 6, FRAG_ATTRIB_TEX3 = 7, FRAG_ATTRIB_TEX4 =
75 8, FRAG_ATTRIB_TEX5 = 9, FRAG_ATTRIB_TEX6 = 10, FRAG_ATTRIB_TEX7 =
76 11, FRAG_ATTRIB_FACE = 12, FRAG_ATTRIB_PNTC = 13, FRAG_ATTRIB_VAR0 =
77 14, FRAG_ATTRIB_MAX = (FRAG_ATTRIB_VAR0 + 16)
78 } gl_frag_result;
79 struct gl_config {
80 GLint depthBits;
81 };
82 struct gl_lightmodel {
83 GLenum ColorControl;
84 };
85 struct gl_depthbuffer_attrib {
86 GLenum Func;
87 GLboolean Mask;
88 };
89 struct gl_hint_attrib {
90 GLenum PerspectiveCorrection;
91 };
92 struct gl_light_attrib {
93 struct gl_lightmodel Model;
94 };
95 struct gl_polygon_attrib {
96 GLboolean StippleFlag;
97 };
98 typedef enum {
99 TEXTURE_BUFFER_INDEX, TEXTURE_2D_ARRAY_INDEX, TEXTURE_1D_ARRAY_INDEX,
100 TEXTURE_CUBE_INDEX, TEXTURE_3D_INDEX, TEXTURE_RECT_INDEX,
101 TEXTURE_2D_INDEX, TEXTURE_1D_INDEX, NUM_TEXTURE_TARGETS
102 } gl_texture_index;
103 struct gl_texture_image {
104 GLuint Border;
105 GLuint Width;
106 GLuint Height;
107 GLuint WidthLog2;
108 GLboolean _IsPowerOfTwo;
109 GLuint RowStride;
110 GLvoid *Data;
111 };
112 typedef enum {
113 FACE_POS_X = 0, FACE_NEG_X = 1, FACE_POS_Y = 2, FACE_NEG_Y =
114 3, FACE_POS_Z = 4, FACE_NEG_Z = 5, MAX_FACES = 6
115 } gl_face_index;
116 struct gl_sampler_object {
117 GLenum WrapS;
118 GLenum WrapT;
119 };
120 struct gl_texture_object {
121 struct gl_sampler_object Sampler;
122 GLint BaseLevel;
123 GLuint _Swizzle;
124 struct gl_texture_image *Image[MAX_FACES][15];
125 };
126 struct gl_texture_unit {
127 GLbitfield _ReallyEnabled;
128 GLenum EnvMode;
129 struct gl_texture_object *CurrentTex[NUM_TEXTURE_TARGETS];
130 };
131 struct gl_texture_attrib {
132 struct gl_texture_unit Unit[(16 + 16)];
133 GLbitfield _EnabledUnits;
134 GLbitfield _EnabledCoordUnits;
135 };
136 struct gl_fragment_program_state {
137 struct gl_fragment_program *_Current;
138 };
139 struct gl_ati_fragment_shader_state {
140 GLboolean _Enabled;
141 };
142 struct gl_renderbuffer {
143 void (*PutRowRGB) (struct gl_context * ctx, struct gl_renderbuffer * rb,
144 GLuint count, GLint x, GLint y, const void *values,
145 const GLubyte * mask);
146 };
147 struct gl_framebuffer {
148 struct gl_config Visual;
149 struct gl_renderbuffer *_ColorDrawBuffers[8];
150 };
151 struct gl_context {
152 struct gl_framebuffer *DrawBuffer;
153 struct gl_depthbuffer_attrib Depth;
154 struct gl_hint_attrib Hint;
155 struct gl_light_attrib Light;
156 struct gl_polygon_attrib Polygon;
157 struct gl_texture_attrib Texture;
158 struct gl_fragment_program_state FragmentProgram;
159 struct gl_ati_fragment_shader_state ATIFragmentShader;
160 GLenum RenderMode;
161 };
162 typedef struct {
163 GLfloat attrib[FRAG_ATTRIB_MAX][4];
164 } SWvertex;
165 typedef struct sw_span {
166 GLint x, y;
167 GLuint end;
168 GLfloat attrStepX[FRAG_ATTRIB_MAX][4];
169 GLfixed intTex[2], intTexStep[2];
170 } SWspan;
171 typedef void (*swrast_tri_func) (struct gl_context * ctx, const SWvertex *,
172 const SWvertex *, const SWvertex *);
173 typedef struct {
174 GLbitfield _RasterMask;
175 GLboolean _FogEnabled;
176 swrast_tri_func Triangle;
177 } SWcontext;
178 static __inline__ SWcontext *SWRAST_CONTEXT(struct gl_context *ctx)
179 {
180 }
181
182 static void simple_textured_triangle(struct gl_context *ctx,
183 const SWvertex * v0, const SWvertex * v1,
184 const SWvertex * v2)
185 {
186 typedef struct {
187 GLfloat dx;
188 GLfloat dy;
189 GLfixed fsx;
190 GLfixed fx0;
191 GLint lines;
192 } EdgeT;
193 EdgeT eMaj, eTop, eBot;
194 GLfloat oneOverArea;
195 const SWvertex *vMin, *vMid, *vMax;
196 const GLint snapMask = ~(((1 << 11) / (1 << 4)) - 1);
197 GLfixed vMin_fx, vMin_fy, vMid_fx, vMid_fy, vMax_fx, vMax_fy;
198 SWspan span;
199 {
200 const GLfixed fy0 =
201 (((int)
202 ((((v0->attrib[FRAG_ATTRIB_WPOS][1] -
203 0.5F) * ((float)(1 << 11))) >=
204 0.0F) ? (((v0->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) *
205 ((float)(1 << 11))) +
206 0.5F)
207 : (((v0->attrib[FRAG_ATTRIB_WPOS][1] -
208 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
209 const GLfixed fy1 =
210 (((int)
211 ((((v1->attrib[FRAG_ATTRIB_WPOS][1] -
212 0.5F) * ((float)(1 << 11))) >=
213 0.0F) ? (((v1->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) *
214 ((float)(1 << 11))) +
215 0.5F)
216 : (((v1->attrib[FRAG_ATTRIB_WPOS][1] -
217 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
218 const GLfixed fy2 =
219 (((int)
220 ((((v2->attrib[FRAG_ATTRIB_WPOS][1] -
221 0.5F) * ((float)(1 << 11))) >=
222 0.0F) ? (((v2->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) *
223 ((float)(1 << 11))) +
224 0.5F)
225 : (((v2->attrib[FRAG_ATTRIB_WPOS][1] -
226 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
227 if (fy0 <= fy1) {
228 if (fy1 <= fy2) {
229 vMin = v0;
230 vMax = v1;
231 vMin_fy = fy0;
232 }
233 }
234 vMin_fx =
235 (((int)
236 ((((vMin->attrib[FRAG_ATTRIB_WPOS][0] +
237 0.5F) * ((float)(1 << 11))) >=
238 0.0F) ? (((vMin->attrib[FRAG_ATTRIB_WPOS][0] + 0.5F) *
239 ((float)(1 << 11))) +
240 0.5F)
241 : (((vMin->attrib[FRAG_ATTRIB_WPOS][0] +
242 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
243 vMid_fx =
244 (((int)
245 ((((vMid->attrib[FRAG_ATTRIB_WPOS][0] +
246 0.5F) * ((float)(1 << 11))) >=
247 0.0F) ? (((vMid->attrib[FRAG_ATTRIB_WPOS][0] + 0.5F) *
248 ((float)(1 << 11))) +
249 0.5F)
250 : (((vMid->attrib[FRAG_ATTRIB_WPOS][0] +
251 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask;
252 }
253 eMaj.dx = ((vMax_fx - vMin_fx) * (1.0F / ((float)(1 << 11))));
254 eMaj.dy = ((vMax_fy - vMin_fy) * (1.0F / ((float)(1 << 11))));
255 eTop.dx = ((vMax_fx - vMid_fx) * (1.0F / ((float)(1 << 11))));
256 eBot.dy = ((vMid_fy - vMin_fy) * (1.0F / ((float)(1 << 11))));
257 {
258 const GLfloat area = eMaj.dx * eBot.dy - eBot.dx * eMaj.dy;
259 if (IS_INF_OR_NAN(area) || area == 0.0F)
260 return;
261 oneOverArea = 1.0F / area;
262 if (eBot.lines > 0) {
263 eBot.fx0 = vMin_fx;
264 }
265 GLint scan_from_left_to_right;
266 struct gl_renderbuffer *rb =
267 ctx->DrawBuffer->_ColorDrawBuffers[0];
268 const struct gl_texture_object *obj =
269 ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];
270 const struct gl_texture_image *texImg =
271 obj->Image[0][obj->BaseLevel];
272 const GLfloat twidth = (GLfloat) texImg->Width;
273 const GLint twidth_log2 = texImg->WidthLog2;
274 const GLubyte *texture = (const GLubyte *)texImg->Data;
275 const GLint smask = texImg->Width - 1;
276 const GLint tmask = texImg->Height - 1;
277 if (!rb || !texture) {
278 return;
279 }
280 {
281 GLfloat eMaj_ds =
282 (vMax->attrib[FRAG_ATTRIB_TEX0][0] -
283 vMin->attrib[FRAG_ATTRIB_TEX0][0]) * twidth;
284 GLfloat eBot_ds =
285 (vMid->attrib[FRAG_ATTRIB_TEX0][0] -
286 vMin->attrib[FRAG_ATTRIB_TEX0][0]) * twidth;
287 span.attrStepX[FRAG_ATTRIB_TEX0][0] =
288 oneOverArea * (eMaj_ds * eBot.dy -
289 eMaj.dy * eBot_ds);
290 span.intTexStep[0] =
291 (((int)
292 ((((span.attrStepX[FRAG_ATTRIB_TEX0][0]) *
293 ((float)(1 << 11))) >=
294 0.0F) ? (((span.attrStepX[FRAG_ATTRIB_TEX0][0])
295 * ((float)(1 << 11))) +
296 0.5F)
297 : (((span.attrStepX[FRAG_ATTRIB_TEX0][0]) *
298 ((float)(1 << 11))) - 0.5F))));
299 GLint subTriangle;
300 GLfixed fxLeftEdge = 0, fxRightEdge = 0;
301 GLfixed sLeft = 0, dsOuter = 0, dsInner;
302 for (subTriangle = 0; subTriangle <= 1; subTriangle++) {
303 EdgeT *eLeft, *eRight;
304 int lines;
305 if (subTriangle == 0) {
306 if (scan_from_left_to_right) {
307 eRight = &eBot;
308 lines = eRight->lines;
309 } else {
310 eRight = &eMaj;
311 }
312 } else {
313 if (scan_from_left_to_right) {
314 eRight = &eTop;
315 }
316 fxRightEdge = eRight->fsx - 1;
317 }
318 while (lines > 0) {
319 const GLint right =
320 ((fxRightEdge) >> 11);
321 span.x = ((fxLeftEdge) >> 11);
322 if (right <= span.x)
323 span.end = 0;
324 else
325 span.end = right - span.x;
326 span.intTex[0] = sLeft;
327 if (span.end > 0 && span.y >= 0) {
328 {
329 GLuint i;
330 GLubyte rgb[16384][3];
331 for (i = 0;
332 i < span.end;
333 i++) {
334 GLint s =
335 ((span.
336 intTex[0])
337 >> 11) &
338 smask;
339 GLint t =
340 ((span.
341 intTex[1])
342 >> 11) &
343 tmask;
344 GLint pos =
345 (t <<
346 twidth_log2)
347 + s;
348 rgb[i][0] =
349 texture[pos
350 +
351 2];
352 span.
353 intTex[0] +=
354 span.
355 intTexStep
356 [0];
357 }
358 rb->PutRowRGB(ctx, rb,
359 span.end,
360 span.x,
361 span.y,
362 rgb,
363 ((void *)
364 0));
365 }
366 }
367 }
368 }
369 }
370 }
371 }
372
373 void _swrast_choose_triangle(struct gl_context *ctx)
374 {
375 SWcontext *swrast = SWRAST_CONTEXT(ctx);
376 if (ctx->RenderMode == 0x1C00) {
377 if (ctx->Texture._EnabledCoordUnits
378 || ctx->FragmentProgram._Current
379 || ctx->ATIFragmentShader._Enabled
380 || _mesa_need_secondary_color(ctx) || swrast->_FogEnabled) {
381 const struct gl_texture_object *texObj2D;
382 const struct gl_texture_image *texImg;
383 GLenum minFilter, magFilter, envMode;
384 gl_format format;
385 if (ctx->Texture._EnabledCoordUnits == 0x1
386 && !ctx->FragmentProgram._Current
387 && !ctx->ATIFragmentShader._Enabled
388 && ctx->Texture._EnabledUnits == 0x1
389 && ctx->Texture.Unit[0]._ReallyEnabled ==
390 (1 << TEXTURE_2D_INDEX)
391 && texObj2D->Sampler.WrapS == 0x2901
392 && texObj2D->Sampler.WrapT == 0x2901
393 && texObj2D->_Swizzle ==
394 (((0) << 0) | ((1) << 3) | ((2) << 6) | ((3) << 9))
395 && texImg->_IsPowerOfTwo && texImg->Border == 0
396 && texImg->Width == texImg->RowStride
397 && (format == MESA_FORMAT_RGB888
398 || format == MESA_FORMAT_RGBA8888)
399 && minFilter == magFilter
400 && ctx->Light.Model.ColorControl == 0x81F9
401 && !swrast->_FogEnabled
402 && ctx->Texture.Unit[0].EnvMode != 0x8570
403 && ctx->Texture.Unit[0].EnvMode != 0x8503) {
404 if (ctx->Hint.PerspectiveCorrection == 0x1101) {
405 if (minFilter == 0x2600
406 && format == MESA_FORMAT_RGB888
407 && (envMode == 0x1E01
408 || envMode == 0x2101)
409 &&
410 ((swrast->_RasterMask ==
411 (0x004 | 0x1000)
412 && ctx->Depth.Func == 0x0201
413 && ctx->Depth.Mask == 0x1)
414 || swrast->_RasterMask == 0x1000)
415 && ctx->Polygon.StippleFlag == 0x0
416 && ctx->DrawBuffer->Visual.
417 depthBits <= 16) {
418 if (swrast->_RasterMask ==
419 (0x004 | 0x1000)) {
420 swrast->Triangle =
421 simple_textured_triangle;
422 }
423 }
424 }
425 }
426 }
427 }
428 }