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_8R8G8B line into an XImage.
156 #define NAME flat_8R8G8B_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_8R8G8B24 line into an XImage.
173 #define NAME flat_8R8G8B24_line
175 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
176 const GLubyte *color = vert1->color;
177 #define PIXEL_TYPE bgr_t
178 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
179 #define PIXEL_ADDRESS(X,Y) PIXELADDR3(xmesa->xm_buffer,X,Y)
181 #define PLOT(X,Y) { \
182 pixelPtr->r = color[RCOMP]; \
183 pixelPtr->g = color[GCOMP]; \
184 pixelPtr->b = color[BCOMP]; \
186 #include "swrast/s_linetemp.h"
191 * Draw a flat-shaded, PF_5R6G5B line into an XImage.
193 #define NAME flat_5R6G5B_line
195 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
196 const GLubyte *color = vert1->color; \
197 GLushort pixel = PACK_5R6G5B( color[0], color[1], color[2] );
198 #define PIXEL_TYPE GLushort
199 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
200 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
202 #define PLOT(X,Y) *pixelPtr = pixel;
203 #include "swrast/s_linetemp.h"
208 * Draw a flat-shaded, PF_DITHER_5R6G5B line into an XImage.
210 #define NAME flat_DITHER_5R6G5B_line
212 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
213 const GLubyte *color = vert1->color;
214 #define PIXEL_TYPE GLushort
215 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
216 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
218 #define PLOT(X,Y) PACK_TRUEDITHER( *pixelPtr, X, Y, color[0], color[1], color[2] );
219 #include "swrast/s_linetemp.h"
225 * Draw a flat-shaded, PF_DITHER 8-bit line into an XImage.
227 #define NAME flat_DITHER8_line
229 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
230 const GLubyte *color = vert1->color; \
231 GLint r = color[0], g = color[1], b = color[2]; \
233 #define PIXEL_TYPE GLubyte
234 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
235 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
237 #define PLOT(X,Y) *pixelPtr = DITHER(X,Y,r,g,b);
238 #include "swrast/s_linetemp.h"
243 * Draw a flat-shaded, PF_LOOKUP 8-bit line into an XImage.
245 #define NAME flat_LOOKUP8_line
247 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
248 const GLubyte *color = vert1->color; \
251 pixel = (GLubyte) LOOKUP( color[0], color[1], color[2] );
252 #define PIXEL_TYPE GLubyte
253 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
254 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
256 #define PLOT(X,Y) *pixelPtr = pixel;
257 #include "swrast/s_linetemp.h"
262 * Draw a flat-shaded, PF_HPCR line into an XImage.
264 #define NAME flat_HPCR_line
266 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
267 const GLubyte *color = vert1->color; \
268 GLint r = color[0], g = color[1], b = 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 = (GLubyte) DITHER_HPCR(X,Y,r,g,b);
274 #include "swrast/s_linetemp.h"
280 * Draw a flat-shaded, Z-less, PF_TRUECOLOR line into an XImage.
282 #define NAME flat_TRUECOLOR_z_line
284 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
285 const GLubyte *color = vert1->color; \
286 XMesaImage *img = xmesa->xm_buffer->backimage; \
287 unsigned long pixel; \
288 PACK_TRUECOLOR( pixel, color[0], color[1], color[2] );
290 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
295 XMesaPutPixel( img, X, FLIP(xmesa->xm_buffer, Y), pixel ); \
297 #include "swrast/s_linetemp.h"
302 * Draw a flat-shaded, Z-less, PF_8A8B8G8R line into an XImage.
304 #define NAME flat_8A8B8G8R_z_line
306 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
307 const GLubyte *color = vert1->color; \
308 GLuint pixel = PACK_8B8G8R( color[0], color[1], color[2] );
310 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
311 #define PIXEL_TYPE GLuint
312 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
313 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
320 #include "swrast/s_linetemp.h"
325 * Draw a flat-shaded, Z-less, PF_8R8G8B line into an XImage.
327 #define NAME flat_8R8G8B_z_line
329 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
330 const GLubyte *color = vert1->color; \
331 GLuint pixel = PACK_8R8G8B( color[0], color[1], color[2] );
333 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
334 #define PIXEL_TYPE GLuint
335 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
336 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
343 #include "swrast/s_linetemp.h"
348 * Draw a flat-shaded, Z-less, PF_8R8G8B24 line into an XImage.
350 #define NAME flat_8R8G8B24_z_line
352 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
353 const GLubyte *color = vert1->color;
355 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
356 #define PIXEL_TYPE bgr_t
357 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
358 #define PIXEL_ADDRESS(X,Y) PIXELADDR3(xmesa->xm_buffer,X,Y)
363 pixelPtr->r = color[RCOMP]; \
364 pixelPtr->g = color[GCOMP]; \
365 pixelPtr->b = color[BCOMP]; \
367 #include "swrast/s_linetemp.h"
372 * Draw a flat-shaded, Z-less, PF_5R6G5B line into an XImage.
374 #define NAME flat_5R6G5B_z_line
376 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
377 const GLubyte *color = vert1->color; \
378 GLushort pixel = PACK_5R6G5B( color[0], color[1], color[2] );
380 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
381 #define PIXEL_TYPE GLushort
382 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
383 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
390 #include "swrast/s_linetemp.h"
395 * Draw a flat-shaded, Z-less, PF_DITHER_5R6G5B line into an XImage.
397 #define NAME flat_DITHER_5R6G5B_z_line
399 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
400 const GLubyte *color = vert1->color;
402 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
403 #define PIXEL_TYPE GLushort
404 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
405 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
410 PACK_TRUEDITHER(*pixelPtr, X, Y, color[0], color[1], color[2]); \
412 #include "swrast/s_linetemp.h"
417 * Draw a flat-shaded, Z-less, PF_DITHER 8-bit line into an XImage.
419 #define NAME flat_DITHER8_z_line
421 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
422 const GLubyte *color = vert1->color; \
423 GLint r = color[0], g = color[1], b = color[2]; \
426 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
427 #define PIXEL_TYPE GLubyte
428 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
429 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
434 *pixelPtr = (GLubyte) DITHER( X, Y, r, g, b); \
436 #include "swrast/s_linetemp.h"
441 * Draw a flat-shaded, Z-less, PF_LOOKUP 8-bit line into an XImage.
443 #define NAME flat_LOOKUP8_z_line
445 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
446 const GLubyte *color = vert1->color; \
449 pixel = (GLubyte) LOOKUP( color[0], color[1], color[2] );
451 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
452 #define PIXEL_TYPE GLubyte
453 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
454 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
461 #include "swrast/s_linetemp.h"
466 * Draw a flat-shaded, Z-less, PF_HPCR line into an XImage.
468 #define NAME flat_HPCR_z_line
470 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
471 const GLubyte *color = vert1->color; \
472 GLint r = color[0], g = color[1], b = color[2];
474 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
475 #define PIXEL_TYPE GLubyte
476 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
477 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
482 *pixelPtr = (GLubyte) DITHER_HPCR( X, Y, r, g, b); \
484 #include "swrast/s_linetemp.h"
488 static swrast_line_func
get_line_func( GLcontext
*ctx
)
490 XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
491 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
492 int depth
= GET_VISUAL_DEPTH(xmesa
->xm_visual
);
494 if ((ctx
->Color
._DrawDestMask
[0] & (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
)) ==0)
495 return (swrast_line_func
) NULL
;
496 if (ctx
->RenderMode
!= GL_RENDER
) return (swrast_line_func
) NULL
;
497 if (ctx
->Line
.SmoothFlag
) return (swrast_line_func
) NULL
;
498 if (ctx
->Texture
._EnabledUnits
) return (swrast_line_func
) NULL
;
499 if (ctx
->Light
.ShadeModel
!= GL_FLAT
) return (swrast_line_func
) NULL
;
500 if (ctx
->Line
.StippleFlag
) return (swrast_line_func
) NULL
;
501 if (swrast
->_RasterMask
& MULTI_DRAW_BIT
) return (swrast_line_func
) NULL
;
503 if (xmesa
->xm_buffer
->buffer
==XIMAGE
504 && swrast
->_RasterMask
==DEPTH_BIT
505 && ctx
->Depth
.Func
==GL_LESS
506 && ctx
->Depth
.Mask
==GL_TRUE
507 && ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
508 && ctx
->Line
.Width
==1.0F
) {
509 switch (xmesa
->pixelformat
) {
511 return flat_TRUECOLOR_z_line
;
513 return flat_8A8B8G8R_z_line
;
515 return flat_8R8G8B_z_line
;
517 return flat_8R8G8B24_z_line
;
519 return flat_5R6G5B_z_line
;
520 case PF_Dither_5R6G5B
:
521 return flat_DITHER_5R6G5B_z_line
;
523 return (depth
==8) ? flat_DITHER8_z_line
: (swrast_line_func
) NULL
;
525 return (depth
==8) ? flat_LOOKUP8_z_line
: (swrast_line_func
) NULL
;
527 return flat_HPCR_z_line
;
529 return (swrast_line_func
)NULL
;
532 if (xmesa
->xm_buffer
->buffer
==XIMAGE
533 && swrast
->_RasterMask
==0
534 && ctx
->Line
.Width
==1.0F
) {
535 switch (xmesa
->pixelformat
) {
537 return flat_TRUECOLOR_line
;
539 return flat_8A8B8G8R_line
;
541 return flat_8R8G8B_line
;
543 return flat_8R8G8B24_line
;
545 return flat_5R6G5B_line
;
546 case PF_Dither_5R6G5B
:
547 return flat_DITHER_5R6G5B_line
;
549 return (depth
==8) ? flat_DITHER8_line
: (swrast_line_func
) NULL
;
551 return (depth
==8) ? flat_LOOKUP8_line
: (swrast_line_func
) NULL
;
553 return flat_HPCR_line
;
555 return (swrast_line_func
)NULL
;
559 return (swrast_line_func
) NULL
;
562 /* Override for the swrast line-selection function. Try to use one
563 * of our internal line functions, otherwise fall back to the
564 * standard swrast functions.
566 void xmesa_choose_line( GLcontext
*ctx
)
568 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
570 if (!(swrast
->Line
= get_line_func( ctx
)))
571 _swrast_choose_line( ctx
);