b83b7502790f4c8ccc8a5e17cad550808a3c8f19
[mesa.git] / src / mesa / drivers / x11 / xm_tri.c
1 /* $Id: xm_tri.c,v 1.28 2002/10/24 23:57:23 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 4.1
6 *
7 * Copyright (C) 1999-2002 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 "imports.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 #define INTERP_RGB 1
1048 #define RENDER_SPAN( span ) \
1049 GLuint i; \
1050 GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \
1051 XDITHER_SETUP(y); \
1052 for (i = 0; i < span.end; i++, x++) { \
1053 unsigned long p = XDITHER(x, FixedToInt(span.red), \
1054 FixedToInt(span.green), FixedToInt(span.blue) ); \
1055 XMesaPutPixel(img, x, y, p); \
1056 span.red += span.redStep; \
1057 span.green += span.greenStep; \
1058 span.blue += span.blueStep; \
1059 }
1060
1061 #include "swrast/s_tritemp.h"
1062 }
1063
1064
1065 /*
1066 * XImage, smooth, NON-depth-buffered, 8-bit PF_LOOKUP triangle.
1067 */
1068 static void smooth_LOOKUP8_triangle( GLcontext *ctx,
1069 const SWvertex *v0,
1070 const SWvertex *v1,
1071 const SWvertex *v2 )
1072 {
1073 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 RENDER_SPAN( span ) \
1079 GLuint i; \
1080 LOOKUP_SETUP; \
1081 for (i = 0; i < span.end; i++) { \
1082 pRow[i] = LOOKUP(FixedToInt(span.red), \
1083 FixedToInt(span.green), FixedToInt(span.blue));\
1084 span.red += span.redStep; \
1085 span.green += span.greenStep; \
1086 span.blue += span.blueStep; \
1087 }
1088
1089 #include "swrast/s_tritemp.h"
1090 }
1091
1092
1093
1094 /*
1095 * XImage, smooth, NON-depth-buffered, 8-bit PF_HPCR triangle.
1096 */
1097 static void smooth_HPCR_triangle( GLcontext *ctx,
1098 const SWvertex *v0,
1099 const SWvertex *v1,
1100 const SWvertex *v2 )
1101 {
1102 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1103 #define INTERP_RGB 1
1104 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
1105 #define PIXEL_TYPE GLubyte
1106 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1107 #define RENDER_SPAN( span ) \
1108 GLuint i; \
1109 GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \
1110 for (i = 0; i < span.end; i++, x++) { \
1111 pRow[i] = DITHER_HPCR(x, y, FixedToInt(span.red), \
1112 FixedToInt(span.green), FixedToInt(span.blue)); \
1113 span.red += span.redStep; \
1114 span.green += span.greenStep; \
1115 span.blue += span.blueStep; \
1116 }
1117
1118 #include "swrast/s_tritemp.h"
1119 }
1120
1121
1122 /*
1123 * XImage, flat, NON-depth-buffered, PF_TRUECOLOR triangle.
1124 */
1125 static void flat_TRUECOLOR_triangle( GLcontext *ctx,
1126 const SWvertex *v0,
1127 const SWvertex *v1,
1128 const SWvertex *v2 )
1129 {
1130 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1131 XMesaImage *img = xmesa->xm_buffer->backimage;
1132 #define SETUP_CODE \
1133 unsigned long pixel; \
1134 PACK_TRUECOLOR(pixel, v2->color[0], v2->color[1], v2->color[2]);
1135
1136 #define RENDER_SPAN( span ) \
1137 GLuint i; \
1138 GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \
1139 for (i = 0; i < span.end; i++, x++) { \
1140 XMesaPutPixel(img, x, y, pixel); \
1141 }
1142
1143 #include "swrast/s_tritemp.h"
1144 }
1145
1146
1147 /*
1148 * XImage, flat, NON-depth-buffered, PF_8A8B8G8R triangle.
1149 */
1150 static void flat_8A8B8G8R_triangle( GLcontext *ctx,
1151 const SWvertex *v0,
1152 const SWvertex *v1,
1153 const SWvertex *v2 )
1154 {
1155 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1156 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
1157 #define PIXEL_TYPE GLuint
1158 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1159 #define SETUP_CODE \
1160 unsigned long p = PACK_8B8G8R( v2->color[0], \
1161 v2->color[1], v2->color[2] );
1162 #define RENDER_SPAN( span ) \
1163 GLuint i; \
1164 for (i = 0; i < span.end; i++) { \
1165 pRow[i] = (PIXEL_TYPE) p; \
1166 }
1167
1168 #include "swrast/s_tritemp.h"
1169 }
1170
1171
1172 /*
1173 * XImage, flat, NON-depth-buffered, PF_8R8G8B triangle.
1174 */
1175 static void flat_8R8G8B_triangle( GLcontext *ctx,
1176 const SWvertex *v0,
1177 const SWvertex *v1,
1178 const SWvertex *v2 )
1179 {
1180 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1181 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
1182 #define PIXEL_TYPE GLuint
1183 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1184 #define SETUP_CODE \
1185 unsigned long p = PACK_8R8G8B( v2->color[0], \
1186 v2->color[1], v2->color[2] );
1187 #define RENDER_SPAN( span ) \
1188 GLuint i; \
1189 for (i = 0; i < span.end; i++) { \
1190 pRow[i] = (PIXEL_TYPE) p; \
1191 }
1192
1193 #include "swrast/s_tritemp.h"
1194 }
1195
1196
1197 /*
1198 * XImage, flat, NON-depth-buffered, PF_8R8G8B24 triangle.
1199 */
1200 static void flat_8R8G8B24_triangle( GLcontext *ctx,
1201 const SWvertex *v0,
1202 const SWvertex *v1,
1203 const SWvertex *v2 )
1204 {
1205 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1206 const GLubyte *color = v2->color;
1207 #define PIXEL_ADDRESS(X,Y) PIXELADDR3(xmesa->xm_buffer,X,Y)
1208 #define PIXEL_TYPE bgr_t
1209 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1210 #define RENDER_SPAN( span ) \
1211 GLuint i; \
1212 PIXEL_TYPE *pixel = pRow; \
1213 for (i = 0; i < span.end; i++, pixel++) { \
1214 pixel->r = color[RCOMP]; \
1215 pixel->g = color[GCOMP]; \
1216 pixel->b = color[BCOMP]; \
1217 }
1218
1219 #include "swrast/s_tritemp.h"
1220 }
1221
1222 /*
1223 * XImage, flat, NON-depth-buffered, PF_TRUEDITHER triangle.
1224 */
1225 static void flat_TRUEDITHER_triangle( GLcontext *ctx,
1226 const SWvertex *v0,
1227 const SWvertex *v1,
1228 const SWvertex *v2 )
1229 {
1230 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1231 XMesaImage *img = xmesa->xm_buffer->backimage;
1232 #define RENDER_SPAN( span ) \
1233 GLuint i; \
1234 GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \
1235 for (i = 0; i < span.end; i++, x++) { \
1236 unsigned long p; \
1237 PACK_TRUEDITHER(p, x, y, v2->color[0], \
1238 v2->color[1], v2->color[2] ); \
1239 XMesaPutPixel(img, x, y, p); \
1240 }
1241
1242 #include "swrast/s_tritemp.h"
1243 }
1244
1245
1246
1247 /*
1248 * XImage, flat, NON-depth-buffered, PF_5R6G5B triangle.
1249 */
1250 static void flat_5R6G5B_triangle( GLcontext *ctx,
1251 const SWvertex *v0,
1252 const SWvertex *v1,
1253 const SWvertex *v2 )
1254 {
1255 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1256 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
1257 #define PIXEL_TYPE GLushort
1258 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1259 #define SETUP_CODE \
1260 unsigned long p = PACK_5R6G5B( v2->color[0], \
1261 v2->color[1], v2->color[2] );
1262 #define RENDER_SPAN( span ) \
1263 GLuint i; \
1264 for (i = 0; i < span.end; i++) { \
1265 pRow[i] = (PIXEL_TYPE) p; \
1266 }
1267
1268 #include "swrast/s_tritemp.h"
1269 }
1270
1271
1272 /*
1273 * XImage, flat, NON-depth-buffered, PF_DITHER_5R6G5B triangle.
1274 */
1275 static void flat_DITHER_5R6G5B_triangle( GLcontext *ctx,
1276 const SWvertex *v0,
1277 const SWvertex *v1,
1278 const SWvertex *v2 )
1279 {
1280 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1281 const GLubyte *color = v2->color;
1282 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
1283 #define PIXEL_TYPE GLushort
1284 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1285 #define RENDER_SPAN( span ) \
1286 GLuint i; \
1287 GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \
1288 for (i = 0; i < span.end; i++, x++) { \
1289 PACK_TRUEDITHER(pRow[i], x, y, color[RCOMP], \
1290 color[GCOMP], color[BCOMP]); \
1291 }
1292
1293 #include "swrast/s_tritemp.h"
1294 }
1295
1296
1297 /*
1298 * XImage, flat, NON-depth-buffered, 8-bit PF_DITHER triangle.
1299 */
1300 static void flat_DITHER8_triangle( GLcontext *ctx,
1301 const SWvertex *v0,
1302 const SWvertex *v1,
1303 const SWvertex *v2 )
1304 {
1305 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1306 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
1307 #define PIXEL_TYPE GLubyte
1308 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1309 #define SETUP_CODE \
1310 FLAT_DITHER_SETUP( v2->color[0], v2->color[1], v2->color[2] );
1311
1312 #define RENDER_SPAN( span ) \
1313 GLuint i; \
1314 GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \
1315 FLAT_DITHER_ROW_SETUP(FLIP(xmesa->xm_buffer, y)); \
1316 for (i = 0; i < span.end; i++, x++) { \
1317 pRow[i] = (PIXEL_TYPE) FLAT_DITHER(x); \
1318 }
1319
1320 #include "swrast/s_tritemp.h"
1321 }
1322
1323
1324 /*
1325 * XImage, flat, NON-depth-buffered, PF_DITHER triangle.
1326 */
1327 static void flat_DITHER_triangle( GLcontext *ctx,
1328 const SWvertex *v0,
1329 const SWvertex *v1,
1330 const SWvertex *v2 )
1331 {
1332 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1333 XMesaImage *img = xmesa->xm_buffer->backimage;
1334 #define SETUP_CODE \
1335 FLAT_DITHER_SETUP( v2->color[0], v2->color[1], v2->color[2] );
1336
1337 #define RENDER_SPAN( span ) \
1338 GLuint i; \
1339 GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \
1340 FLAT_DITHER_ROW_SETUP(y); \
1341 for (i = 0; i < span.end; i++, x++) { \
1342 unsigned long p = FLAT_DITHER(x); \
1343 XMesaPutPixel(img, x, y, p ); \
1344 }
1345
1346 #include "swrast/s_tritemp.h"
1347 }
1348
1349
1350 /*
1351 * XImage, flat, NON-depth-buffered, 8-bit PF_HPCR triangle.
1352 */
1353 static void flat_HPCR_triangle( GLcontext *ctx,
1354 const SWvertex *v0,
1355 const SWvertex *v1,
1356 const SWvertex *v2 )
1357 {
1358 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1359 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
1360 #define PIXEL_TYPE GLubyte
1361 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1362 #define SETUP_CODE \
1363 GLubyte r = v2->color[0]; \
1364 GLubyte g = v2->color[1]; \
1365 GLubyte b = v2->color[2];
1366 #define RENDER_SPAN( span ) \
1367 GLuint i; \
1368 GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \
1369 for (i = 0; i < span.end; i++, x++) { \
1370 pRow[i] = (PIXEL_TYPE) DITHER_HPCR(x, y, r, g, b); \
1371 }
1372
1373 #include "swrast/s_tritemp.h"
1374 }
1375
1376
1377 /*
1378 * XImage, flat, NON-depth-buffered, 8-bit PF_LOOKUP triangle.
1379 */
1380 static void flat_LOOKUP8_triangle( GLcontext *ctx,
1381 const SWvertex *v0,
1382 const SWvertex *v1,
1383 const SWvertex *v2 )
1384 {
1385 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1386 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
1387 #define PIXEL_TYPE GLubyte
1388 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1389 #define SETUP_CODE \
1390 LOOKUP_SETUP; \
1391 GLubyte r = v2->color[0]; \
1392 GLubyte g = v2->color[1]; \
1393 GLubyte b = v2->color[2]; \
1394 GLubyte p = LOOKUP(r,g,b);
1395 #define RENDER_SPAN( span ) \
1396 GLuint i; \
1397 for (i = 0; i < span.end; i++) { \
1398 pRow[i] = (PIXEL_TYPE) p; \
1399 }
1400
1401 #include "swrast/s_tritemp.h"
1402 }
1403
1404
1405 #ifdef DEBUG
1406 extern void _xmesa_print_triangle_func( swrast_tri_func triFunc );
1407 void _xmesa_print_triangle_func( swrast_tri_func triFunc )
1408 {
1409 printf("XMesa tri func = ");
1410 if (triFunc ==smooth_TRUECOLOR_z_triangle)
1411 printf("smooth_TRUECOLOR_z_triangle\n");
1412 else if (triFunc ==smooth_8A8B8G8R_z_triangle)
1413 printf("smooth_8A8B8G8R_z_triangle\n");
1414 else if (triFunc ==smooth_8R8G8B_z_triangle)
1415 printf("smooth_8R8G8B_z_triangle\n");
1416 else if (triFunc ==smooth_8R8G8B24_z_triangle)
1417 printf("smooth_8R8G8B24_z_triangle\n");
1418 else if (triFunc ==smooth_TRUEDITHER_z_triangle)
1419 printf("smooth_TRUEDITHER_z_triangle\n");
1420 else if (triFunc ==smooth_5R6G5B_z_triangle)
1421 printf("smooth_5R6G5B_z_triangle\n");
1422 else if (triFunc ==smooth_DITHER_5R6G5B_z_triangle)
1423 printf("smooth_DITHER_5R6G5B_z_triangle\n");
1424 else if (triFunc ==smooth_HPCR_z_triangle)
1425 printf("smooth_HPCR_z_triangle\n");
1426 else if (triFunc ==smooth_DITHER8_z_triangle)
1427 printf("smooth_DITHER8_z_triangle\n");
1428 else if (triFunc ==smooth_LOOKUP8_z_triangle)
1429 printf("smooth_LOOKUP8_z_triangle\n");
1430 else if (triFunc ==flat_TRUECOLOR_z_triangle)
1431 printf("flat_TRUECOLOR_z_triangle\n");
1432 else if (triFunc ==flat_8A8B8G8R_z_triangle)
1433 printf("flat_8A8B8G8R_z_triangle\n");
1434 else if (triFunc ==flat_8R8G8B_z_triangle)
1435 printf("flat_8R8G8B_z_triangle\n");
1436 else if (triFunc ==flat_8R8G8B24_z_triangle)
1437 printf("flat_8R8G8B24_z_triangle\n");
1438 else if (triFunc ==flat_TRUEDITHER_z_triangle)
1439 printf("flat_TRUEDITHER_z_triangle\n");
1440 else if (triFunc ==flat_5R6G5B_z_triangle)
1441 printf("flat_5R6G5B_z_triangle\n");
1442 else if (triFunc ==flat_DITHER_5R6G5B_z_triangle)
1443 printf("flat_DITHER_5R6G5B_z_triangle\n");
1444 else if (triFunc ==flat_HPCR_z_triangle)
1445 printf("flat_HPCR_z_triangle\n");
1446 else if (triFunc ==flat_DITHER8_z_triangle)
1447 printf("flat_DITHER8_z_triangle\n");
1448 else if (triFunc ==flat_LOOKUP8_z_triangle)
1449 printf("flat_LOOKUP8_z_triangle\n");
1450 else if (triFunc ==smooth_TRUECOLOR_triangle)
1451 printf("smooth_TRUECOLOR_triangle\n");
1452 else if (triFunc ==smooth_8A8B8G8R_triangle)
1453 printf("smooth_8A8B8G8R_triangle\n");
1454 else if (triFunc ==smooth_8R8G8B_triangle)
1455 printf("smooth_8R8G8B_triangle\n");
1456 else if (triFunc ==smooth_8R8G8B24_triangle)
1457 printf("smooth_8R8G8B24_triangle\n");
1458 else if (triFunc ==smooth_TRUEDITHER_triangle)
1459 printf("smooth_TRUEDITHER_triangle\n");
1460 else if (triFunc ==smooth_5R6G5B_triangle)
1461 printf("smooth_5R6G5B_triangle\n");
1462 else if (triFunc ==smooth_DITHER_5R6G5B_triangle)
1463 printf("smooth_DITHER_5R6G5B_triangle\n");
1464 else if (triFunc ==smooth_HPCR_triangle)
1465 printf("smooth_HPCR_triangle\n");
1466 else if (triFunc ==smooth_DITHER8_triangle)
1467 printf("smooth_DITHER8_triangle\n");
1468 else if (triFunc ==smooth_LOOKUP8_triangle)
1469 printf("smooth_LOOKUP8_triangle\n");
1470 else if (triFunc ==flat_TRUECOLOR_triangle)
1471 printf("flat_TRUECOLOR_triangle\n");
1472 else if (triFunc ==flat_TRUEDITHER_triangle)
1473 printf("flat_TRUEDITHER_triangle\n");
1474 else if (triFunc ==flat_8A8B8G8R_triangle)
1475 printf("flat_8A8B8G8R_triangle\n");
1476 else if (triFunc ==flat_8R8G8B_triangle)
1477 printf("flat_8R8G8B_triangle\n");
1478 else if (triFunc ==flat_8R8G8B24_triangle)
1479 printf("flat_8R8G8B24_triangle\n");
1480 else if (triFunc ==flat_5R6G5B_triangle)
1481 printf("flat_5R6G5B_triangle\n");
1482 else if (triFunc ==flat_DITHER_5R6G5B_triangle)
1483 printf("flat_DITHER_5R6G5B_triangle\n");
1484 else if (triFunc ==flat_HPCR_triangle)
1485 printf("flat_HPCR_triangle\n");
1486 else if (triFunc ==flat_DITHER8_triangle)
1487 printf("flat_DITHER8_triangle\n");
1488 else if (triFunc ==flat_LOOKUP8_triangle)
1489 printf("flat_LOOKUP8_triangle\n");
1490 else
1491 printf("???\n");
1492 }
1493 #endif
1494
1495
1496 #ifdef DEBUG
1497
1498 /* record the current triangle function name */
1499 static const char *triFuncName = NULL;
1500
1501 #define USE(triFunc) \
1502 do { \
1503 triFuncName = #triFunc; \
1504 return triFunc; \
1505 } while (0)
1506
1507 #else
1508
1509 #define USE(triFunc) return triFunc
1510
1511 #endif
1512
1513
1514 static swrast_tri_func get_triangle_func( GLcontext *ctx )
1515 {
1516 SWcontext *swrast = SWRAST_CONTEXT(ctx);
1517 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1518 int depth = GET_VISUAL_DEPTH(xmesa->xm_visual);
1519
1520 (void) kernel1;
1521
1522 #ifdef DEBUG
1523 triFuncName = NULL;
1524 #endif
1525
1526 if (ctx->RenderMode != GL_RENDER) return (swrast_tri_func) NULL;
1527 if (ctx->Polygon.SmoothFlag) return (swrast_tri_func) NULL;
1528 if (ctx->Texture._EnabledUnits) return (swrast_tri_func) NULL;
1529 if (swrast->_RasterMask & MULTI_DRAW_BIT) return (swrast_tri_func) NULL;
1530 if (ctx->Polygon.CullFlag &&
1531 ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK)
1532 return (swrast_tri_func) NULL;
1533
1534 if (xmesa->xm_buffer->buffer==XIMAGE) {
1535 if ( ctx->Light.ShadeModel==GL_SMOOTH
1536 && swrast->_RasterMask==DEPTH_BIT
1537 && ctx->Depth.Func==GL_LESS
1538 && ctx->Depth.Mask==GL_TRUE
1539 && ctx->Visual.depthBits == DEFAULT_SOFTWARE_DEPTH_BITS
1540 && ctx->Polygon.StippleFlag==GL_FALSE) {
1541 switch (xmesa->pixelformat) {
1542 case PF_TRUECOLOR:
1543 USE(smooth_TRUECOLOR_z_triangle);
1544 case PF_8A8B8G8R:
1545 USE(smooth_8A8B8G8R_z_triangle);
1546 case PF_8R8G8B:
1547 USE(smooth_8R8G8B_z_triangle);
1548 case PF_8R8G8B24:
1549 USE(smooth_8R8G8B24_z_triangle);
1550 case PF_TRUEDITHER:
1551 USE(smooth_TRUEDITHER_z_triangle);
1552 case PF_5R6G5B:
1553 USE(smooth_5R6G5B_z_triangle);
1554 case PF_DITHER_5R6G5B:
1555 USE(smooth_DITHER_5R6G5B_z_triangle);
1556 case PF_HPCR:
1557 USE(smooth_HPCR_z_triangle);
1558 case PF_DITHER:
1559 if (depth == 8)
1560 USE(smooth_DITHER8_z_triangle);
1561 else
1562 USE(smooth_DITHER_z_triangle);
1563 break;
1564 case PF_LOOKUP:
1565 if (depth == 8)
1566 USE(smooth_LOOKUP8_z_triangle);
1567 else
1568 return (swrast_tri_func) NULL;
1569 default:
1570 return (swrast_tri_func) NULL;
1571 }
1572 }
1573 if ( ctx->Light.ShadeModel==GL_FLAT
1574 && swrast->_RasterMask==DEPTH_BIT
1575 && ctx->Depth.Func==GL_LESS
1576 && ctx->Depth.Mask==GL_TRUE
1577 && ctx->Visual.depthBits == DEFAULT_SOFTWARE_DEPTH_BITS
1578 && ctx->Polygon.StippleFlag==GL_FALSE) {
1579 switch (xmesa->pixelformat) {
1580 case PF_TRUECOLOR:
1581 USE(flat_TRUECOLOR_z_triangle);
1582 case PF_8A8B8G8R:
1583 USE(flat_8A8B8G8R_z_triangle);
1584 case PF_8R8G8B:
1585 USE(flat_8R8G8B_z_triangle);
1586 case PF_8R8G8B24:
1587 USE(flat_8R8G8B24_z_triangle);
1588 case PF_TRUEDITHER:
1589 USE(flat_TRUEDITHER_z_triangle);
1590 case PF_5R6G5B:
1591 USE(flat_5R6G5B_z_triangle);
1592 case PF_DITHER_5R6G5B:
1593 USE(flat_DITHER_5R6G5B_z_triangle);
1594 case PF_HPCR:
1595 USE(flat_HPCR_z_triangle);
1596 case PF_DITHER:
1597 if (depth == 8)
1598 USE(flat_DITHER8_z_triangle);
1599 else
1600 USE(flat_DITHER_z_triangle);
1601 break;
1602 case PF_LOOKUP:
1603 if (depth == 8)
1604 USE(flat_LOOKUP8_z_triangle);
1605 else
1606 return (swrast_tri_func) NULL;
1607 default:
1608 return (swrast_tri_func) NULL;
1609 }
1610 }
1611 if ( swrast->_RasterMask==0 /* no depth test */
1612 && ctx->Light.ShadeModel==GL_SMOOTH
1613 && ctx->Polygon.StippleFlag==GL_FALSE) {
1614 switch (xmesa->pixelformat) {
1615 case PF_TRUECOLOR:
1616 USE(smooth_TRUECOLOR_triangle);
1617 case PF_8A8B8G8R:
1618 USE(smooth_8A8B8G8R_triangle);
1619 case PF_8R8G8B:
1620 USE(smooth_8R8G8B_triangle);
1621 case PF_8R8G8B24:
1622 USE(smooth_8R8G8B24_triangle);
1623 case PF_TRUEDITHER:
1624 USE(smooth_TRUEDITHER_triangle);
1625 case PF_5R6G5B:
1626 USE(smooth_5R6G5B_triangle);
1627 case PF_DITHER_5R6G5B:
1628 USE(smooth_DITHER_5R6G5B_triangle);
1629 case PF_HPCR:
1630 USE(smooth_HPCR_triangle);
1631 case PF_DITHER:
1632 if (depth == 8)
1633 USE(smooth_DITHER8_triangle);
1634 else
1635 USE(smooth_DITHER_triangle);
1636 break;
1637 case PF_LOOKUP:
1638 if (depth == 8)
1639 USE(smooth_LOOKUP8_triangle);
1640 else
1641 return (swrast_tri_func) NULL;
1642 default:
1643 return (swrast_tri_func) NULL;
1644 }
1645 }
1646
1647 if ( swrast->_RasterMask==0 /* no depth test */
1648 && ctx->Light.ShadeModel==GL_FLAT
1649 && ctx->Polygon.StippleFlag==GL_FALSE) {
1650 switch (xmesa->pixelformat) {
1651 case PF_TRUECOLOR:
1652 USE(flat_TRUECOLOR_triangle);
1653 case PF_TRUEDITHER:
1654 USE(flat_TRUEDITHER_triangle);
1655 case PF_8A8B8G8R:
1656 USE(flat_8A8B8G8R_triangle);
1657 case PF_8R8G8B:
1658 USE(flat_8R8G8B_triangle);
1659 case PF_8R8G8B24:
1660 USE(flat_8R8G8B24_triangle);
1661 case PF_5R6G5B:
1662 USE(flat_5R6G5B_triangle);
1663 case PF_DITHER_5R6G5B:
1664 USE(flat_DITHER_5R6G5B_triangle);
1665 case PF_HPCR:
1666 USE(flat_HPCR_triangle);
1667 case PF_DITHER:
1668 if (depth == 8)
1669 USE(flat_DITHER8_triangle);
1670 else
1671 USE(flat_DITHER_triangle);
1672 break;
1673 case PF_LOOKUP:
1674 if (depth == 8)
1675 USE(flat_LOOKUP8_triangle);
1676 else
1677 return (swrast_tri_func) NULL;
1678 default:
1679 return (swrast_tri_func) NULL;
1680 }
1681 }
1682
1683 return (swrast_tri_func) NULL;
1684 }
1685 else {
1686 /* draw to pixmap */
1687 return (swrast_tri_func) NULL;
1688 }
1689 }
1690
1691
1692 /* Override for the swrast tri-selection function. Try to use one
1693 * of our internal tri functions, otherwise fall back to the
1694 * standard swrast functions.
1695 */
1696 void xmesa_choose_triangle( GLcontext *ctx )
1697 {
1698 SWcontext *swrast = SWRAST_CONTEXT(ctx);
1699
1700 if (!(swrast->Triangle = get_triangle_func( ctx )))
1701 _swrast_choose_triangle( ctx );
1702 }
1703