1 /* $Id: xm_line.c,v 1.24 2003/04/01 17:28:12 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
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.
35 #include "glxheader.h"
41 /* Internal swrast includes:
43 #include "swrast/s_depth.h"
44 #include "swrast/s_points.h"
45 #include "swrast/s_lines.h"
46 #include "swrast/s_context.h"
49 /**********************************************************************/
50 /*** Point rendering ***/
51 /**********************************************************************/
55 * Render an array of points into a pixmap, any pixel format.
58 /* XXX don't use this, it doesn't dither correctly */
59 static void draw_points_ANY_pixmap( GLcontext
*ctx
, const SWvertex
*vert
)
61 XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
62 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
63 XMesaDrawable buffer
= xmesa
->xm_buffer
->buffer
;
64 XMesaGC gc
= xmesa
->xm_buffer
->gc
;
66 if (xmesa
->xm_visual
->mesa_visual
.RGBAflag
) {
68 const GLubyte
*color
= vert
->color
;
69 unsigned long pixel
= xmesa_color_to_pixel( xmesa
,
73 XMesaSetForeground( dpy
, gc
, pixel
);
74 x
= (GLint
) vert
->win
[0];
75 y
= FLIP( xmesa
->xm_buffer
, (GLint
) vert
->win
[1] );
76 XMesaDrawPoint( dpy
, buffer
, gc
, x
, y
);
79 /* Color index mode */
81 XMesaSetForeground( dpy
, gc
, vert
->index
);
82 x
= (GLint
) vert
->win
[0];
83 y
= FLIP( xmesa
->xm_buffer
, (GLint
) vert
->win
[1] );
84 XMesaDrawPoint( dpy
, buffer
, gc
, x
, y
);
90 /* Override the swrast point-selection function. Try to use one of
91 * our internal point functions, otherwise fall back to the standard
94 void xmesa_choose_point( GLcontext
*ctx
)
97 XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
98 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
100 if (ctx
->RenderMode
== GL_RENDER
101 && ctx
->Point
.Size
== 1.0F
&& !ctx
->Point
.SmoothFlag
102 && swrast
->_RasterMask
== 0
103 && !ctx
->Texture
._EnabledUnits
104 && xmesa
->xm_buffer
->buffer
!= XIMAGE
) {
105 swrast
->Point
= draw_points_ANY_pixmap
;
108 _swrast_choose_point( ctx
);
111 _swrast_choose_point( ctx
);
117 /**********************************************************************/
118 /*** Line rendering ***/
119 /**********************************************************************/
123 * Draw a flat-shaded, PF_TRUECOLOR line into an XImage.
125 #define NAME flat_TRUECOLOR_line
127 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
128 const GLubyte *color = vert1->color; \
129 XMesaImage *img = xmesa->xm_buffer->backimage; \
130 unsigned long pixel; \
131 PACK_TRUECOLOR( pixel, color[0], color[1], color[2] );
133 #define PLOT(X,Y) XMesaPutPixel( img, X, FLIP(xmesa->xm_buffer, Y), pixel );
134 #include "swrast/s_linetemp.h"
139 * Draw a flat-shaded, PF_8A8B8G8R line into an XImage.
141 #define NAME flat_8A8B8G8R_line
143 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
144 const GLubyte *color = vert1->color; \
145 GLuint pixel = PACK_8B8G8R( color[0], color[1], color[2] );
146 #define PIXEL_TYPE GLuint
147 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
148 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
150 #define PLOT(X,Y) *pixelPtr = pixel;
151 #include "swrast/s_linetemp.h"
156 * Draw a flat-shaded, PF_8R8G8B line into an XImage.
158 #define NAME flat_8R8G8B_line
160 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
161 const GLubyte *color = vert1->color; \
162 GLuint pixel = PACK_8R8G8B( color[0], color[1], color[2] );
163 #define PIXEL_TYPE GLuint
164 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
165 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
167 #define PLOT(X,Y) *pixelPtr = pixel;
168 #include "swrast/s_linetemp.h"
173 * Draw a flat-shaded, PF_8R8G8B24 line into an XImage.
175 #define NAME flat_8R8G8B24_line
177 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
178 const GLubyte *color = vert1->color;
179 #define PIXEL_TYPE bgr_t
180 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
181 #define PIXEL_ADDRESS(X,Y) PIXELADDR3(xmesa->xm_buffer,X,Y)
183 #define PLOT(X,Y) { \
184 pixelPtr->r = color[RCOMP]; \
185 pixelPtr->g = color[GCOMP]; \
186 pixelPtr->b = color[BCOMP]; \
188 #include "swrast/s_linetemp.h"
193 * Draw a flat-shaded, PF_5R6G5B line into an XImage.
195 #define NAME flat_5R6G5B_line
197 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
198 const GLubyte *color = vert1->color; \
199 GLushort pixel = PACK_5R6G5B( color[0], color[1], color[2] );
200 #define PIXEL_TYPE GLushort
201 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
202 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
204 #define PLOT(X,Y) *pixelPtr = pixel;
205 #include "swrast/s_linetemp.h"
210 * Draw a flat-shaded, PF_DITHER_5R6G5B line into an XImage.
212 #define NAME flat_DITHER_5R6G5B_line
214 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
215 const GLubyte *color = vert1->color;
216 #define PIXEL_TYPE GLushort
217 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
218 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
220 #define PLOT(X,Y) PACK_TRUEDITHER( *pixelPtr, X, Y, color[0], color[1], color[2] );
221 #include "swrast/s_linetemp.h"
227 * Draw a flat-shaded, PF_DITHER 8-bit line into an XImage.
229 #define NAME flat_DITHER8_line
231 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
232 const GLubyte *color = vert1->color; \
233 GLint r = color[0], g = color[1], b = color[2]; \
235 #define PIXEL_TYPE GLubyte
236 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
237 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
239 #define PLOT(X,Y) *pixelPtr = DITHER(X,Y,r,g,b);
240 #include "swrast/s_linetemp.h"
245 * Draw a flat-shaded, PF_LOOKUP 8-bit line into an XImage.
247 #define NAME flat_LOOKUP8_line
249 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
250 const GLubyte *color = vert1->color; \
253 pixel = (GLubyte) LOOKUP( color[0], color[1], color[2] );
254 #define PIXEL_TYPE GLubyte
255 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
256 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
258 #define PLOT(X,Y) *pixelPtr = pixel;
259 #include "swrast/s_linetemp.h"
264 * Draw a flat-shaded, PF_HPCR line into an XImage.
266 #define NAME flat_HPCR_line
268 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
269 const GLubyte *color = vert1->color; \
270 GLint r = color[0], g = color[1], b = color[2];
271 #define PIXEL_TYPE GLubyte
272 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
273 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
275 #define PLOT(X,Y) *pixelPtr = (GLubyte) DITHER_HPCR(X,Y,r,g,b);
276 #include "swrast/s_linetemp.h"
282 * Draw a flat-shaded, Z-less, PF_TRUECOLOR line into an XImage.
284 #define NAME flat_TRUECOLOR_z_line
286 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
287 const GLubyte *color = vert1->color; \
288 XMesaImage *img = xmesa->xm_buffer->backimage; \
289 unsigned long pixel; \
290 PACK_TRUECOLOR( pixel, color[0], color[1], color[2] );
292 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
297 XMesaPutPixel( img, X, FLIP(xmesa->xm_buffer, Y), pixel ); \
299 #include "swrast/s_linetemp.h"
304 * Draw a flat-shaded, Z-less, PF_8A8B8G8R line into an XImage.
306 #define NAME flat_8A8B8G8R_z_line
308 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
309 const GLubyte *color = vert1->color; \
310 GLuint pixel = PACK_8B8G8R( color[0], color[1], color[2] );
312 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
313 #define PIXEL_TYPE GLuint
314 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
315 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
322 #include "swrast/s_linetemp.h"
327 * Draw a flat-shaded, Z-less, PF_8R8G8B line into an XImage.
329 #define NAME flat_8R8G8B_z_line
331 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
332 const GLubyte *color = vert1->color; \
333 GLuint pixel = PACK_8R8G8B( color[0], color[1], color[2] );
335 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
336 #define PIXEL_TYPE GLuint
337 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
338 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
345 #include "swrast/s_linetemp.h"
350 * Draw a flat-shaded, Z-less, PF_8R8G8B24 line into an XImage.
352 #define NAME flat_8R8G8B24_z_line
354 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
355 const GLubyte *color = vert1->color;
357 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
358 #define PIXEL_TYPE bgr_t
359 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
360 #define PIXEL_ADDRESS(X,Y) PIXELADDR3(xmesa->xm_buffer,X,Y)
365 pixelPtr->r = color[RCOMP]; \
366 pixelPtr->g = color[GCOMP]; \
367 pixelPtr->b = color[BCOMP]; \
369 #include "swrast/s_linetemp.h"
374 * Draw a flat-shaded, Z-less, PF_5R6G5B line into an XImage.
376 #define NAME flat_5R6G5B_z_line
378 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
379 const GLubyte *color = vert1->color; \
380 GLushort pixel = PACK_5R6G5B( color[0], color[1], color[2] );
382 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
383 #define PIXEL_TYPE GLushort
384 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
385 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
392 #include "swrast/s_linetemp.h"
397 * Draw a flat-shaded, Z-less, PF_DITHER_5R6G5B line into an XImage.
399 #define NAME flat_DITHER_5R6G5B_z_line
401 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
402 const GLubyte *color = vert1->color;
404 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
405 #define PIXEL_TYPE GLushort
406 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
407 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
412 PACK_TRUEDITHER(*pixelPtr, X, Y, color[0], color[1], color[2]); \
414 #include "swrast/s_linetemp.h"
419 * Draw a flat-shaded, Z-less, PF_DITHER 8-bit line into an XImage.
421 #define NAME flat_DITHER8_z_line
423 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
424 const GLubyte *color = vert1->color; \
425 GLint r = color[0], g = color[1], b = color[2]; \
428 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
429 #define PIXEL_TYPE GLubyte
430 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
431 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
436 *pixelPtr = (GLubyte) DITHER( X, Y, r, g, b); \
438 #include "swrast/s_linetemp.h"
443 * Draw a flat-shaded, Z-less, PF_LOOKUP 8-bit line into an XImage.
445 #define NAME flat_LOOKUP8_z_line
447 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
448 const GLubyte *color = vert1->color; \
451 pixel = (GLubyte) LOOKUP( color[0], color[1], color[2] );
453 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
454 #define PIXEL_TYPE GLubyte
455 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
456 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
463 #include "swrast/s_linetemp.h"
468 * Draw a flat-shaded, Z-less, PF_HPCR line into an XImage.
470 #define NAME flat_HPCR_z_line
472 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
473 const GLubyte *color = vert1->color; \
474 GLint r = color[0], g = color[1], b = color[2];
476 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
477 #define PIXEL_TYPE GLubyte
478 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
479 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
484 *pixelPtr = (GLubyte) DITHER_HPCR( X, Y, r, g, b); \
486 #include "swrast/s_linetemp.h"
490 static swrast_line_func
get_line_func( GLcontext
*ctx
)
492 XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
493 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
494 int depth
= GET_VISUAL_DEPTH(xmesa
->xm_visual
);
496 (void) DitherValues
; /* silence unused var warning */
497 (void) kernel1
; /* silence unused var warning */
499 if (ctx
->RenderMode
!= GL_RENDER
) return (swrast_line_func
) NULL
;
500 if (ctx
->Line
.SmoothFlag
) return (swrast_line_func
) NULL
;
501 if (ctx
->Texture
._EnabledUnits
) return (swrast_line_func
) NULL
;
502 if (ctx
->Light
.ShadeModel
!= GL_FLAT
) return (swrast_line_func
) NULL
;
503 if (ctx
->Line
.StippleFlag
) return (swrast_line_func
) NULL
;
504 if (swrast
->_RasterMask
& MULTI_DRAW_BIT
) return (swrast_line_func
) NULL
;
506 if (xmesa
->xm_buffer
->buffer
==XIMAGE
507 && swrast
->_RasterMask
==DEPTH_BIT
508 && ctx
->Depth
.Func
==GL_LESS
509 && ctx
->Depth
.Mask
==GL_TRUE
510 && ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
511 && ctx
->Line
.Width
==1.0F
) {
512 switch (xmesa
->pixelformat
) {
514 return flat_TRUECOLOR_z_line
;
516 return flat_8A8B8G8R_z_line
;
518 return flat_8R8G8B_z_line
;
520 return flat_8R8G8B24_z_line
;
522 return flat_5R6G5B_z_line
;
523 case PF_Dither_5R6G5B
:
524 return flat_DITHER_5R6G5B_z_line
;
526 return (depth
==8) ? flat_DITHER8_z_line
: (swrast_line_func
) NULL
;
528 return (depth
==8) ? flat_LOOKUP8_z_line
: (swrast_line_func
) NULL
;
530 return flat_HPCR_z_line
;
532 return (swrast_line_func
)NULL
;
535 if (xmesa
->xm_buffer
->buffer
==XIMAGE
536 && swrast
->_RasterMask
==0
537 && ctx
->Line
.Width
==1.0F
) {
538 switch (xmesa
->pixelformat
) {
540 return flat_TRUECOLOR_line
;
542 return flat_8A8B8G8R_line
;
544 return flat_8R8G8B_line
;
546 return flat_8R8G8B24_line
;
548 return flat_5R6G5B_line
;
549 case PF_Dither_5R6G5B
:
550 return flat_DITHER_5R6G5B_line
;
552 return (depth
==8) ? flat_DITHER8_line
: (swrast_line_func
) NULL
;
554 return (depth
==8) ? flat_LOOKUP8_line
: (swrast_line_func
) NULL
;
556 return flat_HPCR_line
;
558 return (swrast_line_func
)NULL
;
562 return (swrast_line_func
) NULL
;
565 /* Override for the swrast line-selection function. Try to use one
566 * of our internal line functions, otherwise fall back to the
567 * standard swrast functions.
569 void xmesa_choose_line( GLcontext
*ctx
)
571 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
573 if (!(swrast
->Line
= get_line_func( ctx
)))
574 _swrast_choose_line( ctx
);