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