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]_[mono]_[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 /*** Write MONO COLOR SPAN functions ***/
1815 /**********************************************************************/
1817 #define PUT_MONO_ROW_ARGS \
1818 struct gl_context *ctx, struct gl_renderbuffer *rb, \
1819 GLuint n, GLint x, GLint y, const void *value, \
1820 const GLubyte mask[]
1825 * Write a span of identical pixels to a pixmap.
1827 static void put_mono_row_pixmap( PUT_MONO_ROW_ARGS
)
1829 const GLubyte
*color
= (const GLubyte
*) value
;
1831 XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1832 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
1833 XMesaDrawable buffer
= xrb
->drawable
;
1834 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
1835 const unsigned long pixel
= xmesa_color_to_pixel(ctx
, color
[RCOMP
],
1836 color
[GCOMP
], color
[BCOMP
], color
[ACOMP
], xmesa
->pixelformat
);
1838 XMesaSetForeground( xmesa
->display
, gc
, pixel
);
1841 /* New code contributed by Jeff Epler and cleaned up by Keith
1844 for (i
= 0; i
< n
; ) {
1847 /* Identify and emit contiguous rendered pixels
1849 while (i
< n
&& (!mask
|| mask
[i
]))
1853 XMesaFillRectangle( dpy
, buffer
, gc
,
1854 (int)(x
+start
), (int) y
,
1857 /* Eat up non-rendered pixels
1859 while (i
< n
&& !mask
[i
])
1867 * Write a span of PF_TRUEDITHER pixels to a pixmap.
1869 static void put_mono_row_TRUEDITHER_pixmap( PUT_MONO_ROW_ARGS
)
1871 const GLubyte
*color
= (const GLubyte
*) value
;
1873 XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1874 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
1875 XMesaDrawable buffer
= xrb
->drawable
;
1876 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
1877 const GLubyte r
= color
[RCOMP
], g
= color
[GCOMP
], b
= color
[BCOMP
];
1879 int yy
= YFLIP(xrb
, y
);
1880 for (i
=0;i
<n
;i
++,x
++) {
1881 if (!mask
|| mask
[i
]) {
1883 PACK_TRUEDITHER(p
, x
, yy
, r
, g
, b
);
1884 XMesaSetForeground( dpy
, gc
, p
);
1885 XMesaDrawPoint( dpy
, buffer
, gc
, (int) x
, (int) yy
);
1892 * Write a span of identical pixels to an XImage.
1894 static void put_mono_row_ximage( PUT_MONO_ROW_ARGS
)
1896 const GLubyte
*color
= (const GLubyte
*) value
;
1898 XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1899 XMesaImage
*img
= xrb
->ximage
;
1901 const unsigned long pixel
= xmesa_color_to_pixel(ctx
, color
[RCOMP
],
1902 color
[GCOMP
], color
[BCOMP
], color
[ACOMP
], xmesa
->pixelformat
);
1904 for (i
=0;i
<n
;i
++,x
++) {
1905 if (!mask
|| mask
[i
]) {
1906 XMesaPutPixel( img
, x
, y
, pixel
);
1913 * Write a span of identical PF_TRUEDITHER pixels to an XImage.
1915 static void put_mono_row_TRUEDITHER_ximage( PUT_MONO_ROW_ARGS
)
1917 const GLubyte
*color
= (const GLubyte
*) value
;
1919 XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1920 XMesaImage
*img
= xrb
->ximage
;
1921 const GLint r
= color
[RCOMP
], g
= color
[GCOMP
], b
= color
[BCOMP
];
1925 if (!mask
|| mask
[i
]) {
1927 PACK_TRUEDITHER( p
, x
+i
, y
, r
, g
, b
);
1928 XMesaPutPixel( img
, x
+i
, y
, p
);
1935 * Write a span of identical 8A8B8G8R pixels to an XImage.
1937 static void put_mono_row_8A8B8G8R_ximage( PUT_MONO_ROW_ARGS
)
1939 const GLubyte
*color
= (const GLubyte
*) value
;
1941 XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1943 const unsigned long pixel
= xmesa_color_to_pixel(ctx
, color
[RCOMP
],
1944 color
[GCOMP
], color
[BCOMP
], color
[ACOMP
], xmesa
->pixelformat
);
1945 ptr
= PIXEL_ADDR4(xrb
, x
, y
);
1947 if (!mask
|| mask
[i
]) {
1954 * Write a span of identical 8A8R8G8B pixels to an XImage.
1956 static void put_mono_row_8A8R8G8B_ximage( PUT_MONO_ROW_ARGS
)
1958 const GLubyte
*color
= (const GLubyte
*) value
;
1961 XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1962 const unsigned long pixel
= xmesa_color_to_pixel(ctx
, color
[RCOMP
],
1963 color
[GCOMP
], color
[BCOMP
], color
[ACOMP
], xmesa
->pixelformat
);
1964 ptr
= PIXEL_ADDR4(xrb
, x
, y
);
1966 if (!mask
|| mask
[i
]) {
1974 * Write a span of identical 8R8G8B pixels to an XImage.
1976 static void put_mono_row_8R8G8B_ximage( PUT_MONO_ROW_ARGS
)
1978 const GLubyte
*color
= (const GLubyte
*) value
;
1980 const GLuint pixel
= PACK_8R8G8B(color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
1981 GLuint
*ptr
= PIXEL_ADDR4(xrb
, x
, y
);
1984 if (!mask
|| mask
[i
]) {
1992 * Write a span of identical 8R8G8B pixels to an XImage.
1994 static void put_mono_row_8R8G8B24_ximage( PUT_MONO_ROW_ARGS
)
1996 const GLubyte
*color
= (const GLubyte
*) value
;
1998 const GLubyte r
= color
[RCOMP
];
1999 const GLubyte g
= color
[GCOMP
];
2000 const GLubyte b
= color
[BCOMP
];
2002 bgr_t
*ptr
= PIXEL_ADDR3(xrb
, x
, y
);
2004 if (!mask
|| mask
[i
]) {
2014 * Write a span of identical PF_DITHER_5R6G5B pixels to an XImage.
2016 static void put_mono_row_DITHER_5R6G5B_ximage( PUT_MONO_ROW_ARGS
)
2018 const GLubyte
*color
= (const GLubyte
*) value
;
2020 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
2021 register GLushort
*ptr
= PIXEL_ADDR2(xrb
, x
, y
);
2022 const GLint r
= color
[RCOMP
], g
= color
[GCOMP
], b
= color
[BCOMP
];
2026 if (!mask
|| mask
[i
]) {
2027 PACK_TRUEDITHER(ptr
[i
], x
+i
, y
, r
, g
, b
);
2034 /**********************************************************************/
2035 /*** Write MONO COLOR PIXELS functions ***/
2036 /**********************************************************************/
2038 #define PUT_MONO_VALUES_ARGS \
2039 struct gl_context *ctx, struct gl_renderbuffer *rb, \
2040 GLuint n, const GLint x[], const GLint y[], \
2041 const void *value, const GLubyte mask[]
2046 * Write an array of identical pixels to a pixmap.
2048 static void put_mono_values_pixmap( PUT_MONO_VALUES_ARGS
)
2050 const GLubyte
*color
= (const GLubyte
*) value
;
2051 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
2053 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
2054 XMesaDrawable buffer
= xrb
->drawable
;
2055 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
2057 const unsigned long pixel
= xmesa_color_to_pixel(ctx
, color
[RCOMP
],
2058 color
[GCOMP
], color
[BCOMP
], color
[ACOMP
], xmesa
->pixelformat
);
2059 XMesaSetForeground( xmesa
->display
, gc
, pixel
);
2062 XMesaDrawPoint( dpy
, buffer
, gc
,
2063 (int) x
[i
], (int) YFLIP(xrb
, y
[i
]) );
2070 * Write an array of PF_TRUEDITHER pixels to a pixmap.
2072 static void put_mono_values_TRUEDITHER_pixmap( PUT_MONO_VALUES_ARGS
)
2074 const GLubyte
*color
= (const GLubyte
*) value
;
2075 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
2077 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
2078 XMesaDrawable buffer
= xrb
->drawable
;
2079 XMesaGC gc
= XMESA_BUFFER(ctx
->DrawBuffer
)->gc
;
2081 const GLubyte r
= color
[RCOMP
], g
= color
[GCOMP
], b
= color
[BCOMP
];
2085 PACK_TRUEDITHER(p
, x
[i
], y
[i
], r
, g
, b
);
2086 XMesaSetForeground( dpy
, gc
, p
);
2087 XMesaDrawPoint( dpy
, buffer
, gc
,
2088 (int) x
[i
], (int) YFLIP(xrb
, y
[i
]) );
2095 * Write an array of identical pixels to an XImage.
2097 static void put_mono_values_ximage( PUT_MONO_VALUES_ARGS
)
2099 const GLubyte
*color
= (const GLubyte
*) value
;
2100 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
2102 XMesaImage
*img
= xrb
->ximage
;
2104 const unsigned long pixel
= xmesa_color_to_pixel(ctx
, color
[RCOMP
],
2105 color
[GCOMP
], color
[BCOMP
], color
[ACOMP
], xmesa
->pixelformat
);
2108 XMesaPutPixel( img
, x
[i
], YFLIP(xrb
, y
[i
]), pixel
);
2115 * Write an array of identical TRUEDITHER pixels to an XImage.
2117 static void put_mono_values_TRUEDITHER_ximage( PUT_MONO_VALUES_ARGS
)
2119 const GLubyte
*color
= (const GLubyte
*) value
;
2120 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
2122 XMesaImage
*img
= xrb
->ximage
;
2124 const int r
= color
[RCOMP
], g
= color
[GCOMP
], b
= color
[BCOMP
];
2128 PACK_TRUEDITHER(p
, x
[i
], YFLIP(xrb
, y
[i
]), r
, g
, b
);
2129 XMesaPutPixel( img
, x
[i
], YFLIP(xrb
, y
[i
]), p
);
2137 * Write an array of identical 8A8B8G8R pixels to an XImage
2139 static void put_mono_values_8A8B8G8R_ximage( PUT_MONO_VALUES_ARGS
)
2141 const GLubyte
*color
= (const GLubyte
*) value
;
2143 const GLuint p
= PACK_8A8B8G8R(color
[RCOMP
], color
[GCOMP
],
2144 color
[BCOMP
], color
[ACOMP
]);
2148 GLuint
*ptr
= PIXEL_ADDR4(xrb
, x
[i
], y
[i
] );
2155 * Write an array of identical 8A8R8G8B pixels to an XImage
2157 static void put_mono_values_8A8R8G8B_ximage( PUT_MONO_VALUES_ARGS
)
2159 const GLubyte
*color
= (const GLubyte
*) value
;
2161 const GLuint p
= PACK_8A8R8G8B(color
[RCOMP
], color
[GCOMP
],
2162 color
[BCOMP
], color
[ACOMP
]);
2166 GLuint
*ptr
= PIXEL_ADDR4(xrb
, x
[i
], y
[i
] );
2173 * Write an array of identical 8R8G8B pixels to an XImage.
2175 static void put_mono_values_8R8G8B_ximage( PUT_MONO_VALUES_ARGS
)
2177 const GLubyte
*color
= (const GLubyte
*) value
;
2180 const GLuint p
= PACK_8R8G8B(color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
2183 GLuint
*ptr
= PIXEL_ADDR4(xrb
, x
[i
], y
[i
] );
2191 * Write an array of identical 8R8G8B pixels to an XImage.
2193 static void put_mono_values_8R8G8B24_ximage( PUT_MONO_VALUES_ARGS
)
2195 const GLubyte
*color
= (const GLubyte
*) value
;
2197 const GLubyte r
= color
[RCOMP
], g
= color
[GCOMP
], b
= color
[BCOMP
];
2201 bgr_t
*ptr
= PIXEL_ADDR3(xrb
, x
[i
], y
[i
] );
2211 * Write an array of identical PF_DITHER_5R6G5B pixels to an XImage.
2213 static void put_mono_values_DITHER_5R6G5B_ximage( PUT_MONO_VALUES_ARGS
)
2215 const GLubyte
*color
= (const GLubyte
*) value
;
2217 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
2218 const int r
= color
[RCOMP
], g
= color
[GCOMP
], b
= color
[BCOMP
];
2222 GLushort
*ptr
= PIXEL_ADDR2(xrb
, x
[i
], y
[i
] );
2223 PACK_TRUEDITHER(*ptr
, x
[i
], y
[i
], r
, g
, b
);
2230 /**********************************************************************/
2231 /***** Pixel reading *****/
2232 /**********************************************************************/
2235 * Do clip testing prior to calling XGetImage. If any of the region lies
2236 * outside the screen's bounds, XGetImage will return NULL.
2237 * We use XTranslateCoordinates() to check if that's the case and
2238 * adjust the x, y and length parameters accordingly.
2239 * \return -1 if span is totally clipped away,
2240 * else return number of pixels to skip in the destination array.
2243 clip_for_xgetimage(struct gl_context
*ctx
, XMesaPixmap pixmap
, GLuint
*n
, GLint
*x
, GLint
*y
)
2245 XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
2246 XMesaBuffer source
= XMESA_BUFFER(ctx
->DrawBuffer
);
2247 Window rootWin
= RootWindow(xmesa
->display
, 0);
2249 GLint screenWidth
= WidthOfScreen(DefaultScreenOfDisplay(xmesa
->display
));
2251 if (source
->type
== PBUFFER
|| source
->type
== PIXMAP
)
2253 XTranslateCoordinates(xmesa
->display
, pixmap
, rootWin
,
2254 *x
, *y
, &dx
, &dy
, &child
);
2255 if (dx
>= screenWidth
) {
2256 /* totally clipped on right */
2260 /* clipped on left */
2262 if (clip
>= (GLint
) *n
)
2263 return -1; /* totally clipped on left */
2269 if ((GLint
) (dx
+ *n
) > screenWidth
) {
2270 /* clipped on right */
2271 GLint clip
= dx
+ *n
- screenWidth
;
2279 * Read a horizontal span of color pixels.
2282 get_row_rgba(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2283 GLuint n
, GLint x
, GLint y
, void *values
)
2285 GLubyte (*rgba
)[4] = (GLubyte (*)[4]) values
;
2286 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
2290 /* Read from Pixmap or Window */
2291 XMesaImage
*span
= NULL
;
2295 k
= clip_for_xgetimage(ctx
, xrb
->pixmap
, &n
, &x
, &y
);
2299 catch_xgetimage_errors( xmesa
->display
);
2300 span
= XGetImage( xmesa
->display
, xrb
->pixmap
,
2301 x
, y
, n
, 1, AllPlanes
, ZPixmap
);
2302 error
= check_xgetimage_errors();
2303 if (span
&& !error
) {
2304 switch (xmesa
->pixelformat
) {
2306 case PF_Dither_True
:
2308 const GLubyte
*pixelToR
= xmesa
->xm_visual
->PixelToR
;
2309 const GLubyte
*pixelToG
= xmesa
->xm_visual
->PixelToG
;
2310 const GLubyte
*pixelToB
= xmesa
->xm_visual
->PixelToB
;
2311 unsigned long rMask
= GET_REDMASK(xmesa
->xm_visual
);
2312 unsigned long gMask
= GET_GREENMASK(xmesa
->xm_visual
);
2313 unsigned long bMask
= GET_BLUEMASK(xmesa
->xm_visual
);
2314 GLint rShift
= xmesa
->xm_visual
->rshift
;
2315 GLint gShift
= xmesa
->xm_visual
->gshift
;
2316 GLint bShift
= xmesa
->xm_visual
->bshift
;
2320 p
= XMesaGetPixel( span
, i
, 0 );
2321 rgba
[i
][RCOMP
] = pixelToR
[(p
& rMask
) >> rShift
];
2322 rgba
[i
][GCOMP
] = pixelToG
[(p
& gMask
) >> gShift
];
2323 rgba
[i
][BCOMP
] = pixelToB
[(p
& bMask
) >> bShift
];
2324 rgba
[i
][ACOMP
] = 255;
2329 case PF_Dither_5R6G5B
:
2331 const GLubyte
*pixelToR
= xmesa
->xm_visual
->PixelToR
;
2332 const GLubyte
*pixelToG
= xmesa
->xm_visual
->PixelToG
;
2333 const GLubyte
*pixelToB
= xmesa
->xm_visual
->PixelToB
;
2336 unsigned long p
= XMesaGetPixel( span
, i
, 0 );
2337 /* fast, but not quite accurate
2338 rgba[i][RCOMP] = ((p >> 8) & 0xf8);
2339 rgba[i][GCOMP] = ((p >> 3) & 0xfc);
2340 rgba[i][BCOMP] = ((p << 3) & 0xff);
2342 rgba
[i
][RCOMP
] = pixelToR
[p
>> 11];
2343 rgba
[i
][GCOMP
] = pixelToG
[(p
>> 5) & 0x3f];
2344 rgba
[i
][BCOMP
] = pixelToB
[p
& 0x1f];
2345 rgba
[i
][ACOMP
] = 255;
2351 const GLuint
*ptr4
= (GLuint
*) span
->data
;
2354 GLuint p4
= *ptr4
++;
2355 rgba
[i
][RCOMP
] = (GLubyte
) ( p4
& 0xff);
2356 rgba
[i
][GCOMP
] = (GLubyte
) ((p4
>> 8) & 0xff);
2357 rgba
[i
][BCOMP
] = (GLubyte
) ((p4
>> 16) & 0xff);
2358 rgba
[i
][ACOMP
] = (GLubyte
) ((p4
>> 24) & 0xff);
2364 const GLuint
*ptr4
= (GLuint
*) span
->data
;
2367 GLuint p4
= *ptr4
++;
2368 rgba
[i
][RCOMP
] = (GLubyte
) ((p4
>> 16) & 0xff);
2369 rgba
[i
][GCOMP
] = (GLubyte
) ((p4
>> 8) & 0xff);
2370 rgba
[i
][BCOMP
] = (GLubyte
) ( p4
& 0xff);
2371 rgba
[i
][ACOMP
] = (GLubyte
) ((p4
>> 24) & 0xff);
2377 const GLuint
*ptr4
= (GLuint
*) span
->data
;
2380 GLuint p4
= *ptr4
++;
2381 rgba
[i
][RCOMP
] = (GLubyte
) ((p4
>> 16) & 0xff);
2382 rgba
[i
][GCOMP
] = (GLubyte
) ((p4
>> 8) & 0xff);
2383 rgba
[i
][BCOMP
] = (GLubyte
) ( p4
& 0xff);
2384 rgba
[i
][ACOMP
] = 255;
2390 const bgr_t
*ptr3
= (bgr_t
*) span
->data
;
2393 rgba
[i
][RCOMP
] = ptr3
[i
].r
;
2394 rgba
[i
][GCOMP
] = ptr3
[i
].g
;
2395 rgba
[i
][BCOMP
] = ptr3
[i
].b
;
2396 rgba
[i
][ACOMP
] = 255;
2401 _mesa_problem(NULL
,"Problem in DD.read_color_span (1)");
2406 /* return black pixels */
2409 rgba
[i
][RCOMP
] = rgba
[i
][GCOMP
] = rgba
[i
][BCOMP
] = rgba
[i
][ACOMP
] = 0;
2413 XMesaDestroyImage( span
);
2416 else if (xrb
->ximage
) {
2417 /* Read from XImage back buffer */
2418 switch (xmesa
->pixelformat
) {
2420 case PF_Dither_True
:
2422 const GLubyte
*pixelToR
= xmesa
->xm_visual
->PixelToR
;
2423 const GLubyte
*pixelToG
= xmesa
->xm_visual
->PixelToG
;
2424 const GLubyte
*pixelToB
= xmesa
->xm_visual
->PixelToB
;
2425 unsigned long rMask
= GET_REDMASK(xmesa
->xm_visual
);
2426 unsigned long gMask
= GET_GREENMASK(xmesa
->xm_visual
);
2427 unsigned long bMask
= GET_BLUEMASK(xmesa
->xm_visual
);
2428 GLint rShift
= xmesa
->xm_visual
->rshift
;
2429 GLint gShift
= xmesa
->xm_visual
->gshift
;
2430 GLint bShift
= xmesa
->xm_visual
->bshift
;
2431 XMesaImage
*img
= xrb
->ximage
;
2436 p
= XMesaGetPixel( img
, x
+i
, y
);
2437 rgba
[i
][RCOMP
] = pixelToR
[(p
& rMask
) >> rShift
];
2438 rgba
[i
][GCOMP
] = pixelToG
[(p
& gMask
) >> gShift
];
2439 rgba
[i
][BCOMP
] = pixelToB
[(p
& bMask
) >> bShift
];
2440 rgba
[i
][ACOMP
] = 255;
2445 case PF_Dither_5R6G5B
:
2447 const GLubyte
*pixelToR
= xmesa
->xm_visual
->PixelToR
;
2448 const GLubyte
*pixelToG
= xmesa
->xm_visual
->PixelToG
;
2449 const GLubyte
*pixelToB
= xmesa
->xm_visual
->PixelToB
;
2450 const GLushort
*ptr2
= PIXEL_ADDR2(xrb
, x
, y
);
2452 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
2453 const GLuint
*ptr4
= (const GLuint
*) ptr2
;
2454 GLuint extraPixel
= (n
& 1);
2456 for (i
= 0; i
< n
; i
+= 2) {
2457 const GLuint p
= *ptr4
++;
2458 const GLuint p0
= p
& 0xffff;
2459 const GLuint p1
= p
>> 16;
2460 /* fast, but not quite accurate
2461 rgba[i][RCOMP] = ((p >> 8) & 0xf8);
2462 rgba[i][GCOMP] = ((p >> 3) & 0xfc);
2463 rgba[i][BCOMP] = ((p << 3) & 0xff);
2465 rgba
[i
][RCOMP
] = pixelToR
[p0
>> 11];
2466 rgba
[i
][GCOMP
] = pixelToG
[(p0
>> 5) & 0x3f];
2467 rgba
[i
][BCOMP
] = pixelToB
[p0
& 0x1f];
2468 rgba
[i
][ACOMP
] = 255;
2469 rgba
[i
+1][RCOMP
] = pixelToR
[p1
>> 11];
2470 rgba
[i
+1][GCOMP
] = pixelToG
[(p1
>> 5) & 0x3f];
2471 rgba
[i
+1][BCOMP
] = pixelToB
[p1
& 0x1f];
2472 rgba
[i
+1][ACOMP
] = 255;
2475 GLushort p
= ptr2
[n
];
2476 rgba
[n
][RCOMP
] = pixelToR
[p
>> 11];
2477 rgba
[n
][GCOMP
] = pixelToG
[(p
>> 5) & 0x3f];
2478 rgba
[n
][BCOMP
] = pixelToB
[p
& 0x1f];
2479 rgba
[n
][ACOMP
] = 255;
2482 for (i
= 0; i
< n
; i
++) {
2483 const GLushort p
= ptr2
[i
];
2484 rgba
[i
][RCOMP
] = pixelToR
[p
>> 11];
2485 rgba
[i
][GCOMP
] = pixelToG
[(p
>> 5) & 0x3f];
2486 rgba
[i
][BCOMP
] = pixelToB
[p
& 0x1f];
2487 rgba
[i
][ACOMP
] = 255;
2494 const GLuint
*ptr4
= PIXEL_ADDR4(xrb
, x
, y
);
2497 GLuint p4
= *ptr4
++;
2498 rgba
[i
][RCOMP
] = (GLubyte
) ( p4
& 0xff);
2499 rgba
[i
][GCOMP
] = (GLubyte
) ((p4
>> 8) & 0xff);
2500 rgba
[i
][BCOMP
] = (GLubyte
) ((p4
>> 16) & 0xff);
2501 rgba
[i
][ACOMP
] = (GLint
) ((p4
>> 24) & 0xff);
2507 const GLuint
*ptr4
= PIXEL_ADDR4(xrb
, x
, y
);
2510 GLuint p4
= *ptr4
++;
2511 rgba
[i
][RCOMP
] = (GLubyte
) ((p4
>> 16) & 0xff);
2512 rgba
[i
][GCOMP
] = (GLubyte
) ((p4
>> 8) & 0xff);
2513 rgba
[i
][BCOMP
] = (GLubyte
) ( p4
& 0xff);
2514 rgba
[i
][ACOMP
] = (GLint
) ((p4
>> 24) & 0xff);
2520 const GLuint
*ptr4
= PIXEL_ADDR4(xrb
, x
, y
);
2523 GLuint p4
= *ptr4
++;
2524 rgba
[i
][RCOMP
] = (GLubyte
) ((p4
>> 16) & 0xff);
2525 rgba
[i
][GCOMP
] = (GLubyte
) ((p4
>> 8) & 0xff);
2526 rgba
[i
][BCOMP
] = (GLubyte
) ( p4
& 0xff);
2527 rgba
[i
][ACOMP
] = 255;
2533 const bgr_t
*ptr3
= PIXEL_ADDR3(xrb
, x
, y
);
2536 rgba
[i
][RCOMP
] = ptr3
[i
].r
;
2537 rgba
[i
][GCOMP
] = ptr3
[i
].g
;
2538 rgba
[i
][BCOMP
] = ptr3
[i
].b
;
2539 rgba
[i
][ACOMP
] = 255;
2544 _mesa_problem(NULL
,"Problem in DD.read_color_span (2)");
2553 get_values_rgba(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2554 GLuint n
, const GLint x
[], const GLint y
[], void *values
)
2556 GLubyte (*rgba
)[4] = (GLubyte (*)[4]) values
;
2558 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
2559 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
2563 XMesaDrawable buffer
= xrb
->drawable
;
2564 switch (xmesa
->pixelformat
) {
2566 case PF_Dither_True
:
2568 case PF_Dither_5R6G5B
:
2570 unsigned long rMask
= GET_REDMASK(xmesa
->xm_visual
);
2571 unsigned long gMask
= GET_GREENMASK(xmesa
->xm_visual
);
2572 unsigned long bMask
= GET_BLUEMASK(xmesa
->xm_visual
);
2573 GLubyte
*pixelToR
= xmesa
->xm_visual
->PixelToR
;
2574 GLubyte
*pixelToG
= xmesa
->xm_visual
->PixelToG
;
2575 GLubyte
*pixelToB
= xmesa
->xm_visual
->PixelToB
;
2576 GLint rShift
= xmesa
->xm_visual
->rshift
;
2577 GLint gShift
= xmesa
->xm_visual
->gshift
;
2578 GLint bShift
= xmesa
->xm_visual
->bshift
;
2580 unsigned long p
= read_pixel( dpy
, buffer
,
2581 x
[i
], YFLIP(xrb
, y
[i
]) );
2582 rgba
[i
][RCOMP
] = pixelToR
[(p
& rMask
) >> rShift
];
2583 rgba
[i
][GCOMP
] = pixelToG
[(p
& gMask
) >> gShift
];
2584 rgba
[i
][BCOMP
] = pixelToB
[(p
& bMask
) >> bShift
];
2585 rgba
[i
][ACOMP
] = 255;
2591 unsigned long p
= read_pixel( dpy
, buffer
,
2592 x
[i
], YFLIP(xrb
, y
[i
]) );
2593 rgba
[i
][RCOMP
] = (GLubyte
) ( p
& 0xff);
2594 rgba
[i
][GCOMP
] = (GLubyte
) ((p
>> 8) & 0xff);
2595 rgba
[i
][BCOMP
] = (GLubyte
) ((p
>> 16) & 0xff);
2596 rgba
[i
][ACOMP
] = (GLubyte
) ((p
>> 24) & 0xff);
2601 unsigned long p
= read_pixel( dpy
, buffer
,
2602 x
[i
], YFLIP(xrb
, y
[i
]) );
2603 rgba
[i
][RCOMP
] = (GLubyte
) ((p
>> 16) & 0xff);
2604 rgba
[i
][GCOMP
] = (GLubyte
) ((p
>> 8) & 0xff);
2605 rgba
[i
][BCOMP
] = (GLubyte
) ( p
& 0xff);
2606 rgba
[i
][ACOMP
] = (GLubyte
) ((p
>> 24) & 0xff);
2611 unsigned long p
= read_pixel( dpy
, buffer
,
2612 x
[i
], YFLIP(xrb
, y
[i
]) );
2613 rgba
[i
][RCOMP
] = (GLubyte
) ((p
>> 16) & 0xff);
2614 rgba
[i
][GCOMP
] = (GLubyte
) ((p
>> 8) & 0xff);
2615 rgba
[i
][BCOMP
] = (GLubyte
) ( p
& 0xff);
2616 rgba
[i
][ACOMP
] = 255;
2621 unsigned long p
= read_pixel( dpy
, buffer
,
2622 x
[i
], YFLIP(xrb
, y
[i
]) );
2623 rgba
[i
][RCOMP
] = (GLubyte
) ((p
>> 16) & 0xff);
2624 rgba
[i
][GCOMP
] = (GLubyte
) ((p
>> 8) & 0xff);
2625 rgba
[i
][BCOMP
] = (GLubyte
) ( p
& 0xff);
2626 rgba
[i
][ACOMP
] = 255;
2630 _mesa_problem(NULL
,"Problem in DD.read_color_pixels (1)");
2634 else if (xrb
->ximage
) {
2635 /* Read from XImage back buffer */
2636 switch (xmesa
->pixelformat
) {
2638 case PF_Dither_True
:
2640 case PF_Dither_5R6G5B
:
2642 unsigned long rMask
= GET_REDMASK(xmesa
->xm_visual
);
2643 unsigned long gMask
= GET_GREENMASK(xmesa
->xm_visual
);
2644 unsigned long bMask
= GET_BLUEMASK(xmesa
->xm_visual
);
2645 GLubyte
*pixelToR
= xmesa
->xm_visual
->PixelToR
;
2646 GLubyte
*pixelToG
= xmesa
->xm_visual
->PixelToG
;
2647 GLubyte
*pixelToB
= xmesa
->xm_visual
->PixelToB
;
2648 GLint rShift
= xmesa
->xm_visual
->rshift
;
2649 GLint gShift
= xmesa
->xm_visual
->gshift
;
2650 GLint bShift
= xmesa
->xm_visual
->bshift
;
2651 XMesaImage
*img
= xrb
->ximage
;
2654 p
= XMesaGetPixel( img
, x
[i
], YFLIP(xrb
, y
[i
]) );
2655 rgba
[i
][RCOMP
] = pixelToR
[(p
& rMask
) >> rShift
];
2656 rgba
[i
][GCOMP
] = pixelToG
[(p
& gMask
) >> gShift
];
2657 rgba
[i
][BCOMP
] = pixelToB
[(p
& bMask
) >> bShift
];
2658 rgba
[i
][ACOMP
] = 255;
2664 GLuint
*ptr4
= PIXEL_ADDR4(xrb
, x
[i
], y
[i
]);
2666 rgba
[i
][RCOMP
] = (GLubyte
) ( p4
& 0xff);
2667 rgba
[i
][GCOMP
] = (GLubyte
) ((p4
>> 8) & 0xff);
2668 rgba
[i
][BCOMP
] = (GLubyte
) ((p4
>> 16) & 0xff);
2669 rgba
[i
][ACOMP
] = (GLubyte
) ((p4
>> 24) & 0xff);
2674 GLuint
*ptr4
= PIXEL_ADDR4(xrb
, x
[i
], y
[i
]);
2676 rgba
[i
][RCOMP
] = (GLubyte
) ((p4
>> 16) & 0xff);
2677 rgba
[i
][GCOMP
] = (GLubyte
) ((p4
>> 8) & 0xff);
2678 rgba
[i
][BCOMP
] = (GLubyte
) ( p4
& 0xff);
2679 rgba
[i
][ACOMP
] = (GLubyte
) ((p4
>> 24) & 0xff);
2684 GLuint
*ptr4
= PIXEL_ADDR4(xrb
, x
[i
], y
[i
]);
2686 rgba
[i
][RCOMP
] = (GLubyte
) ((p4
>> 16) & 0xff);
2687 rgba
[i
][GCOMP
] = (GLubyte
) ((p4
>> 8) & 0xff);
2688 rgba
[i
][BCOMP
] = (GLubyte
) ( p4
& 0xff);
2689 rgba
[i
][ACOMP
] = 255;
2694 bgr_t
*ptr3
= PIXEL_ADDR3(xrb
, x
[i
], y
[i
]);
2695 rgba
[i
][RCOMP
] = ptr3
->r
;
2696 rgba
[i
][GCOMP
] = ptr3
->g
;
2697 rgba
[i
][BCOMP
] = ptr3
->b
;
2698 rgba
[i
][ACOMP
] = 255;
2702 _mesa_problem(NULL
,"Problem in DD.read_color_pixels (1)");
2710 * Initialize the renderbuffer's PutRow, GetRow, etc. functions.
2711 * This would generally only need to be called once when the renderbuffer
2712 * is created. However, we can change pixel formats on the fly if dithering
2713 * is enabled/disabled. Therefore, we may call this more often than that.
2716 xmesa_set_renderbuffer_funcs(struct xmesa_renderbuffer
*xrb
,
2717 enum pixel_format pixelformat
, GLint depth
)
2719 const GLboolean pixmap
= xrb
->pixmap
? GL_TRUE
: GL_FALSE
;
2721 switch (pixelformat
) {
2724 xrb
->Base
.PutRow
= put_row_TRUECOLOR_pixmap
;
2725 xrb
->Base
.PutRowRGB
= put_row_rgb_TRUECOLOR_pixmap
;
2726 xrb
->Base
.PutMonoRow
= put_mono_row_pixmap
;
2727 xrb
->Base
.PutValues
= put_values_TRUECOLOR_pixmap
;
2728 xrb
->Base
.PutMonoValues
= put_mono_values_pixmap
;
2731 xrb
->Base
.PutRow
= put_row_TRUECOLOR_ximage
;
2732 xrb
->Base
.PutRowRGB
= put_row_rgb_TRUECOLOR_ximage
;
2733 xrb
->Base
.PutMonoRow
= put_mono_row_ximage
;
2734 xrb
->Base
.PutValues
= put_values_TRUECOLOR_ximage
;
2735 xrb
->Base
.PutMonoValues
= put_mono_values_ximage
;
2738 case PF_Dither_True
:
2740 xrb
->Base
.PutRow
= put_row_TRUEDITHER_pixmap
;
2741 xrb
->Base
.PutRowRGB
= put_row_rgb_TRUEDITHER_pixmap
;
2742 xrb
->Base
.PutMonoRow
= put_mono_row_TRUEDITHER_pixmap
;
2743 xrb
->Base
.PutValues
= put_values_TRUEDITHER_pixmap
;
2744 xrb
->Base
.PutMonoValues
= put_mono_values_TRUEDITHER_pixmap
;
2747 xrb
->Base
.PutRow
= put_row_TRUEDITHER_ximage
;
2748 xrb
->Base
.PutRowRGB
= put_row_rgb_TRUEDITHER_ximage
;
2749 xrb
->Base
.PutMonoRow
= put_mono_row_TRUEDITHER_ximage
;
2750 xrb
->Base
.PutValues
= put_values_TRUEDITHER_ximage
;
2751 xrb
->Base
.PutMonoValues
= put_mono_values_TRUEDITHER_ximage
;
2756 xrb
->Base
.PutRow
= put_row_8A8B8G8R_pixmap
;
2757 xrb
->Base
.PutRowRGB
= put_row_rgb_8A8B8G8R_pixmap
;
2758 xrb
->Base
.PutMonoRow
= put_mono_row_pixmap
;
2759 xrb
->Base
.PutValues
= put_values_8A8B8G8R_pixmap
;
2760 xrb
->Base
.PutMonoValues
= put_mono_values_pixmap
;
2763 xrb
->Base
.PutRow
= put_row_8A8B8G8R_ximage
;
2764 xrb
->Base
.PutRowRGB
= put_row_rgb_8A8B8G8R_ximage
;
2765 xrb
->Base
.PutMonoRow
= put_mono_row_8A8B8G8R_ximage
;
2766 xrb
->Base
.PutValues
= put_values_8A8B8G8R_ximage
;
2767 xrb
->Base
.PutMonoValues
= put_mono_values_8A8B8G8R_ximage
;
2772 xrb
->Base
.PutRow
= put_row_8A8R8G8B_pixmap
;
2773 xrb
->Base
.PutRowRGB
= put_row_rgb_8A8R8G8B_pixmap
;
2774 xrb
->Base
.PutMonoRow
= put_mono_row_pixmap
;
2775 xrb
->Base
.PutValues
= put_values_8A8R8G8B_pixmap
;
2776 xrb
->Base
.PutMonoValues
= put_mono_values_pixmap
;
2779 xrb
->Base
.PutRow
= put_row_8A8R8G8B_ximage
;
2780 xrb
->Base
.PutRowRGB
= put_row_rgb_8A8R8G8B_ximage
;
2781 xrb
->Base
.PutMonoRow
= put_mono_row_8A8R8G8B_ximage
;
2782 xrb
->Base
.PutValues
= put_values_8A8R8G8B_ximage
;
2783 xrb
->Base
.PutMonoValues
= put_mono_values_8A8R8G8B_ximage
;
2788 xrb
->Base
.PutRow
= put_row_8R8G8B_pixmap
;
2789 xrb
->Base
.PutRowRGB
= put_row_rgb_8R8G8B_pixmap
;
2790 xrb
->Base
.PutMonoRow
= put_mono_row_pixmap
;
2791 xrb
->Base
.PutValues
= put_values_8R8G8B_pixmap
;
2792 xrb
->Base
.PutMonoValues
= put_mono_values_pixmap
;
2795 xrb
->Base
.PutRow
= put_row_8R8G8B_ximage
;
2796 xrb
->Base
.PutRowRGB
= put_row_rgb_8R8G8B_ximage
;
2797 xrb
->Base
.PutMonoRow
= put_mono_row_8R8G8B_ximage
;
2798 xrb
->Base
.PutValues
= put_values_8R8G8B_ximage
;
2799 xrb
->Base
.PutMonoValues
= put_mono_values_8R8G8B_ximage
;
2804 xrb
->Base
.PutRow
= put_row_8R8G8B24_pixmap
;
2805 xrb
->Base
.PutRowRGB
= put_row_rgb_8R8G8B24_pixmap
;
2806 xrb
->Base
.PutMonoRow
= put_mono_row_pixmap
;
2807 xrb
->Base
.PutValues
= put_values_8R8G8B24_pixmap
;
2808 xrb
->Base
.PutMonoValues
= put_mono_values_pixmap
;
2811 xrb
->Base
.PutRow
= put_row_8R8G8B24_ximage
;
2812 xrb
->Base
.PutRowRGB
= put_row_rgb_8R8G8B24_ximage
;
2813 xrb
->Base
.PutMonoRow
= put_mono_row_8R8G8B24_ximage
;
2814 xrb
->Base
.PutValues
= put_values_8R8G8B24_ximage
;
2815 xrb
->Base
.PutMonoValues
= put_mono_values_8R8G8B24_ximage
;
2820 xrb
->Base
.PutRow
= put_row_5R6G5B_pixmap
;
2821 xrb
->Base
.PutRowRGB
= put_row_rgb_5R6G5B_pixmap
;
2822 xrb
->Base
.PutMonoRow
= put_mono_row_pixmap
;
2823 xrb
->Base
.PutValues
= put_values_5R6G5B_pixmap
;
2824 xrb
->Base
.PutMonoValues
= put_mono_values_pixmap
;
2827 xrb
->Base
.PutRow
= put_row_5R6G5B_ximage
;
2828 xrb
->Base
.PutRowRGB
= put_row_rgb_5R6G5B_ximage
;
2829 xrb
->Base
.PutMonoRow
= put_mono_row_ximage
;
2830 xrb
->Base
.PutValues
= put_values_5R6G5B_ximage
;
2831 xrb
->Base
.PutMonoValues
= put_mono_values_ximage
;
2834 case PF_Dither_5R6G5B
:
2836 xrb
->Base
.PutRow
= put_row_DITHER_5R6G5B_pixmap
;
2837 xrb
->Base
.PutRowRGB
= put_row_rgb_DITHER_5R6G5B_pixmap
;
2838 xrb
->Base
.PutMonoRow
= put_mono_row_TRUEDITHER_pixmap
;
2839 xrb
->Base
.PutValues
= put_values_DITHER_5R6G5B_pixmap
;
2840 xrb
->Base
.PutMonoValues
= put_mono_values_TRUEDITHER_pixmap
;
2843 xrb
->Base
.PutRow
= put_row_DITHER_5R6G5B_ximage
;
2844 xrb
->Base
.PutRowRGB
= put_row_rgb_DITHER_5R6G5B_ximage
;
2845 xrb
->Base
.PutMonoRow
= put_mono_row_DITHER_5R6G5B_ximage
;
2846 xrb
->Base
.PutValues
= put_values_DITHER_5R6G5B_ximage
;
2847 xrb
->Base
.PutMonoValues
= put_mono_values_DITHER_5R6G5B_ximage
;
2851 _mesa_problem(NULL
, "Bad pixel format in xmesa_update_state (1)");
2857 xrb
->Base
.GetRow
= get_row_rgba
;
2858 xrb
->Base
.GetValues
= get_values_rgba
;