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.
25 #include "glxheader.h"
26 #include "main/context.h"
27 #include "main/macros.h"
28 #include "main/imports.h"
29 #include "main/mtypes.h"
32 #include "swrast/swrast.h"
36 * The following functions are used to trap XGetImage() calls which
37 * generate BadMatch errors if the drawable isn't mapped.
40 static int caught_xgetimage_error
= 0;
41 static int (*old_xerror_handler
)( XMesaDisplay
*dpy
, XErrorEvent
*ev
);
42 static unsigned long xgetimage_serial
;
45 * This is the error handler which will be called if XGetImage fails.
47 static int xgetimage_error_handler( XMesaDisplay
*dpy
, XErrorEvent
*ev
)
49 if (ev
->serial
==xgetimage_serial
&& ev
->error_code
==BadMatch
) {
50 /* caught the expected error */
51 caught_xgetimage_error
= 0;
54 /* call the original X error handler, if any. otherwise ignore */
55 if (old_xerror_handler
) {
56 (*old_xerror_handler
)( dpy
, ev
);
64 * Call this right before XGetImage to setup error trap.
66 static void catch_xgetimage_errors( XMesaDisplay
*dpy
)
68 xgetimage_serial
= NextRequest( dpy
);
69 old_xerror_handler
= XSetErrorHandler( xgetimage_error_handler
);
70 caught_xgetimage_error
= 0;
75 * Call this right after XGetImage to check if an error occured.
77 static int check_xgetimage_errors( void )
79 /* restore old handler */
80 (void) XSetErrorHandler( old_xerror_handler
);
81 /* return 0=no error, 1=error caught */
82 return caught_xgetimage_error
;
87 * Read a pixel from an X drawable.
89 static unsigned long read_pixel( XMesaDisplay
*dpy
,
90 XMesaDrawable d
, int x
, int y
)
93 XMesaImage
*pixel
= NULL
;
96 catch_xgetimage_errors( dpy
);
97 pixel
= XGetImage( dpy
, d
, x
, y
, 1, 1, AllPlanes
, ZPixmap
);
98 error
= check_xgetimage_errors();
99 if (pixel
&& !error
) {
100 p
= XMesaGetPixel( pixel
, 0, 0 );
106 XMesaDestroyImage( pixel
);
114 * The Mesa library needs to be able to draw pixels in a number of ways:
115 * 1. RGB vs Color Index
116 * 2. as horizontal spans (polygons, images) vs random locations (points,
118 * 3. different color per-pixel or same color for all pixels
120 * Furthermore, the X driver needs to support rendering to 3 possible
121 * "buffers", usually one, but sometimes two at a time:
122 * 1. The front buffer as an X window
123 * 2. The back buffer as a Pixmap
124 * 3. The back buffer as an XImage
126 * Finally, if the back buffer is an XImage, we can avoid using XPutPixel and
127 * optimize common cases such as 24-bit and 8-bit modes.
129 * By multiplication, there's at least 48 possible combinations of the above.
131 * Below are implementations of the most commonly used combinations. They are
132 * accessed through function pointers which get initialized here and are used
133 * directly from the Mesa library. The 8 function pointers directly correspond
134 * to the first 3 cases listed above.
137 * The function naming convention is:
139 * [put|get]_[row|values]_[format]_[pixmap|ximage]
141 * New functions optimized for specific cases can be added without too much
142 * trouble. An example might be the 24-bit TrueColor mode 8A8R8G8B which is
143 * found on IBM RS/6000 X servers.
149 /**********************************************************************/
150 /*** Write COLOR SPAN functions ***/
151 /**********************************************************************/
154 #define PUT_ROW_ARGS \
155 struct gl_context *ctx, \
156 struct gl_renderbuffer *rb, \
157 GLuint n, GLint x, GLint y, \
158 const void *values, const GLubyte mask[]
160 #define RGB_SPAN_ARGS \
161 struct gl_context *ctx, \
162 struct gl_renderbuffer *rb, \
163 GLuint n, GLint x, GLint y, \
164 const void *values, const GLubyte mask[]
167 #define GET_XRB(XRB) \
168 struct xmesa_renderbuffer *XRB = xmesa_renderbuffer(rb)
172 * Write a span of PF_TRUECOLOR pixels to a pixmap.
174 static void put_row_TRUECOLOR_pixmap( PUT_ROW_ARGS
)
176 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
177 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
179 XMesaDisplay
*dpy
= XMESA_BUFFER(ctx
->DrawBuffer
)->display
;
180 XMesaDrawable buffer
= xrb
->drawable
;
181 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
186 for (i
=0;i
<n
;i
++,x
++) {
189 PACK_TRUECOLOR( p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
] );
190 XMesaSetForeground( dpy
, gc
, p
);
191 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
, (int) y
);
196 /* draw all pixels */
197 XMesaImage
*rowimg
= XMESA_BUFFER(ctx
->DrawBuffer
)->rowimage
;
200 PACK_TRUECOLOR( p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
] );
201 XMesaPutPixel( rowimg
, i
, 0, p
);
203 XMesaPutImage( dpy
, buffer
, gc
, rowimg
, 0, 0, x
, y
, n
, 1 );
209 * Write a span of PF_TRUECOLOR pixels to a pixmap.
211 static void put_row_rgb_TRUECOLOR_pixmap( RGB_SPAN_ARGS
)
213 const GLubyte (*rgb
)[3] = (const GLubyte (*)[3]) values
;
214 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
216 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
217 XMesaDrawable buffer
= xrb
->drawable
;
218 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
222 for (i
=0;i
<n
;i
++,x
++) {
225 PACK_TRUECOLOR( p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
] );
226 XMesaSetForeground( dpy
, gc
, p
);
227 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
, (int) y
);
232 /* draw all pixels */
233 XMesaImage
*rowimg
= XMESA_BUFFER(ctx
->DrawBuffer
)->rowimage
;
236 PACK_TRUECOLOR( p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
] );
237 XMesaPutPixel( rowimg
, i
, 0, p
);
239 XMesaPutImage( dpy
, buffer
, gc
, rowimg
, 0, 0, x
, y
, n
, 1 );
244 * Write a span of PF_TRUEDITHER pixels to a pixmap.
246 static void put_row_TRUEDITHER_pixmap( PUT_ROW_ARGS
)
248 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
249 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
251 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
252 XMesaDrawable buffer
= xrb
->drawable
;
253 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
257 for (i
=0;i
<n
;i
++,x
++) {
260 PACK_TRUEDITHER(p
, x
, y
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
261 XMesaSetForeground( dpy
, gc
, p
);
262 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
, (int) y
);
267 XMesaImage
*rowimg
= XMESA_BUFFER(ctx
->DrawBuffer
)->rowimage
;
270 PACK_TRUEDITHER(p
, x
+i
, y
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
271 XMesaPutPixel( rowimg
, i
, 0, p
);
273 XMesaPutImage( dpy
, buffer
, gc
, rowimg
, 0, 0, x
, y
, n
, 1 );
279 * Write a span of PF_TRUEDITHER pixels to a pixmap (no alpha).
281 static void put_row_rgb_TRUEDITHER_pixmap( RGB_SPAN_ARGS
)
283 const GLubyte (*rgb
)[3] = (const GLubyte (*)[3]) values
;
284 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
286 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
287 XMesaDrawable buffer
= xrb
->drawable
;
288 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
292 for (i
=0;i
<n
;i
++,x
++) {
295 PACK_TRUEDITHER(p
, x
, y
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
296 XMesaSetForeground( dpy
, gc
, p
);
297 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
, (int) y
);
302 XMesaImage
*rowimg
= XMESA_BUFFER(ctx
->DrawBuffer
)->rowimage
;
305 PACK_TRUEDITHER(p
, x
+i
, y
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
306 XMesaPutPixel( rowimg
, i
, 0, p
);
308 XMesaPutImage( dpy
, buffer
, gc
, rowimg
, 0, 0, x
, y
, n
, 1 );
314 * Write a span of PF_8A8B8G8R pixels to a pixmap.
316 static void put_row_8A8B8G8R_pixmap( PUT_ROW_ARGS
)
318 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
319 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
321 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
322 XMesaDrawable buffer
= xrb
->drawable
;
323 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
327 for (i
=0;i
<n
;i
++,x
++) {
329 XMesaSetForeground( dpy
, gc
,
330 PACK_8A8B8G8R(rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
], rgba
[i
][ACOMP
]) );
331 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
, (int) y
);
336 /* draw all pixels */
337 XMesaImage
*rowimg
= XMESA_BUFFER(ctx
->DrawBuffer
)->rowimage
;
338 register GLuint
*ptr4
= (GLuint
*) rowimg
->data
;
340 *ptr4
++ = PACK_8A8B8G8R( rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
], rgba
[i
][ACOMP
] );
342 XMesaPutImage( dpy
, buffer
, gc
, rowimg
, 0, 0, x
, y
, n
, 1 );
348 * Write a span of PF_8A8B8G8R pixels to a pixmap (no alpha).
350 static void put_row_rgb_8A8B8G8R_pixmap( RGB_SPAN_ARGS
)
352 const GLubyte (*rgb
)[3] = (const GLubyte (*)[3]) values
;
353 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
355 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
356 XMesaDrawable buffer
= xrb
->drawable
;
357 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
361 for (i
=0;i
<n
;i
++,x
++) {
363 XMesaSetForeground( dpy
, gc
,
364 PACK_8B8G8R(rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]) );
365 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
, (int) y
);
370 /* draw all pixels */
371 XMesaImage
*rowimg
= XMESA_BUFFER(ctx
->DrawBuffer
)->rowimage
;
372 register GLuint
*ptr4
= (GLuint
*) rowimg
->data
;
374 *ptr4
++ = PACK_8B8G8R(rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
376 XMesaPutImage( dpy
, buffer
, gc
, rowimg
, 0, 0, x
, y
, n
, 1 );
381 * Write a span of PF_8A8R8G8B pixels to a pixmap.
383 static void put_row_8A8R8G8B_pixmap( PUT_ROW_ARGS
)
385 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
386 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
388 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
389 XMesaDrawable buffer
= xrb
->drawable
;
390 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
394 for (i
=0;i
<n
;i
++,x
++) {
396 XMesaSetForeground( dpy
, gc
,
397 PACK_8A8R8G8B(rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
], rgba
[i
][ACOMP
]) );
398 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
, (int) y
);
403 /* draw all pixels */
404 XMesaImage
*rowimg
= XMESA_BUFFER(ctx
->DrawBuffer
)->rowimage
;
405 register GLuint
*ptr4
= (GLuint
*) rowimg
->data
;
407 *ptr4
++ = PACK_8A8R8G8B( rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
], rgba
[i
][ACOMP
] );
409 XMesaPutImage( dpy
, buffer
, gc
, rowimg
, 0, 0, x
, y
, n
, 1 );
415 * Write a span of PF_8A8R8G8B pixels to a pixmap (no alpha).
417 static void put_row_rgb_8A8R8G8B_pixmap( RGB_SPAN_ARGS
)
419 const GLubyte (*rgb
)[3] = (const GLubyte (*)[3]) values
;
420 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
422 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
423 XMesaDrawable buffer
= xrb
->drawable
;
424 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
428 for (i
=0;i
<n
;i
++,x
++) {
430 XMesaSetForeground( dpy
, gc
,
431 PACK_8R8G8B(rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]) );
432 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
, (int) y
);
437 /* draw all pixels */
438 XMesaImage
*rowimg
= XMESA_BUFFER(ctx
->DrawBuffer
)->rowimage
;
439 register GLuint
*ptr4
= (GLuint
*) rowimg
->data
;
441 *ptr4
++ = PACK_8R8G8B(rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
443 XMesaPutImage( dpy
, buffer
, gc
, rowimg
, 0, 0, x
, y
, n
, 1 );
448 * Write a span of PF_8R8G8B pixels to a pixmap.
450 static void put_row_8R8G8B_pixmap( PUT_ROW_ARGS
)
452 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
453 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
455 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
456 XMesaDrawable buffer
= xrb
->drawable
;
457 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
461 for (i
=0;i
<n
;i
++,x
++) {
465 * XXX Something funny is going on here.
466 * If we're drawing into a window that uses a depth 32 TrueColor
467 * visual, we see the right pixels on screen, but when we read
468 * them back with XGetImage() we get random colors.
469 * The alternative code below which uses XPutImage() instead
470 * seems to mostly fix the problem, but not always.
471 * We don't normally create windows with this visual, but glean
472 * does and we're seeing some failures there.
474 XMesaSetForeground( dpy
, gc
, PACK_8R8G8B( rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
] ));
475 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
, (int) y
);
477 /* This code works more often, but not always */
478 XMesaImage
*rowimg
= XMESA_BUFFER(ctx
->DrawBuffer
)->rowimage
;
479 GLuint
*ptr4
= (GLuint
*) rowimg
->data
;
480 *ptr4
= PACK_8R8G8B( rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
] );
481 XMesaPutImage( dpy
, buffer
, gc
, rowimg
, 0, 0, x
, y
, 1, 1 );
487 /* draw all pixels */
488 XMesaImage
*rowimg
= XMESA_BUFFER(ctx
->DrawBuffer
)->rowimage
;
489 register GLuint
*ptr4
= (GLuint
*) rowimg
->data
;
491 *ptr4
++ = PACK_8R8G8B( rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
] );
493 XMesaPutImage( dpy
, buffer
, gc
, rowimg
, 0, 0, x
, y
, n
, 1 );
499 * Write a span of PF_8R8G8B24 pixels to a pixmap.
501 static void put_row_8R8G8B24_pixmap( PUT_ROW_ARGS
)
503 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
504 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
506 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
507 XMesaDrawable buffer
= xrb
->drawable
;
508 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
512 for (i
=0;i
<n
;i
++,x
++) {
514 XMesaSetForeground( dpy
, gc
,
515 PACK_8R8G8B( rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
] ));
516 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
, (int) y
);
521 /* draw all pixels */
522 XMesaImage
*rowimg
= XMESA_BUFFER(ctx
->DrawBuffer
)->rowimage
;
523 register GLuint
*ptr4
= (GLuint
*) rowimg
->data
;
524 register GLuint pixel
;
525 static const GLuint shift
[4] = {0, 8, 16, 24};
526 register GLuint i
= 0;
529 pixel
= rgba
[i
][BCOMP
] /* << shift[0]*/;
530 pixel
|= rgba
[i
][GCOMP
] << shift
[1];
531 pixel
|= rgba
[i
++][RCOMP
] << shift
[2];
532 pixel
|= rgba
[i
][BCOMP
] << shift
[3];
535 pixel
= rgba
[i
][GCOMP
] /* << shift[0]*/;
536 pixel
|= rgba
[i
++][RCOMP
] << shift
[1];
537 pixel
|= rgba
[i
][BCOMP
] << shift
[2];
538 pixel
|= rgba
[i
][GCOMP
] << shift
[3];
541 pixel
= rgba
[i
++][RCOMP
]/* << shift[0]*/;
542 pixel
|= rgba
[i
][BCOMP
] << shift
[1];
543 pixel
|= rgba
[i
][GCOMP
] << shift
[2];
544 pixel
|= rgba
[i
++][RCOMP
] << shift
[3];
552 pixel
|= rgba
[i
][BCOMP
] /*<< shift[0]*/;
553 pixel
|= rgba
[i
][GCOMP
] << shift
[1];
554 pixel
|= rgba
[i
++][RCOMP
] << shift
[2];
555 pixel
|= rgba
[i
][BCOMP
] << shift
[3];
558 pixel
|= rgba
[i
][GCOMP
] /*<< shift[0]*/;
559 pixel
|= rgba
[i
++][RCOMP
] << shift
[1];
560 pixel
|= rgba
[i
][BCOMP
] << shift
[2];
561 pixel
|= rgba
[i
][GCOMP
] << shift
[3];
563 pixel
= 0xffffff00 & *ptr4
;
564 pixel
|= rgba
[i
][RCOMP
] /*<< shift[0]*/;
569 pixel
|= rgba
[i
][BCOMP
] /*<< shift[0]*/;
570 pixel
|= rgba
[i
][GCOMP
] << shift
[1];
571 pixel
|= rgba
[i
++][RCOMP
] << shift
[2];
572 pixel
|= rgba
[i
][BCOMP
] << shift
[3];
574 pixel
= 0xffff0000 & *ptr4
;
575 pixel
|= rgba
[i
][GCOMP
] /*<< shift[0]*/;
576 pixel
|= rgba
[i
][RCOMP
] << shift
[1];
580 pixel
= 0xff000000 & *ptr4
;
581 pixel
|= rgba
[i
][BCOMP
] /*<< shift[0]*/;
582 pixel
|= rgba
[i
][GCOMP
] << shift
[1];
583 pixel
|= rgba
[i
][RCOMP
] << shift
[2];
589 XMesaPutImage( dpy
, buffer
, gc
, rowimg
, 0, 0, x
, y
, n
, 1 );
595 * Write a span of PF_8R8G8B pixels to a pixmap (no alpha).
597 static void put_row_rgb_8R8G8B_pixmap( RGB_SPAN_ARGS
)
599 const GLubyte (*rgb
)[3] = (const GLubyte (*)[3]) values
;
600 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
602 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
603 XMesaDrawable buffer
= xrb
->drawable
;
604 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
608 for (i
=0;i
<n
;i
++,x
++) {
610 XMesaSetForeground( dpy
, gc
, PACK_8R8G8B( rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
] ));
611 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
, (int) y
);
616 /* draw all pixels */
617 XMesaImage
*rowimg
= XMESA_BUFFER(ctx
->DrawBuffer
)->rowimage
;
618 register GLuint
*ptr4
= (GLuint
*) rowimg
->data
;
620 *ptr4
++ = PACK_8R8G8B( rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
] );
622 XMesaPutImage( dpy
, buffer
, gc
, rowimg
, 0, 0, x
, y
, n
, 1 );
627 * Write a span of PF_8R8G8B24 pixels to a pixmap (no alpha).
629 static void put_row_rgb_8R8G8B24_pixmap( RGB_SPAN_ARGS
)
631 const GLubyte (*rgb
)[3] = (const GLubyte (*)[3]) values
;
632 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
634 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
635 XMesaDrawable buffer
= xrb
->drawable
;
636 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
640 for (i
=0;i
<n
;i
++,x
++) {
642 XMesaSetForeground( dpy
, gc
,
643 PACK_8R8G8B( rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
] ));
644 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
, (int) y
);
649 /* draw all pixels */
650 XMesaImage
*rowimg
= XMESA_BUFFER(ctx
->DrawBuffer
)->rowimage
;
651 register GLuint
*ptr4
= (GLuint
*) rowimg
->data
;
652 register GLuint pixel
;
653 static const GLuint shift
[4] = {0, 8, 16, 24};
655 register GLuint i
= 0;
658 pixel
|= rgb
[i
][BCOMP
]/* << shift[0]*/;
659 pixel
|= rgb
[i
][GCOMP
] << shift
[1];
660 pixel
|= rgb
[i
++][RCOMP
] << shift
[2];
661 pixel
|= rgb
[i
][BCOMP
] <<shift
[3];
665 pixel
|= rgb
[i
][GCOMP
]/* << shift[0]*/;
666 pixel
|= rgb
[i
++][RCOMP
] << shift
[1];
667 pixel
|= rgb
[i
][BCOMP
] << shift
[2];
668 pixel
|= rgb
[i
][GCOMP
] << shift
[3];
672 pixel
|= rgb
[i
++][RCOMP
]/* << shift[0]*/;
673 pixel
|= rgb
[i
][BCOMP
] << shift
[1];
674 pixel
|= rgb
[i
][GCOMP
] << shift
[2];
675 pixel
|= rgb
[i
++][RCOMP
] << shift
[3];
682 pixel
|= rgb
[i
][BCOMP
]/* << shift[0]*/;
683 pixel
|= rgb
[i
][GCOMP
] << shift
[1];
684 pixel
|= rgb
[i
++][RCOMP
] << shift
[2];
685 pixel
|= rgb
[i
][BCOMP
] << shift
[3];
688 pixel
|= rgb
[i
][GCOMP
]/* << shift[0]*/;
689 pixel
|= rgb
[i
++][RCOMP
] << shift
[1];
690 pixel
|= rgb
[i
][BCOMP
] << shift
[2];
691 pixel
|= rgb
[i
][GCOMP
] << shift
[3];
695 pixel
|= rgb
[i
++][RCOMP
]/* << shift[0]*/;
700 pixel
|= rgb
[i
][BCOMP
]/* << shift[0]*/;
701 pixel
|= rgb
[i
][GCOMP
] << shift
[1];
702 pixel
|= rgb
[i
++][RCOMP
] << shift
[2];
703 pixel
|= rgb
[i
][BCOMP
] << shift
[3];
707 pixel
|= rgb
[i
][GCOMP
]/* << shift[0]*/;
708 pixel
|= rgb
[i
++][RCOMP
] << shift
[1];
714 pixel
|= rgb
[i
][BCOMP
]/* << shift[0]*/;
715 pixel
|= rgb
[i
][GCOMP
] << shift
[1];
716 pixel
|= rgb
[i
++][RCOMP
] << shift
[2];
722 XMesaPutImage( dpy
, buffer
, gc
, rowimg
, 0, 0, x
, y
, n
, 1 );
728 * Write a span of PF_5R6G5B pixels to a pixmap.
730 static void put_row_5R6G5B_pixmap( PUT_ROW_ARGS
)
732 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
733 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
735 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
736 XMesaDrawable buffer
= xrb
->drawable
;
737 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
741 for (i
=0;i
<n
;i
++,x
++) {
743 XMesaSetForeground( dpy
, gc
, PACK_5R6G5B( rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
] ));
744 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
, (int) y
);
749 /* draw all pixels */
750 XMesaImage
*rowimg
= XMESA_BUFFER(ctx
->DrawBuffer
)->rowimage
;
751 register GLushort
*ptr2
= (GLushort
*) rowimg
->data
;
753 ptr2
[i
] = PACK_5R6G5B( rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
] );
755 XMesaPutImage( dpy
, buffer
, gc
, rowimg
, 0, 0, x
, y
, n
, 1 );
761 * Write a span of PF_DITHER_5R6G5B pixels to a pixmap.
763 static void put_row_DITHER_5R6G5B_pixmap( PUT_ROW_ARGS
)
765 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
766 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
768 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
769 XMesaDrawable buffer
= xrb
->drawable
;
770 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
774 for (i
=0;i
<n
;i
++,x
++) {
777 PACK_TRUEDITHER(p
, x
, y
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
778 XMesaSetForeground( dpy
, gc
, p
);
779 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
, (int) y
);
784 /* draw all pixels */
785 XMesaImage
*rowimg
= XMESA_BUFFER(ctx
->DrawBuffer
)->rowimage
;
786 register GLushort
*ptr2
= (GLushort
*) rowimg
->data
;
788 PACK_TRUEDITHER( ptr2
[i
], x
+i
, y
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
] );
790 XMesaPutImage( dpy
, buffer
, gc
, rowimg
, 0, 0, x
, y
, n
, 1 );
796 * Write a span of PF_5R6G5B pixels to a pixmap (no alpha).
798 static void put_row_rgb_5R6G5B_pixmap( RGB_SPAN_ARGS
)
800 const GLubyte (*rgb
)[3] = (const GLubyte (*)[3]) values
;
801 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
803 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
804 XMesaDrawable buffer
= xrb
->drawable
;
805 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
809 for (i
=0;i
<n
;i
++,x
++) {
811 XMesaSetForeground( dpy
, gc
, PACK_5R6G5B( rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
] ));
812 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
, (int) y
);
817 /* draw all pixels */
818 XMesaImage
*rowimg
= XMESA_BUFFER(ctx
->DrawBuffer
)->rowimage
;
819 register GLushort
*ptr2
= (GLushort
*) rowimg
->data
;
821 ptr2
[i
] = PACK_5R6G5B( rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
] );
823 XMesaPutImage( dpy
, buffer
, gc
, rowimg
, 0, 0, x
, y
, n
, 1 );
829 * Write a span of PF_DITHER_5R6G5B pixels to a pixmap (no alpha).
831 static void put_row_rgb_DITHER_5R6G5B_pixmap( RGB_SPAN_ARGS
)
833 const GLubyte (*rgb
)[3] = (const GLubyte (*)[3]) values
;
834 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
836 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
837 XMesaDrawable buffer
= xrb
->drawable
;
838 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
842 for (i
=0;i
<n
;i
++,x
++) {
845 PACK_TRUEDITHER(p
, x
, y
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
846 XMesaSetForeground( dpy
, gc
, p
);
847 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
, (int) y
);
852 /* draw all pixels */
853 XMesaImage
*rowimg
= XMESA_BUFFER(ctx
->DrawBuffer
)->rowimage
;
854 register GLushort
*ptr2
= (GLushort
*) rowimg
->data
;
856 PACK_TRUEDITHER( ptr2
[i
], x
+i
, y
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
] );
858 XMesaPutImage( dpy
, buffer
, gc
, rowimg
, 0, 0, x
, y
, n
, 1 );
864 * Write a span of PF_TRUECOLOR pixels to an XImage.
866 static void put_row_TRUECOLOR_ximage( PUT_ROW_ARGS
)
868 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
869 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
871 XMesaImage
*img
= xrb
->ximage
;
875 for (i
=0;i
<n
;i
++,x
++) {
878 PACK_TRUECOLOR( p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
] );
879 XMesaPutPixel( img
, x
, y
, p
);
884 /* draw all pixels */
885 for (i
=0;i
<n
;i
++,x
++) {
887 PACK_TRUECOLOR( p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
] );
888 XMesaPutPixel( img
, x
, y
, p
);
895 * Write a span of PF_TRUECOLOR pixels to an XImage (no alpha).
897 static void put_row_rgb_TRUECOLOR_ximage( RGB_SPAN_ARGS
)
899 const GLubyte (*rgb
)[3] = (const GLubyte (*)[3]) values
;
900 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
902 XMesaImage
*img
= xrb
->ximage
;
906 for (i
=0;i
<n
;i
++,x
++) {
909 PACK_TRUECOLOR( p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
] );
910 XMesaPutPixel( img
, x
, y
, p
);
915 /* draw all pixels */
916 for (i
=0;i
<n
;i
++,x
++) {
918 PACK_TRUECOLOR( p
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
] );
919 XMesaPutPixel( img
, x
, y
, p
);
926 * Write a span of PF_TRUEDITHER pixels to an XImage.
928 static void put_row_TRUEDITHER_ximage( PUT_ROW_ARGS
)
930 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
931 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
933 XMesaImage
*img
= xrb
->ximage
;
937 for (i
=0;i
<n
;i
++,x
++) {
940 PACK_TRUEDITHER(p
, x
, y
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
941 XMesaPutPixel( img
, x
, y
, p
);
946 /* draw all pixels */
947 for (i
=0;i
<n
;i
++,x
++) {
949 PACK_TRUEDITHER(p
, x
, y
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
950 XMesaPutPixel( img
, x
, y
, p
);
957 * Write a span of PF_TRUEDITHER pixels to an XImage (no alpha).
959 static void put_row_rgb_TRUEDITHER_ximage( RGB_SPAN_ARGS
)
961 const GLubyte (*rgb
)[3] = (const GLubyte (*)[3]) values
;
962 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
964 XMesaImage
*img
= xrb
->ximage
;
968 for (i
=0;i
<n
;i
++,x
++) {
971 PACK_TRUEDITHER(p
, x
, y
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
972 XMesaPutPixel( img
, x
, y
, p
);
977 /* draw all pixels */
978 for (i
=0;i
<n
;i
++,x
++) {
980 PACK_TRUEDITHER(p
, x
, y
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
981 XMesaPutPixel( img
, x
, y
, p
);
988 * Write a span of PF_8A8B8G8R-format pixels to an ximage.
990 static void put_row_8A8B8G8R_ximage( PUT_ROW_ARGS
)
992 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
995 register GLuint
*ptr
= PIXEL_ADDR4(xrb
, x
, y
);
1000 ptr
[i
] = PACK_8A8B8G8R( rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
], rgba
[i
][ACOMP
] );
1005 /* draw all pixels */
1007 ptr
[i
] = PACK_8A8B8G8R( rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
], rgba
[i
][ACOMP
] );
1014 * Write a span of PF_8A8B8G8R-format pixels to an ximage (no alpha).
1016 static void put_row_rgb_8A8B8G8R_ximage( RGB_SPAN_ARGS
)
1018 const GLubyte (*rgb
)[3] = (const GLubyte (*)[3]) values
;
1021 register GLuint
*ptr
= PIXEL_ADDR4(xrb
, x
, y
);
1025 ptr
[i
] = PACK_8A8B8G8R( rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
], 255 );
1030 /* draw all pixels */
1032 ptr
[i
] = PACK_8A8B8G8R( rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
], 255 );
1038 * Write a span of PF_8A8R8G8B-format pixels to an ximage.
1040 static void put_row_8A8R8G8B_ximage( PUT_ROW_ARGS
)
1042 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
1045 register GLuint
*ptr
= PIXEL_ADDR4(xrb
, x
, y
);
1049 ptr
[i
] = PACK_8A8R8G8B( rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
], rgba
[i
][ACOMP
] );
1054 /* draw all pixels */
1056 ptr
[i
] = PACK_8A8R8G8B( rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
], rgba
[i
][ACOMP
] );
1063 * Write a span of PF_8A8R8G8B-format pixels to an ximage (no alpha).
1065 static void put_row_rgb_8A8R8G8B_ximage( RGB_SPAN_ARGS
)
1067 const GLubyte (*rgb
)[3] = (const GLubyte (*)[3]) values
;
1070 register GLuint
*ptr
= PIXEL_ADDR4(xrb
, x
, y
);
1074 ptr
[i
] = PACK_8A8R8G8B( rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
], 255 );
1079 /* draw all pixels */
1081 ptr
[i
] = PACK_8A8R8G8B( rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
], 255 );
1088 * Write a span of PF_8R8G8B-format pixels to an ximage.
1090 static void put_row_8R8G8B_ximage( PUT_ROW_ARGS
)
1092 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
1095 register GLuint
*ptr
= PIXEL_ADDR4(xrb
, x
, y
);
1099 ptr
[i
] = PACK_8R8G8B(rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1105 ptr
[i
] = PACK_8R8G8B(rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1112 * Write a span of PF_8R8G8B24-format pixels to an ximage.
1114 static void put_row_8R8G8B24_ximage( PUT_ROW_ARGS
)
1116 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
1119 register GLubyte
*ptr
= (GLubyte
*) PIXEL_ADDR3(xrb
, x
, y
);
1123 GLuint
*ptr4
= (GLuint
*) ptr
;
1124 register GLuint pixel
= *ptr4
;
1125 switch (3 & (int)(ptr
- (GLubyte
*)ptr4
)) {
1127 pixel
&= 0xff000000;
1128 pixel
|= rgba
[i
][BCOMP
];
1129 pixel
|= rgba
[i
][GCOMP
] << 8;
1130 pixel
|= rgba
[i
][RCOMP
] << 16;
1134 pixel
&= 0x00ffffff;
1135 pixel
|= rgba
[i
][BCOMP
] << 24;
1137 pixel
= *ptr4
& 0xffff0000;
1138 pixel
|= rgba
[i
][GCOMP
];
1139 pixel
|= rgba
[i
][RCOMP
] << 8;
1143 pixel
&= 0x0000ffff;
1144 pixel
|= rgba
[i
][BCOMP
] << 16;
1145 pixel
|= rgba
[i
][GCOMP
] << 24;
1147 pixel
= *ptr4
& 0xffffff00;
1148 pixel
|= rgba
[i
][RCOMP
];
1152 pixel
&= 0x000000ff;
1153 pixel
|= rgba
[i
][BCOMP
] << 8;
1154 pixel
|= rgba
[i
][GCOMP
] << 16;
1155 pixel
|= rgba
[i
][RCOMP
] << 24;
1164 /* write all pixels */
1166 GLuint
*ptr4
= (GLuint
*) ptr
;
1167 register GLuint pixel
= *ptr4
;
1168 int index
= (int)(ptr
- (GLubyte
*)ptr4
);
1169 register GLuint i
= 0;
1174 pixel
&= 0x00ffffff;
1175 pixel
|= rgba
[i
][BCOMP
] << 24;
1177 pixel
= *ptr4
& 0xffff0000;
1178 pixel
|= rgba
[i
][GCOMP
];
1179 pixel
|= rgba
[i
++][RCOMP
] << 8;
1184 pixel
&= 0x0000ffff;
1185 pixel
|= rgba
[i
][BCOMP
] << 16;
1186 pixel
|= rgba
[i
][GCOMP
] << 24;
1188 pixel
= *ptr4
& 0xffffff00;
1189 pixel
|= rgba
[i
++][RCOMP
];
1194 pixel
&= 0x000000ff;
1195 pixel
|= rgba
[i
][BCOMP
] << 8;
1196 pixel
|= rgba
[i
][GCOMP
] << 16;
1197 pixel
|= rgba
[i
++][RCOMP
] << 24;
1204 pixel
= rgba
[i
][BCOMP
];
1205 pixel
|= rgba
[i
][GCOMP
] << 8;
1206 pixel
|= rgba
[i
++][RCOMP
] << 16;
1207 pixel
|= rgba
[i
][BCOMP
] << 24;
1209 pixel
= rgba
[i
][GCOMP
];
1210 pixel
|= rgba
[i
++][RCOMP
] << 8;
1211 pixel
|= rgba
[i
][BCOMP
] << 16;
1212 pixel
|= rgba
[i
][GCOMP
] << 24;
1214 pixel
= rgba
[i
++][RCOMP
];
1215 pixel
|= rgba
[i
][BCOMP
] << 8;
1216 pixel
|= rgba
[i
][GCOMP
] << 16;
1217 pixel
|= rgba
[i
++][RCOMP
] << 24;
1225 pixel
= *ptr4
& 0xff000000;
1226 pixel
|= rgba
[i
][BCOMP
];
1227 pixel
|= rgba
[i
][GCOMP
] << 8;
1228 pixel
|= rgba
[i
][RCOMP
] << 16;
1232 pixel
= rgba
[i
][BCOMP
];
1233 pixel
|= rgba
[i
][GCOMP
] << 8;
1234 pixel
|= rgba
[i
++][RCOMP
] << 16;
1235 pixel
|= rgba
[i
][BCOMP
] << 24;
1237 pixel
= *ptr4
& 0xffff0000;
1238 pixel
|= rgba
[i
][GCOMP
];
1239 pixel
|= rgba
[i
][RCOMP
] << 8;
1243 pixel
= rgba
[i
][BCOMP
];
1244 pixel
|= rgba
[i
][GCOMP
] << 8;
1245 pixel
|= rgba
[i
++][RCOMP
] << 16;
1246 pixel
|= rgba
[i
][BCOMP
] << 24;
1248 pixel
= rgba
[i
][GCOMP
];
1249 pixel
|= rgba
[i
++][RCOMP
] << 8;
1250 pixel
|= rgba
[i
][BCOMP
] << 16;
1251 pixel
|= rgba
[i
][GCOMP
] << 24;
1253 pixel
= *ptr4
& 0xffffff00;
1254 pixel
|= rgba
[i
][RCOMP
];
1263 * Write a span of PF_8R8G8B-format pixels to an ximage (no alpha).
1265 static void put_row_rgb_8R8G8B_ximage( RGB_SPAN_ARGS
)
1267 const GLubyte (*rgb
)[3] = (const GLubyte (*)[3]) values
;
1270 register GLuint
*ptr
= PIXEL_ADDR4(xrb
, x
, y
);
1274 ptr
[i
] = PACK_8R8G8B(rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
1279 /* draw all pixels */
1281 ptr
[i
] = PACK_8R8G8B(rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
1288 * Write a span of PF_8R8G8B24-format pixels to an ximage (no alpha).
1290 static void put_row_rgb_8R8G8B24_ximage( RGB_SPAN_ARGS
)
1292 const GLubyte (*rgb
)[3] = (const GLubyte (*)[3]) values
;
1295 register GLubyte
*ptr
= (GLubyte
*) PIXEL_ADDR3(xrb
, x
, y
);
1299 *ptr
++ = rgb
[i
][BCOMP
];
1300 *ptr
++ = rgb
[i
][GCOMP
];
1301 *ptr
++ = rgb
[i
][RCOMP
];
1309 /* draw all pixels */
1311 *ptr
++ = rgb
[i
][BCOMP
];
1312 *ptr
++ = rgb
[i
][GCOMP
];
1313 *ptr
++ = rgb
[i
][RCOMP
];
1320 * Write a span of PF_5R6G5B-format pixels to an ximage.
1322 static void put_row_5R6G5B_ximage( PUT_ROW_ARGS
)
1324 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
1327 register GLushort
*ptr
= PIXEL_ADDR2(xrb
, x
, y
);
1331 ptr
[i
] = PACK_5R6G5B( rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
] );
1336 /* draw all pixels */
1337 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
1338 GLuint
*ptr32
= (GLuint
*) ptr
;
1339 GLuint extraPixel
= (n
& 1);
1341 for (i
= 0; i
< n
; i
+= 2) {
1343 p0
= PACK_5R6G5B(rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1344 p1
= PACK_5R6G5B(rgba
[i
+1][RCOMP
], rgba
[i
+1][GCOMP
], rgba
[i
+1][BCOMP
]);
1345 *ptr32
++ = (p1
<< 16) | p0
;
1348 ptr
[n
] = PACK_5R6G5B(rgba
[n
][RCOMP
], rgba
[n
][GCOMP
], rgba
[n
][BCOMP
]);
1351 for (i
= 0; i
< n
; i
++) {
1352 ptr
[i
] = PACK_5R6G5B(rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1360 * Write a span of PF_DITHER_5R6G5B-format pixels to an ximage.
1362 static void put_row_DITHER_5R6G5B_ximage( PUT_ROW_ARGS
)
1364 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
1366 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1368 register GLushort
*ptr
= PIXEL_ADDR2(xrb
, x
, y
);
1369 const GLint y2
= YFLIP(xrb
, y
);
1371 for (i
=0;i
<n
;i
++,x
++) {
1373 PACK_TRUEDITHER( ptr
[i
], x
, y2
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
] );
1378 /* draw all pixels */
1379 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
1380 GLuint
*ptr32
= (GLuint
*) ptr
;
1381 GLuint extraPixel
= (n
& 1);
1383 for (i
= 0; i
< n
; i
+= 2, x
+= 2) {
1385 PACK_TRUEDITHER( p0
, x
, y2
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
] );
1386 PACK_TRUEDITHER( p1
, x
+1, y2
, rgba
[i
+1][RCOMP
], rgba
[i
+1][GCOMP
], rgba
[i
+1][BCOMP
] );
1387 *ptr32
++ = (p1
<< 16) | p0
;
1390 PACK_TRUEDITHER( ptr
[n
], x
+n
, y2
, rgba
[n
][RCOMP
], rgba
[n
][GCOMP
], rgba
[n
][BCOMP
]);
1393 for (i
= 0; i
< n
; i
++, x
++) {
1394 PACK_TRUEDITHER( ptr
[i
], x
, y2
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1402 * Write a span of PF_5R6G5B-format pixels to an ximage (no alpha).
1404 static void put_row_rgb_5R6G5B_ximage( RGB_SPAN_ARGS
)
1406 const GLubyte (*rgb
)[3] = (const GLubyte (*)[3]) values
;
1409 register GLushort
*ptr
= PIXEL_ADDR2(xrb
, x
, y
);
1413 ptr
[i
] = PACK_5R6G5B( rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
] );
1418 /* draw all pixels */
1419 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
1420 GLuint
*ptr32
= (GLuint
*) ptr
;
1421 GLuint extraPixel
= (n
& 1);
1423 for (i
= 0; i
< n
; i
+= 2) {
1425 p0
= PACK_5R6G5B(rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
]);
1426 p1
= PACK_5R6G5B(rgb
[i
+1][RCOMP
], rgb
[i
+1][GCOMP
], rgb
[i
+1][BCOMP
]);
1427 *ptr32
++ = (p1
<< 16) | p0
;
1430 ptr
[n
] = PACK_5R6G5B(rgb
[n
][RCOMP
], rgb
[n
][GCOMP
], rgb
[n
][BCOMP
]);
1434 ptr
[i
] = PACK_5R6G5B( rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
] );
1442 * Write a span of PF_DITHER_5R6G5B-format pixels to an ximage (no alpha).
1444 static void put_row_rgb_DITHER_5R6G5B_ximage( RGB_SPAN_ARGS
)
1446 const GLubyte (*rgb
)[3] = (const GLubyte (*)[3]) values
;
1448 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1450 register GLushort
*ptr
= PIXEL_ADDR2(xrb
, x
, y
);
1452 for (i
=0;i
<n
;i
++,x
++) {
1454 PACK_TRUEDITHER( ptr
[i
], x
, y
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
] );
1459 /* draw all pixels */
1460 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
1461 GLuint
*ptr32
= (GLuint
*) ptr
;
1462 GLuint extraPixel
= (n
& 1);
1464 for (i
= 0; i
< n
; i
+= 2, x
+= 2) {
1466 PACK_TRUEDITHER( p0
, x
, y
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
] );
1467 PACK_TRUEDITHER( p1
, x
+1, y
, rgb
[i
+1][RCOMP
], rgb
[i
+1][GCOMP
], rgb
[i
+1][BCOMP
] );
1468 *ptr32
++ = (p1
<< 16) | p0
;
1471 PACK_TRUEDITHER( ptr
[n
], x
+n
, y
, rgb
[n
][RCOMP
], rgb
[n
][GCOMP
], rgb
[n
][BCOMP
]);
1474 for (i
=0;i
<n
;i
++,x
++) {
1475 PACK_TRUEDITHER( ptr
[i
], x
, y
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
], rgb
[i
][BCOMP
] );
1483 /**********************************************************************/
1484 /*** Write COLOR PIXEL functions ***/
1485 /**********************************************************************/
1488 #define PUT_VALUES_ARGS \
1489 struct gl_context *ctx, struct gl_renderbuffer *rb, \
1490 GLuint n, const GLint x[], const GLint y[], \
1491 const void *values, const GLubyte mask[]
1495 * Write an array of PF_TRUECOLOR pixels to a pixmap.
1497 static void put_values_TRUECOLOR_pixmap( PUT_VALUES_ARGS
)
1499 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
1500 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1502 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
1503 XMesaDrawable buffer
= xrb
->drawable
;
1504 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
1509 PACK_TRUECOLOR( p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
] );
1510 XMesaSetForeground( dpy
, gc
, p
);
1511 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
[i
], (int) YFLIP(xrb
, y
[i
]) );
1518 * Write an array of PF_TRUEDITHER pixels to a pixmap.
1520 static void put_values_TRUEDITHER_pixmap( PUT_VALUES_ARGS
)
1522 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
1523 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1525 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
1526 XMesaDrawable buffer
= xrb
->drawable
;
1527 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
1532 PACK_TRUEDITHER(p
, x
[i
], y
[i
], rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1533 XMesaSetForeground( dpy
, gc
, p
);
1534 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
[i
], (int) YFLIP(xrb
, y
[i
]) );
1541 * Write an array of PF_8A8B8G8R pixels to a pixmap.
1543 static void put_values_8A8B8G8R_pixmap( PUT_VALUES_ARGS
)
1545 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
1546 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1548 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
1549 XMesaDrawable buffer
= xrb
->drawable
;
1550 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
1554 XMesaSetForeground( dpy
, gc
,
1555 PACK_8A8B8G8R( rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
], rgba
[i
][ACOMP
] ));
1556 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
[i
], (int) YFLIP(xrb
, y
[i
]) );
1562 * Write an array of PF_8A8R8G8B pixels to a pixmap.
1564 static void put_values_8A8R8G8B_pixmap( PUT_VALUES_ARGS
)
1566 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
1567 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1569 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
1570 XMesaDrawable buffer
= xrb
->drawable
;
1571 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
1575 XMesaSetForeground( dpy
, gc
,
1576 PACK_8A8R8G8B( rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
], rgba
[i
][ACOMP
] ));
1577 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
[i
], (int) YFLIP(xrb
, y
[i
]) );
1583 * Write an array of PF_8R8G8B pixels to a pixmap.
1585 static void put_values_8R8G8B_pixmap( PUT_VALUES_ARGS
)
1587 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
1588 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1590 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
1591 XMesaDrawable buffer
= xrb
->drawable
;
1592 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
1596 XMesaSetForeground( dpy
, gc
, PACK_8R8G8B( rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
] ) );
1597 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
[i
], (int) YFLIP(xrb
, y
[i
]) );
1604 * Write an array of PF_8R8G8B24 pixels to a pixmap.
1606 static void put_values_8R8G8B24_pixmap( PUT_VALUES_ARGS
)
1608 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
1609 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1611 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
1612 XMesaDrawable buffer
= xrb
->drawable
;
1613 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
1617 XMesaSetForeground( dpy
, gc
, PACK_8R8G8B( rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
] ) );
1618 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
[i
], (int) YFLIP(xrb
, y
[i
]) );
1625 * Write an array of PF_5R6G5B pixels to a pixmap.
1627 static void put_values_5R6G5B_pixmap( PUT_VALUES_ARGS
)
1629 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
1630 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1632 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
1633 XMesaDrawable buffer
= xrb
->drawable
;
1634 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
1638 XMesaSetForeground( dpy
, gc
, PACK_5R6G5B( rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
] ) );
1639 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
[i
], (int) YFLIP(xrb
, y
[i
]) );
1646 * Write an array of PF_DITHER_5R6G5B pixels to a pixmap.
1648 static void put_values_DITHER_5R6G5B_pixmap( PUT_VALUES_ARGS
)
1650 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
1651 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1653 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
1654 XMesaDrawable buffer
= xrb
->drawable
;
1655 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
1660 PACK_TRUEDITHER(p
, x
[i
], y
[i
], rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
] );
1661 XMesaSetForeground( dpy
, gc
, p
);
1662 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
[i
], (int) YFLIP(xrb
, y
[i
]) );
1669 * Write an array of PF_TRUECOLOR pixels to an ximage.
1671 static void put_values_TRUECOLOR_ximage( PUT_VALUES_ARGS
)
1673 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
1674 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1676 XMesaImage
*img
= xrb
->ximage
;
1681 PACK_TRUECOLOR( p
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
] );
1682 XMesaPutPixel( img
, x
[i
], YFLIP(xrb
, y
[i
]), p
);
1689 * Write an array of PF_TRUEDITHER pixels to an XImage.
1691 static void put_values_TRUEDITHER_ximage( PUT_VALUES_ARGS
)
1693 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
1694 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1696 XMesaImage
*img
= xrb
->ximage
;
1701 PACK_TRUEDITHER(p
, x
[i
], y
[i
], rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
]);
1702 XMesaPutPixel( img
, x
[i
], YFLIP(xrb
, y
[i
]), p
);
1709 * Write an array of PF_8A8B8G8R pixels to an ximage.
1711 static void put_values_8A8B8G8R_ximage( PUT_VALUES_ARGS
)
1713 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
1718 GLuint
*ptr
= PIXEL_ADDR4(xrb
, x
[i
], y
[i
] );
1719 *ptr
= PACK_8A8B8G8R( rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
], rgba
[i
][ACOMP
] );
1725 * Write an array of PF_8A8R8G8B pixels to an ximage.
1727 static void put_values_8A8R8G8B_ximage( PUT_VALUES_ARGS
)
1729 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
1734 GLuint
*ptr
= PIXEL_ADDR4(xrb
, x
[i
], y
[i
]);
1735 *ptr
= PACK_8A8R8G8B( rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
], rgba
[i
][ACOMP
] );
1742 * Write an array of PF_8R8G8B pixels to an ximage.
1744 static void put_values_8R8G8B_ximage( PUT_VALUES_ARGS
)
1746 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
1751 GLuint
*ptr
= PIXEL_ADDR4(xrb
, x
[i
], y
[i
]);
1752 *ptr
= PACK_8R8G8B( rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
] );
1759 * Write an array of PF_8R8G8B24 pixels to an ximage.
1761 static void put_values_8R8G8B24_ximage( PUT_VALUES_ARGS
)
1763 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
1768 bgr_t
*ptr
= PIXEL_ADDR3(xrb
, x
[i
], y
[i
] );
1769 ptr
->r
= rgba
[i
][RCOMP
];
1770 ptr
->g
= rgba
[i
][GCOMP
];
1771 ptr
->b
= rgba
[i
][BCOMP
];
1778 * Write an array of PF_5R6G5B pixels to an ximage.
1780 static void put_values_5R6G5B_ximage( PUT_VALUES_ARGS
)
1782 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
1787 GLushort
*ptr
= PIXEL_ADDR2(xrb
, x
[i
], y
[i
] );
1788 *ptr
= PACK_5R6G5B( rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
] );
1795 * Write an array of PF_DITHER_5R6G5B pixels to an ximage.
1797 static void put_values_DITHER_5R6G5B_ximage( PUT_VALUES_ARGS
)
1799 const GLubyte (*rgba
)[4] = (const GLubyte (*)[4]) values
;
1801 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1805 GLushort
*ptr
= PIXEL_ADDR2(xrb
, x
[i
], y
[i
] );
1806 PACK_TRUEDITHER( *ptr
, x
[i
], y
[i
], rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
] );
1813 /**********************************************************************/
1814 /***** Pixel reading *****/
1815 /**********************************************************************/
1818 * Do clip testing prior to calling XGetImage. If any of the region lies
1819 * outside the screen's bounds, XGetImage will return NULL.
1820 * We use XTranslateCoordinates() to check if that's the case and
1821 * adjust the x, y and length parameters accordingly.
1822 * \return -1 if span is totally clipped away,
1823 * else return number of pixels to skip in the destination array.
1826 clip_for_xgetimage(struct gl_context
*ctx
, XMesaPixmap pixmap
, GLuint
*n
, GLint
*x
, GLint
*y
)
1828 XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1829 XMesaBuffer source
= XMESA_BUFFER(ctx
->DrawBuffer
);
1830 Window rootWin
= RootWindow(xmesa
->display
, 0);
1832 GLint screenWidth
= WidthOfScreen(DefaultScreenOfDisplay(xmesa
->display
));
1834 if (source
->type
== PBUFFER
|| source
->type
== PIXMAP
)
1836 XTranslateCoordinates(xmesa
->display
, pixmap
, rootWin
,
1837 *x
, *y
, &dx
, &dy
, &child
);
1838 if (dx
>= screenWidth
) {
1839 /* totally clipped on right */
1843 /* clipped on left */
1845 if (clip
>= (GLint
) *n
)
1846 return -1; /* totally clipped on left */
1852 if ((GLint
) (dx
+ *n
) > screenWidth
) {
1853 /* clipped on right */
1854 GLint clip
= dx
+ *n
- screenWidth
;
1862 * Read a horizontal span of color pixels.
1865 get_row_rgba(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1866 GLuint n
, GLint x
, GLint y
, void *values
)
1868 GLubyte (*rgba
)[4] = (GLubyte (*)[4]) values
;
1869 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1873 /* Read from Pixmap or Window */
1874 XMesaImage
*span
= NULL
;
1878 k
= clip_for_xgetimage(ctx
, xrb
->pixmap
, &n
, &x
, &y
);
1882 catch_xgetimage_errors( xmesa
->display
);
1883 span
= XGetImage( xmesa
->display
, xrb
->pixmap
,
1884 x
, y
, n
, 1, AllPlanes
, ZPixmap
);
1885 error
= check_xgetimage_errors();
1886 if (span
&& !error
) {
1887 switch (xmesa
->pixelformat
) {
1889 case PF_Dither_True
:
1891 const GLubyte
*pixelToR
= xmesa
->xm_visual
->PixelToR
;
1892 const GLubyte
*pixelToG
= xmesa
->xm_visual
->PixelToG
;
1893 const GLubyte
*pixelToB
= xmesa
->xm_visual
->PixelToB
;
1894 unsigned long rMask
= GET_REDMASK(xmesa
->xm_visual
);
1895 unsigned long gMask
= GET_GREENMASK(xmesa
->xm_visual
);
1896 unsigned long bMask
= GET_BLUEMASK(xmesa
->xm_visual
);
1897 GLint rShift
= xmesa
->xm_visual
->rshift
;
1898 GLint gShift
= xmesa
->xm_visual
->gshift
;
1899 GLint bShift
= xmesa
->xm_visual
->bshift
;
1903 p
= XMesaGetPixel( span
, i
, 0 );
1904 rgba
[i
][RCOMP
] = pixelToR
[(p
& rMask
) >> rShift
];
1905 rgba
[i
][GCOMP
] = pixelToG
[(p
& gMask
) >> gShift
];
1906 rgba
[i
][BCOMP
] = pixelToB
[(p
& bMask
) >> bShift
];
1907 rgba
[i
][ACOMP
] = 255;
1912 case PF_Dither_5R6G5B
:
1914 const GLubyte
*pixelToR
= xmesa
->xm_visual
->PixelToR
;
1915 const GLubyte
*pixelToG
= xmesa
->xm_visual
->PixelToG
;
1916 const GLubyte
*pixelToB
= xmesa
->xm_visual
->PixelToB
;
1919 unsigned long p
= XMesaGetPixel( span
, i
, 0 );
1920 /* fast, but not quite accurate
1921 rgba[i][RCOMP] = ((p >> 8) & 0xf8);
1922 rgba[i][GCOMP] = ((p >> 3) & 0xfc);
1923 rgba[i][BCOMP] = ((p << 3) & 0xff);
1925 rgba
[i
][RCOMP
] = pixelToR
[p
>> 11];
1926 rgba
[i
][GCOMP
] = pixelToG
[(p
>> 5) & 0x3f];
1927 rgba
[i
][BCOMP
] = pixelToB
[p
& 0x1f];
1928 rgba
[i
][ACOMP
] = 255;
1934 const GLuint
*ptr4
= (GLuint
*) span
->data
;
1937 GLuint p4
= *ptr4
++;
1938 rgba
[i
][RCOMP
] = (GLubyte
) ( p4
& 0xff);
1939 rgba
[i
][GCOMP
] = (GLubyte
) ((p4
>> 8) & 0xff);
1940 rgba
[i
][BCOMP
] = (GLubyte
) ((p4
>> 16) & 0xff);
1941 rgba
[i
][ACOMP
] = (GLubyte
) ((p4
>> 24) & 0xff);
1947 const GLuint
*ptr4
= (GLuint
*) span
->data
;
1950 GLuint p4
= *ptr4
++;
1951 rgba
[i
][RCOMP
] = (GLubyte
) ((p4
>> 16) & 0xff);
1952 rgba
[i
][GCOMP
] = (GLubyte
) ((p4
>> 8) & 0xff);
1953 rgba
[i
][BCOMP
] = (GLubyte
) ( p4
& 0xff);
1954 rgba
[i
][ACOMP
] = (GLubyte
) ((p4
>> 24) & 0xff);
1960 const GLuint
*ptr4
= (GLuint
*) span
->data
;
1963 GLuint p4
= *ptr4
++;
1964 rgba
[i
][RCOMP
] = (GLubyte
) ((p4
>> 16) & 0xff);
1965 rgba
[i
][GCOMP
] = (GLubyte
) ((p4
>> 8) & 0xff);
1966 rgba
[i
][BCOMP
] = (GLubyte
) ( p4
& 0xff);
1967 rgba
[i
][ACOMP
] = 255;
1973 const bgr_t
*ptr3
= (bgr_t
*) span
->data
;
1976 rgba
[i
][RCOMP
] = ptr3
[i
].r
;
1977 rgba
[i
][GCOMP
] = ptr3
[i
].g
;
1978 rgba
[i
][BCOMP
] = ptr3
[i
].b
;
1979 rgba
[i
][ACOMP
] = 255;
1984 _mesa_problem(NULL
,"Problem in DD.read_color_span (1)");
1989 /* return black pixels */
1992 rgba
[i
][RCOMP
] = rgba
[i
][GCOMP
] = rgba
[i
][BCOMP
] = rgba
[i
][ACOMP
] = 0;
1996 XMesaDestroyImage( span
);
1999 else if (xrb
->ximage
) {
2000 /* Read from XImage back buffer */
2001 switch (xmesa
->pixelformat
) {
2003 case PF_Dither_True
:
2005 const GLubyte
*pixelToR
= xmesa
->xm_visual
->PixelToR
;
2006 const GLubyte
*pixelToG
= xmesa
->xm_visual
->PixelToG
;
2007 const GLubyte
*pixelToB
= xmesa
->xm_visual
->PixelToB
;
2008 unsigned long rMask
= GET_REDMASK(xmesa
->xm_visual
);
2009 unsigned long gMask
= GET_GREENMASK(xmesa
->xm_visual
);
2010 unsigned long bMask
= GET_BLUEMASK(xmesa
->xm_visual
);
2011 GLint rShift
= xmesa
->xm_visual
->rshift
;
2012 GLint gShift
= xmesa
->xm_visual
->gshift
;
2013 GLint bShift
= xmesa
->xm_visual
->bshift
;
2014 XMesaImage
*img
= xrb
->ximage
;
2019 p
= XMesaGetPixel( img
, x
+i
, y
);
2020 rgba
[i
][RCOMP
] = pixelToR
[(p
& rMask
) >> rShift
];
2021 rgba
[i
][GCOMP
] = pixelToG
[(p
& gMask
) >> gShift
];
2022 rgba
[i
][BCOMP
] = pixelToB
[(p
& bMask
) >> bShift
];
2023 rgba
[i
][ACOMP
] = 255;
2028 case PF_Dither_5R6G5B
:
2030 const GLubyte
*pixelToR
= xmesa
->xm_visual
->PixelToR
;
2031 const GLubyte
*pixelToG
= xmesa
->xm_visual
->PixelToG
;
2032 const GLubyte
*pixelToB
= xmesa
->xm_visual
->PixelToB
;
2033 const GLushort
*ptr2
= PIXEL_ADDR2(xrb
, x
, y
);
2035 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
2036 const GLuint
*ptr4
= (const GLuint
*) ptr2
;
2037 GLuint extraPixel
= (n
& 1);
2039 for (i
= 0; i
< n
; i
+= 2) {
2040 const GLuint p
= *ptr4
++;
2041 const GLuint p0
= p
& 0xffff;
2042 const GLuint p1
= p
>> 16;
2043 /* fast, but not quite accurate
2044 rgba[i][RCOMP] = ((p >> 8) & 0xf8);
2045 rgba[i][GCOMP] = ((p >> 3) & 0xfc);
2046 rgba[i][BCOMP] = ((p << 3) & 0xff);
2048 rgba
[i
][RCOMP
] = pixelToR
[p0
>> 11];
2049 rgba
[i
][GCOMP
] = pixelToG
[(p0
>> 5) & 0x3f];
2050 rgba
[i
][BCOMP
] = pixelToB
[p0
& 0x1f];
2051 rgba
[i
][ACOMP
] = 255;
2052 rgba
[i
+1][RCOMP
] = pixelToR
[p1
>> 11];
2053 rgba
[i
+1][GCOMP
] = pixelToG
[(p1
>> 5) & 0x3f];
2054 rgba
[i
+1][BCOMP
] = pixelToB
[p1
& 0x1f];
2055 rgba
[i
+1][ACOMP
] = 255;
2058 GLushort p
= ptr2
[n
];
2059 rgba
[n
][RCOMP
] = pixelToR
[p
>> 11];
2060 rgba
[n
][GCOMP
] = pixelToG
[(p
>> 5) & 0x3f];
2061 rgba
[n
][BCOMP
] = pixelToB
[p
& 0x1f];
2062 rgba
[n
][ACOMP
] = 255;
2065 for (i
= 0; i
< n
; i
++) {
2066 const GLushort p
= ptr2
[i
];
2067 rgba
[i
][RCOMP
] = pixelToR
[p
>> 11];
2068 rgba
[i
][GCOMP
] = pixelToG
[(p
>> 5) & 0x3f];
2069 rgba
[i
][BCOMP
] = pixelToB
[p
& 0x1f];
2070 rgba
[i
][ACOMP
] = 255;
2077 const GLuint
*ptr4
= PIXEL_ADDR4(xrb
, x
, y
);
2080 GLuint p4
= *ptr4
++;
2081 rgba
[i
][RCOMP
] = (GLubyte
) ( p4
& 0xff);
2082 rgba
[i
][GCOMP
] = (GLubyte
) ((p4
>> 8) & 0xff);
2083 rgba
[i
][BCOMP
] = (GLubyte
) ((p4
>> 16) & 0xff);
2084 rgba
[i
][ACOMP
] = (GLint
) ((p4
>> 24) & 0xff);
2090 const GLuint
*ptr4
= PIXEL_ADDR4(xrb
, x
, y
);
2093 GLuint p4
= *ptr4
++;
2094 rgba
[i
][RCOMP
] = (GLubyte
) ((p4
>> 16) & 0xff);
2095 rgba
[i
][GCOMP
] = (GLubyte
) ((p4
>> 8) & 0xff);
2096 rgba
[i
][BCOMP
] = (GLubyte
) ( p4
& 0xff);
2097 rgba
[i
][ACOMP
] = (GLint
) ((p4
>> 24) & 0xff);
2103 const GLuint
*ptr4
= PIXEL_ADDR4(xrb
, x
, y
);
2106 GLuint p4
= *ptr4
++;
2107 rgba
[i
][RCOMP
] = (GLubyte
) ((p4
>> 16) & 0xff);
2108 rgba
[i
][GCOMP
] = (GLubyte
) ((p4
>> 8) & 0xff);
2109 rgba
[i
][BCOMP
] = (GLubyte
) ( p4
& 0xff);
2110 rgba
[i
][ACOMP
] = 255;
2116 const bgr_t
*ptr3
= PIXEL_ADDR3(xrb
, x
, y
);
2119 rgba
[i
][RCOMP
] = ptr3
[i
].r
;
2120 rgba
[i
][GCOMP
] = ptr3
[i
].g
;
2121 rgba
[i
][BCOMP
] = ptr3
[i
].b
;
2122 rgba
[i
][ACOMP
] = 255;
2127 _mesa_problem(NULL
,"Problem in DD.read_color_span (2)");
2136 get_values_rgba(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2137 GLuint n
, const GLint x
[], const GLint y
[], void *values
)
2139 GLubyte (*rgba
)[4] = (GLubyte (*)[4]) values
;
2141 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
2142 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
2146 XMesaDrawable buffer
= xrb
->drawable
;
2147 switch (xmesa
->pixelformat
) {
2149 case PF_Dither_True
:
2151 case PF_Dither_5R6G5B
:
2153 unsigned long rMask
= GET_REDMASK(xmesa
->xm_visual
);
2154 unsigned long gMask
= GET_GREENMASK(xmesa
->xm_visual
);
2155 unsigned long bMask
= GET_BLUEMASK(xmesa
->xm_visual
);
2156 GLubyte
*pixelToR
= xmesa
->xm_visual
->PixelToR
;
2157 GLubyte
*pixelToG
= xmesa
->xm_visual
->PixelToG
;
2158 GLubyte
*pixelToB
= xmesa
->xm_visual
->PixelToB
;
2159 GLint rShift
= xmesa
->xm_visual
->rshift
;
2160 GLint gShift
= xmesa
->xm_visual
->gshift
;
2161 GLint bShift
= xmesa
->xm_visual
->bshift
;
2163 unsigned long p
= read_pixel( dpy
, buffer
,
2164 x
[i
], YFLIP(xrb
, y
[i
]) );
2165 rgba
[i
][RCOMP
] = pixelToR
[(p
& rMask
) >> rShift
];
2166 rgba
[i
][GCOMP
] = pixelToG
[(p
& gMask
) >> gShift
];
2167 rgba
[i
][BCOMP
] = pixelToB
[(p
& bMask
) >> bShift
];
2168 rgba
[i
][ACOMP
] = 255;
2174 unsigned long p
= read_pixel( dpy
, buffer
,
2175 x
[i
], YFLIP(xrb
, y
[i
]) );
2176 rgba
[i
][RCOMP
] = (GLubyte
) ( p
& 0xff);
2177 rgba
[i
][GCOMP
] = (GLubyte
) ((p
>> 8) & 0xff);
2178 rgba
[i
][BCOMP
] = (GLubyte
) ((p
>> 16) & 0xff);
2179 rgba
[i
][ACOMP
] = (GLubyte
) ((p
>> 24) & 0xff);
2184 unsigned long p
= read_pixel( dpy
, buffer
,
2185 x
[i
], YFLIP(xrb
, y
[i
]) );
2186 rgba
[i
][RCOMP
] = (GLubyte
) ((p
>> 16) & 0xff);
2187 rgba
[i
][GCOMP
] = (GLubyte
) ((p
>> 8) & 0xff);
2188 rgba
[i
][BCOMP
] = (GLubyte
) ( p
& 0xff);
2189 rgba
[i
][ACOMP
] = (GLubyte
) ((p
>> 24) & 0xff);
2194 unsigned long p
= read_pixel( dpy
, buffer
,
2195 x
[i
], YFLIP(xrb
, y
[i
]) );
2196 rgba
[i
][RCOMP
] = (GLubyte
) ((p
>> 16) & 0xff);
2197 rgba
[i
][GCOMP
] = (GLubyte
) ((p
>> 8) & 0xff);
2198 rgba
[i
][BCOMP
] = (GLubyte
) ( p
& 0xff);
2199 rgba
[i
][ACOMP
] = 255;
2204 unsigned long p
= read_pixel( dpy
, buffer
,
2205 x
[i
], YFLIP(xrb
, y
[i
]) );
2206 rgba
[i
][RCOMP
] = (GLubyte
) ((p
>> 16) & 0xff);
2207 rgba
[i
][GCOMP
] = (GLubyte
) ((p
>> 8) & 0xff);
2208 rgba
[i
][BCOMP
] = (GLubyte
) ( p
& 0xff);
2209 rgba
[i
][ACOMP
] = 255;
2213 _mesa_problem(NULL
,"Problem in DD.read_color_pixels (1)");
2217 else if (xrb
->ximage
) {
2218 /* Read from XImage back buffer */
2219 switch (xmesa
->pixelformat
) {
2221 case PF_Dither_True
:
2223 case PF_Dither_5R6G5B
:
2225 unsigned long rMask
= GET_REDMASK(xmesa
->xm_visual
);
2226 unsigned long gMask
= GET_GREENMASK(xmesa
->xm_visual
);
2227 unsigned long bMask
= GET_BLUEMASK(xmesa
->xm_visual
);
2228 GLubyte
*pixelToR
= xmesa
->xm_visual
->PixelToR
;
2229 GLubyte
*pixelToG
= xmesa
->xm_visual
->PixelToG
;
2230 GLubyte
*pixelToB
= xmesa
->xm_visual
->PixelToB
;
2231 GLint rShift
= xmesa
->xm_visual
->rshift
;
2232 GLint gShift
= xmesa
->xm_visual
->gshift
;
2233 GLint bShift
= xmesa
->xm_visual
->bshift
;
2234 XMesaImage
*img
= xrb
->ximage
;
2237 p
= XMesaGetPixel( img
, x
[i
], YFLIP(xrb
, y
[i
]) );
2238 rgba
[i
][RCOMP
] = pixelToR
[(p
& rMask
) >> rShift
];
2239 rgba
[i
][GCOMP
] = pixelToG
[(p
& gMask
) >> gShift
];
2240 rgba
[i
][BCOMP
] = pixelToB
[(p
& bMask
) >> bShift
];
2241 rgba
[i
][ACOMP
] = 255;
2247 GLuint
*ptr4
= PIXEL_ADDR4(xrb
, x
[i
], y
[i
]);
2249 rgba
[i
][RCOMP
] = (GLubyte
) ( p4
& 0xff);
2250 rgba
[i
][GCOMP
] = (GLubyte
) ((p4
>> 8) & 0xff);
2251 rgba
[i
][BCOMP
] = (GLubyte
) ((p4
>> 16) & 0xff);
2252 rgba
[i
][ACOMP
] = (GLubyte
) ((p4
>> 24) & 0xff);
2257 GLuint
*ptr4
= PIXEL_ADDR4(xrb
, x
[i
], y
[i
]);
2259 rgba
[i
][RCOMP
] = (GLubyte
) ((p4
>> 16) & 0xff);
2260 rgba
[i
][GCOMP
] = (GLubyte
) ((p4
>> 8) & 0xff);
2261 rgba
[i
][BCOMP
] = (GLubyte
) ( p4
& 0xff);
2262 rgba
[i
][ACOMP
] = (GLubyte
) ((p4
>> 24) & 0xff);
2267 GLuint
*ptr4
= PIXEL_ADDR4(xrb
, x
[i
], y
[i
]);
2269 rgba
[i
][RCOMP
] = (GLubyte
) ((p4
>> 16) & 0xff);
2270 rgba
[i
][GCOMP
] = (GLubyte
) ((p4
>> 8) & 0xff);
2271 rgba
[i
][BCOMP
] = (GLubyte
) ( p4
& 0xff);
2272 rgba
[i
][ACOMP
] = 255;
2277 bgr_t
*ptr3
= PIXEL_ADDR3(xrb
, x
[i
], y
[i
]);
2278 rgba
[i
][RCOMP
] = ptr3
->r
;
2279 rgba
[i
][GCOMP
] = ptr3
->g
;
2280 rgba
[i
][BCOMP
] = ptr3
->b
;
2281 rgba
[i
][ACOMP
] = 255;
2285 _mesa_problem(NULL
,"Problem in DD.read_color_pixels (1)");
2293 * Initialize the renderbuffer's PutRow, GetRow, etc. functions.
2294 * This would generally only need to be called once when the renderbuffer
2295 * is created. However, we can change pixel formats on the fly if dithering
2296 * is enabled/disabled. Therefore, we may call this more often than that.
2299 xmesa_set_renderbuffer_funcs(struct xmesa_renderbuffer
*xrb
,
2300 enum pixel_format pixelformat
, GLint depth
)
2302 const GLboolean pixmap
= xrb
->pixmap
? GL_TRUE
: GL_FALSE
;
2304 switch (pixelformat
) {
2307 xrb
->Base
.PutRow
= put_row_TRUECOLOR_pixmap
;
2308 xrb
->Base
.PutRowRGB
= put_row_rgb_TRUECOLOR_pixmap
;
2309 xrb
->Base
.PutValues
= put_values_TRUECOLOR_pixmap
;
2312 xrb
->Base
.PutRow
= put_row_TRUECOLOR_ximage
;
2313 xrb
->Base
.PutRowRGB
= put_row_rgb_TRUECOLOR_ximage
;
2314 xrb
->Base
.PutValues
= put_values_TRUECOLOR_ximage
;
2317 case PF_Dither_True
:
2319 xrb
->Base
.PutRow
= put_row_TRUEDITHER_pixmap
;
2320 xrb
->Base
.PutRowRGB
= put_row_rgb_TRUEDITHER_pixmap
;
2321 xrb
->Base
.PutValues
= put_values_TRUEDITHER_pixmap
;
2324 xrb
->Base
.PutRow
= put_row_TRUEDITHER_ximage
;
2325 xrb
->Base
.PutRowRGB
= put_row_rgb_TRUEDITHER_ximage
;
2326 xrb
->Base
.PutValues
= put_values_TRUEDITHER_ximage
;
2331 xrb
->Base
.PutRow
= put_row_8A8B8G8R_pixmap
;
2332 xrb
->Base
.PutRowRGB
= put_row_rgb_8A8B8G8R_pixmap
;
2333 xrb
->Base
.PutValues
= put_values_8A8B8G8R_pixmap
;
2336 xrb
->Base
.PutRow
= put_row_8A8B8G8R_ximage
;
2337 xrb
->Base
.PutRowRGB
= put_row_rgb_8A8B8G8R_ximage
;
2338 xrb
->Base
.PutValues
= put_values_8A8B8G8R_ximage
;
2343 xrb
->Base
.PutRow
= put_row_8A8R8G8B_pixmap
;
2344 xrb
->Base
.PutRowRGB
= put_row_rgb_8A8R8G8B_pixmap
;
2345 xrb
->Base
.PutValues
= put_values_8A8R8G8B_pixmap
;
2348 xrb
->Base
.PutRow
= put_row_8A8R8G8B_ximage
;
2349 xrb
->Base
.PutRowRGB
= put_row_rgb_8A8R8G8B_ximage
;
2350 xrb
->Base
.PutValues
= put_values_8A8R8G8B_ximage
;
2355 xrb
->Base
.PutRow
= put_row_8R8G8B_pixmap
;
2356 xrb
->Base
.PutRowRGB
= put_row_rgb_8R8G8B_pixmap
;
2357 xrb
->Base
.PutValues
= put_values_8R8G8B_pixmap
;
2360 xrb
->Base
.PutRow
= put_row_8R8G8B_ximage
;
2361 xrb
->Base
.PutRowRGB
= put_row_rgb_8R8G8B_ximage
;
2362 xrb
->Base
.PutValues
= put_values_8R8G8B_ximage
;
2367 xrb
->Base
.PutRow
= put_row_8R8G8B24_pixmap
;
2368 xrb
->Base
.PutRowRGB
= put_row_rgb_8R8G8B24_pixmap
;
2369 xrb
->Base
.PutValues
= put_values_8R8G8B24_pixmap
;
2372 xrb
->Base
.PutRow
= put_row_8R8G8B24_ximage
;
2373 xrb
->Base
.PutRowRGB
= put_row_rgb_8R8G8B24_ximage
;
2374 xrb
->Base
.PutValues
= put_values_8R8G8B24_ximage
;
2379 xrb
->Base
.PutRow
= put_row_5R6G5B_pixmap
;
2380 xrb
->Base
.PutRowRGB
= put_row_rgb_5R6G5B_pixmap
;
2381 xrb
->Base
.PutValues
= put_values_5R6G5B_pixmap
;
2384 xrb
->Base
.PutRow
= put_row_5R6G5B_ximage
;
2385 xrb
->Base
.PutRowRGB
= put_row_rgb_5R6G5B_ximage
;
2386 xrb
->Base
.PutValues
= put_values_5R6G5B_ximage
;
2389 case PF_Dither_5R6G5B
:
2391 xrb
->Base
.PutRow
= put_row_DITHER_5R6G5B_pixmap
;
2392 xrb
->Base
.PutRowRGB
= put_row_rgb_DITHER_5R6G5B_pixmap
;
2393 xrb
->Base
.PutValues
= put_values_DITHER_5R6G5B_pixmap
;
2396 xrb
->Base
.PutRow
= put_row_DITHER_5R6G5B_ximage
;
2397 xrb
->Base
.PutRowRGB
= put_row_rgb_DITHER_5R6G5B_ximage
;
2398 xrb
->Base
.PutValues
= put_values_DITHER_5R6G5B_ximage
;
2402 _mesa_problem(NULL
, "Bad pixel format in xmesa_update_state (1)");
2408 xrb
->Base
.GetRow
= get_row_rgba
;
2409 xrb
->Base
.GetValues
= get_values_rgba
;