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