2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
27 * This file contains "accelerated" triangle functions. It should be
28 * fairly easy to write new special-purpose triangle functions and hook
29 * them into this module.
34 #include "main/imports.h"
35 #include "main/mtypes.h"
36 #include "glxheader.h"
39 /* Internal swrast includes:
41 #include "swrast/s_context.h"
42 #include "swrast/s_depth.h"
43 #include "swrast/s_triangle.h"
46 #define GET_XRB(XRB) struct xmesa_renderbuffer *XRB = \
47 xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0])
50 /**********************************************************************/
51 /*** Triangle rendering ***/
52 /**********************************************************************/
58 * XImage, smooth, depth-buffered, PF_TRUECOLOR triangle.
60 #define NAME smooth_TRUECOLOR_z_triangle
62 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
65 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
68 #define RENDER_SPAN( span ) { \
69 GLint x = span.x, y = YFLIP(xrb, span.y); \
71 for (i = 0; i < span.end; i++, x++) { \
72 const DEPTH_TYPE z = FixedToDepth(span.z); \
75 PACK_TRUECOLOR(p, FixedToInt(span.red), \
76 FixedToInt(span.green), FixedToInt(span.blue)); \
77 XMesaPutPixel(xrb->ximage, x, y, p); \
80 span.red += span.redStep; \
81 span.green += span.greenStep; \
82 span.blue += span.blueStep; \
83 span.z += span.zStep; \
86 #include "swrast/s_tritemp.h"
92 * XImage, smooth, depth-buffered, PF_8A8B8G8R triangle.
94 #define NAME smooth_8A8B8G8R_z_triangle
96 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
98 #define INTERP_ALPHA 1
99 #define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y)
100 #define PIXEL_TYPE GLuint
101 #define BYTES_PER_ROW (xrb->ximage->bytes_per_line)
104 #define RENDER_SPAN( span ) { \
106 for (i = 0; i < span.end; i++) { \
107 const DEPTH_TYPE z = FixedToDepth(span.z); \
109 pRow[i] = PACK_8A8B8G8R(FixedToInt(span.red), \
110 FixedToInt(span.green), FixedToInt(span.blue), \
111 FixedToInt(span.alpha)); \
114 span.red += span.redStep; \
115 span.green += span.greenStep; \
116 span.blue += span.blueStep; \
117 span.alpha += span.alphaStep; \
118 span.z += span.zStep; \
121 #include "swrast/s_tritemp.h"
126 * XImage, smooth, depth-buffered, PF_8A8R8G8B triangle.
128 #define NAME smooth_8A8R8G8B_z_triangle
130 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
132 #define INTERP_ALPHA 1
133 #define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y)
134 #define PIXEL_TYPE GLuint
135 #define BYTES_PER_ROW (xrb->ximage->bytes_per_line)
139 #define RENDER_SPAN( span ) { \
141 for (i = 0; i < span.end; i++) { \
142 const DEPTH_TYPE z = FixedToDepth(span.z); \
144 pRow[i] = PACK_8A8R8G8B(FixedToInt(span.red), \
145 FixedToInt(span.green), FixedToInt(span.blue), \
146 FixedToInt(span.alpha)); \
149 span.red += span.redStep; \
150 span.green += span.greenStep; \
151 span.blue += span.blueStep; \
152 span.alpha += span.alphaStep; \
153 span.z += span.zStep; \
156 #include "swrast/s_tritemp.h"
161 * XImage, smooth, depth-buffered, PF_8R8G8B triangle.
163 #define NAME smooth_8R8G8B_z_triangle
165 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
167 #define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y)
168 #define PIXEL_TYPE GLuint
169 #define BYTES_PER_ROW (xrb->ximage->bytes_per_line)
173 #define RENDER_SPAN( span ) { \
175 for (i = 0; i < span.end; i++) { \
176 const DEPTH_TYPE z = FixedToDepth(span.z); \
178 pRow[i] = PACK_8R8G8B(FixedToInt(span.red), \
179 FixedToInt(span.green), FixedToInt(span.blue)); \
182 span.red += span.redStep; \
183 span.green += span.greenStep; \
184 span.blue += span.blueStep; \
185 span.z += span.zStep; \
188 #include "swrast/s_tritemp.h"
193 * XImage, smooth, depth-buffered, PF_8R8G8B24 triangle.
195 #define NAME smooth_8R8G8B24_z_triangle
197 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
199 #define PIXEL_ADDRESS(X,Y) PIXEL_ADDR3(xrb, X, Y)
200 #define PIXEL_TYPE bgr_t
201 #define BYTES_PER_ROW (xrb->ximage->bytes_per_line)
204 #define RENDER_SPAN( span ) { \
206 for (i = 0; i < span.end; i++) { \
207 const DEPTH_TYPE z = FixedToDepth(span.z); \
209 PIXEL_TYPE *ptr = pRow + i; \
210 ptr->r = FixedToInt(span.red); \
211 ptr->g = FixedToInt(span.green); \
212 ptr->b = FixedToInt(span.blue); \
215 span.red += span.redStep; \
216 span.green += span.greenStep; \
217 span.blue += span.blueStep; \
218 span.z += span.zStep; \
220 #include "swrast/s_tritemp.h"
225 * XImage, smooth, depth-buffered, PF_TRUEDITHER triangle.
227 #define NAME smooth_TRUEDITHER_z_triangle
229 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
232 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
234 #define RENDER_SPAN( span ) { \
236 GLint x = span.x, y = YFLIP(xrb, span.y); \
237 for (i = 0; i < span.end; i++, x++) { \
238 const DEPTH_TYPE z = FixedToDepth(span.z); \
241 PACK_TRUEDITHER(p, x, y, FixedToInt(span.red), \
242 FixedToInt(span.green), FixedToInt(span.blue)); \
243 XMesaPutPixel(xrb->ximage, x, y, p); \
246 span.red += span.redStep; \
247 span.green += span.greenStep; \
248 span.blue += span.blueStep; \
249 span.z += span.zStep; \
251 #include "swrast/s_tritemp.h"
256 * XImage, smooth, depth-buffered, PF_5R6G5B triangle.
258 #define NAME smooth_5R6G5B_z_triangle
260 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
262 #define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X, Y)
263 #define PIXEL_TYPE GLushort
264 #define BYTES_PER_ROW (xrb->ximage->bytes_per_line)
267 #define RENDER_SPAN( span ) { \
269 for (i = 0; i < span.end; i++) { \
270 const DEPTH_TYPE z = FixedToDepth(span.z); \
272 pRow[i] = PACK_5R6G5B(FixedToInt(span.red), \
273 FixedToInt(span.green), FixedToInt(span.blue)); \
276 span.red += span.redStep; \
277 span.green += span.greenStep; \
278 span.blue += span.blueStep; \
279 span.z += span.zStep; \
281 #include "swrast/s_tritemp.h"
286 * XImage, smooth, depth-buffered, PF_DITHER_5R6G5B triangle.
288 #define NAME smooth_DITHER_5R6G5B_z_triangle
290 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
292 #define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X, Y)
293 #define PIXEL_TYPE GLushort
294 #define BYTES_PER_ROW (xrb->ximage->bytes_per_line)
296 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
298 #define RENDER_SPAN( span ) { \
300 GLint x = span.x, y = YFLIP(xrb, span.y); \
301 for (i = 0; i < span.end; i++, x++) { \
302 const DEPTH_TYPE z = FixedToDepth(span.z); \
304 PACK_TRUEDITHER(pRow[i], x, y, FixedToInt(span.red), \
305 FixedToInt(span.green), FixedToInt(span.blue)); \
308 span.red += span.redStep; \
309 span.green += span.greenStep; \
310 span.blue += span.blueStep; \
311 span.z += span.zStep; \
313 #include "swrast/s_tritemp.h"
318 * XImage, flat, depth-buffered, PF_TRUECOLOR triangle.
320 #define NAME flat_TRUECOLOR_z_triangle
322 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
324 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
326 XMesaImage *img = xrb->ximage; \
327 unsigned long pixel; \
328 PACK_TRUECOLOR(pixel, v2->color[0], v2->color[1], v2->color[2]);
329 #define RENDER_SPAN( span ) { \
331 GLint x = span.x, y = YFLIP(xrb, span.y); \
332 for (i = 0; i < span.end; i++, x++) { \
333 const DEPTH_TYPE z = FixedToDepth(span.z); \
335 XMesaPutPixel(img, x, y, pixel); \
338 span.z += span.zStep; \
340 #include "swrast/s_tritemp.h"
345 * XImage, flat, depth-buffered, PF_8A8B8G8R triangle.
347 #define NAME flat_8A8B8G8R_z_triangle
349 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
350 #define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y)
351 #define PIXEL_TYPE GLuint
352 #define BYTES_PER_ROW (xrb->ximage->bytes_per_line)
355 GLuint p = PACK_8A8B8G8R( v2->color[0], v2->color[1],\
356 v2->color[2], v2->color[3]);
357 #define RENDER_SPAN( span ) { \
359 for (i = 0; i < span.end; i++) { \
360 const DEPTH_TYPE z = FixedToDepth(span.z); \
362 pRow[i] = (PIXEL_TYPE) p; \
365 span.z += span.zStep; \
367 #include "swrast/s_tritemp.h"
372 * XImage, flat, depth-buffered, PF_8A8R8G8B triangle.
374 #define NAME flat_8A8R8G8B_z_triangle
376 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
377 #define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y)
378 #define PIXEL_TYPE GLuint
379 #define BYTES_PER_ROW (xrb->ximage->bytes_per_line)
382 GLuint p = PACK_8A8R8G8B(v2->color[0], v2->color[1], \
383 v2->color[2], v2->color[3]);
384 #define RENDER_SPAN( span ) { \
386 for (i = 0; i < span.end; i++) { \
387 const DEPTH_TYPE z = FixedToDepth(span.z); \
389 pRow[i] = (PIXEL_TYPE) p; \
392 span.z += span.zStep; \
394 #include "swrast/s_tritemp.h"
399 * XImage, flat, depth-buffered, PF_8R8G8B triangle.
401 #define NAME flat_8R8G8B_z_triangle
403 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
404 #define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y)
405 #define PIXEL_TYPE GLuint
406 #define BYTES_PER_ROW (xrb->ximage->bytes_per_line)
409 GLuint p = PACK_8R8G8B( v2->color[0], v2->color[1], v2->color[2] );
410 #define RENDER_SPAN( span ) { \
412 for (i = 0; i < span.end; i++) { \
413 DEPTH_TYPE z = FixedToDepth(span.z); \
415 pRow[i] = (PIXEL_TYPE) p; \
418 span.z += span.zStep; \
421 #include "swrast/s_tritemp.h"
426 * XImage, flat, depth-buffered, PF_8R8G8B24 triangle.
428 #define NAME flat_8R8G8B24_z_triangle
430 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
431 #define PIXEL_ADDRESS(X,Y) PIXEL_ADDR3(xrb, X, Y)
432 #define PIXEL_TYPE bgr_t
433 #define BYTES_PER_ROW (xrb->ximage->bytes_per_line)
436 const GLubyte *color = v2->color;
437 #define RENDER_SPAN( span ) { \
439 for (i = 0; i < span.end; i++) { \
440 const DEPTH_TYPE z = FixedToDepth(span.z); \
442 PIXEL_TYPE *ptr = pRow + i; \
443 ptr->r = color[RCOMP]; \
444 ptr->g = color[GCOMP]; \
445 ptr->b = color[BCOMP]; \
448 span.z += span.zStep; \
450 #include "swrast/s_tritemp.h"
455 * XImage, flat, depth-buffered, PF_TRUEDITHER triangle.
457 #define NAME flat_TRUEDITHER_z_triangle
459 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
461 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
463 XMesaImage *img = xrb->ximage;
464 #define RENDER_SPAN( span ) { \
466 GLint x = span.x, y = YFLIP(xrb, span.y); \
467 for (i = 0; i < span.end; i++, x++) { \
468 const DEPTH_TYPE z = FixedToDepth(span.z); \
471 PACK_TRUEDITHER(p, x, y, v2->color[0], \
472 v2->color[1], v2->color[2]); \
473 XMesaPutPixel(img, x, y, p); \
476 span.z += span.zStep; \
478 #include "swrast/s_tritemp.h"
483 * XImage, flat, depth-buffered, PF_5R6G5B triangle.
485 #define NAME flat_5R6G5B_z_triangle
487 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
488 #define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X, Y)
489 #define PIXEL_TYPE GLushort
490 #define BYTES_PER_ROW (xrb->ximage->bytes_per_line)
493 GLushort p = PACK_5R6G5B( v2->color[0], v2->color[1], v2->color[2] );
494 #define RENDER_SPAN( span ) { \
496 for (i = 0; i < span.end; i++) { \
497 const DEPTH_TYPE z = FixedToDepth(span.z); \
499 pRow[i] = (PIXEL_TYPE) p; \
502 span.z += span.zStep; \
504 #include "swrast/s_tritemp.h"
509 * XImage, flat, depth-buffered, PF_DITHER_5R6G5B triangle.
511 #define NAME flat_DITHER_5R6G5B_z_triangle
513 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
514 #define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X, Y)
515 #define PIXEL_TYPE GLushort
516 #define BYTES_PER_ROW (xrb->ximage->bytes_per_line)
518 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
520 const GLubyte *color = v2->color;
521 #define RENDER_SPAN( span ) { \
523 GLint x = span.x, y = YFLIP(xrb, span.y); \
524 for (i = 0; i < span.end; i++, x++) { \
525 const DEPTH_TYPE z = FixedToDepth(span.z); \
527 PACK_TRUEDITHER(pRow[i], x, y, color[RCOMP], \
528 color[GCOMP], color[BCOMP]); \
531 span.z += span.zStep; \
533 #include "swrast/s_tritemp.h"
537 * XImage, smooth, NON-depth-buffered, PF_TRUECOLOR triangle.
539 #define NAME smooth_TRUECOLOR_triangle
542 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
544 XMesaImage *img = xrb->ximage;
545 #define RENDER_SPAN( span ) { \
547 GLint x = span.x, y = YFLIP(xrb, span.y); \
548 for (i = 0; i < span.end; i++, x++) { \
550 PACK_TRUECOLOR(p, FixedToInt(span.red), \
551 FixedToInt(span.green), FixedToInt(span.blue)); \
552 XMesaPutPixel(img, x, y, p); \
553 span.red += span.redStep; \
554 span.green += span.greenStep; \
555 span.blue += span.blueStep; \
557 #include "swrast/s_tritemp.h"
562 * XImage, smooth, NON-depth-buffered, PF_8A8B8G8R triangle.
564 #define NAME smooth_8A8B8G8R_triangle
566 #define INTERP_ALPHA 1
567 #define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y)
568 #define PIXEL_TYPE GLuint
569 #define BYTES_PER_ROW (xrb->ximage->bytes_per_line)
572 #define RENDER_SPAN( span ) { \
574 for (i = 0; i < span.end; i++) { \
575 pRow[i] = PACK_8A8B8G8R(FixedToInt(span.red), \
576 FixedToInt(span.green), FixedToInt(span.blue), \
577 FixedToInt(span.alpha)); \
578 span.red += span.redStep; \
579 span.green += span.greenStep; \
580 span.blue += span.blueStep; \
581 span.alpha += span.alphaStep; \
583 #include "swrast/s_tritemp.h"
588 * XImage, smooth, NON-depth-buffered, PF_8A8R8G8B triangle.
590 #define NAME smooth_8A8R8G8B_triangle
592 #define INTERP_ALPHA 1
593 #define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y)
594 #define PIXEL_TYPE GLuint
595 #define BYTES_PER_ROW (xrb->ximage->bytes_per_line)
598 #define RENDER_SPAN( span ) { \
600 for (i = 0; i < span.end; i++) { \
601 pRow[i] = PACK_8A8R8G8B(FixedToInt(span.red), \
602 FixedToInt(span.green), FixedToInt(span.blue), \
603 FixedToInt(span.alpha)); \
604 span.red += span.redStep; \
605 span.green += span.greenStep; \
606 span.blue += span.blueStep; \
607 span.alpha += span.alphaStep; \
609 #include "swrast/s_tritemp.h"
614 * XImage, smooth, NON-depth-buffered, PF_8R8G8B triangle.
616 #define NAME smooth_8R8G8B_triangle
618 #define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y)
619 #define PIXEL_TYPE GLuint
620 #define BYTES_PER_ROW (xrb->ximage->bytes_per_line)
623 #define RENDER_SPAN( span ) { \
625 for (i = 0; i < span.end; i++) { \
626 pRow[i] = PACK_8R8G8B(FixedToInt(span.red), \
627 FixedToInt(span.green), FixedToInt(span.blue) ); \
628 span.red += span.redStep; \
629 span.green += span.greenStep; \
630 span.blue += span.blueStep; \
632 #include "swrast/s_tritemp.h"
637 * XImage, smooth, NON-depth-buffered, PF_8R8G8B triangle.
639 #define NAME smooth_8R8G8B24_triangle
641 #define PIXEL_ADDRESS(X,Y) PIXEL_ADDR3(xrb, X, Y)
642 #define PIXEL_TYPE bgr_t
643 #define BYTES_PER_ROW (xrb->ximage->bytes_per_line)
646 #define RENDER_SPAN( span ) { \
648 PIXEL_TYPE *pixel = pRow; \
649 for (i = 0; i < span.end; i++, pixel++) { \
650 pixel->r = FixedToInt(span.red); \
651 pixel->g = FixedToInt(span.green); \
652 pixel->b = FixedToInt(span.blue); \
653 span.red += span.redStep; \
654 span.green += span.greenStep; \
655 span.blue += span.blueStep; \
657 #include "swrast/s_tritemp.h"
662 * XImage, smooth, NON-depth-buffered, PF_TRUEDITHER triangle.
664 #define NAME smooth_TRUEDITHER_triangle
667 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
669 XMesaImage *img = xrb->ximage;
670 #define RENDER_SPAN( span ) { \
672 GLint x = span.x, y = YFLIP(xrb, span.y); \
673 for (i = 0; i < span.end; i++, x++) { \
675 PACK_TRUEDITHER(p, x, y, FixedToInt(span.red), \
676 FixedToInt(span.green), FixedToInt(span.blue)); \
677 XMesaPutPixel(img, x, y, p ); \
678 span.red += span.redStep; \
679 span.green += span.greenStep; \
680 span.blue += span.blueStep; \
682 #include "swrast/s_tritemp.h"
687 * XImage, smooth, NON-depth-buffered, PF_5R6G5B triangle.
689 #define NAME smooth_5R6G5B_triangle
691 #define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X, Y)
692 #define PIXEL_TYPE GLushort
693 #define BYTES_PER_ROW (xrb->ximage->bytes_per_line)
696 #define RENDER_SPAN( span ) { \
698 for (i = 0; i < span.end; i++) { \
699 pRow[i] = (PIXEL_TYPE) PACK_5R6G5B(FixedToInt(span.red), \
700 FixedToInt(span.green), FixedToInt(span.blue)); \
701 span.red += span.redStep; \
702 span.green += span.greenStep; \
703 span.blue += span.blueStep; \
705 #include "swrast/s_tritemp.h"
710 * XImage, smooth, NON-depth-buffered, PF_DITHER_5R6G5B triangle.
712 #define NAME smooth_DITHER_5R6G5B_triangle
714 #define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X, Y)
715 #define PIXEL_TYPE GLushort
716 #define BYTES_PER_ROW (xrb->ximage->bytes_per_line)
718 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
720 #define RENDER_SPAN( span ) { \
722 GLint x = span.x, y = YFLIP(xrb, span.y); \
723 for (i = 0; i < span.end; i++, x++) { \
724 PACK_TRUEDITHER(pRow[i], x, y, FixedToInt(span.red), \
725 FixedToInt(span.green), FixedToInt(span.blue)); \
726 span.red += span.redStep; \
727 span.green += span.greenStep; \
728 span.blue += span.blueStep; \
730 #include "swrast/s_tritemp.h"
735 * XImage, flat, NON-depth-buffered, PF_TRUECOLOR triangle.
737 #define NAME flat_TRUECOLOR_triangle
739 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
741 XMesaImage *img = xrb->ximage; \
742 unsigned long pixel; \
743 PACK_TRUECOLOR(pixel, v2->color[0], v2->color[1], v2->color[2]);
744 #define RENDER_SPAN( span ) { \
746 GLint x = span.x, y = YFLIP(xrb, span.y); \
747 for (i = 0; i < span.end; i++, x++) { \
748 XMesaPutPixel(img, x, y, pixel); \
750 #include "swrast/s_tritemp.h"
755 * XImage, flat, NON-depth-buffered, PF_8A8B8G8R triangle.
757 #define NAME flat_8A8B8G8R_triangle
758 #define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y)
759 #define PIXEL_TYPE GLuint
760 #define BYTES_PER_ROW (xrb->ximage->bytes_per_line)
763 unsigned long p = PACK_8B8G8R( v2->color[0], \
764 v2->color[1], v2->color[2] );
765 #define RENDER_SPAN( span ) { \
767 for (i = 0; i < span.end; i++) { \
768 pRow[i] = (PIXEL_TYPE) p; \
770 #include "swrast/s_tritemp.h"
775 * XImage, flat, NON-depth-buffered, PF_8A8R8G8B triangle.
777 #define NAME flat_8A8R8G8B_triangle
778 #define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y)
779 #define PIXEL_TYPE GLuint
780 #define BYTES_PER_ROW (xrb->ximage->bytes_per_line)
783 unsigned long p = PACK_8R8G8B( v2->color[0], \
784 v2->color[1], v2->color[2] );
785 #define RENDER_SPAN( span ) { \
787 for (i = 0; i < span.end; i++) { \
788 pRow[i] = (PIXEL_TYPE) p; \
790 #include "swrast/s_tritemp.h"
795 * XImage, flat, NON-depth-buffered, PF_8R8G8B triangle.
797 #define NAME flat_8R8G8B_triangle
798 #define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y)
799 #define PIXEL_TYPE GLuint
800 #define BYTES_PER_ROW (xrb->ximage->bytes_per_line)
803 unsigned long p = PACK_8R8G8B( v2->color[0], \
804 v2->color[1], v2->color[2] );
805 #define RENDER_SPAN( span ) { \
807 for (i = 0; i < span.end; i++) { \
808 pRow[i] = (PIXEL_TYPE) p; \
810 #include "swrast/s_tritemp.h"
815 * XImage, flat, NON-depth-buffered, PF_8R8G8B24 triangle.
817 #define NAME flat_8R8G8B24_triangle
818 #define PIXEL_ADDRESS(X,Y) PIXEL_ADDR3(xrb, X, Y)
819 #define PIXEL_TYPE bgr_t
820 #define BYTES_PER_ROW (xrb->ximage->bytes_per_line)
823 const GLubyte *color = v2->color;
824 #define RENDER_SPAN( span ) { \
826 PIXEL_TYPE *pixel = pRow; \
827 for (i = 0; i < span.end; i++, pixel++) { \
828 pixel->r = color[RCOMP]; \
829 pixel->g = color[GCOMP]; \
830 pixel->b = color[BCOMP]; \
832 #include "swrast/s_tritemp.h"
837 * XImage, flat, NON-depth-buffered, PF_TRUEDITHER triangle.
839 #define NAME flat_TRUEDITHER_triangle
841 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
843 XMesaImage *img = xrb->ximage;
844 #define RENDER_SPAN( span ) { \
846 GLint x = span.x, y = YFLIP(xrb, span.y); \
847 for (i = 0; i < span.end; i++, x++) { \
849 PACK_TRUEDITHER(p, x, y, v2->color[0], \
850 v2->color[1], v2->color[2] ); \
851 XMesaPutPixel(img, x, y, p); \
853 #include "swrast/s_tritemp.h"
858 * XImage, flat, NON-depth-buffered, PF_5R6G5B triangle.
860 #define NAME flat_5R6G5B_triangle
861 #define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X, Y)
862 #define PIXEL_TYPE GLushort
863 #define BYTES_PER_ROW (xrb->ximage->bytes_per_line)
866 unsigned long p = PACK_5R6G5B( v2->color[0], \
867 v2->color[1], v2->color[2] );
868 #define RENDER_SPAN( span ) { \
870 for (i = 0; i < span.end; i++) { \
871 pRow[i] = (PIXEL_TYPE) p; \
873 #include "swrast/s_tritemp.h"
878 * XImage, flat, NON-depth-buffered, PF_DITHER_5R6G5B triangle.
880 #define NAME flat_DITHER_5R6G5B_triangle
881 #define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X, Y)
882 #define PIXEL_TYPE GLushort
883 #define BYTES_PER_ROW (xrb->ximage->bytes_per_line)
885 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
887 const GLubyte *color = v2->color;
888 #define RENDER_SPAN( span ) { \
890 GLint x = span.x, y = YFLIP(xrb, span.y); \
891 for (i = 0; i < span.end; i++, x++) { \
892 PACK_TRUEDITHER(pRow[i], x, y, color[RCOMP], \
893 color[GCOMP], color[BCOMP]); \
895 #include "swrast/s_tritemp.h"
899 #endif /* CHAN_BITS == 8 */
902 #if defined(DEBUG) && CHAN_BITS == 8
903 extern void _xmesa_print_triangle_func( swrast_tri_func triFunc
);
904 void _xmesa_print_triangle_func( swrast_tri_func triFunc
)
906 printf("XMesa tri func = ");
907 if (triFunc
==smooth_TRUECOLOR_z_triangle
)
908 printf("smooth_TRUECOLOR_z_triangle\n");
909 else if (triFunc
==smooth_8A8B8G8R_z_triangle
)
910 printf("smooth_8A8B8G8R_z_triangle\n");
911 else if (triFunc
==smooth_8A8R8G8B_z_triangle
)
912 printf("smooth_8A8R8G8B_z_triangle\n");
913 else if (triFunc
==smooth_8R8G8B_z_triangle
)
914 printf("smooth_8R8G8B_z_triangle\n");
915 else if (triFunc
==smooth_8R8G8B24_z_triangle
)
916 printf("smooth_8R8G8B24_z_triangle\n");
917 else if (triFunc
==smooth_TRUEDITHER_z_triangle
)
918 printf("smooth_TRUEDITHER_z_triangle\n");
919 else if (triFunc
==smooth_5R6G5B_z_triangle
)
920 printf("smooth_5R6G5B_z_triangle\n");
921 else if (triFunc
==smooth_DITHER_5R6G5B_z_triangle
)
922 printf("smooth_DITHER_5R6G5B_z_triangle\n");
923 else if (triFunc
==flat_TRUECOLOR_z_triangle
)
924 printf("flat_TRUECOLOR_z_triangle\n");
925 else if (triFunc
==flat_8A8B8G8R_z_triangle
)
926 printf("flat_8A8B8G8R_z_triangle\n");
927 else if (triFunc
==flat_8A8R8G8B_z_triangle
)
928 printf("flat_8A8R8G8B_z_triangle\n");
929 else if (triFunc
==flat_8R8G8B_z_triangle
)
930 printf("flat_8R8G8B_z_triangle\n");
931 else if (triFunc
==flat_8R8G8B24_z_triangle
)
932 printf("flat_8R8G8B24_z_triangle\n");
933 else if (triFunc
==flat_TRUEDITHER_z_triangle
)
934 printf("flat_TRUEDITHER_z_triangle\n");
935 else if (triFunc
==flat_5R6G5B_z_triangle
)
936 printf("flat_5R6G5B_z_triangle\n");
937 else if (triFunc
==flat_DITHER_5R6G5B_z_triangle
)
938 printf("flat_DITHER_5R6G5B_z_triangle\n");
939 else if (triFunc
==smooth_TRUECOLOR_triangle
)
940 printf("smooth_TRUECOLOR_triangle\n");
941 else if (triFunc
==smooth_8A8B8G8R_triangle
)
942 printf("smooth_8A8B8G8R_triangle\n");
943 else if (triFunc
==smooth_8A8R8G8B_triangle
)
944 printf("smooth_8A8R8G8B_triangle\n");
945 else if (triFunc
==smooth_8R8G8B_triangle
)
946 printf("smooth_8R8G8B_triangle\n");
947 else if (triFunc
==smooth_8R8G8B24_triangle
)
948 printf("smooth_8R8G8B24_triangle\n");
949 else if (triFunc
==smooth_TRUEDITHER_triangle
)
950 printf("smooth_TRUEDITHER_triangle\n");
951 else if (triFunc
==smooth_5R6G5B_triangle
)
952 printf("smooth_5R6G5B_triangle\n");
953 else if (triFunc
==smooth_DITHER_5R6G5B_triangle
)
954 printf("smooth_DITHER_5R6G5B_triangle\n");
955 else if (triFunc
==flat_TRUECOLOR_triangle
)
956 printf("flat_TRUECOLOR_triangle\n");
957 else if (triFunc
==flat_TRUEDITHER_triangle
)
958 printf("flat_TRUEDITHER_triangle\n");
959 else if (triFunc
==flat_8A8B8G8R_triangle
)
960 printf("flat_8A8B8G8R_triangle\n");
961 else if (triFunc
==flat_8A8R8G8B_triangle
)
962 printf("flat_8A8R8G8B_triangle\n");
963 else if (triFunc
==flat_8R8G8B_triangle
)
964 printf("flat_8R8G8B_triangle\n");
965 else if (triFunc
==flat_8R8G8B24_triangle
)
966 printf("flat_8R8G8B24_triangle\n");
967 else if (triFunc
==flat_5R6G5B_triangle
)
968 printf("flat_5R6G5B_triangle\n");
969 else if (triFunc
==flat_DITHER_5R6G5B_triangle
)
970 printf("flat_DITHER_5R6G5B_triangle\n");
979 /* record the current triangle function name */
980 static const char *triFuncName
= NULL
;
982 #define USE(triFunc) \
984 triFuncName = #triFunc; \
990 #define USE(triFunc) return triFunc
996 * Return pointer to line drawing function, or NULL if we should use a
999 static swrast_tri_func
1000 get_triangle_func(struct gl_context
*ctx
)
1003 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1004 XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1005 const struct xmesa_renderbuffer
*xrb
;
1011 /* trivial fallback tests */
1012 if ((ctx
->DrawBuffer
->_ColorDrawBufferIndexes
[0] != BUFFER_BIT_FRONT_LEFT
) &&
1013 (ctx
->DrawBuffer
->_ColorDrawBufferIndexes
[0] != BUFFER_BIT_BACK_LEFT
))
1014 return (swrast_tri_func
) NULL
;
1015 if (ctx
->RenderMode
!= GL_RENDER
)
1016 return (swrast_tri_func
) NULL
;
1017 if (ctx
->Polygon
.SmoothFlag
)
1018 return (swrast_tri_func
) NULL
;
1019 if (ctx
->Texture
._MaxEnabledTexImageUnit
!= -1)
1020 return (swrast_tri_func
) NULL
;
1021 if (swrast
->_RasterMask
& MULTI_DRAW_BIT
)
1022 return (swrast_tri_func
) NULL
;
1023 if (ctx
->Polygon
.CullFlag
&&
1024 ctx
->Polygon
.CullFaceMode
== GL_FRONT_AND_BACK
)
1025 return (swrast_tri_func
) NULL
;
1027 xrb
= xmesa_renderbuffer(ctx
->DrawBuffer
->_ColorDrawBuffers
[0]);
1030 if ( ctx
->Light
.ShadeModel
==GL_SMOOTH
1031 && swrast
->_RasterMask
==DEPTH_BIT
1032 && ctx
->Depth
.Func
==GL_LESS
1033 && ctx
->Depth
.Mask
==GL_TRUE
1034 && ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
1035 && ctx
->Polygon
.StippleFlag
==GL_FALSE
) {
1036 switch (xmesa
->pixelformat
) {
1038 USE(smooth_TRUECOLOR_z_triangle
);
1040 USE(smooth_8A8B8G8R_z_triangle
);
1042 USE(smooth_8A8R8G8B_z_triangle
);
1044 USE(smooth_8R8G8B_z_triangle
);
1046 USE(smooth_8R8G8B24_z_triangle
);
1047 case PF_Dither_True
:
1048 USE(smooth_TRUEDITHER_z_triangle
);
1050 USE(smooth_5R6G5B_z_triangle
);
1051 case PF_Dither_5R6G5B
:
1052 USE(smooth_DITHER_5R6G5B_z_triangle
);
1054 return (swrast_tri_func
) NULL
;
1057 if ( ctx
->Light
.ShadeModel
==GL_FLAT
1058 && swrast
->_RasterMask
==DEPTH_BIT
1059 && ctx
->Depth
.Func
==GL_LESS
1060 && ctx
->Depth
.Mask
==GL_TRUE
1061 && ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
1062 && ctx
->Polygon
.StippleFlag
==GL_FALSE
) {
1063 switch (xmesa
->pixelformat
) {
1065 USE(flat_TRUECOLOR_z_triangle
);
1067 USE(flat_8A8B8G8R_z_triangle
);
1069 USE(flat_8A8R8G8B_z_triangle
);
1071 USE(flat_8R8G8B_z_triangle
);
1073 USE(flat_8R8G8B24_z_triangle
);
1074 case PF_Dither_True
:
1075 USE(flat_TRUEDITHER_z_triangle
);
1077 USE(flat_5R6G5B_z_triangle
);
1078 case PF_Dither_5R6G5B
:
1079 USE(flat_DITHER_5R6G5B_z_triangle
);
1081 return (swrast_tri_func
) NULL
;
1084 if ( swrast
->_RasterMask
==0 /* no depth test */
1085 && ctx
->Light
.ShadeModel
==GL_SMOOTH
1086 && ctx
->Polygon
.StippleFlag
==GL_FALSE
) {
1087 switch (xmesa
->pixelformat
) {
1089 USE(smooth_TRUECOLOR_triangle
);
1091 USE(smooth_8A8B8G8R_triangle
);
1093 USE(smooth_8A8R8G8B_triangle
);
1095 USE(smooth_8R8G8B_triangle
);
1097 USE(smooth_8R8G8B24_triangle
);
1098 case PF_Dither_True
:
1099 USE(smooth_TRUEDITHER_triangle
);
1101 USE(smooth_5R6G5B_triangle
);
1102 case PF_Dither_5R6G5B
:
1103 USE(smooth_DITHER_5R6G5B_triangle
);
1105 return (swrast_tri_func
) NULL
;
1109 if ( swrast
->_RasterMask
==0 /* no depth test */
1110 && ctx
->Light
.ShadeModel
==GL_FLAT
1111 && ctx
->Polygon
.StippleFlag
==GL_FALSE
) {
1112 switch (xmesa
->pixelformat
) {
1114 USE(flat_TRUECOLOR_triangle
);
1115 case PF_Dither_True
:
1116 USE(flat_TRUEDITHER_triangle
);
1118 USE(flat_8A8B8G8R_triangle
);
1120 USE(flat_8A8R8G8B_triangle
);
1122 USE(flat_8R8G8B_triangle
);
1124 USE(flat_8R8G8B24_triangle
);
1126 USE(flat_5R6G5B_triangle
);
1127 case PF_Dither_5R6G5B
:
1128 USE(flat_DITHER_5R6G5B_triangle
);
1130 return (swrast_tri_func
) NULL
;
1134 #endif /* CHAN_BITS == 8 */
1136 return (swrast_tri_func
) NULL
;
1140 /* Override for the swrast tri-selection function. Try to use one
1141 * of our internal tri functions, otherwise fall back to the
1142 * standard swrast functions.
1144 void xmesa_choose_triangle( struct gl_context
*ctx
)
1146 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1148 if (!(swrast
->Triangle
= get_triangle_func( ctx
)))
1149 _swrast_choose_triangle( ctx
);