1 /* $Id: xm_tri.c,v 1.6 2000/10/31 18:09:47 keithw Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
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.
35 #include "glxheader.h"
42 /* Internal swrast includes:
44 #include "swrast/s_depth.h"
49 /**********************************************************************/
50 /*** Triangle rendering ***/
51 /**********************************************************************/
56 * Render a triangle into a pixmap, any pixel format, flat shaded and
59 static void flat_pixmap_triangle( GLcontext
*ctx
,
60 GLuint v0
, GLuint v1
, GLuint v2
, GLuint pv
)
62 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
63 struct vertex_buffer
*VB
= ctx
->VB
;
67 if (0 /*VB->MonoColor*/) {
68 gc
= xmesa
->xm_buffer
->gc1
; /* use current color */
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],
79 pixel
= VB
->IndexPtr
->data
[pv
];
81 gc
= xmesa
->xm_buffer
->gc2
;
82 XMesaSetForeground( xmesa
->display
, gc
, pixel
);
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
);
97 * XImage, smooth, depth-buffered, PF_TRUECOLOR triangle.
99 static void smooth_TRUECOLOR_z_triangle( GLcontext
*ctx
,
100 GLuint v0
, GLuint v1
, GLuint v2
,
103 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
104 XMesaImage
*img
= xmesa
->xm_buffer
->backimage
;
107 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
109 #define INNER_LOOP( LEFT, RIGHT, Y ) \
111 GLint i, xx = LEFT, yy = FLIP(xmesa->xm_buffer, Y); \
112 GLint len = RIGHT-LEFT; \
114 for (i=0;i<len;i++,xx++) { \
115 GLdepth z = FixedToDepth(ffz); \
118 PACK_TRUECOLOR(p, FixedToInt(ffr), FixedToInt(ffg), FixedToInt(ffb));\
119 XMesaPutPixel( img, xx, yy, p ); \
122 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
126 #include "swrast/s_tritemp.h"
132 * XImage, smooth, depth-buffered, PF_8A8B8G8R triangle.
134 static void smooth_8A8B8G8R_z_triangle( GLcontext
*ctx
,
135 GLuint v0
, GLuint v1
, GLuint v2
,
138 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
141 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
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 ) \
148 GLint i, len = RIGHT-LEFT; \
150 for (i=0;i<len;i++) { \
151 GLdepth z = FixedToDepth(ffz); \
153 pRow[i] = PACK_8B8G8R( FixedToInt(ffr), FixedToInt(ffg), \
157 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
161 #include "swrast/s_tritemp.h"
166 * XImage, smooth, depth-buffered, PF_8R8G8B triangle.
168 static void smooth_8R8G8B_z_triangle( GLcontext
*ctx
,
169 GLuint v0
, GLuint v1
, GLuint v2
,
172 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
175 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
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 ) \
182 GLint i, len = RIGHT-LEFT; \
184 for (i=0;i<len;i++) { \
185 GLdepth z = FixedToDepth(ffz); \
187 pRow[i] = PACK_8R8G8B( FixedToInt(ffr), FixedToInt(ffg), \
191 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
195 #include "swrast/s_tritemp.h"
200 * XImage, smooth, depth-buffered, PF_8R8G8B24 triangle.
202 static void smooth_8R8G8B24_z_triangle( GLcontext
*ctx
,
203 GLuint v0
, GLuint v1
, GLuint v2
,
206 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
209 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
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 ) \
216 GLint i, len = RIGHT-LEFT; \
218 for (i=0;i<len;i++) { \
219 GLdepth z = FixedToDepth(ffz); \
221 PIXEL_TYPE *ptr = pRow + i; \
222 ptr->r = FixedToInt(ffr); \
223 ptr->g = FixedToInt(ffg); \
224 ptr->b = FixedToInt(ffb); \
227 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
231 #include "swrast/s_tritemp.h"
236 * XImage, smooth, depth-buffered, PF_TRUEDITHER triangle.
238 static void smooth_TRUEDITHER_z_triangle( GLcontext
*ctx
,
239 GLuint v0
, GLuint v1
, GLuint v2
,
242 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
243 XMesaImage
*img
= xmesa
->xm_buffer
->backimage
;
246 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
248 #define INNER_LOOP( LEFT, RIGHT, Y ) \
250 GLint i, xx = LEFT, yy = FLIP(xmesa->xm_buffer,Y), len = RIGHT-LEFT; \
252 for (i=0;i<len;i++,xx++) { \
253 GLdepth z = FixedToDepth(ffz); \
256 PACK_TRUEDITHER( p, xx, yy, FixedToInt(ffr), \
257 FixedToInt(ffg), FixedToInt(ffb) ); \
258 XMesaPutPixel( img, xx, yy, p ); \
261 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
265 #include "swrast/s_tritemp.h"
270 * XImage, smooth, depth-buffered, PF_5R6G5B triangle.
272 static void smooth_5R6G5B_z_triangle( GLcontext
*ctx
,
273 GLuint v0
, GLuint v1
, GLuint v2
,
276 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
279 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
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 ) \
286 GLint i, len = RIGHT-LEFT; \
288 for (i=0;i<len;i++) { \
289 DEPTH_TYPE z = FixedToDepth(ffz); \
291 pRow[i] = PACK_5R6G5B( FixedToInt(ffr), FixedToInt(ffg), \
295 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
299 #include "swrast/s_tritemp.h"
304 * XImage, smooth, depth-buffered, PF_DITHER_5R6G5B triangle.
306 static void smooth_DITHER_5R6G5B_z_triangle( GLcontext
*ctx
,
307 GLuint v0
, GLuint v1
, GLuint v2
,
310 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
313 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
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 ) \
320 GLint i, len = RIGHT-LEFT; \
322 for (i=0;i<len;i++) { \
323 GLdepth z = FixedToDepth(ffz); \
325 PACK_TRUEDITHER(pRow[i], LEFT+i, Y, FixedToInt(ffr), \
326 FixedToInt(ffg), FixedToInt(ffb) ); \
329 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
333 #include "swrast/s_tritemp.h"
338 * XImage, smooth, depth-buffered, 8-bit, PF_DITHER8 triangle.
340 static void smooth_DITHER8_z_triangle( GLcontext
*ctx
,
341 GLuint v0
, GLuint v1
, GLuint v2
,
344 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
347 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
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 ) \
354 GLint i, xx = LEFT, yy = FLIP(xmesa->xm_buffer,Y), len = RIGHT-LEFT; \
357 for (i=0;i<len;i++,xx++) { \
358 GLdepth z = FixedToDepth(ffz); \
360 pRow[i] = (PIXEL_TYPE) XDITHER( xx, FixedToInt(ffr), \
361 FixedToInt(ffg), FixedToInt(ffb) ); \
364 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
368 #include "swrast/s_tritemp.h"
373 * XImage, smooth, depth-buffered, PF_DITHER triangle.
375 static void smooth_DITHER_z_triangle( GLcontext
*ctx
,
376 GLuint v0
, GLuint v1
, GLuint v2
,
379 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
380 XMesaImage
*img
= xmesa
->xm_buffer
->backimage
;
383 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
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 ) \
390 GLint i, xx = LEFT, yy = FLIP(xmesa->xm_buffer,Y), len = RIGHT-LEFT; \
393 for (i=0;i<len;i++,xx++) { \
394 GLdepth z = FixedToDepth(ffz); \
396 unsigned long p = XDITHER( xx, FixedToInt(ffr), \
397 FixedToInt(ffg), FixedToInt(ffb) ); \
398 XMesaPutPixel( img, xx, yy, p ); \
401 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
405 #include "swrast/s_tritemp.h"
410 * XImage, smooth, depth-buffered, 8-bit PF_LOOKUP triangle.
412 static void smooth_LOOKUP8_z_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
413 GLuint v2
, GLuint pv
)
415 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
418 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
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 ) \
425 GLint i, len = RIGHT-LEFT; \
428 for (i=0;i<len;i++) { \
429 GLdepth z = FixedToDepth(ffz); \
431 pRow[i] = LOOKUP( FixedToInt(ffr), FixedToInt(ffg), \
435 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
439 #include "swrast/s_tritemp.h"
445 * XImage, smooth, depth-buffered, 8-bit PF_HPCR triangle.
447 static void smooth_HPCR_z_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
448 GLuint v2
, GLuint pv
)
450 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
453 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
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 ) \
460 GLint i, xx = LEFT, yy = FLIP(xmesa->xm_buffer,Y), len = RIGHT-LEFT; \
462 for (i=0;i<len;i++,xx++) { \
463 GLdepth z = FixedToDepth(ffz); \
465 pRow[i] = DITHER_HPCR( xx, yy, FixedToInt(ffr), \
466 FixedToInt(ffg), FixedToInt(ffb) ); \
469 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
473 #include "swrast/s_tritemp.h"
478 * XImage, flat, depth-buffered, PF_TRUECOLOR triangle.
480 static void flat_TRUECOLOR_z_triangle( GLcontext
*ctx
,
481 GLuint v0
, GLuint v1
, GLuint v2
,
484 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
485 XMesaImage
*img
= xmesa
->xm_buffer
->backimage
;
487 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
489 unsigned long pixel; \
490 PACK_TRUECOLOR(pixel, VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2]);
492 #define INNER_LOOP( LEFT, RIGHT, Y ) \
494 GLint i, xx = LEFT, yy = FLIP(xmesa->xm_buffer,Y), len = RIGHT-LEFT; \
496 for (i=0;i<len;i++,xx++) { \
497 GLdepth z = FixedToDepth(ffz); \
499 XMesaPutPixel( img, xx, yy, pixel ); \
505 #include "swrast/s_tritemp.h"
510 * XImage, flat, depth-buffered, PF_8A8B8G8R triangle.
512 static void flat_8A8B8G8R_z_triangle( GLcontext
*ctx
, GLuint v0
,
513 GLuint v1
, GLuint v2
, GLuint pv
)
515 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
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)
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 ) \
526 GLint i, len = RIGHT-LEFT; \
528 for (i=0;i<len;i++) { \
529 GLdepth z = FixedToDepth(ffz); \
531 pRow[i] = (PIXEL_TYPE) p; \
537 #include "swrast/s_tritemp.h"
542 * XImage, flat, depth-buffered, PF_8R8G8B triangle.
544 static void flat_8R8G8B_z_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
545 GLuint v2
, GLuint pv
)
547 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
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)
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 ) \
558 GLint i, len = RIGHT-LEFT; \
560 for (i=0;i<len;i++) { \
561 GLdepth z = FixedToDepth(ffz); \
563 pRow[i] = (PIXEL_TYPE) p; \
569 #include "swrast/s_tritemp.h"
574 * XImage, flat, depth-buffered, PF_8R8G8B24 triangle.
576 static void flat_8R8G8B24_z_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
577 GLuint v2
, GLuint pv
)
579 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
580 const GLubyte
*color
= ctx
->VB
->ColorPtr
->data
[pv
];
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 ) \
588 GLint i, len = RIGHT-LEFT; \
590 for (i=0;i<len;i++) { \
591 GLdepth z = FixedToDepth(ffz); \
593 PIXEL_TYPE *ptr = pRow+i; \
594 ptr->r = color[RCOMP]; \
595 ptr->g = color[GCOMP]; \
596 ptr->b = color[BCOMP]; \
602 #include "swrast/s_tritemp.h"
607 * XImage, flat, depth-buffered, PF_TRUEDITHER triangle.
609 static void flat_TRUEDITHER_z_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
610 GLuint v2
, GLuint pv
)
612 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
613 XMesaImage
*img
= xmesa
->xm_buffer
->backimage
;
615 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
616 #define INNER_LOOP( LEFT, RIGHT, Y ) \
618 GLint i, xx = LEFT, yy = FLIP(xmesa->xm_buffer,Y), len = RIGHT-LEFT; \
620 for (i=0;i<len;i++,xx++) { \
621 GLdepth z = FixedToDepth(ffz); \
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 ); \
632 #include "swrast/s_tritemp.h"
637 * XImage, flat, depth-buffered, PF_5R6G5B triangle.
639 static void flat_5R6G5B_z_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
640 GLuint v2
, GLuint pv
)
642 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
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)
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 ) \
653 GLint i, len = RIGHT-LEFT; \
655 for (i=0;i<len;i++) { \
656 DEPTH_TYPE z = FixedToDepth(ffz); \
658 pRow[i] = (PIXEL_TYPE) p; \
664 #include "swrast/s_tritemp.h"
669 * XImage, flat, depth-buffered, PF_DITHER_5R6G5B triangle.
671 static void flat_DITHER_5R6G5B_z_triangle( GLcontext
*ctx
, GLuint v0
,
672 GLuint v1
, GLuint v2
, GLuint pv
)
674 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
675 const GLubyte
*color
= ctx
->VB
->ColorPtr
->data
[pv
];
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 ) \
683 GLint i, len = RIGHT-LEFT; \
685 for (i=0;i<len;i++) { \
686 DEPTH_TYPE z = FixedToDepth(ffz); \
688 PACK_TRUEDITHER(pRow[i], LEFT+i, Y, color[RCOMP], \
689 color[GCOMP], color[BCOMP]); \
695 #include "swrast/s_tritemp.h"
700 * XImage, flat, depth-buffered, 8-bit PF_DITHER triangle.
702 static void flat_DITHER8_z_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
703 GLuint v2
, GLuint pv
)
705 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
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)
712 FLAT_DITHER_SETUP( VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
714 #define INNER_LOOP( LEFT, RIGHT, Y ) \
716 GLint i, xx = LEFT, len = RIGHT-LEFT; \
717 FLAT_DITHER_ROW_SETUP(FLIP(xmesa->xm_buffer, Y)); \
719 for (i=0;i<len;i++,xx++) { \
720 GLdepth z = FixedToDepth(ffz); \
722 pRow[i] = (PIXEL_TYPE) FLAT_DITHER(xx); \
728 #include "swrast/s_tritemp.h"
733 * XImage, flat, depth-buffered, PF_DITHER triangle.
735 static void flat_DITHER_z_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
736 GLuint v2
, GLuint pv
)
738 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
739 XMesaImage
*img
= xmesa
->xm_buffer
->backimage
;
741 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
743 FLAT_DITHER_SETUP( VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
745 #define INNER_LOOP( LEFT, RIGHT, Y ) \
747 GLint i, xx = LEFT, yy = FLIP(xmesa->xm_buffer,Y), len = RIGHT-LEFT; \
748 FLAT_DITHER_ROW_SETUP(yy); \
750 for (i=0;i<len;i++,xx++) { \
751 GLdepth z = FixedToDepth(ffz); \
753 unsigned long p = FLAT_DITHER(xx); \
754 XMesaPutPixel( img, xx, yy, p ); \
760 #include "swrast/s_tritemp.h"
765 * XImage, flat, depth-buffered, 8-bit PF_HPCR triangle.
767 static void flat_HPCR_z_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
768 GLuint v2
, GLuint pv
)
770 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
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)
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 ) \
782 GLint i, xx = LEFT, yy = FLIP(xmesa->xm_buffer,Y), len = RIGHT-LEFT; \
784 for (i=0;i<len;i++,xx++) { \
785 GLdepth z = FixedToDepth(ffz); \
787 pRow[i] = (PIXEL_TYPE) DITHER_HPCR( xx, yy, r, g, b ); \
793 #include "swrast/s_tritemp.h"
798 * XImage, flat, depth-buffered, 8-bit PF_LOOKUP triangle.
800 static void flat_LOOKUP8_z_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
801 GLuint v2
, GLuint pv
)
803 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
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)
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 ) \
817 GLint i, len = RIGHT-LEFT; \
819 for (i=0;i<len;i++) { \
820 GLdepth z = FixedToDepth(ffz); \
828 #include "swrast/s_tritemp.h"
834 * XImage, smooth, NON-depth-buffered, PF_TRUECOLOR triangle.
836 static void smooth_TRUECOLOR_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
837 GLuint v2
, GLuint pv
)
839 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
840 XMesaImage
*img
= xmesa
->xm_buffer
->backimage
;
843 #define INNER_LOOP( LEFT, RIGHT, Y ) \
845 GLint xx, yy = FLIP(xmesa->xm_buffer, Y); \
846 for (xx=LEFT;xx<RIGHT;xx++) { \
848 PACK_TRUECOLOR(p, FixedToInt(ffr), FixedToInt(ffg), FixedToInt(ffb));\
849 XMesaPutPixel( img, xx, yy, p ); \
850 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
853 #include "swrast/s_tritemp.h"
858 * XImage, smooth, NON-depth-buffered, PF_8A8B8G8R triangle.
860 static void smooth_8A8B8G8R_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
861 GLuint v2
, GLuint pv
)
863 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
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 ) \
872 PIXEL_TYPE *pixel = pRow; \
873 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
874 *pixel = PACK_8B8G8R( FixedToInt(ffr), FixedToInt(ffg), \
876 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
879 #include "swrast/s_tritemp.h"
884 * XImage, smooth, NON-depth-buffered, PF_8R8G8B triangle.
886 static void smooth_8R8G8B_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
887 GLuint v2
, GLuint pv
)
889 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
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 ) \
898 PIXEL_TYPE *pixel = pRow; \
899 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
900 *pixel = PACK_8R8G8B( FixedToInt(ffr), FixedToInt(ffg), \
902 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
905 #include "swrast/s_tritemp.h"
910 * XImage, smooth, NON-depth-buffered, PF_8R8G8B triangle.
912 static void smooth_8R8G8B24_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
913 GLuint v2
, GLuint pv
)
915 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
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 ) \
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; \
933 #include "swrast/s_tritemp.h"
938 * XImage, smooth, NON-depth-buffered, PF_TRUEDITHER triangle.
940 static void smooth_TRUEDITHER_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
941 GLuint v2
, GLuint pv
)
943 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
944 XMesaImage
*img
= xmesa
->xm_buffer
->backimage
;
947 #define INNER_LOOP( LEFT, RIGHT, Y ) \
949 GLint xx, yy = FLIP(xmesa->xm_buffer, Y); \
950 for (xx=LEFT;xx<RIGHT;xx++) { \
952 PACK_TRUEDITHER( p, xx, yy, FixedToInt(ffr), FixedToInt(ffg), \
954 XMesaPutPixel( img, xx, yy, p ); \
955 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
958 #include "swrast/s_tritemp.h"
963 * XImage, smooth, NON-depth-buffered, PF_5R6G5B triangle.
965 static void smooth_5R6G5B_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
966 GLuint v2
, GLuint pv
)
968 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
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 ) \
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; \
984 #include "swrast/s_tritemp.h"
989 * XImage, smooth, NON-depth-buffered, PF_DITHER_5R6G5B triangle.
991 static void smooth_DITHER_5R6G5B_triangle( GLcontext
*ctx
, GLuint v0
,
992 GLuint v1
, GLuint v2
, GLuint pv
)
994 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
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 ) \
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; \
1010 #include "swrast/s_tritemp.h"
1015 * XImage, smooth, NON-depth-buffered, 8-bit PF_DITHER triangle.
1017 static void smooth_DITHER8_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
1018 GLuint v2
, GLuint pv
)
1020 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
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 ) \
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; \
1037 #include "swrast/s_tritemp.h"
1042 * XImage, smooth, NON-depth-buffered, PF_DITHER triangle.
1044 static void smooth_DITHER_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
1045 GLuint v2
, GLuint pv
)
1047 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
1048 XMesaImage
*img
= xmesa
->xm_buffer
->backimage
;
1050 #define INTERP_RGB 1
1051 #define INNER_LOOP( LEFT, RIGHT, Y ) \
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; \
1062 #include "swrast/s_tritemp.h"
1067 * XImage, smooth, NON-depth-buffered, 8-bit PF_LOOKUP triangle.
1069 static void smooth_LOOKUP8_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
1070 GLuint v2
, GLuint pv
)
1072 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
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 ) \
1081 PIXEL_TYPE *pixel = pRow; \
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; \
1089 #include "swrast/s_tritemp.h"
1095 * XImage, smooth, NON-depth-buffered, 8-bit PF_HPCR triangle.
1097 static void smooth_HPCR_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
1098 GLuint v2
, GLuint pv
)
1100 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
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 ) \
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; \
1116 #include "swrast/s_tritemp.h"
1121 * XImage, flat, NON-depth-buffered, PF_TRUECOLOR triangle.
1123 static void flat_TRUECOLOR_triangle( GLcontext
*ctx
, GLuint v0
,
1124 GLuint v1
, GLuint v2
, GLuint pv
)
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]);
1132 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1134 GLint xx, yy = FLIP(xmesa->xm_buffer, Y); \
1135 for (xx=LEFT;xx<RIGHT;xx++) { \
1136 XMesaPutPixel( img, xx, yy, pixel ); \
1139 #include "swrast/s_tritemp.h"
1144 * XImage, flat, NON-depth-buffered, PF_8A8B8G8R triangle.
1146 static void flat_8A8B8G8R_triangle( GLcontext
*ctx
, GLuint v0
,
1147 GLuint v1
, GLuint v2
, GLuint pv
)
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 ) \
1159 PIXEL_TYPE *pixel = pRow; \
1160 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1161 *pixel = (PIXEL_TYPE) p; \
1164 #include "swrast/s_tritemp.h"
1169 * XImage, flat, NON-depth-buffered, PF_8R8G8B triangle.
1171 static void flat_8R8G8B_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
1172 GLuint v2
, GLuint pv
)
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 ) \
1184 PIXEL_TYPE *pixel = pRow; \
1185 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1186 *pixel = (PIXEL_TYPE) p; \
1189 #include "swrast/s_tritemp.h"
1194 * XImage, flat, NON-depth-buffered, PF_8R8G8B24 triangle.
1196 static void flat_8R8G8B24_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
1197 GLuint v2
, GLuint pv
)
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 ) \
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]; \
1215 #include "swrast/s_tritemp.h"
1219 * XImage, flat, NON-depth-buffered, PF_TRUEDITHER triangle.
1221 static void flat_TRUEDITHER_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
1222 GLuint v2
, GLuint pv
)
1224 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
1225 XMesaImage
*img
= xmesa
->xm_buffer
->backimage
;
1226 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1228 GLint xx, yy = FLIP(xmesa->xm_buffer, Y); \
1229 for (xx=LEFT;xx<RIGHT;xx++) { \
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 ); \
1236 #include "swrast/s_tritemp.h"
1242 * XImage, flat, NON-depth-buffered, PF_5R6G5B triangle.
1244 static void flat_5R6G5B_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
1245 GLuint v2
, GLuint pv
)
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 ) \
1257 PIXEL_TYPE *pixel = pRow; \
1258 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1259 *pixel = (PIXEL_TYPE) p; \
1262 #include "swrast/s_tritemp.h"
1267 * XImage, flat, NON-depth-buffered, PF_DITHER_5R6G5B triangle.
1269 static void flat_DITHER_5R6G5B_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
1270 GLuint v2
, GLuint pv
)
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 ) \
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]); \
1286 #include "swrast/s_tritemp.h"
1291 * XImage, flat, NON-depth-buffered, 8-bit PF_DITHER triangle.
1293 static void flat_DITHER8_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
1294 GLuint v2
, GLuint pv
)
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] );
1303 #define INNER_LOOP( LEFT, RIGHT, Y ) \
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); \
1312 #include "swrast/s_tritemp.h"
1317 * XImage, flat, NON-depth-buffered, PF_DITHER triangle.
1319 static void flat_DITHER_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
1320 GLuint v2
, GLuint pv
)
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] );
1327 #define INNER_LOOP( LEFT, RIGHT, Y ) \
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 ); \
1336 #include "swrast/s_tritemp.h"
1341 * XImage, flat, NON-depth-buffered, 8-bit PF_HPCR triangle.
1343 static void flat_HPCR_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
1344 GLuint v2
, GLuint pv
)
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 ) \
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 ); \
1362 #include "swrast/s_tritemp.h"
1367 * XImage, flat, NON-depth-buffered, 8-bit PF_LOOKUP triangle.
1369 static void flat_LOOKUP8_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
1370 GLuint v2
, GLuint pv
)
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 \
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 ) \
1385 PIXEL_TYPE *pixel = pRow; \
1386 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1390 #include "swrast/s_tritemp.h"
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.
1400 static void setup_x_polygon_options( GLcontext
*ctx
)
1402 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
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);
1414 b
->stipple_gc
= XCreateGC(xmesa
->display
, b
->stipple_pixmap
, 0, NULL
);
1416 XMesaSetFunction(xmesa
->display
, b
->stipple_gc
, GXcopy
);
1417 XMesaSetForeground(xmesa
->display
, b
->stipple_gc
, 1);
1418 XMesaSetBackground(xmesa
->display
, b
->stipple_gc
, 0);
1422 * NOTE: We don't handle the following here!
1423 * GL_UNPACK_SWAP_BYTES
1424 * GL_UNPACK_LSB_FIRST
1426 /* Copy Mesa stipple pattern to an XImage then to Pixmap */
1428 XMesaImage
*stipple_ximage
;
1431 int shift
= xmesa
->xm_buffer
->height
% 32;
1432 for (i
=0;i
<32;i
++) {
1433 stipple
[31-i
] = ctx
->PolygonStipple
[(i
+shift
) % 32];
1435 #ifdef XFree86Server
1436 stipple_ximage
= XMesaCreateImage(1, 32, 32, (char *)stipple
);
1438 stipple_ximage
= XCreateImage( xmesa
->display
,
1439 xmesa
->xm_visual
->visinfo
->visual
,
1443 stipple_ximage
->byte_order
= LSBFirst
;
1444 stipple_ximage
->bitmap_bit_order
= LSBFirst
;
1445 stipple_ximage
->bitmap_unit
= 32;
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
);
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
;
1462 fill_type
= FillSolid
;
1465 XMesaSetFillStyle( xmesa
->display
, xmesa
->xm_buffer
->gc1
, fill_type
);
1466 XMesaSetFillStyle( xmesa
->display
, xmesa
->xm_buffer
->gc2
, fill_type
);
1473 _xmesa_print_triangle_func( triangle_func triFunc
)
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");
1562 triangle_func
xmesa_get_triangle_func( GLcontext
*ctx
)
1564 XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
1565 int depth
= GET_VISUAL_DEPTH(xmesa
->xm_visual
);
1569 if (ctx
->Polygon
.SmoothFlag
) return (triangle_func
)NULL
;
1570 if (ctx
->Texture
.ReallyEnabled
) return (triangle_func
)NULL
;
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
) {
1581 return smooth_TRUECOLOR_z_triangle
;
1583 return smooth_8A8B8G8R_z_triangle
;
1585 return smooth_8R8G8B_z_triangle
;
1587 return smooth_8R8G8B24_z_triangle
;
1589 return smooth_TRUEDITHER_z_triangle
;
1591 return smooth_5R6G5B_z_triangle
;
1592 case PF_DITHER_5R6G5B
:
1593 return smooth_DITHER_5R6G5B_z_triangle
;
1595 return smooth_HPCR_z_triangle
;
1597 return (depth
==8) ? smooth_DITHER8_z_triangle
1598 : smooth_DITHER_z_triangle
;
1600 return (depth
==8) ? smooth_LOOKUP8_z_triangle
: (triangle_func
)NULL
;
1602 return (triangle_func
)NULL
;
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
) {
1613 return flat_TRUECOLOR_z_triangle
;
1615 return flat_8A8B8G8R_z_triangle
;
1617 return flat_8R8G8B_z_triangle
;
1619 return flat_8R8G8B24_z_triangle
;
1621 return flat_TRUEDITHER_z_triangle
;
1623 return flat_5R6G5B_z_triangle
;
1624 case PF_DITHER_5R6G5B
:
1625 return flat_DITHER_5R6G5B_z_triangle
;
1627 return flat_HPCR_z_triangle
;
1629 return (depth
==8) ? flat_DITHER8_z_triangle
1630 : flat_DITHER_z_triangle
;
1632 return (depth
==8) ? flat_LOOKUP8_z_triangle
: (triangle_func
)NULL
;
1634 return (triangle_func
)NULL
;
1637 if ( ctx
->RasterMask
==0 /* no depth test */
1638 && ctx
->Light
.ShadeModel
==GL_SMOOTH
1639 && ctx
->Polygon
.StippleFlag
==GL_FALSE
) {
1640 switch (xmesa
->pixelformat
) {
1642 return smooth_TRUECOLOR_triangle
;
1644 return smooth_8A8B8G8R_triangle
;
1646 return smooth_8R8G8B_triangle
;
1648 return smooth_8R8G8B24_triangle
;
1650 return smooth_TRUEDITHER_triangle
;
1652 return smooth_5R6G5B_triangle
;
1653 case PF_DITHER_5R6G5B
:
1654 return smooth_DITHER_5R6G5B_triangle
;
1656 return smooth_HPCR_triangle
;
1658 return (depth
==8) ? smooth_DITHER8_triangle
1659 : smooth_DITHER_triangle
;
1661 return (depth
==8) ? smooth_LOOKUP8_triangle
: (triangle_func
)NULL
;
1663 return (triangle_func
)NULL
;
1667 if ( ctx
->RasterMask
==0 /* no depth test */
1668 && ctx
->Light
.ShadeModel
==GL_FLAT
1669 && ctx
->Polygon
.StippleFlag
==GL_FALSE
) {
1670 switch (xmesa
->pixelformat
) {
1672 return flat_TRUECOLOR_triangle
;
1674 return flat_TRUEDITHER_triangle
;
1676 return flat_8A8B8G8R_triangle
;
1678 return flat_8R8G8B_triangle
;
1680 return flat_8R8G8B24_triangle
;
1682 return flat_5R6G5B_triangle
;
1683 case PF_DITHER_5R6G5B
:
1684 return flat_DITHER_5R6G5B_triangle
;
1686 return flat_HPCR_triangle
;
1688 return (depth
==8) ? flat_DITHER8_triangle
1689 : flat_DITHER_triangle
;
1691 return (depth
==8) ? flat_LOOKUP8_triangle
: (triangle_func
)NULL
;
1693 return (triangle_func
)NULL
;
1697 return (triangle_func
)NULL
;
1700 /* draw to pixmap */
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.
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
;
1714 return (triangle_func
)NULL
;