4c09187add37c6022694e73876b6335c30ab28f7
[mesa.git] / src / mesa / drivers / x11 / xm_line.c
1 /* $Id: xm_line.c,v 1.8 2000/11/06 17:28:20 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
28 /*
29 * This file contains "accelerated" point, line, and triangle functions.
30 * It should be fairly easy to write new special-purpose point, line or
31 * triangle functions and hook them into this module.
32 */
33
34
35 #include "glxheader.h"
36 #include "depth.h"
37 #include "macros.h"
38 #include "vb.h"
39 #include "types.h"
40 #include "xmesaP.h"
41
42 /* Internal swrast includes:
43 */
44 #include "swrast/s_depth.h"
45 #include "swrast/s_points.h"
46 #include "swrast/s_lines.h"
47 #include "swrast/s_context.h"
48
49
50 /**********************************************************************/
51 /*** Point rendering ***/
52 /**********************************************************************/
53
54
55 /*
56 * Render an array of points into a pixmap, any pixel format.
57 */
58 static void draw_points_ANY_pixmap( GLcontext *ctx, SWvertex *vert )
59 {
60 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
61 XMesaDisplay *dpy = xmesa->xm_visual->display;
62 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
63 XMesaGC gc = xmesa->xm_buffer->gc2;
64
65 if (xmesa->xm_visual->gl_visual->RGBAflag) {
66 register int x, y;
67 const GLubyte *color = vert->color;
68 unsigned long pixel = xmesa_color_to_pixel( xmesa,
69 color[0], color[1],
70 color[2], color[3],
71 xmesa->pixelformat);
72 XMesaSetForeground( dpy, gc, pixel );
73 x = (GLint) vert->win[0];
74 y = FLIP( xmesa->xm_buffer, (GLint) vert->win[1] );
75 XMesaDrawPoint( dpy, buffer, gc, x, y);
76 }
77 else {
78 /* Color index mode */
79 register int x, y;
80 XMesaSetForeground( dpy, gc, vert->index );
81 x = (GLint) vert->win[0];
82 y = FLIP( xmesa->xm_buffer, (GLint) vert->win[1] );
83 XMesaDrawPoint( dpy, buffer, gc, x, y);
84 }
85 }
86
87
88
89 /* Override the swrast point-selection function. Try to use one of
90 * our internal point functions, otherwise fall back to the standard
91 * swrast functions.
92 */
93 void xmesa_choose_point( GLcontext *ctx )
94 {
95 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
96 SWcontext *swrast = SWRAST_CONTEXT(ctx);
97
98 if (ctx->RenderMode == GL_RENDER
99 && ctx->Point.Size == 1.0F && !ctx->Point.SmoothFlag
100 && swrast->_RasterMask == 0
101 && !ctx->Texture._ReallyEnabled
102 && xmesa->xm_buffer->buffer != XIMAGE) {
103 swrast->Point = draw_points_ANY_pixmap;
104 }
105 else {
106 _swrast_choose_point( ctx );
107 }
108 }
109
110
111
112 /**********************************************************************/
113 /*** Line rendering ***/
114 /**********************************************************************/
115
116
117 #if 0
118 /*
119 * Render a line into a pixmap, any pixel format.
120 */
121 static void flat_pixmap_line( GLcontext *ctx,
122 SWvertex *vert0, SWvertex *vert1 )
123 {
124 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
125 register int x0, y0, x1, y1;
126 XMesaGC gc;
127 unsigned long pixel;
128 if (xmesa->xm_visual->gl_visual->RGBAflag) {
129 const GLubyte *color = vert0->color;
130 pixel = xmesa_color_to_pixel( xmesa, color[0], color[1], color[2], color[3],
131 xmesa->pixelformat );
132 }
133 else {
134 pixel = vert0->index;
135 }
136 gc = xmesa->xm_buffer->gc2;
137 XMesaSetForeground( xmesa->display, gc, pixel );
138
139 x0 = (GLint) vert0->win[0];
140 y0 = FLIP( xmesa->xm_buffer, (GLint) vert0->win[1] );
141 x1 = (GLint) vert1->win[0];
142 y1 = FLIP( xmesa->xm_buffer, (GLint) vert1->win[1] );
143 XMesaDrawLine( xmesa->display, xmesa->xm_buffer->buffer, gc,
144 x0, y0, x1, y1 );
145 }
146 #endif
147
148
149 /*
150 * Draw a flat-shaded, PF_TRUECOLOR line into an XImage.
151 */
152 static void flat_TRUECOLOR_line( GLcontext *ctx,
153 SWvertex *vert0, SWvertex *vert1 )
154 {
155 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
156 const GLubyte *color = vert0->color;
157 XMesaImage *img = xmesa->xm_buffer->backimage;
158 unsigned long pixel;
159 PACK_TRUECOLOR( pixel, color[0], color[1], color[2] );
160
161 #define INTERP_XY 1
162 #define CLIP_HACK 1
163 #define PLOT(X,Y) XMesaPutPixel( img, X, FLIP(xmesa->xm_buffer, Y), pixel );
164
165 #include "swrast/s_linetemp.h"
166 }
167
168
169
170 /*
171 * Draw a flat-shaded, PF_8A8B8G8R line into an XImage.
172 */
173 static void flat_8A8B8G8R_line( GLcontext *ctx,
174 SWvertex *vert0, SWvertex *vert1 )
175 {
176 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
177 const GLubyte *color = vert0->color;
178 GLuint pixel = PACK_8B8G8R( color[0], color[1], color[2] );
179
180 #define PIXEL_TYPE GLuint
181 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
182 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
183 #define CLIP_HACK 1
184 #define PLOT(X,Y) *pixelPtr = pixel;
185
186 #include "swrast/s_linetemp.h"
187 }
188
189
190 /*
191 * Draw a flat-shaded, PF_8R8G8B line into an XImage.
192 */
193 static void flat_8R8G8B_line( GLcontext *ctx,
194 SWvertex *vert0, SWvertex *vert1 )
195 {
196 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
197 const GLubyte *color = vert0->color;
198 GLuint pixel = PACK_8R8G8B( color[0], color[1], color[2] );
199
200 #define PIXEL_TYPE GLuint
201 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
202 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
203 #define CLIP_HACK 1
204 #define PLOT(X,Y) *pixelPtr = pixel;
205
206 #include "swrast/s_linetemp.h"
207 }
208
209
210 /*
211 * Draw a flat-shaded, PF_8R8G8B24 line into an XImage.
212 */
213 static void flat_8R8G8B24_line( GLcontext *ctx,
214 SWvertex *vert0, SWvertex *vert1 )
215 {
216 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
217 const GLubyte *color = vert0->color;
218
219 #define PIXEL_TYPE bgr_t
220 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
221 #define PIXEL_ADDRESS(X,Y) PIXELADDR3(xmesa->xm_buffer,X,Y)
222 #define CLIP_HACK 1
223 #define PLOT(X,Y) { \
224 pixelPtr->r = color[RCOMP]; \
225 pixelPtr->g = color[GCOMP]; \
226 pixelPtr->b = color[BCOMP]; \
227 }
228
229 #include "swrast/s_linetemp.h"
230 }
231
232
233 /*
234 * Draw a flat-shaded, PF_5R6G5B line into an XImage.
235 */
236 static void flat_5R6G5B_line( GLcontext *ctx,
237 SWvertex *vert0, SWvertex *vert1 )
238 {
239 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
240 const GLubyte *color = vert0->color;
241 GLushort pixel = PACK_5R6G5B( color[0], color[1], color[2] );
242
243 #define PIXEL_TYPE GLushort
244 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
245 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
246 #define CLIP_HACK 1
247 #define PLOT(X,Y) *pixelPtr = pixel;
248
249 #include "swrast/s_linetemp.h"
250 }
251
252
253 /*
254 * Draw a flat-shaded, PF_DITHER_5R6G5B line into an XImage.
255 */
256 static void flat_DITHER_5R6G5B_line( GLcontext *ctx,
257 SWvertex *vert0, SWvertex *vert1 )
258 {
259 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
260 const GLubyte *color = vert0->color;
261
262 #define PIXEL_TYPE GLushort
263 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
264 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
265 #define CLIP_HACK 1
266 #define PLOT(X,Y) PACK_TRUEDITHER( *pixelPtr, X, Y, color[0], color[1], color[2] );
267
268 #include "swrast/s_linetemp.h"
269 }
270
271
272
273 /*
274 * Draw a flat-shaded, PF_DITHER 8-bit line into an XImage.
275 */
276 static void flat_DITHER8_line( GLcontext *ctx,
277 SWvertex *vert0, SWvertex *vert1 )
278 {
279 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
280 const GLubyte *color = vert0->color;
281 GLint r = color[0], g = color[1], b = color[2];
282 DITHER_SETUP;
283
284 #define INTERP_XY 1
285 #define PIXEL_TYPE GLubyte
286 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
287 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
288 #define CLIP_HACK 1
289 #define PLOT(X,Y) *pixelPtr = DITHER(X,Y,r,g,b);
290
291 #include "swrast/s_linetemp.h"
292 }
293
294
295 /*
296 * Draw a flat-shaded, PF_LOOKUP 8-bit line into an XImage.
297 */
298 static void flat_LOOKUP8_line( GLcontext *ctx,
299 SWvertex *vert0, SWvertex *vert1 )
300 {
301 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
302 const GLubyte *color = vert0->color;
303 GLubyte pixel;
304 LOOKUP_SETUP;
305 pixel = (GLubyte) LOOKUP( color[0], color[1], color[2] );
306
307 #define PIXEL_TYPE GLubyte
308 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
309 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
310 #define CLIP_HACK 1
311 #define PLOT(X,Y) *pixelPtr = pixel;
312
313 #include "swrast/s_linetemp.h"
314 }
315
316
317 /*
318 * Draw a flat-shaded, PF_HPCR line into an XImage.
319 */
320 static void flat_HPCR_line( GLcontext *ctx,
321 SWvertex *vert0, SWvertex *vert1 )
322 {
323 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
324 const GLubyte *color = vert0->color;
325 GLint r = color[0], g = color[1], b = color[2];
326
327 #define INTERP_XY 1
328 #define PIXEL_TYPE GLubyte
329 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
330 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
331 #define CLIP_HACK 1
332 #define PLOT(X,Y) *pixelPtr = (GLubyte) DITHER_HPCR(X,Y,r,g,b);
333
334 #include "swrast/s_linetemp.h"
335 }
336
337
338
339 /*
340 * Draw a flat-shaded, Z-less, PF_TRUECOLOR line into an XImage.
341 */
342 static void flat_TRUECOLOR_z_line( GLcontext *ctx,
343 SWvertex *vert0, SWvertex *vert1 )
344 {
345 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
346 const GLubyte *color = vert0->color;
347 XMesaImage *img = xmesa->xm_buffer->backimage;
348 unsigned long pixel;
349 PACK_TRUECOLOR( pixel, color[0], color[1], color[2] );
350
351 #define INTERP_XY 1
352 #define INTERP_Z 1
353 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
354 #define CLIP_HACK 1
355 #define PLOT(X,Y) \
356 if (Z < *zPtr) { \
357 *zPtr = Z; \
358 XMesaPutPixel( img, X, FLIP(xmesa->xm_buffer, Y), pixel ); \
359 }
360
361 #include "swrast/s_linetemp.h"
362 }
363
364
365 /*
366 * Draw a flat-shaded, Z-less, PF_8A8B8G8R line into an XImage.
367 */
368 static void flat_8A8B8G8R_z_line( GLcontext *ctx,
369 SWvertex *vert0, SWvertex *vert1 )
370 {
371 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
372 const GLubyte *color = vert0->color;
373 GLuint pixel = PACK_8B8G8R( color[0], color[1], color[2] );
374
375 #define INTERP_Z 1
376 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
377 #define PIXEL_TYPE GLuint
378 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
379 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
380 #define CLIP_HACK 1
381 #define PLOT(X,Y) \
382 if (Z < *zPtr) { \
383 *zPtr = Z; \
384 *pixelPtr = pixel; \
385 }
386
387 #include "swrast/s_linetemp.h"
388 }
389
390
391 /*
392 * Draw a flat-shaded, Z-less, PF_8R8G8B line into an XImage.
393 */
394 static void flat_8R8G8B_z_line( GLcontext *ctx,
395 SWvertex *vert0, SWvertex *vert1 )
396 {
397 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
398 const GLubyte *color = vert0->color;
399 GLuint pixel = PACK_8R8G8B( color[0], color[1], color[2] );
400
401 #define INTERP_Z 1
402 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
403 #define PIXEL_TYPE GLuint
404 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
405 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
406 #define CLIP_HACK 1
407 #define PLOT(X,Y) \
408 if (Z < *zPtr) { \
409 *zPtr = Z; \
410 *pixelPtr = pixel; \
411 }
412
413 #include "swrast/s_linetemp.h"
414 }
415
416
417 /*
418 * Draw a flat-shaded, Z-less, PF_8R8G8B24 line into an XImage.
419 */
420 static void flat_8R8G8B24_z_line( GLcontext *ctx,
421 SWvertex *vert0, SWvertex *vert1 )
422 {
423 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
424 const GLubyte *color = vert0->color;
425
426 #define INTERP_Z 1
427 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
428 #define PIXEL_TYPE bgr_t
429 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
430 #define PIXEL_ADDRESS(X,Y) PIXELADDR3(xmesa->xm_buffer,X,Y)
431 #define CLIP_HACK 1
432 #define PLOT(X,Y) \
433 if (Z < *zPtr) { \
434 *zPtr = Z; \
435 pixelPtr->r = color[RCOMP]; \
436 pixelPtr->g = color[GCOMP]; \
437 pixelPtr->b = color[BCOMP]; \
438 }
439
440 #include "swrast/s_linetemp.h"
441 }
442
443
444 /*
445 * Draw a flat-shaded, Z-less, PF_5R6G5B line into an XImage.
446 */
447 static void flat_5R6G5B_z_line( GLcontext *ctx,
448 SWvertex *vert0, SWvertex *vert1 )
449 {
450 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
451 const GLubyte *color = vert0->color;
452 GLushort pixel = PACK_5R6G5B( color[0], color[1], color[2] );
453
454 #define INTERP_Z 1
455 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
456 #define PIXEL_TYPE GLushort
457 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
458 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
459 #define CLIP_HACK 1
460 #define PLOT(X,Y) \
461 if (Z < *zPtr) { \
462 *zPtr = Z; \
463 *pixelPtr = pixel; \
464 }
465 #include "swrast/s_linetemp.h"
466 }
467
468
469 /*
470 * Draw a flat-shaded, Z-less, PF_DITHER_5R6G5B line into an XImage.
471 */
472 static void flat_DITHER_5R6G5B_z_line( GLcontext *ctx,
473 SWvertex *vert0, SWvertex *vert1 )
474 {
475 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
476 const GLubyte *color = vert0->color;
477
478 #define INTERP_Z 1
479 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
480 #define PIXEL_TYPE GLushort
481 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
482 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
483 #define CLIP_HACK 1
484 #define PLOT(X,Y) \
485 if (Z < *zPtr) { \
486 *zPtr = Z; \
487 PACK_TRUEDITHER(*pixelPtr, X, Y, color[0], color[1], color[2]); \
488 }
489 #include "swrast/s_linetemp.h"
490 }
491
492
493 /*
494 * Draw a flat-shaded, Z-less, PF_DITHER 8-bit line into an XImage.
495 */
496 static void flat_DITHER8_z_line( GLcontext *ctx,
497 SWvertex *vert0, SWvertex *vert1 )
498 {
499 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
500 const GLubyte *color = vert0->color;
501 GLint r = color[0], g = color[1], b = color[2];
502 DITHER_SETUP;
503
504 #define INTERP_XY 1
505 #define INTERP_Z 1
506 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
507 #define PIXEL_TYPE GLubyte
508 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
509 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
510 #define CLIP_HACK 1
511 #define PLOT(X,Y) \
512 if (Z < *zPtr) { \
513 *zPtr = Z; \
514 *pixelPtr = (GLubyte) DITHER( X, Y, r, g, b); \
515 }
516 #include "swrast/s_linetemp.h"
517 }
518
519
520 /*
521 * Draw a flat-shaded, Z-less, PF_LOOKUP 8-bit line into an XImage.
522 */
523 static void flat_LOOKUP8_z_line( GLcontext *ctx,
524 SWvertex *vert0, SWvertex *vert1 )
525 {
526 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
527 const GLubyte *color = vert0->color;
528 GLubyte pixel;
529 LOOKUP_SETUP;
530 pixel = (GLubyte) LOOKUP( color[0], color[1], color[2] );
531
532 #define INTERP_Z 1
533 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
534 #define PIXEL_TYPE GLubyte
535 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
536 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
537 #define CLIP_HACK 1
538 #define PLOT(X,Y) \
539 if (Z < *zPtr) { \
540 *zPtr = Z; \
541 *pixelPtr = pixel; \
542 }
543
544 #include "swrast/s_linetemp.h"
545 }
546
547
548 /*
549 * Draw a flat-shaded, Z-less, PF_HPCR line into an XImage.
550 */
551 static void flat_HPCR_z_line( GLcontext *ctx,
552 SWvertex *vert0, SWvertex *vert1 )
553 {
554 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
555 const GLubyte *color = vert0->color;
556 GLint r = color[0], g = color[1], b = color[2];
557
558 #define INTERP_XY 1
559 #define INTERP_Z 1
560 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
561 #define PIXEL_TYPE GLubyte
562 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
563 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
564 #define CLIP_HACK 1
565 #define PLOT(X,Y) \
566 if (Z < *zPtr) { \
567 *zPtr = Z; \
568 *pixelPtr = (GLubyte) DITHER_HPCR( X, Y, r, g, b); \
569 }
570
571 #include "swrast/s_linetemp.h"
572 }
573
574
575 static swrast_line_func get_line_func( GLcontext *ctx )
576 {
577 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
578 SWcontext *swrast = SWRAST_CONTEXT(ctx);
579 int depth = GET_VISUAL_DEPTH(xmesa->xm_visual);
580
581 (void) DitherValues; /* silence unused var warning */
582 (void) kernel1; /* silence unused var warning */
583
584 if (ctx->RenderMode != GL_RENDER) return (swrast_line_func) NULL;
585 if (ctx->Line.SmoothFlag) return (swrast_line_func) NULL;
586 if (ctx->Texture._ReallyEnabled) return (swrast_line_func) NULL;
587 if (ctx->Light.ShadeModel != GL_FLAT) return (swrast_line_func) NULL;
588 if (ctx->Line.StippleFlag) return (swrast_line_func) NULL;
589
590 if (xmesa->xm_buffer->buffer==XIMAGE
591 && swrast->_RasterMask==DEPTH_BIT
592 && ctx->Depth.Func==GL_LESS
593 && ctx->Depth.Mask==GL_TRUE
594 && ctx->Visual.DepthBits == DEFAULT_SOFTWARE_DEPTH_BITS
595 && ctx->Line.Width==1.0F) {
596 switch (xmesa->pixelformat) {
597 case PF_TRUECOLOR:
598 return flat_TRUECOLOR_z_line;
599 case PF_8A8B8G8R:
600 return flat_8A8B8G8R_z_line;
601 case PF_8R8G8B:
602 return flat_8R8G8B_z_line;
603 case PF_8R8G8B24:
604 return flat_8R8G8B24_z_line;
605 case PF_5R6G5B:
606 return flat_5R6G5B_z_line;
607 case PF_DITHER_5R6G5B:
608 return flat_DITHER_5R6G5B_z_line;
609 case PF_DITHER:
610 return (depth==8) ? flat_DITHER8_z_line : (swrast_line_func) NULL;
611 case PF_LOOKUP:
612 return (depth==8) ? flat_LOOKUP8_z_line : (swrast_line_func) NULL;
613 case PF_HPCR:
614 return flat_HPCR_z_line;
615 default:
616 return (swrast_line_func)NULL;
617 }
618 }
619 if (xmesa->xm_buffer->buffer==XIMAGE
620 && swrast->_RasterMask==0
621 && ctx->Line.Width==1.0F) {
622 switch (xmesa->pixelformat) {
623 case PF_TRUECOLOR:
624 return flat_TRUECOLOR_line;
625 case PF_8A8B8G8R:
626 return flat_8A8B8G8R_line;
627 case PF_8R8G8B:
628 return flat_8R8G8B_line;
629 case PF_8R8G8B24:
630 return flat_8R8G8B24_line;
631 case PF_5R6G5B:
632 return flat_5R6G5B_line;
633 case PF_DITHER_5R6G5B:
634 return flat_DITHER_5R6G5B_line;
635 case PF_DITHER:
636 return (depth==8) ? flat_DITHER8_line : (swrast_line_func) NULL;
637 case PF_LOOKUP:
638 return (depth==8) ? flat_LOOKUP8_line : (swrast_line_func) NULL;
639 case PF_HPCR:
640 return flat_HPCR_line;
641 default:
642 return (swrast_line_func)NULL;
643 }
644 }
645
646 return (swrast_line_func) NULL;
647 }
648
649 /* Override for the swrast line-selection function. Try to use one
650 * of our internal line functions, otherwise fall back to the
651 * standard swrast functions.
652 */
653 void xmesa_choose_line( GLcontext *ctx )
654 {
655 SWcontext *swrast = SWRAST_CONTEXT(ctx);
656
657 if (!(swrast->Line = get_line_func( ctx )))
658 _swrast_choose_line( ctx );
659 }
660
661
662 #define XMESA_NEW_POINT (_NEW_POINT | \
663 _NEW_RENDERMODE | \
664 _SWRAST_NEW_RASTERMASK)
665
666 #define XMESA_NEW_LINE (_NEW_LINE | \
667 _NEW_TEXTURE | \
668 _NEW_LIGHT | \
669 _NEW_DEPTH | \
670 _NEW_RENDERMODE | \
671 _SWRAST_NEW_RASTERMASK)
672
673 #define XMESA_NEW_TRIANGLE (_NEW_POLYGON | \
674 _NEW_TEXTURE | \
675 _NEW_LIGHT | \
676 _NEW_DEPTH | \
677 _NEW_RENDERMODE | \
678 _SWRAST_NEW_RASTERMASK)
679
680
681 /* Extend the software rasterizer with our line/point/triangle
682 * functions.
683 */
684 void xmesa_register_swrast_functions( GLcontext *ctx )
685 {
686 SWcontext *swrast = SWRAST_CONTEXT( ctx );
687
688 swrast->choose_point = xmesa_choose_point;
689 swrast->choose_line = xmesa_choose_line;
690 swrast->choose_triangle = xmesa_choose_triangle;
691
692 swrast->invalidate_point |= XMESA_NEW_POINT;
693 swrast->invalidate_line |= XMESA_NEW_LINE;
694 swrast->invalidate_triangle |= XMESA_NEW_TRIANGLE;
695 }