1 /* $Id: xm_dd.c,v 1.41 2002/10/30 20:24:47 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 /* $XFree86: xc/extras/Mesa/src/X/xm_dd.c,v 1.2 2002/02/26 23:37:31 tsi Exp $ */
28 #include "glxheader.h"
33 #include "extensions.h"
39 #include "texformat.h"
41 #include "array_cache/acache.h"
42 #include "swrast/s_context.h"
43 #include "swrast/swrast.h"
44 #include "swrast/s_alphabuf.h"
45 #include "swrast_setup/swrast_setup.h"
47 #include "tnl/t_context.h"
48 #include "tnl/t_pipeline.h"
52 * Return the size (width, height) of the X window for the given GLframebuffer.
53 * Output: width - width of buffer in pixels.
54 * height - height of buffer in pixels.
57 get_buffer_size( GLframebuffer
*buffer
, GLuint
*width
, GLuint
*height
)
59 /* We can do this cast because the first field in the XMesaBuffer
60 * struct is a GLframebuffer struct. If this weren't true, we'd
61 * need a pointer from the GLframebuffer to the XMesaBuffer.
63 const XMesaBuffer xmBuffer
= (XMesaBuffer
) buffer
;
64 unsigned int winwidth
, winheight
;
66 /* XFree86 GLX renderer */
67 winwidth
= xmBuffer
->frontbuffer
->width
;
68 winheight
= xmBuffer
->frontbuffer
->height
;
74 _glthread_LOCK_MUTEX(_xmesa_lock
);
75 XSync(xmBuffer
->xm_visual
->display
, 0); /* added for Chromium */
76 XGetGeometry( xmBuffer
->xm_visual
->display
, xmBuffer
->frontbuffer
, &root
,
77 &winx
, &winy
, &winwidth
, &winheight
, &bw
, &d
);
78 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
81 (void)kernel8
; /* Muffle compiler */
89 finish( GLcontext
*ctx
)
94 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
96 _glthread_LOCK_MUTEX(_xmesa_lock
);
97 XSync( xmesa
->display
, False
);
98 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
105 flush( GLcontext
*ctx
)
110 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
112 _glthread_LOCK_MUTEX(_xmesa_lock
);
113 XFlush( xmesa
->display
);
114 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
122 * This chooses the color buffer for reading and writing spans, points,
123 * lines, and triangles.
126 set_buffer( GLcontext
*ctx
, GLframebuffer
*buffer
, GLuint bufferBit
)
128 /* We can make this cast since the XMesaBuffer wraps GLframebuffer.
129 * GLframebuffer is the first member in a XMesaBuffer struct.
131 XMesaBuffer target
= (XMesaBuffer
) buffer
;
132 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
134 /* This assignment tells the span/point/line/triangle functions
135 * which XMesaBuffer to use.
137 xmesa
->xm_buffer
= target
;
140 * Now determine front vs back color buffer.
142 if (bufferBit
== FRONT_LEFT_BIT
) {
143 target
->buffer
= target
->frontbuffer
;
145 else if (bufferBit
== BACK_LEFT_BIT
) {
146 ASSERT(target
->db_state
);
147 if (target
->backpixmap
) {
148 /* back buffer is a pixmape */
149 target
->buffer
= target
->backpixmap
; /* incompatible types? */
151 else if (target
->backimage
) {
152 /* back buffer is an XImage */
153 target
->buffer
= None
;
156 /* No back buffer!!!! Must be out of memory, use front buffer */
157 target
->buffer
= target
->frontbuffer
;
161 _mesa_problem(ctx
, "invalid buffer 0x%x in set_buffer() in xm_dd.c");
164 xmesa_update_span_funcs(ctx
);
170 clear_index( GLcontext
*ctx
, GLuint index
)
172 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
173 xmesa
->clearpixel
= (unsigned long) index
;
174 XMesaSetForeground( xmesa
->display
, xmesa
->xm_draw_buffer
->cleargc
,
175 (unsigned long) index
);
180 clear_color( GLcontext
*ctx
, const GLfloat color
[4] )
182 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
183 CLAMPED_FLOAT_TO_UBYTE(xmesa
->clearcolor
[0], color
[0]);
184 CLAMPED_FLOAT_TO_UBYTE(xmesa
->clearcolor
[1], color
[1]);
185 CLAMPED_FLOAT_TO_UBYTE(xmesa
->clearcolor
[2], color
[2]);
186 CLAMPED_FLOAT_TO_UBYTE(xmesa
->clearcolor
[3], color
[3]);
187 xmesa
->clearpixel
= xmesa_color_to_pixel( xmesa
,
188 xmesa
->clearcolor
[0],
189 xmesa
->clearcolor
[1],
190 xmesa
->clearcolor
[2],
191 xmesa
->clearcolor
[3],
192 xmesa
->xm_visual
->undithered_pf
);
193 _glthread_LOCK_MUTEX(_xmesa_lock
);
194 XMesaSetForeground( xmesa
->display
, xmesa
->xm_draw_buffer
->cleargc
,
196 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
201 /* Set index mask ala glIndexMask */
203 index_mask( GLcontext
*ctx
, GLuint mask
)
205 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
206 if (xmesa
->xm_draw_buffer
->buffer
!= XIMAGE
) {
208 if (mask
==0xffffffff) {
209 m
= ((unsigned long)~0L);
212 m
= (unsigned long) mask
;
214 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_draw_buffer
->cleargc
, m
);
215 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_draw_buffer
->gc
, m
);
220 /* Implements glColorMask() */
222 color_mask(GLcontext
*ctx
,
223 GLboolean rmask
, GLboolean gmask
, GLboolean bmask
, GLboolean amask
)
225 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
226 int xclass
= GET_VISUAL_CLASS(xmesa
->xm_visual
);
229 if (xclass
== TrueColor
|| xclass
== DirectColor
) {
231 if (rmask
&& gmask
&& bmask
) {
232 m
= ((unsigned long)~0L);
236 if (rmask
) m
|= GET_REDMASK(xmesa
->xm_visual
);
237 if (gmask
) m
|= GET_GREENMASK(xmesa
->xm_visual
);
238 if (bmask
) m
|= GET_BLUEMASK(xmesa
->xm_visual
);
240 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_draw_buffer
->cleargc
, m
);
246 /**********************************************************************/
247 /*** glClear implementations ***/
248 /**********************************************************************/
252 clear_front_pixmap( GLcontext
*ctx
, GLboolean all
,
253 GLint x
, GLint y
, GLint width
, GLint height
)
255 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
257 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_draw_buffer
->frontbuffer
,
258 xmesa
->xm_draw_buffer
->cleargc
,
260 xmesa
->xm_draw_buffer
->width
+1,
261 xmesa
->xm_draw_buffer
->height
+1 );
264 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_draw_buffer
->frontbuffer
,
265 xmesa
->xm_draw_buffer
->cleargc
,
266 x
, xmesa
->xm_draw_buffer
->height
- y
- height
,
273 clear_back_pixmap( GLcontext
*ctx
, GLboolean all
,
274 GLint x
, GLint y
, GLint width
, GLint height
)
276 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
278 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_draw_buffer
->backpixmap
,
279 xmesa
->xm_draw_buffer
->cleargc
,
281 xmesa
->xm_draw_buffer
->width
+1,
282 xmesa
->xm_draw_buffer
->height
+1 );
285 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_draw_buffer
->backpixmap
,
286 xmesa
->xm_draw_buffer
->cleargc
,
287 x
, xmesa
->xm_draw_buffer
->height
- y
- height
,
294 clear_8bit_ximage( GLcontext
*ctx
, GLboolean all
,
295 GLint x
, GLint y
, GLint width
, GLint height
)
297 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
299 size_t n
= xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
300 * xmesa
->xm_draw_buffer
->backimage
->height
;
301 MEMSET( xmesa
->xm_draw_buffer
->backimage
->data
, xmesa
->clearpixel
, n
);
305 for (i
=0;i
<height
;i
++) {
306 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_draw_buffer
, x
, y
+i
);
307 MEMSET( ptr
, xmesa
->clearpixel
, width
);
314 clear_HPCR_ximage( GLcontext
*ctx
, GLboolean all
,
315 GLint x
, GLint y
, GLint width
, GLint height
)
317 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
319 GLint i
, c16
= (xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
>>4)<<4;
320 GLubyte
*ptr
= (GLubyte
*)xmesa
->xm_draw_buffer
->backimage
->data
;
321 for (i
=0; i
<xmesa
->xm_draw_buffer
->backimage
->height
; i
++) {
323 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
327 for (j
=0; j
<c16
; j
+=16) {
346 for (; j
<xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
; j
++) {
354 for (i
=y
; i
<y
+height
; i
++) {
355 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_draw_buffer
, x
, i
);
357 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
361 for (j
=x
; j
<x
+width
; j
++) {
371 clear_16bit_ximage( GLcontext
*ctx
, GLboolean all
,
372 GLint x
, GLint y
, GLint width
, GLint height
)
374 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
375 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
376 if (xmesa
->swapbytes
) {
377 pixel
= ((pixel
>> 8) & 0x00ff) | ((pixel
<< 8) & 0xff00);
381 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_draw_buffer
->backimage
->data
;
382 if ((pixel
& 0xff) == ((pixel
>> 8) & 0xff)) {
383 /* low and high bytes are equal so use memset() */
384 n
= xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
385 * xmesa
->xm_draw_buffer
->height
;
386 MEMSET( ptr4
, pixel
& 0xff, n
);
389 pixel
= pixel
| (pixel
<<16);
390 n
= xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
391 * xmesa
->xm_draw_buffer
->height
/ 4;
397 if ((xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
*
398 xmesa
->xm_draw_buffer
->height
) & 0x2)
399 *(GLushort
*)ptr4
= pixel
& 0xffff;
404 for (j
=0;j
<height
;j
++) {
405 register GLushort
*ptr2
= PIXELADDR2( xmesa
->xm_draw_buffer
, x
, y
+j
);
406 for (i
=0;i
<width
;i
++) {
414 /* Optimized code provided by Nozomi Ytow <noz@xfree86.org> */
416 clear_24bit_ximage( GLcontext
*ctx
, GLboolean all
,
417 GLint x
, GLint y
, GLint width
, GLint height
)
419 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
420 const GLubyte r
= xmesa
->clearcolor
[0];
421 const GLubyte g
= xmesa
->clearcolor
[1];
422 const GLubyte b
= xmesa
->clearcolor
[2];
423 register GLuint clearPixel
;
424 if (xmesa
->swapbytes
) {
425 clearPixel
= (b
<< 16) | (g
<< 8) | r
;
428 clearPixel
= (r
<< 16) | (g
<< 8) | b
;
433 /* same value for all three components (gray) */
434 const GLint w3
= xmesa
->xm_draw_buffer
->width
* 3;
435 const GLint h
= xmesa
->xm_draw_buffer
->height
;
437 for (i
= 0; i
< h
; i
++) {
438 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_draw_buffer
, 0, i
);
444 const GLint w
= xmesa
->xm_draw_buffer
->width
;
445 const GLint h
= xmesa
->xm_draw_buffer
->height
;
447 for (i
= 0; i
< h
; i
++) {
448 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_draw_buffer
, 0, i
);
449 for (j
= 0; j
< w
; j
++) {
456 #if 0 /* this code doesn't work for all window widths */
457 register GLuint
*ptr4
= (GLuint
*) ptr3
;
460 register GLuint
*p
= pixel4
;
461 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
462 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
463 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
464 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
468 px
= *ptr4
& 0x00ffffff;
469 px
|= pixel4
[0] & 0xff000000;
471 px
= *ptr4
& 0xffff0000;
472 px
|= pixel4
[2] & 0x0000ffff;
477 px
= *ptr4
& 0x0000fffff;
478 px
|= pixel4
[1] & 0xffff0000;
480 px
= *ptr4
& 0xffffff00;
481 px
|= pixel4
[2] & 0x000000ff;
486 px
= *ptr4
& 0x000000ff;
487 px
|= pixel4
[2] & 0xffffff00;
504 px
= *ptr4
& 0xffffff00;
505 px
|= clearPixel
& 0xff;
511 px
= *ptr4
& 0xffff0000;
516 px
= *ptr4
& 0xff000000;
527 /* only clear subrect of color buffer */
529 /* same value for all three components (gray) */
531 for (j
=0;j
<height
;j
++) {
532 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_draw_buffer
, x
, y
+j
);
533 MEMSET(ptr3
, r
, 3 * width
);
537 /* non-gray clear color */
539 for (j
= 0; j
< height
; j
++) {
540 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_draw_buffer
, x
, y
+j
);
541 for (i
= 0; i
< width
; i
++) {
548 #if 0 /* this code might not always (seems ptr3 always == ptr4) */
551 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
552 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
553 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
554 for (j
=0;j
<height
;j
++) {
555 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_draw_buffer
, x
, y
+j
);
556 register GLuint
*ptr4
= (GLuint
*)ptr3
;
557 register GLuint
*p
, px
;
559 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
563 px
= *ptr4
& 0x00ffffff;
564 px
|= pixel4
[0] & 0xff000000;
566 px
= *ptr4
& 0xffff0000;
567 px
|= pixel4
[2] & 0x0000ffff;
572 px
= *ptr4
& 0x0000fffff;
573 px
|= pixel4
[1] & 0xffff0000;
575 px
= *ptr4
& 0xffffff00;
576 px
|= pixel4
[2] & 0x000000ff;
581 px
= *ptr4
& 0x000000ff;
582 px
|= pixel4
[2] & 0xffffff00;
599 px
= *ptr4
& 0xffffff00;
606 px
= *ptr4
& 0xffff0000;
611 px
= *ptr4
& 0xff000000;
612 px
|= pixel4
[0] & 0xffffff;
626 clear_32bit_ximage( GLcontext
*ctx
, GLboolean all
,
627 GLint x
, GLint y
, GLint width
, GLint height
)
629 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
630 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
631 if (xmesa
->swapbytes
) {
632 pixel
= ((pixel
>> 24) & 0x000000ff)
633 | ((pixel
>> 8) & 0x0000ff00)
634 | ((pixel
<< 8) & 0x00ff0000)
635 | ((pixel
<< 24) & 0xff000000);
638 register GLint n
= xmesa
->xm_draw_buffer
->width
* xmesa
->xm_draw_buffer
->height
;
639 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_draw_buffer
->backimage
->data
;
641 MEMSET( ptr4
, pixel
, 4*n
);
652 for (j
=0;j
<height
;j
++) {
653 register GLuint
*ptr4
= PIXELADDR4( xmesa
->xm_draw_buffer
, x
, y
+j
);
654 for (i
=0;i
<width
;i
++) {
663 clear_nbit_ximage( GLcontext
*ctx
, GLboolean all
,
664 GLint x
, GLint y
, GLint width
, GLint height
)
666 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
667 XMesaImage
*img
= xmesa
->xm_draw_buffer
->backimage
;
670 width
= xmesa
->xm_draw_buffer
->width
;
671 height
= xmesa
->xm_draw_buffer
->height
;
672 for (j
=0;j
<height
;j
++) {
673 for (i
=0;i
<width
;i
++) {
674 XMesaPutPixel( img
, i
, j
, xmesa
->clearpixel
);
679 /* TODO: optimize this */
681 y
= FLIP(xmesa
->xm_draw_buffer
, y
);
682 for (j
=0;j
<height
;j
++) {
683 for (i
=0;i
<width
;i
++) {
684 XMesaPutPixel( img
, x
+i
, y
-j
, xmesa
->clearpixel
);
693 clear_buffers( GLcontext
*ctx
, GLbitfield mask
,
694 GLboolean all
, GLint x
, GLint y
, GLint width
, GLint height
)
696 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
697 const GLuint
*colorMask
= (GLuint
*) &ctx
->Color
.ColorMask
;
699 if ((mask
& (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
)) &&
700 xmesa
->xm_draw_buffer
->mesa_buffer
.UseSoftwareAlphaBuffers
&&
701 ctx
->Color
.ColorMask
[ACOMP
]) {
702 _mesa_clear_alpha_buffers(ctx
);
705 /* we can't handle color or index masking */
706 if (*colorMask
== 0xffffffff && ctx
->Color
.IndexMask
== 0xffffffff) {
707 if (mask
& DD_FRONT_LEFT_BIT
) {
708 ASSERT(xmesa
->xm_draw_buffer
->front_clear_func
);
709 (*xmesa
->xm_draw_buffer
->front_clear_func
)( ctx
, all
, x
, y
, width
, height
);
710 mask
&= ~DD_FRONT_LEFT_BIT
;
712 if (mask
& DD_BACK_LEFT_BIT
) {
713 ASSERT(xmesa
->xm_draw_buffer
->back_clear_func
);
714 (*xmesa
->xm_draw_buffer
->back_clear_func
)( ctx
, all
, x
, y
, width
, height
);
715 mask
&= ~DD_BACK_LEFT_BIT
;
720 _swrast_Clear( ctx
, mask
, all
, x
, y
, width
, height
);
725 * When we detect that the user has resized the window this function will
726 * get called. Here we'll reallocate the back buffer, depth buffer,
727 * stencil buffer etc. to match the new window size.
730 xmesa_resize_buffers( GLframebuffer
*buffer
)
732 int height
= (int) buffer
->Height
;
733 /* We can do this cast because the first field in the XMesaBuffer
734 * struct is a GLframebuffer struct. If this weren't true, we'd
735 * need a pointer from the GLframebuffer to the XMesaBuffer.
737 XMesaBuffer xmBuffer
= (XMesaBuffer
) buffer
;
739 xmBuffer
->width
= buffer
->Width
;
740 xmBuffer
->height
= buffer
->Height
;
741 xmesa_alloc_back_buffer( xmBuffer
);
743 /* Needed by FLIP macro */
744 xmBuffer
->bottom
= height
- 1;
746 if (xmBuffer
->backimage
) {
747 /* Needed by PIXELADDR1 macro */
748 xmBuffer
->ximage_width1
= xmBuffer
->backimage
->bytes_per_line
;
749 xmBuffer
->ximage_origin1
= (GLubyte
*) xmBuffer
->backimage
->data
750 + xmBuffer
->ximage_width1
* (height
-1);
752 /* Needed by PIXELADDR2 macro */
753 xmBuffer
->ximage_width2
= xmBuffer
->backimage
->bytes_per_line
/ 2;
754 xmBuffer
->ximage_origin2
= (GLushort
*) xmBuffer
->backimage
->data
755 + xmBuffer
->ximage_width2
* (height
-1);
757 /* Needed by PIXELADDR3 macro */
758 xmBuffer
->ximage_width3
= xmBuffer
->backimage
->bytes_per_line
;
759 xmBuffer
->ximage_origin3
= (GLubyte
*) xmBuffer
->backimage
->data
760 + xmBuffer
->ximage_width3
* (height
-1);
762 /* Needed by PIXELADDR4 macro */
763 xmBuffer
->ximage_width4
= xmBuffer
->backimage
->width
;
764 xmBuffer
->ximage_origin4
= (GLuint
*) xmBuffer
->backimage
->data
765 + xmBuffer
->ximage_width4
* (height
-1);
768 _swrast_alloc_buffers( buffer
);
773 * This function implements glDrawPixels() with an XPutImage call when
774 * drawing to the front buffer (X Window drawable).
775 * The image format must be GL_BGRA to match the PF_8R8G8B pixel format.
776 * XXX top/bottom edge clipping is broken!
779 drawpixels_8R8G8B( GLcontext
*ctx
,
780 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
781 GLenum format
, GLenum type
,
782 const struct gl_pixelstore_attrib
*unpack
,
783 const GLvoid
*pixels
)
785 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
786 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
787 XMesaDrawable buffer
= xmesa
->xm_draw_buffer
->buffer
;
788 XMesaGC gc
= xmesa
->xm_draw_buffer
->gc
;
793 /* XXX also check for pixel scale/bias/lookup/zooming! */
794 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
) {
799 int srcX
= unpack
->SkipPixels
;
800 int srcY
= unpack
->SkipRows
;
801 if (_mesa_clip_pixelrect(ctx
, &dstX
, &dstY
, &w
, &h
, &srcX
, &srcY
)) {
803 MEMSET(&ximage
, 0, sizeof(XMesaImage
));
804 ximage
.width
= width
;
805 ximage
.height
= height
;
806 ximage
.format
= ZPixmap
;
807 ximage
.data
= (char *) pixels
+ (height
- 1) * width
* 4;
808 ximage
.byte_order
= LSBFirst
;
809 ximage
.bitmap_unit
= 32;
810 ximage
.bitmap_bit_order
= LSBFirst
;
811 ximage
.bitmap_pad
= 32;
813 ximage
.bytes_per_line
= -width
* 4;
814 ximage
.bits_per_pixel
= 32;
815 ximage
.red_mask
= 0xff0000;
816 ximage
.green_mask
= 0x00ff00;
817 ximage
.blue_mask
= 0x0000ff;
818 dstY
= FLIP(xmesa
->xm_draw_buffer
,dstY
) - height
+ 1;
819 XPutImage(dpy
, buffer
, gc
, &ximage
, srcX
, srcY
, dstX
, dstY
, w
, h
);
829 static const GLubyte
*
830 get_string( GLcontext
*ctx
, GLenum name
)
836 return (const GLubyte
*) "Mesa GLX Indirect";
838 return (const GLubyte
*) "Mesa X11";
842 return (const GLubyte
*) "Mesa project: www.mesa3d.org";
853 enable( GLcontext
*ctx
, GLenum pname
, GLboolean state
)
855 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
860 xmesa
->pixelformat
= xmesa
->xm_visual
->dithered_pf
;
862 xmesa
->pixelformat
= xmesa
->xm_visual
->undithered_pf
;
865 ; /* silence compiler warning */
870 void xmesa_update_state( GLcontext
*ctx
, GLuint new_state
)
872 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
874 /* Propogate statechange information to swrast and swrast_setup
875 * modules. The X11 driver has no internal GL-dependent state.
877 _swrast_InvalidateState( ctx
, new_state
);
878 _ac_InvalidateState( ctx
, new_state
);
879 _tnl_InvalidateState( ctx
, new_state
);
880 _swsetup_InvalidateState( ctx
, new_state
);
883 /* setup pointers to front and back buffer clear functions */
884 xmesa
->xm_draw_buffer
->front_clear_func
= clear_front_pixmap
;
885 if (xmesa
->xm_draw_buffer
->backpixmap
!= XIMAGE
) {
886 xmesa
->xm_draw_buffer
->back_clear_func
= clear_back_pixmap
;
888 else if (sizeof(GLushort
)!=2 || sizeof(GLuint
)!=4) {
889 xmesa
->xm_draw_buffer
->back_clear_func
= clear_nbit_ximage
;
891 else switch (xmesa
->xm_visual
->BitsPerPixel
) {
893 if (xmesa
->xm_visual
->hpcr_clear_flag
) {
894 xmesa
->xm_draw_buffer
->back_clear_func
= clear_HPCR_ximage
;
897 xmesa
->xm_draw_buffer
->back_clear_func
= clear_8bit_ximage
;
901 xmesa
->xm_draw_buffer
->back_clear_func
= clear_16bit_ximage
;
904 xmesa
->xm_draw_buffer
->back_clear_func
= clear_24bit_ximage
;
907 xmesa
->xm_draw_buffer
->back_clear_func
= clear_32bit_ximage
;
910 xmesa
->xm_draw_buffer
->back_clear_func
= clear_nbit_ximage
;
914 xmesa_update_span_funcs(ctx
);
919 /* Setup pointers and other driver state that is constant for the life
922 void xmesa_init_pointers( GLcontext
*ctx
)
925 struct swrast_device_driver
*dd
= _swrast_GetDeviceDriverReference( ctx
);
927 ctx
->Driver
.GetString
= get_string
;
928 ctx
->Driver
.GetBufferSize
= get_buffer_size
;
929 ctx
->Driver
.Flush
= flush
;
930 ctx
->Driver
.Finish
= finish
;
932 /* Software rasterizer pixel paths:
934 ctx
->Driver
.Accum
= _swrast_Accum
;
935 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
936 ctx
->Driver
.Clear
= clear_buffers
;
937 ctx
->Driver
.ResizeBuffers
= xmesa_resize_buffers
;
938 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
939 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
940 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;
941 ctx
->Driver
.DrawBuffer
= _swrast_DrawBuffer
;
943 /* Software texture functions:
945 ctx
->Driver
.ChooseTextureFormat
= _mesa_choose_tex_format
;
946 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
947 ctx
->Driver
.TexImage2D
= _mesa_store_teximage2d
;
948 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
949 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
950 ctx
->Driver
.TexSubImage2D
= _mesa_store_texsubimage2d
;
951 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
952 ctx
->Driver
.TestProxyTexImage
= _mesa_test_proxy_teximage
;
954 ctx
->Driver
.CopyTexImage1D
= _swrast_copy_teximage1d
;
955 ctx
->Driver
.CopyTexImage2D
= _swrast_copy_teximage2d
;
956 ctx
->Driver
.CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
957 ctx
->Driver
.CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
958 ctx
->Driver
.CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
960 ctx
->Driver
.CompressedTexImage1D
= _mesa_store_compressed_teximage1d
;
961 ctx
->Driver
.CompressedTexImage2D
= _mesa_store_compressed_teximage2d
;
962 ctx
->Driver
.CompressedTexImage3D
= _mesa_store_compressed_teximage3d
;
963 ctx
->Driver
.CompressedTexSubImage1D
= _mesa_store_compressed_texsubimage1d
;
964 ctx
->Driver
.CompressedTexSubImage2D
= _mesa_store_compressed_texsubimage2d
;
965 ctx
->Driver
.CompressedTexSubImage3D
= _mesa_store_compressed_texsubimage3d
;
967 /* Swrast hooks for imaging extensions:
969 ctx
->Driver
.CopyColorTable
= _swrast_CopyColorTable
;
970 ctx
->Driver
.CopyColorSubTable
= _swrast_CopyColorSubTable
;
971 ctx
->Driver
.CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
972 ctx
->Driver
.CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
975 /* Statechange callbacks:
977 ctx
->Driver
.ClearIndex
= clear_index
;
978 ctx
->Driver
.ClearColor
= clear_color
;
979 ctx
->Driver
.IndexMask
= index_mask
;
980 ctx
->Driver
.ColorMask
= color_mask
;
981 ctx
->Driver
.Enable
= enable
;
984 /* Initialize the TNL driver interface:
986 tnl
= TNL_CONTEXT(ctx
);
987 tnl
->Driver
.RunPipeline
= _tnl_run_pipeline
;
989 dd
->SetBuffer
= set_buffer
;
991 /* Install swsetup for tnl->Driver.Render.*:
993 _swsetup_Wakeup(ctx
);
995 (void) DitherValues
; /* silenced unused var warning */
1002 #define XMESA_NEW_POINT (_NEW_POINT | \
1004 _SWRAST_NEW_RASTERMASK)
1006 #define XMESA_NEW_LINE (_NEW_LINE | \
1011 _SWRAST_NEW_RASTERMASK)
1013 #define XMESA_NEW_TRIANGLE (_NEW_POLYGON | \
1018 _SWRAST_NEW_RASTERMASK)
1021 /* Extend the software rasterizer with our line/point/triangle
1024 void xmesa_register_swrast_functions( GLcontext
*ctx
)
1026 SWcontext
*swrast
= SWRAST_CONTEXT( ctx
);
1028 swrast
->choose_point
= xmesa_choose_point
;
1029 swrast
->choose_line
= xmesa_choose_line
;
1030 swrast
->choose_triangle
= xmesa_choose_triangle
;
1032 swrast
->invalidate_point
|= XMESA_NEW_POINT
;
1033 swrast
->invalidate_line
|= XMESA_NEW_LINE
;
1034 swrast
->invalidate_triangle
|= XMESA_NEW_TRIANGLE
;