3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * This file contains "accelerated" point, line, and triangle functions.
29 * It should be fairly easy to write new special-purpose point, line or
30 * triangle functions and hook them into this module.
34 #include "glxheader.h"
40 /* Internal swrast includes:
42 #include "swrast/s_depth.h"
43 #include "swrast/s_points.h"
44 #include "swrast/s_lines.h"
45 #include "swrast/s_context.h"
48 /**********************************************************************/
49 /*** Point rendering ***/
50 /**********************************************************************/
54 * Render an array of points into a pixmap, any pixel format.
57 /* XXX don't use this, it doesn't dither correctly */
58 static void draw_points_ANY_pixmap( GLcontext
*ctx
, const SWvertex
*vert
)
60 XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
61 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
62 XMesaDrawable buffer
= xmesa
->xm_buffer
->buffer
;
63 XMesaGC gc
= xmesa
->xm_buffer
->gc
;
65 if (xmesa
->xm_visual
->mesa_visual
.RGBAflag
) {
67 const GLubyte
*color
= vert
->color
;
68 unsigned long pixel
= xmesa_color_to_pixel( xmesa
,
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
);
78 /* Color index mode */
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
);
89 /* Override the swrast point-selection function. Try to use one of
90 * our internal point functions, otherwise fall back to the standard
93 void xmesa_choose_point( GLcontext
*ctx
)
96 XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
97 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
99 if (ctx
->RenderMode
== GL_RENDER
100 && ctx
->Point
.Size
== 1.0F
&& !ctx
->Point
.SmoothFlag
101 && swrast
->_RasterMask
== 0
102 && !ctx
->Texture
._EnabledUnits
103 && xmesa
->xm_buffer
->buffer
!= XIMAGE
) {
104 swrast
->Point
= draw_points_ANY_pixmap
;
107 _swrast_choose_point( ctx
);
110 _swrast_choose_point( ctx
);
116 /**********************************************************************/
117 /*** Line rendering ***/
118 /**********************************************************************/
122 * Draw a flat-shaded, PF_TRUECOLOR line into an XImage.
124 #define NAME flat_TRUECOLOR_line
126 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
127 const GLubyte *color = vert1->color; \
128 XMesaImage *img = xmesa->xm_buffer->backimage; \
129 unsigned long pixel; \
130 PACK_TRUECOLOR( pixel, color[0], color[1], color[2] );
132 #define PLOT(X,Y) XMesaPutPixel( img, X, FLIP(xmesa->xm_buffer, Y), pixel );
133 #include "swrast/s_linetemp.h"
138 * Draw a flat-shaded, PF_8A8B8G8R line into an XImage.
140 #define NAME flat_8A8B8G8R_line
142 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
143 const GLubyte *color = vert1->color; \
144 GLuint pixel = PACK_8B8G8R( color[0], color[1], color[2] );
145 #define PIXEL_TYPE GLuint
146 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
147 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
149 #define PLOT(X,Y) *pixelPtr = pixel;
150 #include "swrast/s_linetemp.h"
155 * Draw a flat-shaded, PF_8R8G8B line into an XImage.
157 #define NAME flat_8R8G8B_line
159 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
160 const GLubyte *color = vert1->color; \
161 GLuint pixel = PACK_8R8G8B( color[0], color[1], color[2] );
162 #define PIXEL_TYPE GLuint
163 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
164 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
166 #define PLOT(X,Y) *pixelPtr = pixel;
167 #include "swrast/s_linetemp.h"
172 * Draw a flat-shaded, PF_8R8G8B24 line into an XImage.
174 #define NAME flat_8R8G8B24_line
176 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
177 const GLubyte *color = vert1->color;
178 #define PIXEL_TYPE bgr_t
179 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
180 #define PIXEL_ADDRESS(X,Y) PIXELADDR3(xmesa->xm_buffer,X,Y)
182 #define PLOT(X,Y) { \
183 pixelPtr->r = color[RCOMP]; \
184 pixelPtr->g = color[GCOMP]; \
185 pixelPtr->b = color[BCOMP]; \
187 #include "swrast/s_linetemp.h"
192 * Draw a flat-shaded, PF_5R6G5B line into an XImage.
194 #define NAME flat_5R6G5B_line
196 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
197 const GLubyte *color = vert1->color; \
198 GLushort pixel = PACK_5R6G5B( color[0], color[1], color[2] );
199 #define PIXEL_TYPE GLushort
200 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
201 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
203 #define PLOT(X,Y) *pixelPtr = pixel;
204 #include "swrast/s_linetemp.h"
209 * Draw a flat-shaded, PF_DITHER_5R6G5B line into an XImage.
211 #define NAME flat_DITHER_5R6G5B_line
213 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
214 const GLubyte *color = vert1->color;
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) PACK_TRUEDITHER( *pixelPtr, X, Y, color[0], color[1], color[2] );
220 #include "swrast/s_linetemp.h"
226 * Draw a flat-shaded, PF_DITHER 8-bit line into an XImage.
228 #define NAME flat_DITHER8_line
230 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
231 const GLubyte *color = vert1->color; \
232 GLint r = color[0], g = color[1], b = color[2]; \
234 #define PIXEL_TYPE GLubyte
235 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
236 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
238 #define PLOT(X,Y) *pixelPtr = DITHER(X,Y,r,g,b);
239 #include "swrast/s_linetemp.h"
244 * Draw a flat-shaded, PF_LOOKUP 8-bit line into an XImage.
246 #define NAME flat_LOOKUP8_line
248 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
249 const GLubyte *color = vert1->color; \
252 pixel = (GLubyte) LOOKUP( color[0], color[1], color[2] );
253 #define PIXEL_TYPE GLubyte
254 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
255 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
257 #define PLOT(X,Y) *pixelPtr = pixel;
258 #include "swrast/s_linetemp.h"
263 * Draw a flat-shaded, PF_HPCR line into an XImage.
265 #define NAME flat_HPCR_line
267 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
268 const GLubyte *color = vert1->color; \
269 GLint r = color[0], g = color[1], b = color[2];
270 #define PIXEL_TYPE GLubyte
271 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
272 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
274 #define PLOT(X,Y) *pixelPtr = (GLubyte) DITHER_HPCR(X,Y,r,g,b);
275 #include "swrast/s_linetemp.h"
281 * Draw a flat-shaded, Z-less, PF_TRUECOLOR line into an XImage.
283 #define NAME flat_TRUECOLOR_z_line
285 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
286 const GLubyte *color = vert1->color; \
287 XMesaImage *img = xmesa->xm_buffer->backimage; \
288 unsigned long pixel; \
289 PACK_TRUECOLOR( pixel, color[0], color[1], color[2] );
291 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
296 XMesaPutPixel( img, X, FLIP(xmesa->xm_buffer, Y), pixel ); \
298 #include "swrast/s_linetemp.h"
303 * Draw a flat-shaded, Z-less, PF_8A8B8G8R line into an XImage.
305 #define NAME flat_8A8B8G8R_z_line
307 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
308 const GLubyte *color = vert1->color; \
309 GLuint pixel = PACK_8B8G8R( color[0], color[1], color[2] );
311 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
312 #define PIXEL_TYPE GLuint
313 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
314 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
321 #include "swrast/s_linetemp.h"
326 * Draw a flat-shaded, Z-less, PF_8R8G8B line into an XImage.
328 #define NAME flat_8R8G8B_z_line
330 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
331 const GLubyte *color = vert1->color; \
332 GLuint pixel = PACK_8R8G8B( color[0], color[1], color[2] );
334 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
335 #define PIXEL_TYPE GLuint
336 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
337 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
344 #include "swrast/s_linetemp.h"
349 * Draw a flat-shaded, Z-less, PF_8R8G8B24 line into an XImage.
351 #define NAME flat_8R8G8B24_z_line
353 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
354 const GLubyte *color = vert1->color;
356 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
357 #define PIXEL_TYPE bgr_t
358 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
359 #define PIXEL_ADDRESS(X,Y) PIXELADDR3(xmesa->xm_buffer,X,Y)
364 pixelPtr->r = color[RCOMP]; \
365 pixelPtr->g = color[GCOMP]; \
366 pixelPtr->b = color[BCOMP]; \
368 #include "swrast/s_linetemp.h"
373 * Draw a flat-shaded, Z-less, PF_5R6G5B line into an XImage.
375 #define NAME flat_5R6G5B_z_line
377 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
378 const GLubyte *color = vert1->color; \
379 GLushort pixel = PACK_5R6G5B( color[0], color[1], color[2] );
381 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
382 #define PIXEL_TYPE GLushort
383 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
384 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
391 #include "swrast/s_linetemp.h"
396 * Draw a flat-shaded, Z-less, PF_DITHER_5R6G5B line into an XImage.
398 #define NAME flat_DITHER_5R6G5B_z_line
400 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
401 const GLubyte *color = vert1->color;
403 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
404 #define PIXEL_TYPE GLushort
405 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
406 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
411 PACK_TRUEDITHER(*pixelPtr, X, Y, color[0], color[1], color[2]); \
413 #include "swrast/s_linetemp.h"
418 * Draw a flat-shaded, Z-less, PF_DITHER 8-bit line into an XImage.
420 #define NAME flat_DITHER8_z_line
422 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
423 const GLubyte *color = vert1->color; \
424 GLint r = color[0], g = color[1], b = color[2]; \
427 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
428 #define PIXEL_TYPE GLubyte
429 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
430 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
435 *pixelPtr = (GLubyte) DITHER( X, Y, r, g, b); \
437 #include "swrast/s_linetemp.h"
442 * Draw a flat-shaded, Z-less, PF_LOOKUP 8-bit line into an XImage.
444 #define NAME flat_LOOKUP8_z_line
446 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
447 const GLubyte *color = vert1->color; \
450 pixel = (GLubyte) LOOKUP( color[0], color[1], color[2] );
452 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
453 #define PIXEL_TYPE GLubyte
454 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
455 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
462 #include "swrast/s_linetemp.h"
467 * Draw a flat-shaded, Z-less, PF_HPCR line into an XImage.
469 #define NAME flat_HPCR_z_line
471 XMesaContext xmesa = XMESA_CONTEXT(ctx); \
472 const GLubyte *color = vert1->color; \
473 GLint r = color[0], g = color[1], b = color[2];
475 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
476 #define PIXEL_TYPE GLubyte
477 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
478 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
483 *pixelPtr = (GLubyte) DITHER_HPCR( X, Y, r, g, b); \
485 #include "swrast/s_linetemp.h"
489 static swrast_line_func
get_line_func( GLcontext
*ctx
)
491 XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
492 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
493 int depth
= GET_VISUAL_DEPTH(xmesa
->xm_visual
);
495 if (ctx
->RenderMode
!= GL_RENDER
) return (swrast_line_func
) NULL
;
496 if (ctx
->Line
.SmoothFlag
) return (swrast_line_func
) NULL
;
497 if (ctx
->Texture
._EnabledUnits
) return (swrast_line_func
) NULL
;
498 if (ctx
->Light
.ShadeModel
!= GL_FLAT
) return (swrast_line_func
) NULL
;
499 if (ctx
->Line
.StippleFlag
) return (swrast_line_func
) NULL
;
500 if (swrast
->_RasterMask
& MULTI_DRAW_BIT
) return (swrast_line_func
) NULL
;
502 if (xmesa
->xm_buffer
->buffer
==XIMAGE
503 && swrast
->_RasterMask
==DEPTH_BIT
504 && ctx
->Depth
.Func
==GL_LESS
505 && ctx
->Depth
.Mask
==GL_TRUE
506 && ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
507 && ctx
->Line
.Width
==1.0F
) {
508 switch (xmesa
->pixelformat
) {
510 return flat_TRUECOLOR_z_line
;
512 return flat_8A8B8G8R_z_line
;
514 return flat_8R8G8B_z_line
;
516 return flat_8R8G8B24_z_line
;
518 return flat_5R6G5B_z_line
;
519 case PF_Dither_5R6G5B
:
520 return flat_DITHER_5R6G5B_z_line
;
522 return (depth
==8) ? flat_DITHER8_z_line
: (swrast_line_func
) NULL
;
524 return (depth
==8) ? flat_LOOKUP8_z_line
: (swrast_line_func
) NULL
;
526 return flat_HPCR_z_line
;
528 return (swrast_line_func
)NULL
;
531 if (xmesa
->xm_buffer
->buffer
==XIMAGE
532 && swrast
->_RasterMask
==0
533 && ctx
->Line
.Width
==1.0F
) {
534 switch (xmesa
->pixelformat
) {
536 return flat_TRUECOLOR_line
;
538 return flat_8A8B8G8R_line
;
540 return flat_8R8G8B_line
;
542 return flat_8R8G8B24_line
;
544 return flat_5R6G5B_line
;
545 case PF_Dither_5R6G5B
:
546 return flat_DITHER_5R6G5B_line
;
548 return (depth
==8) ? flat_DITHER8_line
: (swrast_line_func
) NULL
;
550 return (depth
==8) ? flat_LOOKUP8_line
: (swrast_line_func
) NULL
;
552 return flat_HPCR_line
;
554 return (swrast_line_func
)NULL
;
558 return (swrast_line_func
) NULL
;
561 /* Override for the swrast line-selection function. Try to use one
562 * of our internal line functions, otherwise fall back to the
563 * standard swrast functions.
565 void xmesa_choose_line( GLcontext
*ctx
)
567 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
569 if (!(swrast
->Line
= get_line_func( ctx
)))
570 _swrast_choose_line( ctx
);