6d60e31a72da7aafcc035977f6f0d952aff20ae2
[mesa.git] / src / mesa / drivers / x11 / xm_tri.c
1 /* $Id: xm_tri.c,v 1.6 2000/10/31 18:09:47 keithw Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
28 /*
29 * This file contains "accelerated" triangle functions. It should be
30 * fairly easy to write new special-purpose triangle functions and hook
31 * them into this module.
32 */
33
34
35 #include "glxheader.h"
36 #include "depth.h"
37 #include "macros.h"
38 #include "vb.h"
39 #include "types.h"
40 #include "xmesaP.h"
41
42 /* Internal swrast includes:
43 */
44 #include "swrast/s_depth.h"
45
46
47
48
49 /**********************************************************************/
50 /*** Triangle rendering ***/
51 /**********************************************************************/
52
53
54 #if 0
55 /*
56 * Render a triangle into a pixmap, any pixel format, flat shaded and
57 * no raster ops.
58 */
59 static void flat_pixmap_triangle( GLcontext *ctx,
60 GLuint v0, GLuint v1, GLuint v2, GLuint pv )
61 {
62 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
63 struct vertex_buffer *VB = ctx->VB;
64 XMesaPoint p[3];
65 XMesaGC gc;
66
67 if (0 /*VB->MonoColor*/) {
68 gc = xmesa->xm_buffer->gc1; /* use current color */
69 }
70 else {
71 unsigned long pixel;
72 if (xmesa->xm_visual->gl_visual->RGBAflag) {
73 pixel = xmesa_color_to_pixel( xmesa,
74 VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1],
75 VB->ColorPtr->data[pv][2], VB->ColorPtr->data[pv][3],
76 xmesa->pixelformat );
77 }
78 else {
79 pixel = VB->IndexPtr->data[pv];
80 }
81 gc = xmesa->xm_buffer->gc2;
82 XMesaSetForeground( xmesa->display, gc, pixel );
83 }
84 p[0].x = (GLint) (VB->Win.data[v0][0] + 0.5f);
85 p[0].y = FLIP( xmesa->xm_buffer, (GLint) (VB->Win.data[v0][1] - 0.5f) );
86 p[1].x = (GLint) (VB->Win.data[v1][0] + 0.5f);
87 p[1].y = FLIP( xmesa->xm_buffer, (GLint) (VB->Win.data[v1][1] - 0.5f) );
88 p[2].x = (GLint) (VB->Win.data[v2][0] + 0.5f);
89 p[2].y = FLIP( xmesa->xm_buffer, (GLint) (VB->Win.data[v2][1] - 0.5f) );
90 XMesaFillPolygon( xmesa->display, xmesa->xm_buffer->buffer, gc,
91 p, 3, Convex, CoordModeOrigin );
92 }
93 #endif
94
95
96 /*
97 * XImage, smooth, depth-buffered, PF_TRUECOLOR triangle.
98 */
99 static void smooth_TRUECOLOR_z_triangle( GLcontext *ctx,
100 GLuint v0, GLuint v1, GLuint v2,
101 GLuint pv )
102 {
103 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
104 XMesaImage *img = xmesa->xm_buffer->backimage;
105 (void) pv;
106 #define INTERP_Z 1
107 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
108 #define INTERP_RGB 1
109 #define INNER_LOOP( LEFT, RIGHT, Y ) \
110 { \
111 GLint i, xx = LEFT, yy = FLIP(xmesa->xm_buffer, Y); \
112 GLint len = RIGHT-LEFT; \
113 (void) fffog; \
114 for (i=0;i<len;i++,xx++) { \
115 GLdepth z = FixedToDepth(ffz); \
116 if (z < zRow[i]) { \
117 unsigned long p; \
118 PACK_TRUECOLOR(p, FixedToInt(ffr), FixedToInt(ffg), FixedToInt(ffb));\
119 XMesaPutPixel( img, xx, yy, p ); \
120 zRow[i] = z; \
121 } \
122 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
123 ffz += fdzdx; \
124 } \
125 }
126 #include "swrast/s_tritemp.h"
127 }
128
129
130
131 /*
132 * XImage, smooth, depth-buffered, PF_8A8B8G8R triangle.
133 */
134 static void smooth_8A8B8G8R_z_triangle( GLcontext *ctx,
135 GLuint v0, GLuint v1, GLuint v2,
136 GLuint pv )
137 {
138 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
139 (void) pv;
140 #define INTERP_Z 1
141 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
142 #define INTERP_RGB 1
143 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
144 #define PIXEL_TYPE GLuint
145 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
146 #define INNER_LOOP( LEFT, RIGHT, Y ) \
147 { \
148 GLint i, len = RIGHT-LEFT; \
149 (void) fffog; \
150 for (i=0;i<len;i++) { \
151 GLdepth z = FixedToDepth(ffz); \
152 if (z < zRow[i]) { \
153 pRow[i] = PACK_8B8G8R( FixedToInt(ffr), FixedToInt(ffg), \
154 FixedToInt(ffb) ); \
155 zRow[i] = z; \
156 } \
157 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
158 ffz += fdzdx; \
159 } \
160 }
161 #include "swrast/s_tritemp.h"
162 }
163
164
165 /*
166 * XImage, smooth, depth-buffered, PF_8R8G8B triangle.
167 */
168 static void smooth_8R8G8B_z_triangle( GLcontext *ctx,
169 GLuint v0, GLuint v1, GLuint v2,
170 GLuint pv )
171 {
172 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
173 (void) pv;
174 #define INTERP_Z 1
175 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
176 #define INTERP_RGB 1
177 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
178 #define PIXEL_TYPE GLuint
179 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
180 #define INNER_LOOP( LEFT, RIGHT, Y ) \
181 { \
182 GLint i, len = RIGHT-LEFT; \
183 (void) fffog; \
184 for (i=0;i<len;i++) { \
185 GLdepth z = FixedToDepth(ffz); \
186 if (z < zRow[i]) { \
187 pRow[i] = PACK_8R8G8B( FixedToInt(ffr), FixedToInt(ffg), \
188 FixedToInt(ffb) ); \
189 zRow[i] = z; \
190 } \
191 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
192 ffz += fdzdx; \
193 } \
194 }
195 #include "swrast/s_tritemp.h"
196 }
197
198
199 /*
200 * XImage, smooth, depth-buffered, PF_8R8G8B24 triangle.
201 */
202 static void smooth_8R8G8B24_z_triangle( GLcontext *ctx,
203 GLuint v0, GLuint v1, GLuint v2,
204 GLuint pv )
205 {
206 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
207 (void) pv;
208 #define INTERP_Z 1
209 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
210 #define INTERP_RGB 1
211 #define PIXEL_ADDRESS(X,Y) PIXELADDR3(xmesa->xm_buffer,X,Y)
212 #define PIXEL_TYPE bgr_t
213 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
214 #define INNER_LOOP( LEFT, RIGHT, Y ) \
215 { \
216 GLint i, len = RIGHT-LEFT; \
217 (void) fffog; \
218 for (i=0;i<len;i++) { \
219 GLdepth z = FixedToDepth(ffz); \
220 if (z < zRow[i]) { \
221 PIXEL_TYPE *ptr = pRow + i; \
222 ptr->r = FixedToInt(ffr); \
223 ptr->g = FixedToInt(ffg); \
224 ptr->b = FixedToInt(ffb); \
225 zRow[i] = z; \
226 } \
227 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
228 ffz += fdzdx; \
229 } \
230 }
231 #include "swrast/s_tritemp.h"
232 }
233
234
235 /*
236 * XImage, smooth, depth-buffered, PF_TRUEDITHER triangle.
237 */
238 static void smooth_TRUEDITHER_z_triangle( GLcontext *ctx,
239 GLuint v0, GLuint v1, GLuint v2,
240 GLuint pv )
241 {
242 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
243 XMesaImage *img = xmesa->xm_buffer->backimage;
244 (void) pv;
245 #define INTERP_Z 1
246 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
247 #define INTERP_RGB 1
248 #define INNER_LOOP( LEFT, RIGHT, Y ) \
249 { \
250 GLint i, xx = LEFT, yy = FLIP(xmesa->xm_buffer,Y), len = RIGHT-LEFT; \
251 (void) fffog; \
252 for (i=0;i<len;i++,xx++) { \
253 GLdepth z = FixedToDepth(ffz); \
254 if (z < zRow[i]) { \
255 unsigned long p; \
256 PACK_TRUEDITHER( p, xx, yy, FixedToInt(ffr), \
257 FixedToInt(ffg), FixedToInt(ffb) ); \
258 XMesaPutPixel( img, xx, yy, p ); \
259 zRow[i] = z; \
260 } \
261 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
262 ffz += fdzdx; \
263 } \
264 }
265 #include "swrast/s_tritemp.h"
266 }
267
268
269 /*
270 * XImage, smooth, depth-buffered, PF_5R6G5B triangle.
271 */
272 static void smooth_5R6G5B_z_triangle( GLcontext *ctx,
273 GLuint v0, GLuint v1, GLuint v2,
274 GLuint pv )
275 {
276 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
277 (void) pv;
278 #define INTERP_Z 1
279 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
280 #define INTERP_RGB 1
281 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
282 #define PIXEL_TYPE GLushort
283 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
284 #define INNER_LOOP( LEFT, RIGHT, Y ) \
285 { \
286 GLint i, len = RIGHT-LEFT; \
287 (void) fffog; \
288 for (i=0;i<len;i++) { \
289 DEPTH_TYPE z = FixedToDepth(ffz); \
290 if (z < zRow[i]) { \
291 pRow[i] = PACK_5R6G5B( FixedToInt(ffr), FixedToInt(ffg), \
292 FixedToInt(ffb) ); \
293 zRow[i] = z; \
294 } \
295 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
296 ffz += fdzdx; \
297 } \
298 }
299 #include "swrast/s_tritemp.h"
300 }
301
302
303 /*
304 * XImage, smooth, depth-buffered, PF_DITHER_5R6G5B triangle.
305 */
306 static void smooth_DITHER_5R6G5B_z_triangle( GLcontext *ctx,
307 GLuint v0, GLuint v1, GLuint v2,
308 GLuint pv )
309 {
310 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
311 (void) pv;
312 #define INTERP_Z 1
313 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
314 #define INTERP_RGB 1
315 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
316 #define PIXEL_TYPE GLushort
317 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
318 #define INNER_LOOP( LEFT, RIGHT, Y ) \
319 { \
320 GLint i, len = RIGHT-LEFT; \
321 (void) fffog; \
322 for (i=0;i<len;i++) { \
323 GLdepth z = FixedToDepth(ffz); \
324 if (z < zRow[i]) { \
325 PACK_TRUEDITHER(pRow[i], LEFT+i, Y, FixedToInt(ffr), \
326 FixedToInt(ffg), FixedToInt(ffb) ); \
327 zRow[i] = z; \
328 } \
329 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
330 ffz += fdzdx; \
331 } \
332 }
333 #include "swrast/s_tritemp.h"
334 }
335
336
337 /*
338 * XImage, smooth, depth-buffered, 8-bit, PF_DITHER8 triangle.
339 */
340 static void smooth_DITHER8_z_triangle( GLcontext *ctx,
341 GLuint v0, GLuint v1, GLuint v2,
342 GLuint pv )
343 {
344 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
345 (void) pv;
346 #define INTERP_Z 1
347 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
348 #define INTERP_RGB 1
349 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
350 #define PIXEL_TYPE GLubyte
351 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
352 #define INNER_LOOP( LEFT, RIGHT, Y ) \
353 { \
354 GLint i, xx = LEFT, yy = FLIP(xmesa->xm_buffer,Y), len = RIGHT-LEFT; \
355 XDITHER_SETUP(yy); \
356 (void) fffog; \
357 for (i=0;i<len;i++,xx++) { \
358 GLdepth z = FixedToDepth(ffz); \
359 if (z < zRow[i]) { \
360 pRow[i] = (PIXEL_TYPE) XDITHER( xx, FixedToInt(ffr), \
361 FixedToInt(ffg), FixedToInt(ffb) ); \
362 zRow[i] = z; \
363 } \
364 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
365 ffz += fdzdx; \
366 } \
367 }
368 #include "swrast/s_tritemp.h"
369 }
370
371
372 /*
373 * XImage, smooth, depth-buffered, PF_DITHER triangle.
374 */
375 static void smooth_DITHER_z_triangle( GLcontext *ctx,
376 GLuint v0, GLuint v1, GLuint v2,
377 GLuint pv )
378 {
379 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
380 XMesaImage *img = xmesa->xm_buffer->backimage;
381 (void) pv;
382 #define INTERP_Z 1
383 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
384 #define INTERP_RGB 1
385 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
386 #define PIXEL_TYPE GLubyte
387 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
388 #define INNER_LOOP( LEFT, RIGHT, Y ) \
389 { \
390 GLint i, xx = LEFT, yy = FLIP(xmesa->xm_buffer,Y), len = RIGHT-LEFT; \
391 XDITHER_SETUP(yy); \
392 (void) fffog; \
393 for (i=0;i<len;i++,xx++) { \
394 GLdepth z = FixedToDepth(ffz); \
395 if (z < zRow[i]) { \
396 unsigned long p = XDITHER( xx, FixedToInt(ffr), \
397 FixedToInt(ffg), FixedToInt(ffb) ); \
398 XMesaPutPixel( img, xx, yy, p ); \
399 zRow[i] = z; \
400 } \
401 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
402 ffz += fdzdx; \
403 } \
404 }
405 #include "swrast/s_tritemp.h"
406 }
407
408
409 /*
410 * XImage, smooth, depth-buffered, 8-bit PF_LOOKUP triangle.
411 */
412 static void smooth_LOOKUP8_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
413 GLuint v2, GLuint pv )
414 {
415 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
416 (void) pv;
417 #define INTERP_Z 1
418 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
419 #define INTERP_RGB 1
420 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
421 #define PIXEL_TYPE GLubyte
422 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
423 #define INNER_LOOP( LEFT, RIGHT, Y ) \
424 { \
425 GLint i, len = RIGHT-LEFT; \
426 LOOKUP_SETUP; \
427 (void) fffog; \
428 for (i=0;i<len;i++) { \
429 GLdepth z = FixedToDepth(ffz); \
430 if (z < zRow[i]) { \
431 pRow[i] = LOOKUP( FixedToInt(ffr), FixedToInt(ffg), \
432 FixedToInt(ffb) ); \
433 zRow[i] = z; \
434 } \
435 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
436 ffz += fdzdx; \
437 } \
438 }
439 #include "swrast/s_tritemp.h"
440 }
441
442
443
444 /*
445 * XImage, smooth, depth-buffered, 8-bit PF_HPCR triangle.
446 */
447 static void smooth_HPCR_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
448 GLuint v2, GLuint pv )
449 {
450 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
451 (void) pv;
452 #define INTERP_Z 1
453 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
454 #define INTERP_RGB 1
455 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
456 #define PIXEL_TYPE GLubyte
457 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
458 #define INNER_LOOP( LEFT, RIGHT, Y ) \
459 { \
460 GLint i, xx = LEFT, yy = FLIP(xmesa->xm_buffer,Y), len = RIGHT-LEFT; \
461 (void) fffog; \
462 for (i=0;i<len;i++,xx++) { \
463 GLdepth z = FixedToDepth(ffz); \
464 if (z < zRow[i]) { \
465 pRow[i] = DITHER_HPCR( xx, yy, FixedToInt(ffr), \
466 FixedToInt(ffg), FixedToInt(ffb) ); \
467 zRow[i] = z; \
468 } \
469 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
470 ffz += fdzdx; \
471 } \
472 }
473 #include "swrast/s_tritemp.h"
474 }
475
476
477 /*
478 * XImage, flat, depth-buffered, PF_TRUECOLOR triangle.
479 */
480 static void flat_TRUECOLOR_z_triangle( GLcontext *ctx,
481 GLuint v0, GLuint v1, GLuint v2,
482 GLuint pv )
483 {
484 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
485 XMesaImage *img = xmesa->xm_buffer->backimage;
486 #define INTERP_Z 1
487 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
488 #define SETUP_CODE \
489 unsigned long pixel; \
490 PACK_TRUECOLOR(pixel, VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2]);
491
492 #define INNER_LOOP( LEFT, RIGHT, Y ) \
493 { \
494 GLint i, xx = LEFT, yy = FLIP(xmesa->xm_buffer,Y), len = RIGHT-LEFT; \
495 (void) fffog; \
496 for (i=0;i<len;i++,xx++) { \
497 GLdepth z = FixedToDepth(ffz); \
498 if (z < zRow[i]) { \
499 XMesaPutPixel( img, xx, yy, pixel ); \
500 zRow[i] = z; \
501 } \
502 ffz += fdzdx; \
503 } \
504 }
505 #include "swrast/s_tritemp.h"
506 }
507
508
509 /*
510 * XImage, flat, depth-buffered, PF_8A8B8G8R triangle.
511 */
512 static void flat_8A8B8G8R_z_triangle( GLcontext *ctx, GLuint v0,
513 GLuint v1, GLuint v2, GLuint pv )
514 {
515 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
516 #define INTERP_Z 1
517 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
518 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
519 #define PIXEL_TYPE GLuint
520 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
521 #define SETUP_CODE \
522 unsigned long p = PACK_8B8G8R( VB->ColorPtr->data[pv][0], \
523 VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
524 #define INNER_LOOP( LEFT, RIGHT, Y ) \
525 { \
526 GLint i, len = RIGHT-LEFT; \
527 (void) fffog; \
528 for (i=0;i<len;i++) { \
529 GLdepth z = FixedToDepth(ffz); \
530 if (z < zRow[i]) { \
531 pRow[i] = (PIXEL_TYPE) p; \
532 zRow[i] = z; \
533 } \
534 ffz += fdzdx; \
535 } \
536 }
537 #include "swrast/s_tritemp.h"
538 }
539
540
541 /*
542 * XImage, flat, depth-buffered, PF_8R8G8B triangle.
543 */
544 static void flat_8R8G8B_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
545 GLuint v2, GLuint pv )
546 {
547 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
548 #define INTERP_Z 1
549 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
550 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
551 #define PIXEL_TYPE GLuint
552 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
553 #define SETUP_CODE \
554 unsigned long p = PACK_8R8G8B( VB->ColorPtr->data[pv][0], \
555 VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
556 #define INNER_LOOP( LEFT, RIGHT, Y ) \
557 { \
558 GLint i, len = RIGHT-LEFT; \
559 (void) fffog; \
560 for (i=0;i<len;i++) { \
561 GLdepth z = FixedToDepth(ffz); \
562 if (z < zRow[i]) { \
563 pRow[i] = (PIXEL_TYPE) p; \
564 zRow[i] = z; \
565 } \
566 ffz += fdzdx; \
567 } \
568 }
569 #include "swrast/s_tritemp.h"
570 }
571
572
573 /*
574 * XImage, flat, depth-buffered, PF_8R8G8B24 triangle.
575 */
576 static void flat_8R8G8B24_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
577 GLuint v2, GLuint pv )
578 {
579 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
580 const GLubyte *color = ctx->VB->ColorPtr->data[pv];
581 #define INTERP_Z 1
582 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
583 #define PIXEL_ADDRESS(X,Y) PIXELADDR3(xmesa->xm_buffer,X,Y)
584 #define PIXEL_TYPE bgr_t
585 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
586 #define INNER_LOOP( LEFT, RIGHT, Y ) \
587 { \
588 GLint i, len = RIGHT-LEFT; \
589 (void) fffog; \
590 for (i=0;i<len;i++) { \
591 GLdepth z = FixedToDepth(ffz); \
592 if (z < zRow[i]) { \
593 PIXEL_TYPE *ptr = pRow+i; \
594 ptr->r = color[RCOMP]; \
595 ptr->g = color[GCOMP]; \
596 ptr->b = color[BCOMP]; \
597 zRow[i] = z; \
598 } \
599 ffz += fdzdx; \
600 } \
601 }
602 #include "swrast/s_tritemp.h"
603 }
604
605
606 /*
607 * XImage, flat, depth-buffered, PF_TRUEDITHER triangle.
608 */
609 static void flat_TRUEDITHER_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
610 GLuint v2, GLuint pv )
611 {
612 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
613 XMesaImage *img = xmesa->xm_buffer->backimage;
614 #define INTERP_Z 1
615 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
616 #define INNER_LOOP( LEFT, RIGHT, Y ) \
617 { \
618 GLint i, xx = LEFT, yy = FLIP(xmesa->xm_buffer,Y), len = RIGHT-LEFT; \
619 (void) fffog; \
620 for (i=0;i<len;i++,xx++) { \
621 GLdepth z = FixedToDepth(ffz); \
622 if (z < zRow[i]) { \
623 unsigned long p; \
624 PACK_TRUEDITHER( p, xx, yy, VB->ColorPtr->data[pv][0], \
625 VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] ); \
626 XMesaPutPixel( img, xx, yy, p ); \
627 zRow[i] = z; \
628 } \
629 ffz += fdzdx; \
630 } \
631 }
632 #include "swrast/s_tritemp.h"
633 }
634
635
636 /*
637 * XImage, flat, depth-buffered, PF_5R6G5B triangle.
638 */
639 static void flat_5R6G5B_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
640 GLuint v2, GLuint pv )
641 {
642 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
643 #define INTERP_Z 1
644 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
645 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
646 #define PIXEL_TYPE GLushort
647 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
648 #define SETUP_CODE \
649 unsigned long p = PACK_5R6G5B( VB->ColorPtr->data[pv][0], \
650 VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
651 #define INNER_LOOP( LEFT, RIGHT, Y ) \
652 { \
653 GLint i, len = RIGHT-LEFT; \
654 (void) fffog; \
655 for (i=0;i<len;i++) { \
656 DEPTH_TYPE z = FixedToDepth(ffz); \
657 if (z < zRow[i]) { \
658 pRow[i] = (PIXEL_TYPE) p; \
659 zRow[i] = z; \
660 } \
661 ffz += fdzdx; \
662 } \
663 }
664 #include "swrast/s_tritemp.h"
665 }
666
667
668 /*
669 * XImage, flat, depth-buffered, PF_DITHER_5R6G5B triangle.
670 */
671 static void flat_DITHER_5R6G5B_z_triangle( GLcontext *ctx, GLuint v0,
672 GLuint v1, GLuint v2, GLuint pv )
673 {
674 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
675 const GLubyte *color = ctx->VB->ColorPtr->data[pv];
676 #define INTERP_Z 1
677 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
678 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
679 #define PIXEL_TYPE GLushort
680 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
681 #define INNER_LOOP( LEFT, RIGHT, Y ) \
682 { \
683 GLint i, len = RIGHT-LEFT; \
684 (void) fffog; \
685 for (i=0;i<len;i++) { \
686 DEPTH_TYPE z = FixedToDepth(ffz); \
687 if (z < zRow[i]) { \
688 PACK_TRUEDITHER(pRow[i], LEFT+i, Y, color[RCOMP], \
689 color[GCOMP], color[BCOMP]); \
690 zRow[i] = z; \
691 } \
692 ffz += fdzdx; \
693 } \
694 }
695 #include "swrast/s_tritemp.h"
696 }
697
698
699 /*
700 * XImage, flat, depth-buffered, 8-bit PF_DITHER triangle.
701 */
702 static void flat_DITHER8_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
703 GLuint v2, GLuint pv )
704 {
705 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
706 #define INTERP_Z 1
707 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
708 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
709 #define PIXEL_TYPE GLubyte
710 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
711 #define SETUP_CODE \
712 FLAT_DITHER_SETUP( VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
713
714 #define INNER_LOOP( LEFT, RIGHT, Y ) \
715 { \
716 GLint i, xx = LEFT, len = RIGHT-LEFT; \
717 FLAT_DITHER_ROW_SETUP(FLIP(xmesa->xm_buffer, Y)); \
718 (void) fffog; \
719 for (i=0;i<len;i++,xx++) { \
720 GLdepth z = FixedToDepth(ffz); \
721 if (z < zRow[i]) { \
722 pRow[i] = (PIXEL_TYPE) FLAT_DITHER(xx); \
723 zRow[i] = z; \
724 } \
725 ffz += fdzdx; \
726 } \
727 }
728 #include "swrast/s_tritemp.h"
729 }
730
731
732 /*
733 * XImage, flat, depth-buffered, PF_DITHER triangle.
734 */
735 static void flat_DITHER_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
736 GLuint v2, GLuint pv )
737 {
738 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
739 XMesaImage *img = xmesa->xm_buffer->backimage;
740 #define INTERP_Z 1
741 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
742 #define SETUP_CODE \
743 FLAT_DITHER_SETUP( VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
744
745 #define INNER_LOOP( LEFT, RIGHT, Y ) \
746 { \
747 GLint i, xx = LEFT, yy = FLIP(xmesa->xm_buffer,Y), len = RIGHT-LEFT; \
748 FLAT_DITHER_ROW_SETUP(yy); \
749 (void) fffog; \
750 for (i=0;i<len;i++,xx++) { \
751 GLdepth z = FixedToDepth(ffz); \
752 if (z < zRow[i]) { \
753 unsigned long p = FLAT_DITHER(xx); \
754 XMesaPutPixel( img, xx, yy, p ); \
755 zRow[i] = z; \
756 } \
757 ffz += fdzdx; \
758 } \
759 }
760 #include "swrast/s_tritemp.h"
761 }
762
763
764 /*
765 * XImage, flat, depth-buffered, 8-bit PF_HPCR triangle.
766 */
767 static void flat_HPCR_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
768 GLuint v2, GLuint pv )
769 {
770 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
771 #define INTERP_Z 1
772 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
773 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
774 #define PIXEL_TYPE GLubyte
775 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
776 #define SETUP_CODE \
777 GLubyte r = VB->ColorPtr->data[pv][0]; \
778 GLubyte g = VB->ColorPtr->data[pv][1]; \
779 GLubyte b = VB->ColorPtr->data[pv][2];
780 #define INNER_LOOP( LEFT, RIGHT, Y ) \
781 { \
782 GLint i, xx = LEFT, yy = FLIP(xmesa->xm_buffer,Y), len = RIGHT-LEFT; \
783 (void) fffog; \
784 for (i=0;i<len;i++,xx++) { \
785 GLdepth z = FixedToDepth(ffz); \
786 if (z < zRow[i]) { \
787 pRow[i] = (PIXEL_TYPE) DITHER_HPCR( xx, yy, r, g, b ); \
788 zRow[i] = z; \
789 } \
790 ffz += fdzdx; \
791 } \
792 }
793 #include "swrast/s_tritemp.h"
794 }
795
796
797 /*
798 * XImage, flat, depth-buffered, 8-bit PF_LOOKUP triangle.
799 */
800 static void flat_LOOKUP8_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
801 GLuint v2, GLuint pv )
802 {
803 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
804 #define INTERP_Z 1
805 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
806 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
807 #define PIXEL_TYPE GLubyte
808 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
809 #define SETUP_CODE \
810 LOOKUP_SETUP; \
811 GLubyte r = VB->ColorPtr->data[pv][0]; \
812 GLubyte g = VB->ColorPtr->data[pv][1]; \
813 GLubyte b = VB->ColorPtr->data[pv][2]; \
814 GLubyte p = LOOKUP(r,g,b);
815 #define INNER_LOOP( LEFT, RIGHT, Y ) \
816 { \
817 GLint i, len = RIGHT-LEFT; \
818 (void) fffog; \
819 for (i=0;i<len;i++) { \
820 GLdepth z = FixedToDepth(ffz); \
821 if (z < zRow[i]) { \
822 pRow[i] = p; \
823 zRow[i] = z; \
824 } \
825 ffz += fdzdx; \
826 } \
827 }
828 #include "swrast/s_tritemp.h"
829 }
830
831
832
833 /*
834 * XImage, smooth, NON-depth-buffered, PF_TRUECOLOR triangle.
835 */
836 static void smooth_TRUECOLOR_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
837 GLuint v2, GLuint pv )
838 {
839 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
840 XMesaImage *img = xmesa->xm_buffer->backimage;
841 (void) pv;
842 #define INTERP_RGB 1
843 #define INNER_LOOP( LEFT, RIGHT, Y ) \
844 { \
845 GLint xx, yy = FLIP(xmesa->xm_buffer, Y); \
846 for (xx=LEFT;xx<RIGHT;xx++) { \
847 unsigned long p; \
848 PACK_TRUECOLOR(p, FixedToInt(ffr), FixedToInt(ffg), FixedToInt(ffb));\
849 XMesaPutPixel( img, xx, yy, p ); \
850 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
851 } \
852 }
853 #include "swrast/s_tritemp.h"
854 }
855
856
857 /*
858 * XImage, smooth, NON-depth-buffered, PF_8A8B8G8R triangle.
859 */
860 static void smooth_8A8B8G8R_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
861 GLuint v2, GLuint pv )
862 {
863 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
864 (void) pv;
865 #define INTERP_RGB 1
866 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
867 #define PIXEL_TYPE GLuint
868 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
869 #define INNER_LOOP( LEFT, RIGHT, Y ) \
870 { \
871 GLint xx; \
872 PIXEL_TYPE *pixel = pRow; \
873 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
874 *pixel = PACK_8B8G8R( FixedToInt(ffr), FixedToInt(ffg), \
875 FixedToInt(ffb) ); \
876 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
877 } \
878 }
879 #include "swrast/s_tritemp.h"
880 }
881
882
883 /*
884 * XImage, smooth, NON-depth-buffered, PF_8R8G8B triangle.
885 */
886 static void smooth_8R8G8B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
887 GLuint v2, GLuint pv )
888 {
889 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
890 (void) pv;
891 #define INTERP_RGB 1
892 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
893 #define PIXEL_TYPE GLuint
894 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
895 #define INNER_LOOP( LEFT, RIGHT, Y ) \
896 { \
897 GLint xx; \
898 PIXEL_TYPE *pixel = pRow; \
899 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
900 *pixel = PACK_8R8G8B( FixedToInt(ffr), FixedToInt(ffg), \
901 FixedToInt(ffb) ); \
902 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
903 } \
904 }
905 #include "swrast/s_tritemp.h"
906 }
907
908
909 /*
910 * XImage, smooth, NON-depth-buffered, PF_8R8G8B triangle.
911 */
912 static void smooth_8R8G8B24_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
913 GLuint v2, GLuint pv )
914 {
915 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
916 (void) pv;
917 #define INTERP_RGB 1
918 #define PIXEL_ADDRESS(X,Y) PIXELADDR3(xmesa->xm_buffer,X,Y)
919 #define PIXEL_TYPE bgr_t
920 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
921 #define INNER_LOOP( LEFT, RIGHT, Y ) \
922 { \
923 GLint xx; \
924 PIXEL_TYPE *pixel = pRow; \
925 for (xx=LEFT;xx<RIGHT;xx++) { \
926 pixel->r = FixedToInt(ffr); \
927 pixel->g = FixedToInt(ffg); \
928 pixel->b = FixedToInt(ffb); \
929 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
930 pixel++; \
931 } \
932 }
933 #include "swrast/s_tritemp.h"
934 }
935
936
937 /*
938 * XImage, smooth, NON-depth-buffered, PF_TRUEDITHER triangle.
939 */
940 static void smooth_TRUEDITHER_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
941 GLuint v2, GLuint pv )
942 {
943 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
944 XMesaImage *img = xmesa->xm_buffer->backimage;
945 (void) pv;
946 #define INTERP_RGB 1
947 #define INNER_LOOP( LEFT, RIGHT, Y ) \
948 { \
949 GLint xx, yy = FLIP(xmesa->xm_buffer, Y); \
950 for (xx=LEFT;xx<RIGHT;xx++) { \
951 unsigned long p; \
952 PACK_TRUEDITHER( p, xx, yy, FixedToInt(ffr), FixedToInt(ffg), \
953 FixedToInt(ffb) ); \
954 XMesaPutPixel( img, xx, yy, p ); \
955 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
956 } \
957 }
958 #include "swrast/s_tritemp.h"
959 }
960
961
962 /*
963 * XImage, smooth, NON-depth-buffered, PF_5R6G5B triangle.
964 */
965 static void smooth_5R6G5B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
966 GLuint v2, GLuint pv )
967 {
968 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
969 (void) pv;
970 #define INTERP_RGB 1
971 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
972 #define PIXEL_TYPE GLushort
973 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
974 #define INNER_LOOP( LEFT, RIGHT, Y ) \
975 { \
976 GLint xx; \
977 PIXEL_TYPE *pixel = pRow; \
978 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
979 *pixel = (PIXEL_TYPE) PACK_5R6G5B( FixedToInt(ffr), \
980 FixedToInt(ffg), FixedToInt(ffb) ); \
981 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
982 } \
983 }
984 #include "swrast/s_tritemp.h"
985 }
986
987
988 /*
989 * XImage, smooth, NON-depth-buffered, PF_DITHER_5R6G5B triangle.
990 */
991 static void smooth_DITHER_5R6G5B_triangle( GLcontext *ctx, GLuint v0,
992 GLuint v1, GLuint v2, GLuint pv )
993 {
994 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
995 (void) pv;
996 #define INTERP_RGB 1
997 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
998 #define PIXEL_TYPE GLushort
999 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1000 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1001 { \
1002 GLint xx; \
1003 PIXEL_TYPE *pixel = pRow; \
1004 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1005 PACK_TRUEDITHER(*pixel, xx, Y, FixedToInt(ffr), \
1006 FixedToInt(ffg), FixedToInt(ffb) ); \
1007 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
1008 } \
1009 }
1010 #include "swrast/s_tritemp.h"
1011 }
1012
1013
1014 /*
1015 * XImage, smooth, NON-depth-buffered, 8-bit PF_DITHER triangle.
1016 */
1017 static void smooth_DITHER8_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1018 GLuint v2, GLuint pv )
1019 {
1020 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1021 (void) pv;
1022 #define INTERP_RGB 1
1023 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
1024 #define PIXEL_TYPE GLubyte
1025 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1026 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1027 { \
1028 GLint xx, yy = FLIP(xmesa->xm_buffer, Y); \
1029 PIXEL_TYPE *pixel = pRow; \
1030 XDITHER_SETUP(yy); \
1031 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1032 *pixel = (PIXEL_TYPE) XDITHER( xx, FixedToInt(ffr), \
1033 FixedToInt(ffg), FixedToInt(ffb) ); \
1034 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
1035 } \
1036 }
1037 #include "swrast/s_tritemp.h"
1038 }
1039
1040
1041 /*
1042 * XImage, smooth, NON-depth-buffered, PF_DITHER triangle.
1043 */
1044 static void smooth_DITHER_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1045 GLuint v2, GLuint pv )
1046 {
1047 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1048 XMesaImage *img = xmesa->xm_buffer->backimage;
1049 (void) pv;
1050 #define INTERP_RGB 1
1051 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1052 { \
1053 GLint xx, yy = FLIP(xmesa->xm_buffer, Y); \
1054 XDITHER_SETUP(yy); \
1055 for (xx=LEFT;xx<RIGHT;xx++) { \
1056 unsigned long p = XDITHER( xx, FixedToInt(ffr), \
1057 FixedToInt(ffg), FixedToInt(ffb) ); \
1058 XMesaPutPixel( img, xx, yy, p ); \
1059 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
1060 } \
1061 }
1062 #include "swrast/s_tritemp.h"
1063 }
1064
1065
1066 /*
1067 * XImage, smooth, NON-depth-buffered, 8-bit PF_LOOKUP triangle.
1068 */
1069 static void smooth_LOOKUP8_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1070 GLuint v2, GLuint pv )
1071 {
1072 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1073 (void) pv;
1074 #define INTERP_RGB 1
1075 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
1076 #define PIXEL_TYPE GLubyte
1077 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1078 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1079 { \
1080 GLint xx; \
1081 PIXEL_TYPE *pixel = pRow; \
1082 LOOKUP_SETUP; \
1083 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1084 *pixel = LOOKUP( FixedToInt(ffr), FixedToInt(ffg), \
1085 FixedToInt(ffb) ); \
1086 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
1087 } \
1088 }
1089 #include "swrast/s_tritemp.h"
1090 }
1091
1092
1093
1094 /*
1095 * XImage, smooth, NON-depth-buffered, 8-bit PF_HPCR triangle.
1096 */
1097 static void smooth_HPCR_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1098 GLuint v2, GLuint pv )
1099 {
1100 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1101 (void) pv;
1102 #define INTERP_RGB 1
1103 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
1104 #define PIXEL_TYPE GLubyte
1105 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1106 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1107 { \
1108 GLint xx, yy = FLIP(xmesa->xm_buffer, Y); \
1109 PIXEL_TYPE *pixel = pRow; \
1110 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1111 *pixel = DITHER_HPCR( xx, yy, FixedToInt(ffr), \
1112 FixedToInt(ffg), FixedToInt(ffb) ); \
1113 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
1114 } \
1115 }
1116 #include "swrast/s_tritemp.h"
1117 }
1118
1119
1120 /*
1121 * XImage, flat, NON-depth-buffered, PF_TRUECOLOR triangle.
1122 */
1123 static void flat_TRUECOLOR_triangle( GLcontext *ctx, GLuint v0,
1124 GLuint v1, GLuint v2, GLuint pv )
1125 {
1126 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1127 XMesaImage *img = xmesa->xm_buffer->backimage;
1128 #define SETUP_CODE \
1129 unsigned long pixel; \
1130 PACK_TRUECOLOR(pixel, VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2]);
1131
1132 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1133 { \
1134 GLint xx, yy = FLIP(xmesa->xm_buffer, Y); \
1135 for (xx=LEFT;xx<RIGHT;xx++) { \
1136 XMesaPutPixel( img, xx, yy, pixel ); \
1137 } \
1138 }
1139 #include "swrast/s_tritemp.h"
1140 }
1141
1142
1143 /*
1144 * XImage, flat, NON-depth-buffered, PF_8A8B8G8R triangle.
1145 */
1146 static void flat_8A8B8G8R_triangle( GLcontext *ctx, GLuint v0,
1147 GLuint v1, GLuint v2, GLuint pv )
1148 {
1149 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1150 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
1151 #define PIXEL_TYPE GLuint
1152 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1153 #define SETUP_CODE \
1154 unsigned long p = PACK_8B8G8R( VB->ColorPtr->data[pv][0], \
1155 VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
1156 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1157 { \
1158 GLint xx; \
1159 PIXEL_TYPE *pixel = pRow; \
1160 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1161 *pixel = (PIXEL_TYPE) p; \
1162 } \
1163 }
1164 #include "swrast/s_tritemp.h"
1165 }
1166
1167
1168 /*
1169 * XImage, flat, NON-depth-buffered, PF_8R8G8B triangle.
1170 */
1171 static void flat_8R8G8B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1172 GLuint v2, GLuint pv )
1173 {
1174 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1175 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
1176 #define PIXEL_TYPE GLuint
1177 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1178 #define SETUP_CODE \
1179 unsigned long p = PACK_8R8G8B( VB->ColorPtr->data[pv][0], \
1180 VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
1181 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1182 { \
1183 GLint xx; \
1184 PIXEL_TYPE *pixel = pRow; \
1185 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1186 *pixel = (PIXEL_TYPE) p; \
1187 } \
1188 }
1189 #include "swrast/s_tritemp.h"
1190 }
1191
1192
1193 /*
1194 * XImage, flat, NON-depth-buffered, PF_8R8G8B24 triangle.
1195 */
1196 static void flat_8R8G8B24_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1197 GLuint v2, GLuint pv )
1198 {
1199 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1200 const GLubyte *color = ctx->VB->ColorPtr->data[pv];
1201 #define PIXEL_ADDRESS(X,Y) PIXELADDR3(xmesa->xm_buffer,X,Y)
1202 #define PIXEL_TYPE bgr_t
1203 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1204 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1205 { \
1206 GLint xx; \
1207 PIXEL_TYPE *pixel = pRow; \
1208 for (xx=LEFT;xx<RIGHT;xx++) { \
1209 pixel->r = color[RCOMP]; \
1210 pixel->g = color[GCOMP]; \
1211 pixel->b = color[BCOMP]; \
1212 pixel++; \
1213 } \
1214 }
1215 #include "swrast/s_tritemp.h"
1216 }
1217
1218 /*
1219 * XImage, flat, NON-depth-buffered, PF_TRUEDITHER triangle.
1220 */
1221 static void flat_TRUEDITHER_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1222 GLuint v2, GLuint pv )
1223 {
1224 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1225 XMesaImage *img = xmesa->xm_buffer->backimage;
1226 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1227 { \
1228 GLint xx, yy = FLIP(xmesa->xm_buffer, Y); \
1229 for (xx=LEFT;xx<RIGHT;xx++) { \
1230 unsigned long p; \
1231 PACK_TRUEDITHER( p, xx, yy, VB->ColorPtr->data[pv][0], \
1232 VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] ); \
1233 XMesaPutPixel( img, xx, yy, p ); \
1234 } \
1235 }
1236 #include "swrast/s_tritemp.h"
1237 }
1238
1239
1240
1241 /*
1242 * XImage, flat, NON-depth-buffered, PF_5R6G5B triangle.
1243 */
1244 static void flat_5R6G5B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1245 GLuint v2, GLuint pv )
1246 {
1247 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1248 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
1249 #define PIXEL_TYPE GLushort
1250 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1251 #define SETUP_CODE \
1252 unsigned long p = PACK_5R6G5B( VB->ColorPtr->data[pv][0], \
1253 VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
1254 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1255 { \
1256 GLint xx; \
1257 PIXEL_TYPE *pixel = pRow; \
1258 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1259 *pixel = (PIXEL_TYPE) p; \
1260 } \
1261 }
1262 #include "swrast/s_tritemp.h"
1263 }
1264
1265
1266 /*
1267 * XImage, flat, NON-depth-buffered, PF_DITHER_5R6G5B triangle.
1268 */
1269 static void flat_DITHER_5R6G5B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1270 GLuint v2, GLuint pv )
1271 {
1272 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1273 const GLubyte *color = ctx->VB->ColorPtr->data[pv];
1274 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
1275 #define PIXEL_TYPE GLushort
1276 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1277 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1278 { \
1279 GLint xx; \
1280 PIXEL_TYPE *pixel = pRow; \
1281 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1282 PACK_TRUEDITHER(*pixel, xx, Y, color[RCOMP], \
1283 color[GCOMP], color[BCOMP]); \
1284 } \
1285 }
1286 #include "swrast/s_tritemp.h"
1287 }
1288
1289
1290 /*
1291 * XImage, flat, NON-depth-buffered, 8-bit PF_DITHER triangle.
1292 */
1293 static void flat_DITHER8_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1294 GLuint v2, GLuint pv )
1295 {
1296 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1297 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
1298 #define PIXEL_TYPE GLubyte
1299 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1300 #define SETUP_CODE \
1301 FLAT_DITHER_SETUP( VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
1302
1303 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1304 { \
1305 GLint xx; \
1306 PIXEL_TYPE *pixel = pRow; \
1307 FLAT_DITHER_ROW_SETUP(FLIP(xmesa->xm_buffer, Y)); \
1308 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1309 *pixel = (PIXEL_TYPE) FLAT_DITHER(xx); \
1310 } \
1311 }
1312 #include "swrast/s_tritemp.h"
1313 }
1314
1315
1316 /*
1317 * XImage, flat, NON-depth-buffered, PF_DITHER triangle.
1318 */
1319 static void flat_DITHER_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1320 GLuint v2, GLuint pv )
1321 {
1322 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1323 XMesaImage *img = xmesa->xm_buffer->backimage;
1324 #define SETUP_CODE \
1325 FLAT_DITHER_SETUP( VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
1326
1327 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1328 { \
1329 GLint xx, yy = FLIP(xmesa->xm_buffer, Y); \
1330 FLAT_DITHER_ROW_SETUP(yy); \
1331 for (xx=LEFT;xx<RIGHT;xx++) { \
1332 unsigned long p = FLAT_DITHER(xx); \
1333 XMesaPutPixel( img, xx, yy, p ); \
1334 } \
1335 }
1336 #include "swrast/s_tritemp.h"
1337 }
1338
1339
1340 /*
1341 * XImage, flat, NON-depth-buffered, 8-bit PF_HPCR triangle.
1342 */
1343 static void flat_HPCR_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1344 GLuint v2, GLuint pv )
1345 {
1346 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1347 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
1348 #define PIXEL_TYPE GLubyte
1349 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1350 #define SETUP_CODE \
1351 GLubyte r = VB->ColorPtr->data[pv][0]; \
1352 GLubyte g = VB->ColorPtr->data[pv][1]; \
1353 GLubyte b = VB->ColorPtr->data[pv][2];
1354 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1355 { \
1356 GLint xx, yy = FLIP(xmesa->xm_buffer, Y); \
1357 PIXEL_TYPE *pixel = pRow; \
1358 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1359 *pixel = (PIXEL_TYPE) DITHER_HPCR( xx, yy, r, g, b ); \
1360 } \
1361 }
1362 #include "swrast/s_tritemp.h"
1363 }
1364
1365
1366 /*
1367 * XImage, flat, NON-depth-buffered, 8-bit PF_LOOKUP triangle.
1368 */
1369 static void flat_LOOKUP8_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1370 GLuint v2, GLuint pv )
1371 {
1372 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1373 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
1374 #define PIXEL_TYPE GLubyte
1375 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1376 #define SETUP_CODE \
1377 LOOKUP_SETUP; \
1378 GLubyte r = VB->ColorPtr->data[pv][0]; \
1379 GLubyte g = VB->ColorPtr->data[pv][1]; \
1380 GLubyte b = VB->ColorPtr->data[pv][2]; \
1381 GLubyte p = LOOKUP(r,g,b);
1382 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1383 { \
1384 GLint xx; \
1385 PIXEL_TYPE *pixel = pRow; \
1386 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1387 *pixel = p; \
1388 } \
1389 }
1390 #include "swrast/s_tritemp.h"
1391 }
1392
1393
1394
1395 #if 0
1396 /*
1397 * This function is called if we're about to render triangles into an
1398 * X window/pixmap. It sets the polygon stipple pattern if enabled.
1399 */
1400 static void setup_x_polygon_options( GLcontext *ctx )
1401 {
1402 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1403 int fill_type;
1404
1405 if (ctx->Polygon.StippleFlag) {
1406 if (xmesa->xm_buffer->stipple_pixmap == 0) {
1407 /* Allocate polygon stippling stuff once for this context. */
1408 XMesaBuffer b = xmesa->xm_buffer;
1409 b->stipple_pixmap = XMesaCreatePixmap( xmesa->display,
1410 b->buffer, 32, 32, 1 );
1411 #ifdef XFree86Server
1412 b->stipple_gc = CreateScratchGC(xmesa->display, 1);
1413 #else
1414 b->stipple_gc = XCreateGC(xmesa->display, b->stipple_pixmap, 0, NULL);
1415 #endif
1416 XMesaSetFunction(xmesa->display, b->stipple_gc, GXcopy);
1417 XMesaSetForeground(xmesa->display, b->stipple_gc, 1);
1418 XMesaSetBackground(xmesa->display, b->stipple_gc, 0);
1419 }
1420
1421 /*
1422 * NOTE: We don't handle the following here!
1423 * GL_UNPACK_SWAP_BYTES
1424 * GL_UNPACK_LSB_FIRST
1425 */
1426 /* Copy Mesa stipple pattern to an XImage then to Pixmap */
1427 {
1428 XMesaImage *stipple_ximage;
1429 GLuint stipple[32];
1430 int i;
1431 int shift = xmesa->xm_buffer->height % 32;
1432 for (i=0;i<32;i++) {
1433 stipple[31-i] = ctx->PolygonStipple[(i+shift) % 32];
1434 }
1435 #ifdef XFree86Server
1436 stipple_ximage = XMesaCreateImage(1, 32, 32, (char *)stipple);
1437 #else
1438 stipple_ximage = XCreateImage( xmesa->display,
1439 xmesa->xm_visual->visinfo->visual,
1440 1, ZPixmap, 0,
1441 (char *)stipple,
1442 32, 32, 8, 0 );
1443 stipple_ximage->byte_order = LSBFirst;
1444 stipple_ximage->bitmap_bit_order = LSBFirst;
1445 stipple_ximage->bitmap_unit = 32;
1446 #endif
1447 XMesaPutImage( xmesa->display,
1448 (XMesaDrawable)xmesa->xm_buffer->stipple_pixmap,
1449 xmesa->xm_buffer->stipple_gc,
1450 stipple_ximage, 0, 0, 0, 0, 32, 32 );
1451 stipple_ximage->data = NULL;
1452 XMesaDestroyImage( stipple_ximage );
1453 }
1454
1455 XMesaSetStipple( xmesa->display, xmesa->xm_buffer->gc1,
1456 xmesa->xm_buffer->stipple_pixmap );
1457 XMesaSetStipple( xmesa->display, xmesa->xm_buffer->gc2,
1458 xmesa->xm_buffer->stipple_pixmap );
1459 fill_type = FillStippled;
1460 }
1461 else {
1462 fill_type = FillSolid;
1463 }
1464
1465 XMesaSetFillStyle( xmesa->display, xmesa->xm_buffer->gc1, fill_type );
1466 XMesaSetFillStyle( xmesa->display, xmesa->xm_buffer->gc2, fill_type );
1467 }
1468 #endif
1469
1470
1471 #ifdef DEBUG
1472 void
1473 _xmesa_print_triangle_func( triangle_func triFunc )
1474 {
1475 printf("XMesa tri func = ");
1476 if (triFunc ==smooth_TRUECOLOR_z_triangle)
1477 printf("smooth_TRUECOLOR_z_triangle\n");
1478 else if (triFunc ==smooth_8A8B8G8R_z_triangle)
1479 printf("smooth_8A8B8G8R_z_triangle\n");
1480 else if (triFunc ==smooth_8R8G8B_z_triangle)
1481 printf("smooth_8R8G8B_z_triangle\n");
1482 else if (triFunc ==smooth_8R8G8B24_z_triangle)
1483 printf("smooth_8R8G8B24_z_triangle\n");
1484 else if (triFunc ==smooth_TRUEDITHER_z_triangle)
1485 printf("smooth_TRUEDITHER_z_triangle\n");
1486 else if (triFunc ==smooth_5R6G5B_z_triangle)
1487 printf("smooth_5R6G5B_z_triangle\n");
1488 else if (triFunc ==smooth_DITHER_5R6G5B_z_triangle)
1489 printf("smooth_DITHER_5R6G5B_z_triangle\n");
1490 else if (triFunc ==smooth_HPCR_z_triangle)
1491 printf("smooth_HPCR_z_triangle\n");
1492 else if (triFunc ==smooth_DITHER8_z_triangle)
1493 printf("smooth_DITHER8_z_triangle\n");
1494 else if (triFunc ==smooth_LOOKUP8_z_triangle)
1495 printf("smooth_LOOKUP8_z_triangle\n");
1496 else if (triFunc ==flat_TRUECOLOR_z_triangle)
1497 printf("flat_TRUECOLOR_z_triangle\n");
1498 else if (triFunc ==flat_8A8B8G8R_z_triangle)
1499 printf("flat_8A8B8G8R_z_triangle\n");
1500 else if (triFunc ==flat_8R8G8B_z_triangle)
1501 printf("flat_8R8G8B_z_triangle\n");
1502 else if (triFunc ==flat_8R8G8B24_z_triangle)
1503 printf("flat_8R8G8B24_z_triangle\n");
1504 else if (triFunc ==flat_TRUEDITHER_z_triangle)
1505 printf("flat_TRUEDITHER_z_triangle\n");
1506 else if (triFunc ==flat_5R6G5B_z_triangle)
1507 printf("flat_5R6G5B_z_triangle\n");
1508 else if (triFunc ==flat_DITHER_5R6G5B_z_triangle)
1509 printf("flat_DITHER_5R6G5B_z_triangle\n");
1510 else if (triFunc ==flat_HPCR_z_triangle)
1511 printf("flat_HPCR_z_triangle\n");
1512 else if (triFunc ==flat_DITHER8_z_triangle)
1513 printf("flat_DITHER8_z_triangle\n");
1514 else if (triFunc ==flat_LOOKUP8_z_triangle)
1515 printf("flat_LOOKUP8_z_triangle\n");
1516 else if (triFunc ==smooth_TRUECOLOR_triangle)
1517 printf("smooth_TRUECOLOR_triangle\n");
1518 else if (triFunc ==smooth_8A8B8G8R_triangle)
1519 printf("smooth_8A8B8G8R_triangle\n");
1520 else if (triFunc ==smooth_8R8G8B_triangle)
1521 printf("smooth_8R8G8B_triangle\n");
1522 else if (triFunc ==smooth_8R8G8B24_triangle)
1523 printf("smooth_8R8G8B24_triangle\n");
1524 else if (triFunc ==smooth_TRUEDITHER_triangle)
1525 printf("smooth_TRUEDITHER_triangle\n");
1526 else if (triFunc ==smooth_5R6G5B_triangle)
1527 printf("smooth_5R6G5B_triangle\n");
1528 else if (triFunc ==smooth_DITHER_5R6G5B_triangle)
1529 printf("smooth_DITHER_5R6G5B_triangle\n");
1530 else if (triFunc ==smooth_HPCR_triangle)
1531 printf("smooth_HPCR_triangle\n");
1532 else if (triFunc ==smooth_DITHER8_triangle)
1533 printf("smooth_DITHER8_triangle\n");
1534 else if (triFunc ==smooth_LOOKUP8_triangle)
1535 printf("smooth_LOOKUP8_triangle\n");
1536 else if (triFunc ==flat_TRUECOLOR_triangle)
1537 printf("flat_TRUECOLOR_triangle\n");
1538 else if (triFunc ==flat_TRUEDITHER_triangle)
1539 printf("flat_TRUEDITHER_triangle\n");
1540 else if (triFunc ==flat_8A8B8G8R_triangle)
1541 printf("flat_8A8B8G8R_triangle\n");
1542 else if (triFunc ==flat_8R8G8B_triangle)
1543 printf("flat_8R8G8B_triangle\n");
1544 else if (triFunc ==flat_8R8G8B24_triangle)
1545 printf("flat_8R8G8B24_triangle\n");
1546 else if (triFunc ==flat_5R6G5B_triangle)
1547 printf("flat_5R6G5B_triangle\n");
1548 else if (triFunc ==flat_DITHER_5R6G5B_triangle)
1549 printf("flat_DITHER_5R6G5B_triangle\n");
1550 else if (triFunc ==flat_HPCR_triangle)
1551 printf("flat_HPCR_triangle\n");
1552 else if (triFunc ==flat_DITHER8_triangle)
1553 printf("flat_DITHER8_triangle\n");
1554 else if (triFunc ==flat_LOOKUP8_triangle)
1555 printf("flat_LOOKUP8_triangle\n");
1556 else
1557 printf("???\n");
1558 }
1559 #endif
1560
1561
1562 triangle_func xmesa_get_triangle_func( GLcontext *ctx )
1563 {
1564 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1565 int depth = GET_VISUAL_DEPTH(xmesa->xm_visual);
1566
1567 (void) kernel1;
1568
1569 if (ctx->Polygon.SmoothFlag) return (triangle_func)NULL;
1570 if (ctx->Texture.ReallyEnabled) return (triangle_func)NULL;
1571
1572 if (xmesa->xm_buffer->buffer==XIMAGE) {
1573 if ( ctx->Light.ShadeModel==GL_SMOOTH
1574 && ctx->RasterMask==DEPTH_BIT
1575 && ctx->Depth.Func==GL_LESS
1576 && ctx->Depth.Mask==GL_TRUE
1577 && ctx->Visual.DepthBits == DEFAULT_SOFTWARE_DEPTH_BITS
1578 && ctx->Polygon.StippleFlag==GL_FALSE) {
1579 switch (xmesa->pixelformat) {
1580 case PF_TRUECOLOR:
1581 return smooth_TRUECOLOR_z_triangle;
1582 case PF_8A8B8G8R:
1583 return smooth_8A8B8G8R_z_triangle;
1584 case PF_8R8G8B:
1585 return smooth_8R8G8B_z_triangle;
1586 case PF_8R8G8B24:
1587 return smooth_8R8G8B24_z_triangle;
1588 case PF_TRUEDITHER:
1589 return smooth_TRUEDITHER_z_triangle;
1590 case PF_5R6G5B:
1591 return smooth_5R6G5B_z_triangle;
1592 case PF_DITHER_5R6G5B:
1593 return smooth_DITHER_5R6G5B_z_triangle;
1594 case PF_HPCR:
1595 return smooth_HPCR_z_triangle;
1596 case PF_DITHER:
1597 return (depth==8) ? smooth_DITHER8_z_triangle
1598 : smooth_DITHER_z_triangle;
1599 case PF_LOOKUP:
1600 return (depth==8) ? smooth_LOOKUP8_z_triangle : (triangle_func)NULL;
1601 default:
1602 return (triangle_func)NULL;
1603 }
1604 }
1605 if ( ctx->Light.ShadeModel==GL_FLAT
1606 && ctx->RasterMask==DEPTH_BIT
1607 && ctx->Depth.Func==GL_LESS
1608 && ctx->Depth.Mask==GL_TRUE
1609 && ctx->Visual.DepthBits == DEFAULT_SOFTWARE_DEPTH_BITS
1610 && ctx->Polygon.StippleFlag==GL_FALSE) {
1611 switch (xmesa->pixelformat) {
1612 case PF_TRUECOLOR:
1613 return flat_TRUECOLOR_z_triangle;
1614 case PF_8A8B8G8R:
1615 return flat_8A8B8G8R_z_triangle;
1616 case PF_8R8G8B:
1617 return flat_8R8G8B_z_triangle;
1618 case PF_8R8G8B24:
1619 return flat_8R8G8B24_z_triangle;
1620 case PF_TRUEDITHER:
1621 return flat_TRUEDITHER_z_triangle;
1622 case PF_5R6G5B:
1623 return flat_5R6G5B_z_triangle;
1624 case PF_DITHER_5R6G5B:
1625 return flat_DITHER_5R6G5B_z_triangle;
1626 case PF_HPCR:
1627 return flat_HPCR_z_triangle;
1628 case PF_DITHER:
1629 return (depth==8) ? flat_DITHER8_z_triangle
1630 : flat_DITHER_z_triangle;
1631 case PF_LOOKUP:
1632 return (depth==8) ? flat_LOOKUP8_z_triangle : (triangle_func)NULL;
1633 default:
1634 return (triangle_func)NULL;
1635 }
1636 }
1637 if ( ctx->RasterMask==0 /* no depth test */
1638 && ctx->Light.ShadeModel==GL_SMOOTH
1639 && ctx->Polygon.StippleFlag==GL_FALSE) {
1640 switch (xmesa->pixelformat) {
1641 case PF_TRUECOLOR:
1642 return smooth_TRUECOLOR_triangle;
1643 case PF_8A8B8G8R:
1644 return smooth_8A8B8G8R_triangle;
1645 case PF_8R8G8B:
1646 return smooth_8R8G8B_triangle;
1647 case PF_8R8G8B24:
1648 return smooth_8R8G8B24_triangle;
1649 case PF_TRUEDITHER:
1650 return smooth_TRUEDITHER_triangle;
1651 case PF_5R6G5B:
1652 return smooth_5R6G5B_triangle;
1653 case PF_DITHER_5R6G5B:
1654 return smooth_DITHER_5R6G5B_triangle;
1655 case PF_HPCR:
1656 return smooth_HPCR_triangle;
1657 case PF_DITHER:
1658 return (depth==8) ? smooth_DITHER8_triangle
1659 : smooth_DITHER_triangle;
1660 case PF_LOOKUP:
1661 return (depth==8) ? smooth_LOOKUP8_triangle : (triangle_func)NULL;
1662 default:
1663 return (triangle_func)NULL;
1664 }
1665 }
1666
1667 if ( ctx->RasterMask==0 /* no depth test */
1668 && ctx->Light.ShadeModel==GL_FLAT
1669 && ctx->Polygon.StippleFlag==GL_FALSE) {
1670 switch (xmesa->pixelformat) {
1671 case PF_TRUECOLOR:
1672 return flat_TRUECOLOR_triangle;
1673 case PF_TRUEDITHER:
1674 return flat_TRUEDITHER_triangle;
1675 case PF_8A8B8G8R:
1676 return flat_8A8B8G8R_triangle;
1677 case PF_8R8G8B:
1678 return flat_8R8G8B_triangle;
1679 case PF_8R8G8B24:
1680 return flat_8R8G8B24_triangle;
1681 case PF_5R6G5B:
1682 return flat_5R6G5B_triangle;
1683 case PF_DITHER_5R6G5B:
1684 return flat_DITHER_5R6G5B_triangle;
1685 case PF_HPCR:
1686 return flat_HPCR_triangle;
1687 case PF_DITHER:
1688 return (depth==8) ? flat_DITHER8_triangle
1689 : flat_DITHER_triangle;
1690 case PF_LOOKUP:
1691 return (depth==8) ? flat_LOOKUP8_triangle : (triangle_func)NULL;
1692 default:
1693 return (triangle_func)NULL;
1694 }
1695 }
1696
1697 return (triangle_func)NULL;
1698 }
1699 else {
1700 /* draw to pixmap */
1701 #if 0
1702 /* XXX have to disable this because X's rasterization rules
1703 * don't match software Mesa's. This causes a buffer invariance
1704 * test failure in the conformance tests.
1705 * In the future, we might provide a config option to enable this.
1706 */
1707 if (ctx->Light.ShadeModel==GL_FLAT && ctx->RasterMask==0) {
1708 if (ctx->Color.DitherFlag && depth < 24)
1709 return (triangle_func)NULL;
1710 setup_x_polygon_options( ctx );
1711 return flat_pixmap_triangle;
1712 }
1713 #endif
1714 return (triangle_func)NULL;
1715 }
1716 }