2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * This file contains "accelerated" point, line, and triangle functions.
28 * It should be fairly easy to write new special-purpose point, line or
29 * triangle functions and hook them into this module.
33 #include "glxheader.h"
39 /* Internal swrast includes:
41 #include "swrast/s_depth.h"
42 #include "swrast/s_points.h"
43 #include "swrast/s_lines.h"
44 #include "swrast/s_context.h"
47 /**********************************************************************/
48 /*** Point rendering ***/
49 /**********************************************************************/
53 * Render an array of points into a pixmap, any pixel format.
56 /* XXX don't use this, it doesn't dither correctly */
57 static void draw_points_ANY_pixmap( GLcontext
*ctx
, const SWvertex
*vert
)
59 XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
60 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
61 XMesaDrawable buffer
= xmesa
->xm_buffer
->buffer
;
62 XMesaGC gc
= xmesa
->xm_buffer
->gc
;
64 if (xmesa
->xm_visual
->mesa_visual
.RGBAflag
) {
66 const GLubyte
*color
= vert
->color
;
67 unsigned long pixel
= xmesa_color_to_pixel( xmesa
,
71 XMesaSetForeground( dpy
, gc
, pixel
);
72 x
= (GLint
) vert
->win
[0];
73 y
= FLIP( xmesa
->xm_buffer
, (GLint
) vert
->win
[1] );
74 XMesaDrawPoint( dpy
, buffer
, gc
, x
, y
);
77 /* Color index mode */
79 XMesaSetForeground( dpy
, gc
, vert
->index
);
80 x
= (GLint
) vert
->win
[0];
81 y
= FLIP( xmesa
->xm_buffer
, (GLint
) vert
->win
[1] );
82 XMesaDrawPoint( dpy
, buffer
, gc
, x
, y
);
88 /* Override the swrast point-selection function. Try to use one of
89 * our internal point functions, otherwise fall back to the standard
92 void xmesa_choose_point( GLcontext
*ctx
)
95 XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
96 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
98 if (ctx
->RenderMode
== GL_RENDER
99 && ctx
->Point
.Size
== 1.0F
&& !ctx
->Point
.SmoothFlag
100 && swrast
->_RasterMask
== 0
101 && !ctx
->Texture
._EnabledUnits
102 && xmesa
->xm_buffer
->buffer
!= XIMAGE
) {
103 swrast
->Point
= draw_points_ANY_pixmap
;
106 _swrast_choose_point( ctx
);
109 _swrast_choose_point( ctx
);
115 /**********************************************************************/
116 /*** Line rendering ***/
117 /**********************************************************************/
121 * Draw a flat-shaded, PF_TRUECOLOR line into an XImage.
123 #define NAME flat_TRUECOLOR_line
125 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
126 const GLubyte *color = vert1->color; \
127 XMesaImage *img = xmesa->xm_buffer->backimage; \
128 unsigned long pixel; \
129 PACK_TRUECOLOR( pixel, color[0], color[1], color[2] );
131 #define PLOT(X,Y) XMesaPutPixel( img, X, FLIP(xmesa->xm_buffer, Y), pixel );
132 #include "swrast/s_linetemp.h"
137 * Draw a flat-shaded, PF_8A8B8G8R line into an XImage.
139 #define NAME flat_8A8B8G8R_line
141 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
142 const GLubyte *color = vert1->color; \
143 GLuint pixel = PACK_8B8G8R( color[0], color[1], color[2] );
144 #define PIXEL_TYPE GLuint
145 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
146 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
148 #define PLOT(X,Y) *pixelPtr = pixel;
149 #include "swrast/s_linetemp.h"
154 * Draw a flat-shaded, PF_8A8R8G8B line into an XImage.
156 #define NAME flat_8A8R8G8B_line
158 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
159 const GLubyte *color = vert1->color; \
160 GLuint pixel = PACK_8R8G8B( color[0], color[1], color[2] );
161 #define PIXEL_TYPE GLuint
162 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
163 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
165 #define PLOT(X,Y) *pixelPtr = pixel;
166 #include "swrast/s_linetemp.h"
171 * Draw a flat-shaded, PF_8R8G8B line into an XImage.
173 #define NAME flat_8R8G8B_line
175 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
176 const GLubyte *color = vert1->color; \
177 GLuint pixel = PACK_8R8G8B( color[0], color[1], color[2] );
178 #define PIXEL_TYPE GLuint
179 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
180 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
182 #define PLOT(X,Y) *pixelPtr = pixel;
183 #include "swrast/s_linetemp.h"
188 * Draw a flat-shaded, PF_8R8G8B24 line into an XImage.
190 #define NAME flat_8R8G8B24_line
192 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
193 const GLubyte *color = vert1->color;
194 #define PIXEL_TYPE bgr_t
195 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
196 #define PIXEL_ADDRESS(X,Y) PIXELADDR3(xmesa->xm_buffer,X,Y)
198 #define PLOT(X,Y) { \
199 pixelPtr->r = color[RCOMP]; \
200 pixelPtr->g = color[GCOMP]; \
201 pixelPtr->b = color[BCOMP]; \
203 #include "swrast/s_linetemp.h"
208 * Draw a flat-shaded, PF_5R6G5B line into an XImage.
210 #define NAME flat_5R6G5B_line
212 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
213 const GLubyte *color = vert1->color; \
214 GLushort pixel = PACK_5R6G5B( color[0], color[1], color[2] );
215 #define PIXEL_TYPE GLushort
216 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
217 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
219 #define PLOT(X,Y) *pixelPtr = pixel;
220 #include "swrast/s_linetemp.h"
225 * Draw a flat-shaded, PF_DITHER_5R6G5B line into an XImage.
227 #define NAME flat_DITHER_5R6G5B_line
229 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
230 const GLubyte *color = vert1->color;
231 #define PIXEL_TYPE GLushort
232 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
233 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
235 #define PLOT(X,Y) PACK_TRUEDITHER( *pixelPtr, X, Y, color[0], color[1], color[2] );
236 #include "swrast/s_linetemp.h"
242 * Draw a flat-shaded, PF_DITHER 8-bit line into an XImage.
244 #define NAME flat_DITHER8_line
246 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
247 const GLubyte *color = vert1->color; \
248 GLint r = color[0], g = color[1], b = color[2]; \
250 #define PIXEL_TYPE GLubyte
251 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
252 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
254 #define PLOT(X,Y) *pixelPtr = DITHER(X,Y,r,g,b);
255 #include "swrast/s_linetemp.h"
260 * Draw a flat-shaded, PF_LOOKUP 8-bit line into an XImage.
262 #define NAME flat_LOOKUP8_line
264 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
265 const GLubyte *color = vert1->color; \
268 pixel = (GLubyte) LOOKUP( color[0], color[1], color[2] );
269 #define PIXEL_TYPE GLubyte
270 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
271 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
273 #define PLOT(X,Y) *pixelPtr = pixel;
274 #include "swrast/s_linetemp.h"
279 * Draw a flat-shaded, PF_HPCR line into an XImage.
281 #define NAME flat_HPCR_line
283 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
284 const GLubyte *color = vert1->color; \
285 GLint r = color[0], g = color[1], b = color[2];
286 #define PIXEL_TYPE GLubyte
287 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
288 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
290 #define PLOT(X,Y) *pixelPtr = (GLubyte) DITHER_HPCR(X,Y,r,g,b);
291 #include "swrast/s_linetemp.h"
297 * Draw a flat-shaded, Z-less, PF_TRUECOLOR line into an XImage.
299 #define NAME flat_TRUECOLOR_z_line
301 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
302 const GLubyte *color = vert1->color; \
303 XMesaImage *img = xmesa->xm_buffer->backimage; \
304 unsigned long pixel; \
305 PACK_TRUECOLOR( pixel, color[0], color[1], color[2] );
307 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
312 XMesaPutPixel( img, X, FLIP(xmesa->xm_buffer, Y), pixel ); \
314 #include "swrast/s_linetemp.h"
319 * Draw a flat-shaded, Z-less, PF_8A8B8G8R line into an XImage.
321 #define NAME flat_8A8B8G8R_z_line
323 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
324 const GLubyte *color = vert1->color; \
325 GLuint pixel = PACK_8B8G8R( color[0], color[1], color[2] );
327 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
328 #define PIXEL_TYPE GLuint
329 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
330 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
337 #include "swrast/s_linetemp.h"
342 * Draw a flat-shaded, Z-less, PF_8A8R8G8B line into an XImage.
344 #define NAME flat_8A8R8G8B_z_line
346 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
347 const GLubyte *color = vert1->color; \
348 GLuint pixel = PACK_8R8G8B( color[0], color[1], color[2] );
350 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
351 #define PIXEL_TYPE GLuint
352 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
353 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
360 #include "swrast/s_linetemp.h"
365 * Draw a flat-shaded, Z-less, PF_8R8G8B line into an XImage.
367 #define NAME flat_8R8G8B_z_line
369 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
370 const GLubyte *color = vert1->color; \
371 GLuint pixel = PACK_8R8G8B( color[0], color[1], color[2] );
373 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
374 #define PIXEL_TYPE GLuint
375 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
376 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
383 #include "swrast/s_linetemp.h"
388 * Draw a flat-shaded, Z-less, PF_8R8G8B24 line into an XImage.
390 #define NAME flat_8R8G8B24_z_line
392 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
393 const GLubyte *color = vert1->color;
395 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
396 #define PIXEL_TYPE bgr_t
397 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
398 #define PIXEL_ADDRESS(X,Y) PIXELADDR3(xmesa->xm_buffer,X,Y)
403 pixelPtr->r = color[RCOMP]; \
404 pixelPtr->g = color[GCOMP]; \
405 pixelPtr->b = color[BCOMP]; \
407 #include "swrast/s_linetemp.h"
412 * Draw a flat-shaded, Z-less, PF_5R6G5B line into an XImage.
414 #define NAME flat_5R6G5B_z_line
416 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
417 const GLubyte *color = vert1->color; \
418 GLushort pixel = PACK_5R6G5B( color[0], color[1], color[2] );
420 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
421 #define PIXEL_TYPE GLushort
422 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
423 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
430 #include "swrast/s_linetemp.h"
435 * Draw a flat-shaded, Z-less, PF_DITHER_5R6G5B line into an XImage.
437 #define NAME flat_DITHER_5R6G5B_z_line
439 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
440 const GLubyte *color = vert1->color;
442 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
443 #define PIXEL_TYPE GLushort
444 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
445 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
450 PACK_TRUEDITHER(*pixelPtr, X, Y, color[0], color[1], color[2]); \
452 #include "swrast/s_linetemp.h"
457 * Draw a flat-shaded, Z-less, PF_DITHER 8-bit line into an XImage.
459 #define NAME flat_DITHER8_z_line
461 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
462 const GLubyte *color = vert1->color; \
463 GLint r = color[0], g = color[1], b = color[2]; \
466 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
467 #define PIXEL_TYPE GLubyte
468 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
469 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
474 *pixelPtr = (GLubyte) DITHER( X, Y, r, g, b); \
476 #include "swrast/s_linetemp.h"
481 * Draw a flat-shaded, Z-less, PF_LOOKUP 8-bit line into an XImage.
483 #define NAME flat_LOOKUP8_z_line
485 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
486 const GLubyte *color = vert1->color; \
489 pixel = (GLubyte) LOOKUP( color[0], color[1], color[2] );
491 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
492 #define PIXEL_TYPE GLubyte
493 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
494 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
501 #include "swrast/s_linetemp.h"
506 * Draw a flat-shaded, Z-less, PF_HPCR line into an XImage.
508 #define NAME flat_HPCR_z_line
510 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
511 const GLubyte *color = vert1->color; \
512 GLint r = color[0], g = color[1], b = color[2];
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)
522 *pixelPtr = (GLubyte) DITHER_HPCR( X, Y, r, g, b); \
524 #include "swrast/s_linetemp.h"
528 static swrast_line_func
get_line_func( GLcontext
*ctx
)
530 XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
531 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
532 int depth
= GET_VISUAL_DEPTH(xmesa
->xm_visual
);
534 if ((ctx
->Color
._DrawDestMask
[0] & (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
)) ==0)
535 return (swrast_line_func
) NULL
;
536 if (ctx
->RenderMode
!= GL_RENDER
) return (swrast_line_func
) NULL
;
537 if (ctx
->Line
.SmoothFlag
) return (swrast_line_func
) NULL
;
538 if (ctx
->Texture
._EnabledUnits
) return (swrast_line_func
) NULL
;
539 if (ctx
->Light
.ShadeModel
!= GL_FLAT
) return (swrast_line_func
) NULL
;
540 if (ctx
->Line
.StippleFlag
) return (swrast_line_func
) NULL
;
541 if (swrast
->_RasterMask
& MULTI_DRAW_BIT
) return (swrast_line_func
) NULL
;
543 if (xmesa
->xm_buffer
->buffer
==XIMAGE
544 && swrast
->_RasterMask
==DEPTH_BIT
545 && ctx
->Depth
.Func
==GL_LESS
546 && ctx
->Depth
.Mask
==GL_TRUE
547 && ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
548 && ctx
->Line
.Width
==1.0F
) {
549 switch (xmesa
->pixelformat
) {
551 return flat_TRUECOLOR_z_line
;
553 return flat_8A8B8G8R_z_line
;
555 return flat_8A8R8G8B_z_line
;
557 return flat_8R8G8B_z_line
;
559 return flat_8R8G8B24_z_line
;
561 return flat_5R6G5B_z_line
;
562 case PF_Dither_5R6G5B
:
563 return flat_DITHER_5R6G5B_z_line
;
565 return (depth
==8) ? flat_DITHER8_z_line
: (swrast_line_func
) NULL
;
567 return (depth
==8) ? flat_LOOKUP8_z_line
: (swrast_line_func
) NULL
;
569 return flat_HPCR_z_line
;
571 return (swrast_line_func
)NULL
;
574 if (xmesa
->xm_buffer
->buffer
==XIMAGE
575 && swrast
->_RasterMask
==0
576 && ctx
->Line
.Width
==1.0F
) {
577 switch (xmesa
->pixelformat
) {
579 return flat_TRUECOLOR_line
;
581 return flat_8A8B8G8R_line
;
583 return flat_8A8R8G8B_line
;
585 return flat_8R8G8B_line
;
587 return flat_8R8G8B24_line
;
589 return flat_5R6G5B_line
;
590 case PF_Dither_5R6G5B
:
591 return flat_DITHER_5R6G5B_line
;
593 return (depth
==8) ? flat_DITHER8_line
: (swrast_line_func
) NULL
;
595 return (depth
==8) ? flat_LOOKUP8_line
: (swrast_line_func
) NULL
;
597 return flat_HPCR_line
;
599 return (swrast_line_func
)NULL
;
603 return (swrast_line_func
) NULL
;
606 /* Override for the swrast line-selection function. Try to use one
607 * of our internal line functions, otherwise fall back to the
608 * standard swrast functions.
610 void xmesa_choose_line( GLcontext
*ctx
)
612 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
614 if (!(swrast
->Line
= get_line_func( ctx
)))
615 _swrast_choose_line( ctx
);