Moved the software rasterizer to a new directory.
[mesa.git] / src / mesa / drivers / x11 / xm_line.c
1 /* $Id: xm_line.c,v 1.5 2000/10/31 18:09:46 keithw 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
46
47 /**********************************************************************/
48 /*** Point rendering ***/
49 /**********************************************************************/
50
51
52 /*
53 * Render an array of points into a pixmap, any pixel format.
54 */
55 static void draw_points_ANY_pixmap( GLcontext *ctx, GLuint first, GLuint last )
56 {
57 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
58 XMesaDisplay *dpy = xmesa->xm_visual->display;
59 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
60 XMesaGC gc = xmesa->xm_buffer->gc2;
61 struct vertex_buffer *VB = ctx->VB;
62 register GLuint i;
63
64 if (xmesa->xm_visual->gl_visual->RGBAflag) {
65 /* RGB mode */
66 for (i=first;i<=last;i++) {
67 if (VB->ClipMask[i]==0) {
68 register int x, y;
69 const GLubyte *color = VB->ColorPtr->data[i];
70 unsigned long pixel = xmesa_color_to_pixel( xmesa,
71 color[0], color[1], color[2], color[3], xmesa->pixelformat);
72 XMesaSetForeground( dpy, gc, pixel );
73 x = (GLint) VB->Win.data[i][0];
74 y = FLIP( xmesa->xm_buffer, (GLint) VB->Win.data[i][1] );
75 XMesaDrawPoint( dpy, buffer, gc, x, y);
76 }
77 }
78 }
79 else {
80 /* Color index mode */
81 for (i=first;i<=last;i++) {
82 if (VB->ClipMask[i]==0) {
83 register int x, y;
84 XMesaSetForeground( dpy, gc, VB->IndexPtr->data[i] );
85 x = (GLint) VB->Win.data[i][0];
86 y = FLIP( xmesa->xm_buffer, (GLint) VB->Win.data[i][1] );
87 XMesaDrawPoint( dpy, buffer, gc, x, y);
88 }
89 }
90 }
91 }
92
93
94
95 /*
96 * Analyze context state to see if we can provide a fast points drawing
97 * function, like those in points.c. Otherwise, return NULL.
98 */
99 points_func xmesa_get_points_func( GLcontext *ctx )
100 {
101 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
102
103 if (ctx->Point.Size==1.0F && !ctx->Point.SmoothFlag && ctx->RasterMask==0
104 && !ctx->Texture.ReallyEnabled) {
105 if (xmesa->xm_buffer->buffer==XIMAGE) {
106 return (points_func) NULL; /*draw_points_ximage;*/
107 }
108 else {
109 return draw_points_ANY_pixmap;
110 }
111 }
112 else {
113 return (points_func) NULL;
114 }
115 }
116
117
118
119 /**********************************************************************/
120 /*** Line rendering ***/
121 /**********************************************************************/
122
123
124 #if 0
125 /*
126 * Render a line into a pixmap, any pixel format.
127 */
128 static void flat_pixmap_line( GLcontext *ctx,
129 GLuint vert0, GLuint vert1, GLuint pv )
130 {
131 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
132 struct vertex_buffer *VB = ctx->VB;
133 register int x0, y0, x1, y1;
134 XMesaGC gc;
135 unsigned long pixel;
136 if (xmesa->xm_visual->gl_visual->RGBAflag) {
137 const GLubyte *color = VB->ColorPtr->data[pv];
138 pixel = xmesa_color_to_pixel( xmesa, color[0], color[1], color[2], color[3],
139 xmesa->pixelformat );
140 }
141 else {
142 pixel = VB->IndexPtr->data[pv];
143 }
144 gc = xmesa->xm_buffer->gc2;
145 XMesaSetForeground( xmesa->display, gc, pixel );
146
147 x0 = (GLint) VB->Win.data[vert0][0];
148 y0 = FLIP( xmesa->xm_buffer, (GLint) VB->Win.data[vert0][1] );
149 x1 = (GLint) VB->Win.data[vert1][0];
150 y1 = FLIP( xmesa->xm_buffer, (GLint) VB->Win.data[vert1][1] );
151 XMesaDrawLine( xmesa->display, xmesa->xm_buffer->buffer, gc,
152 x0, y0, x1, y1 );
153 }
154 #endif
155
156
157 /*
158 * Draw a flat-shaded, PF_TRUECOLOR line into an XImage.
159 */
160 static void flat_TRUECOLOR_line( GLcontext *ctx,
161 GLuint vert0, GLuint vert1, GLuint pv )
162 {
163 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
164 const GLubyte *color = ctx->VB->ColorPtr->data[pv];
165 XMesaImage *img = xmesa->xm_buffer->backimage;
166 unsigned long pixel;
167 PACK_TRUECOLOR( pixel, color[0], color[1], color[2] );
168
169 #define INTERP_XY 1
170 #define CLIP_HACK 1
171 #define PLOT(X,Y) XMesaPutPixel( img, X, FLIP(xmesa->xm_buffer, Y), pixel );
172
173 #include "swrast/s_linetemp.h"
174 }
175
176
177
178 /*
179 * Draw a flat-shaded, PF_8A8B8G8R line into an XImage.
180 */
181 static void flat_8A8B8G8R_line( GLcontext *ctx,
182 GLuint vert0, GLuint vert1, GLuint pv )
183 {
184 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
185 const GLubyte *color = ctx->VB->ColorPtr->data[pv];
186 GLuint pixel = PACK_8B8G8R( color[0], color[1], color[2] );
187
188 #define PIXEL_TYPE GLuint
189 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
190 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
191 #define CLIP_HACK 1
192 #define PLOT(X,Y) *pixelPtr = pixel;
193
194 #include "swrast/s_linetemp.h"
195 }
196
197
198 /*
199 * Draw a flat-shaded, PF_8R8G8B line into an XImage.
200 */
201 static void flat_8R8G8B_line( GLcontext *ctx,
202 GLuint vert0, GLuint vert1, GLuint pv )
203 {
204 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
205 const GLubyte *color = ctx->VB->ColorPtr->data[pv];
206 GLuint pixel = PACK_8R8G8B( color[0], color[1], color[2] );
207
208 #define PIXEL_TYPE GLuint
209 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
210 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
211 #define CLIP_HACK 1
212 #define PLOT(X,Y) *pixelPtr = pixel;
213
214 #include "swrast/s_linetemp.h"
215 }
216
217
218 /*
219 * Draw a flat-shaded, PF_8R8G8B24 line into an XImage.
220 */
221 static void flat_8R8G8B24_line( GLcontext *ctx,
222 GLuint vert0, GLuint vert1, GLuint pv )
223 {
224 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
225 const GLubyte *color = ctx->VB->ColorPtr->data[pv];
226
227 #define PIXEL_TYPE bgr_t
228 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
229 #define PIXEL_ADDRESS(X,Y) PIXELADDR3(xmesa->xm_buffer,X,Y)
230 #define CLIP_HACK 1
231 #define PLOT(X,Y) { \
232 pixelPtr->r = color[RCOMP]; \
233 pixelPtr->g = color[GCOMP]; \
234 pixelPtr->b = color[BCOMP]; \
235 }
236
237 #include "swrast/s_linetemp.h"
238 }
239
240
241 /*
242 * Draw a flat-shaded, PF_5R6G5B line into an XImage.
243 */
244 static void flat_5R6G5B_line( GLcontext *ctx,
245 GLuint vert0, GLuint vert1, GLuint pv )
246 {
247 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
248 const GLubyte *color = ctx->VB->ColorPtr->data[pv];
249 GLushort pixel = PACK_5R6G5B( color[0], color[1], color[2] );
250
251 #define PIXEL_TYPE GLushort
252 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
253 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
254 #define CLIP_HACK 1
255 #define PLOT(X,Y) *pixelPtr = pixel;
256
257 #include "swrast/s_linetemp.h"
258 }
259
260
261 /*
262 * Draw a flat-shaded, PF_DITHER_5R6G5B line into an XImage.
263 */
264 static void flat_DITHER_5R6G5B_line( GLcontext *ctx,
265 GLuint vert0, GLuint vert1, GLuint pv )
266 {
267 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
268 const GLubyte *color = ctx->VB->ColorPtr->data[pv];
269
270 #define PIXEL_TYPE GLushort
271 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
272 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
273 #define CLIP_HACK 1
274 #define PLOT(X,Y) PACK_TRUEDITHER( *pixelPtr, X, Y, color[0], color[1], color[2] );
275
276 #include "swrast/s_linetemp.h"
277 }
278
279
280
281 /*
282 * Draw a flat-shaded, PF_DITHER 8-bit line into an XImage.
283 */
284 static void flat_DITHER8_line( GLcontext *ctx,
285 GLuint vert0, GLuint vert1, GLuint pv )
286 {
287 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
288 const GLubyte *color = ctx->VB->ColorPtr->data[pv];
289 GLint r = color[0], g = color[1], b = color[2];
290 DITHER_SETUP;
291
292 #define INTERP_XY 1
293 #define PIXEL_TYPE GLubyte
294 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
295 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
296 #define CLIP_HACK 1
297 #define PLOT(X,Y) *pixelPtr = DITHER(X,Y,r,g,b);
298
299 #include "swrast/s_linetemp.h"
300 }
301
302
303 /*
304 * Draw a flat-shaded, PF_LOOKUP 8-bit line into an XImage.
305 */
306 static void flat_LOOKUP8_line( GLcontext *ctx,
307 GLuint vert0, GLuint vert1, GLuint pv )
308 {
309 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
310 const GLubyte *color = ctx->VB->ColorPtr->data[pv];
311 GLubyte pixel;
312 LOOKUP_SETUP;
313 pixel = (GLubyte) LOOKUP( color[0], color[1], color[2] );
314
315 #define PIXEL_TYPE GLubyte
316 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
317 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
318 #define CLIP_HACK 1
319 #define PLOT(X,Y) *pixelPtr = pixel;
320
321 #include "swrast/s_linetemp.h"
322 }
323
324
325 /*
326 * Draw a flat-shaded, PF_HPCR line into an XImage.
327 */
328 static void flat_HPCR_line( GLcontext *ctx,
329 GLuint vert0, GLuint vert1, GLuint pv )
330 {
331 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
332 const GLubyte *color = ctx->VB->ColorPtr->data[pv];
333 GLint r = color[0], g = color[1], b = color[2];
334
335 #define INTERP_XY 1
336 #define PIXEL_TYPE GLubyte
337 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
338 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
339 #define CLIP_HACK 1
340 #define PLOT(X,Y) *pixelPtr = (GLubyte) DITHER_HPCR(X,Y,r,g,b);
341
342 #include "swrast/s_linetemp.h"
343 }
344
345
346
347 /*
348 * Draw a flat-shaded, Z-less, PF_TRUECOLOR line into an XImage.
349 */
350 static void flat_TRUECOLOR_z_line( GLcontext *ctx,
351 GLuint vert0, GLuint vert1, GLuint pv )
352 {
353 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
354 const GLubyte *color = ctx->VB->ColorPtr->data[pv];
355 XMesaImage *img = xmesa->xm_buffer->backimage;
356 unsigned long pixel;
357 PACK_TRUECOLOR( pixel, color[0], color[1], color[2] );
358
359 #define INTERP_XY 1
360 #define INTERP_Z 1
361 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
362 #define CLIP_HACK 1
363 #define PLOT(X,Y) \
364 if (Z < *zPtr) { \
365 *zPtr = Z; \
366 XMesaPutPixel( img, X, FLIP(xmesa->xm_buffer, Y), pixel ); \
367 }
368
369 #include "swrast/s_linetemp.h"
370 }
371
372
373 /*
374 * Draw a flat-shaded, Z-less, PF_8A8B8G8R line into an XImage.
375 */
376 static void flat_8A8B8G8R_z_line( GLcontext *ctx,
377 GLuint vert0, GLuint vert1, GLuint pv )
378 {
379 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
380 const GLubyte *color = ctx->VB->ColorPtr->data[pv];
381 GLuint pixel = PACK_8B8G8R( color[0], color[1], color[2] );
382
383 #define INTERP_Z 1
384 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
385 #define PIXEL_TYPE GLuint
386 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
387 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
388 #define CLIP_HACK 1
389 #define PLOT(X,Y) \
390 if (Z < *zPtr) { \
391 *zPtr = Z; \
392 *pixelPtr = pixel; \
393 }
394
395 #include "swrast/s_linetemp.h"
396 }
397
398
399 /*
400 * Draw a flat-shaded, Z-less, PF_8R8G8B line into an XImage.
401 */
402 static void flat_8R8G8B_z_line( GLcontext *ctx,
403 GLuint vert0, GLuint vert1, GLuint pv )
404 {
405 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
406 const GLubyte *color = ctx->VB->ColorPtr->data[pv];
407 GLuint pixel = PACK_8R8G8B( color[0], color[1], color[2] );
408
409 #define INTERP_Z 1
410 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
411 #define PIXEL_TYPE GLuint
412 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
413 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
414 #define CLIP_HACK 1
415 #define PLOT(X,Y) \
416 if (Z < *zPtr) { \
417 *zPtr = Z; \
418 *pixelPtr = pixel; \
419 }
420
421 #include "swrast/s_linetemp.h"
422 }
423
424
425 /*
426 * Draw a flat-shaded, Z-less, PF_8R8G8B24 line into an XImage.
427 */
428 static void flat_8R8G8B24_z_line( GLcontext *ctx,
429 GLuint vert0, GLuint vert1, GLuint pv )
430 {
431 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
432 const GLubyte *color = ctx->VB->ColorPtr->data[pv];
433
434 #define INTERP_Z 1
435 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
436 #define PIXEL_TYPE bgr_t
437 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
438 #define PIXEL_ADDRESS(X,Y) PIXELADDR3(xmesa->xm_buffer,X,Y)
439 #define CLIP_HACK 1
440 #define PLOT(X,Y) \
441 if (Z < *zPtr) { \
442 *zPtr = Z; \
443 pixelPtr->r = color[RCOMP]; \
444 pixelPtr->g = color[GCOMP]; \
445 pixelPtr->b = color[BCOMP]; \
446 }
447
448 #include "swrast/s_linetemp.h"
449 }
450
451
452 /*
453 * Draw a flat-shaded, Z-less, PF_5R6G5B line into an XImage.
454 */
455 static void flat_5R6G5B_z_line( GLcontext *ctx,
456 GLuint vert0, GLuint vert1, GLuint pv )
457 {
458 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
459 const GLubyte *color = ctx->VB->ColorPtr->data[pv];
460 GLushort pixel = PACK_5R6G5B( color[0], color[1], color[2] );
461
462 #define INTERP_Z 1
463 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
464 #define PIXEL_TYPE GLushort
465 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
466 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
467 #define CLIP_HACK 1
468 #define PLOT(X,Y) \
469 if (Z < *zPtr) { \
470 *zPtr = Z; \
471 *pixelPtr = pixel; \
472 }
473 #include "swrast/s_linetemp.h"
474 }
475
476
477 /*
478 * Draw a flat-shaded, Z-less, PF_DITHER_5R6G5B line into an XImage.
479 */
480 static void flat_DITHER_5R6G5B_z_line( GLcontext *ctx,
481 GLuint vert0, GLuint vert1, GLuint pv )
482 {
483 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
484 const GLubyte *color = ctx->VB->ColorPtr->data[pv];
485
486 #define INTERP_Z 1
487 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
488 #define PIXEL_TYPE GLushort
489 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
490 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
491 #define CLIP_HACK 1
492 #define PLOT(X,Y) \
493 if (Z < *zPtr) { \
494 *zPtr = Z; \
495 PACK_TRUEDITHER(*pixelPtr, X, Y, color[0], color[1], color[2]); \
496 }
497 #include "swrast/s_linetemp.h"
498 }
499
500
501 /*
502 * Draw a flat-shaded, Z-less, PF_DITHER 8-bit line into an XImage.
503 */
504 static void flat_DITHER8_z_line( GLcontext *ctx,
505 GLuint vert0, GLuint vert1, GLuint pv )
506 {
507 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
508 const GLubyte *color = ctx->VB->ColorPtr->data[pv];
509 GLint r = color[0], g = color[1], b = color[2];
510 DITHER_SETUP;
511
512 #define INTERP_XY 1
513 #define INTERP_Z 1
514 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
515 #define PIXEL_TYPE GLubyte
516 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
517 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
518 #define CLIP_HACK 1
519 #define PLOT(X,Y) \
520 if (Z < *zPtr) { \
521 *zPtr = Z; \
522 *pixelPtr = (GLubyte) DITHER( X, Y, r, g, b); \
523 }
524 #include "swrast/s_linetemp.h"
525 }
526
527
528 /*
529 * Draw a flat-shaded, Z-less, PF_LOOKUP 8-bit line into an XImage.
530 */
531 static void flat_LOOKUP8_z_line( GLcontext *ctx,
532 GLuint vert0, GLuint vert1, GLuint pv )
533 {
534 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
535 const GLubyte *color = ctx->VB->ColorPtr->data[pv];
536 GLubyte pixel;
537 LOOKUP_SETUP;
538 pixel = (GLubyte) LOOKUP( color[0], color[1], color[2] );
539
540 #define INTERP_Z 1
541 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
542 #define PIXEL_TYPE GLubyte
543 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
544 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
545 #define CLIP_HACK 1
546 #define PLOT(X,Y) \
547 if (Z < *zPtr) { \
548 *zPtr = Z; \
549 *pixelPtr = pixel; \
550 }
551
552 #include "swrast/s_linetemp.h"
553 }
554
555
556 /*
557 * Draw a flat-shaded, Z-less, PF_HPCR line into an XImage.
558 */
559 static void flat_HPCR_z_line( GLcontext *ctx,
560 GLuint vert0, GLuint vert1, GLuint pv )
561 {
562 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
563 const GLubyte *color = ctx->VB->ColorPtr->data[pv];
564 GLint r = color[0], g = color[1], b = color[2];
565
566 #define INTERP_XY 1
567 #define INTERP_Z 1
568 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
569 #define PIXEL_TYPE GLubyte
570 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
571 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
572 #define CLIP_HACK 1
573 #define PLOT(X,Y) \
574 if (Z < *zPtr) { \
575 *zPtr = Z; \
576 *pixelPtr = (GLubyte) DITHER_HPCR( X, Y, r, g, b); \
577 }
578
579 #include "swrast/s_linetemp.h"
580 }
581
582
583 #if 0
584 /*
585 * Examine ctx->Line attributes and set xmesa->xm_buffer->gc1
586 * and xmesa->xm_buffer->gc2 appropriately.
587 */
588 static void setup_x_line_options( GLcontext *ctx )
589 {
590 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
591 int i, state, state0, new_state, len, offs;
592 int tbit;
593 char *dptr;
594 int n_segments = 0;
595 char dashes[20];
596 int line_width, line_style;
597
598 /*** Line Stipple ***/
599 if (ctx->Line.StippleFlag) {
600 const int pattern = ctx->Line.StipplePattern;
601
602 dptr = dashes;
603 state0 = state = ((pattern & 1) != 0);
604
605 /* Decompose the pattern */
606 for (i=1,tbit=2,len=1;i<16;++i,tbit=(tbit<<1))
607 {
608 new_state = ((tbit & pattern) != 0);
609 if (state != new_state)
610 {
611 *dptr++ = ctx->Line.StippleFactor * len;
612 len = 1;
613 state = new_state;
614 }
615 else
616 ++len;
617 }
618 *dptr = ctx->Line.StippleFactor * len;
619 n_segments = 1 + (dptr - dashes);
620
621 /* ensure an even no. of segments, or X may toggle on/off for consecutive patterns */
622 /* if (n_segments & 1) dashes [n_segments++] = 0; value of 0 not allowed in dash list */
623
624 /* Handle case where line style starts OFF */
625 if (state0 == 0)
626 offs = dashes[0];
627 else
628 offs = 0;
629
630 #if 0
631 fprintf (stderr, "input pattern: 0x%04x, offset %d, %d segments:", pattern, offs, n_segments);
632 for (i = 0; i < n_segments; i++)
633 fprintf (stderr, " %d", dashes[i]);
634 fprintf (stderr, "\n");
635 #endif
636
637 XMesaSetDashes( xmesa->display, xmesa->xm_buffer->gc1,
638 offs, dashes, n_segments );
639 XMesaSetDashes( xmesa->display, xmesa->xm_buffer->gc2,
640 offs, dashes, n_segments );
641
642 line_style = LineOnOffDash;
643 }
644 else {
645 line_style = LineSolid;
646 }
647
648 /*** Line Width ***/
649 line_width = (int) (ctx->Line.Width+0.5F);
650 if (line_width < 2) {
651 /* Use fast lines when possible */
652 line_width = 0;
653 }
654
655 /*** Set GC attributes ***/
656 XMesaSetLineAttributes( xmesa->display, xmesa->xm_buffer->gc1,
657 line_width, line_style, CapButt, JoinBevel);
658 XMesaSetLineAttributes( xmesa->display, xmesa->xm_buffer->gc2,
659 line_width, line_style, CapButt, JoinBevel);
660 XMesaSetFillStyle( xmesa->display, xmesa->xm_buffer->gc1, FillSolid );
661 XMesaSetFillStyle( xmesa->display, xmesa->xm_buffer->gc2, FillSolid );
662 }
663 #endif
664
665
666
667 /*
668 * Analyze context state to see if we can provide a fast line drawing
669 * function, like those in lines.c. Otherwise, return NULL.
670 */
671 line_func xmesa_get_line_func( GLcontext *ctx )
672 {
673 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
674 int depth = GET_VISUAL_DEPTH(xmesa->xm_visual);
675
676 (void) DitherValues; /* silence unused var warning */
677 (void) kernel1; /* silence unused var warning */
678
679 if (ctx->Line.SmoothFlag) return (line_func)NULL;
680 if (ctx->Texture.ReallyEnabled) return (line_func)NULL;
681 if (ctx->Light.ShadeModel!=GL_FLAT) return (line_func)NULL;
682 /* X line stippling doesn't match OpenGL stippling */
683 if (ctx->Line.StippleFlag==GL_TRUE) return (line_func)NULL;
684
685 if (xmesa->xm_buffer->buffer==XIMAGE
686 && ctx->RasterMask==DEPTH_BIT
687 && ctx->Depth.Func==GL_LESS
688 && ctx->Depth.Mask==GL_TRUE
689 && ctx->Visual.DepthBits == DEFAULT_SOFTWARE_DEPTH_BITS
690 && ctx->Line.Width==1.0F) {
691 switch (xmesa->pixelformat) {
692 case PF_TRUECOLOR:
693 return flat_TRUECOLOR_z_line;
694 case PF_8A8B8G8R:
695 return flat_8A8B8G8R_z_line;
696 case PF_8R8G8B:
697 return flat_8R8G8B_z_line;
698 case PF_8R8G8B24:
699 return flat_8R8G8B24_z_line;
700 case PF_5R6G5B:
701 return flat_5R6G5B_z_line;
702 case PF_DITHER_5R6G5B:
703 return flat_DITHER_5R6G5B_z_line;
704 case PF_DITHER:
705 return (depth==8) ? flat_DITHER8_z_line : (line_func)NULL;
706 case PF_LOOKUP:
707 return (depth==8) ? flat_LOOKUP8_z_line : (line_func)NULL;
708 case PF_HPCR:
709 return flat_HPCR_z_line;
710 default:
711 return (line_func)NULL;
712 }
713 }
714 if (xmesa->xm_buffer->buffer==XIMAGE
715 && ctx->RasterMask==0
716 && ctx->Line.Width==1.0F) {
717 switch (xmesa->pixelformat) {
718 case PF_TRUECOLOR:
719 return flat_TRUECOLOR_line;
720 case PF_8A8B8G8R:
721 return flat_8A8B8G8R_line;
722 case PF_8R8G8B:
723 return flat_8R8G8B_line;
724 case PF_8R8G8B24:
725 return flat_8R8G8B24_line;
726 case PF_5R6G5B:
727 return flat_5R6G5B_line;
728 case PF_DITHER_5R6G5B:
729 return flat_DITHER_5R6G5B_line;
730 case PF_DITHER:
731 return (depth==8) ? flat_DITHER8_line : (line_func)NULL;
732 case PF_LOOKUP:
733 return (depth==8) ? flat_LOOKUP8_line : (line_func)NULL;
734 case PF_HPCR:
735 return flat_HPCR_line;
736 default:
737 return (line_func)NULL;
738 }
739 }
740 #if 0
741 /* XXX have to disable this because X's rasterization rules don't match
742 * software Mesa's. This causes the linehv.c conformance test to fail.
743 * In the future, we might provide a config option to enable this.
744 */
745 if (xmesa->xm_buffer->buffer!=XIMAGE && ctx->RasterMask==0) {
746 setup_x_line_options( ctx );
747 return flat_pixmap_line;
748 }
749 #endif
750 return (line_func)NULL;
751 }