1 /* $Id: xm_dd.c,v 1.31 2002/03/19 16:48:06 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"
32 #include "extensions.h"
38 #include "texformat.h"
40 #include "array_cache/acache.h"
41 #include "swrast/s_context.h"
42 #include "swrast/swrast.h"
43 #include "swrast/s_alphabuf.h"
44 #include "swrast_setup/swrast_setup.h"
46 #include "tnl/t_context.h"
47 #include "tnl/t_pipeline.h"
51 * Return the size (width, height) of the X window for the given GLframebuffer.
52 * Output: width - width of buffer in pixels.
53 * height - height of buffer in pixels.
56 get_buffer_size( GLframebuffer
*buffer
, GLuint
*width
, GLuint
*height
)
58 /* We can do this cast because the first field in the XMesaBuffer
59 * struct is a GLframebuffer struct. If this weren't true, we'd
60 * need a pointer from the GLframebuffer to the XMesaBuffer.
62 const XMesaBuffer xmBuffer
= (XMesaBuffer
) buffer
;
63 unsigned int winwidth
, winheight
;
69 _glthread_LOCK_MUTEX(_xmesa_lock
);
70 XGetGeometry( xmBuffer
->xm_visual
->display
, xmBuffer
->frontbuffer
, &root
,
71 &winx
, &winy
, &winwidth
, &winheight
, &bw
, &d
);
72 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
74 /* XFree86 GLX renderer */
75 winwidth
= xmBuffer
->frontbuffer
->width
;
76 winheight
= xmBuffer
->frontbuffer
->height
;
79 (void)kernel8
; /* Muffle compiler */
87 finish( GLcontext
*ctx
)
92 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
94 _glthread_LOCK_MUTEX(_xmesa_lock
);
95 XSync( xmesa
->display
, False
);
96 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
103 flush( GLcontext
*ctx
)
108 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
110 _glthread_LOCK_MUTEX(_xmesa_lock
);
111 XFlush( xmesa
->display
);
112 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
121 set_draw_buffer( GLcontext
*ctx
, GLenum mode
)
123 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
124 if (mode
== GL_FRONT_LEFT
) {
125 /* write to front buffer */
126 xmesa
->xm_buffer
->buffer
= xmesa
->xm_buffer
->frontbuffer
;
127 xmesa_update_span_funcs(ctx
);
130 else if (mode
==GL_BACK_LEFT
&& xmesa
->xm_buffer
->db_state
) {
131 /* write to back buffer */
132 if (xmesa
->xm_buffer
->backpixmap
) {
133 xmesa
->xm_buffer
->buffer
=
134 (XMesaDrawable
)xmesa
->xm_buffer
->backpixmap
;
136 else if (xmesa
->xm_buffer
->backimage
) {
137 xmesa
->xm_buffer
->buffer
= None
;
140 /* just in case there wasn't enough memory for back buffer */
141 xmesa
->xm_buffer
->buffer
= xmesa
->xm_buffer
->frontbuffer
;
143 xmesa_update_span_funcs(ctx
);
153 xmesa_set_read_buffer( GLcontext
*ctx
, GLframebuffer
*buffer
, GLenum mode
)
156 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
158 if (buffer
== ctx
->DrawBuffer
) {
159 target
= xmesa
->xm_buffer
;
160 xmesa
->use_read_buffer
= GL_FALSE
;
163 ASSERT(buffer
== ctx
->ReadBuffer
);
164 target
= xmesa
->xm_read_buffer
;
165 xmesa
->use_read_buffer
= GL_TRUE
;
168 if (mode
== GL_FRONT_LEFT
) {
169 target
->buffer
= target
->frontbuffer
;
170 xmesa_update_span_funcs(ctx
);
172 else if (mode
==GL_BACK_LEFT
&& xmesa
->xm_read_buffer
->db_state
) {
173 if (target
->backpixmap
) {
174 target
->buffer
= (XMesaDrawable
)xmesa
->xm_buffer
->backpixmap
;
176 else if (target
->backimage
) {
177 target
->buffer
= None
;
180 /* just in case there wasn't enough memory for back buffer */
181 target
->buffer
= target
->frontbuffer
;
183 xmesa_update_span_funcs(ctx
);
186 _mesa_problem(ctx
, "invalid buffer in set_read_buffer() in xmesa2.c");
193 clear_index( GLcontext
*ctx
, GLuint index
)
195 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
196 xmesa
->clearpixel
= (unsigned long) index
;
197 XMesaSetForeground( xmesa
->display
, xmesa
->xm_buffer
->cleargc
,
198 (unsigned long) index
);
203 clear_color( GLcontext
*ctx
, const GLchan color
[4] )
205 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
206 xmesa
->clearcolor
[0] = color
[0];
207 xmesa
->clearcolor
[1] = color
[1];
208 xmesa
->clearcolor
[2] = color
[2];
209 xmesa
->clearcolor
[3] = color
[3];
210 xmesa
->clearpixel
= xmesa_color_to_pixel( xmesa
, color
[0], color
[1],
212 xmesa
->xm_visual
->undithered_pf
);
213 _glthread_LOCK_MUTEX(_xmesa_lock
);
214 XMesaSetForeground( xmesa
->display
, xmesa
->xm_buffer
->cleargc
,
216 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
221 /* Set index mask ala glIndexMask */
223 index_mask( GLcontext
*ctx
, GLuint mask
)
225 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
226 if (xmesa
->xm_buffer
->buffer
!= XIMAGE
) {
228 if (mask
==0xffffffff) {
229 m
= ((unsigned long)~0L);
232 m
= (unsigned long) mask
;
234 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_buffer
->cleargc
, m
);
239 /* Implements glColorMask() */
241 color_mask(GLcontext
*ctx
,
242 GLboolean rmask
, GLboolean gmask
, GLboolean bmask
, GLboolean amask
)
244 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
245 int xclass
= GET_VISUAL_CLASS(xmesa
->xm_visual
);
248 if (xclass
== TrueColor
|| xclass
== DirectColor
) {
250 if (rmask
&& gmask
&& bmask
) {
251 m
= ((unsigned long)~0L);
255 if (rmask
) m
|= GET_REDMASK(xmesa
->xm_visual
);
256 if (gmask
) m
|= GET_GREENMASK(xmesa
->xm_visual
);
257 if (bmask
) m
|= GET_BLUEMASK(xmesa
->xm_visual
);
259 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_buffer
->cleargc
, m
);
265 /**********************************************************************/
266 /*** glClear implementations ***/
267 /**********************************************************************/
271 clear_front_pixmap( GLcontext
*ctx
, GLboolean all
,
272 GLint x
, GLint y
, GLint width
, GLint height
)
274 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
276 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->frontbuffer
,
277 xmesa
->xm_buffer
->cleargc
,
279 xmesa
->xm_buffer
->width
+1,
280 xmesa
->xm_buffer
->height
+1 );
283 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->frontbuffer
,
284 xmesa
->xm_buffer
->cleargc
,
285 x
, xmesa
->xm_buffer
->height
- y
- height
,
292 clear_back_pixmap( GLcontext
*ctx
, GLboolean all
,
293 GLint x
, GLint y
, GLint width
, GLint height
)
295 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
297 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->backpixmap
,
298 xmesa
->xm_buffer
->cleargc
,
300 xmesa
->xm_buffer
->width
+1,
301 xmesa
->xm_buffer
->height
+1 );
304 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->backpixmap
,
305 xmesa
->xm_buffer
->cleargc
,
306 x
, xmesa
->xm_buffer
->height
- y
- height
,
313 clear_8bit_ximage( GLcontext
*ctx
, GLboolean all
,
314 GLint x
, GLint y
, GLint width
, GLint height
)
316 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
318 size_t n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
319 * xmesa
->xm_buffer
->backimage
->height
;
320 MEMSET( xmesa
->xm_buffer
->backimage
->data
, xmesa
->clearpixel
, n
);
324 for (i
=0;i
<height
;i
++) {
325 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_buffer
, x
, y
+i
);
326 MEMSET( ptr
, xmesa
->clearpixel
, width
);
333 clear_HPCR_ximage( GLcontext
*ctx
, GLboolean all
,
334 GLint x
, GLint y
, GLint width
, GLint height
)
336 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
338 GLint i
, c16
= (xmesa
->xm_buffer
->backimage
->bytes_per_line
>>4)<<4;
339 GLubyte
*ptr
= (GLubyte
*)xmesa
->xm_buffer
->backimage
->data
;
340 for (i
=0; i
<xmesa
->xm_buffer
->backimage
->height
; i
++) {
342 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
346 for (j
=0; j
<c16
; j
+=16) {
365 for (; j
<xmesa
->xm_buffer
->backimage
->bytes_per_line
; j
++) {
373 for (i
=y
; i
<y
+height
; i
++) {
374 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_buffer
, x
, i
);
376 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
380 for (j
=x
; j
<x
+width
; j
++) {
390 clear_16bit_ximage( GLcontext
*ctx
, GLboolean all
,
391 GLint x
, GLint y
, GLint width
, GLint height
)
393 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
394 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
395 if (xmesa
->swapbytes
) {
396 pixel
= ((pixel
>> 8) & 0x00ff) | ((pixel
<< 8) & 0xff00);
400 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_buffer
->backimage
->data
;
401 if ((pixel
& 0xff) == ((pixel
>> 8) & 0xff)) {
402 /* low and high bytes are equal so use memset() */
403 n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
404 * xmesa
->xm_buffer
->height
;
405 MEMSET( ptr4
, pixel
& 0xff, n
);
408 pixel
= pixel
| (pixel
<<16);
409 n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
410 * xmesa
->xm_buffer
->height
/ 4;
416 if ((xmesa
->xm_buffer
->backimage
->bytes_per_line
*
417 xmesa
->xm_buffer
->height
) & 0x2)
418 *(GLushort
*)ptr4
= pixel
& 0xffff;
423 for (j
=0;j
<height
;j
++) {
424 register GLushort
*ptr2
= PIXELADDR2( xmesa
->xm_buffer
, x
, y
+j
);
425 for (i
=0;i
<width
;i
++) {
433 /* Optimized code provided by Nozomi Ytow <noz@xfree86.org> */
435 clear_24bit_ximage( GLcontext
*ctx
, GLboolean all
,
436 GLint x
, GLint y
, GLint width
, GLint height
)
438 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
439 const GLubyte r
= xmesa
->clearcolor
[0];
440 const GLubyte g
= xmesa
->clearcolor
[1];
441 const GLubyte b
= xmesa
->clearcolor
[2];
442 register GLuint clearPixel
;
443 if (xmesa
->swapbytes
) {
444 clearPixel
= (b
<< 16) | (g
<< 8) | r
;
447 clearPixel
= (r
<< 16) | (g
<< 8) | b
;
452 /* same value for all three components (gray) */
453 const GLint w3
= xmesa
->xm_buffer
->width
* 3;
454 const GLint h
= xmesa
->xm_buffer
->height
;
456 for (i
= 0; i
< h
; i
++) {
457 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_buffer
, 0, i
);
463 const GLint w
= xmesa
->xm_buffer
->width
;
464 const GLint h
= xmesa
->xm_buffer
->height
;
466 for (i
= 0; i
< h
; i
++) {
467 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_buffer
, 0, i
);
468 for (j
= 0; j
< w
; j
++) {
475 #if 0 /* this code doesn't work for all window widths */
476 register GLuint
*ptr4
= (GLuint
*) ptr3
;
479 register GLuint
*p
= pixel4
;
480 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
481 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
482 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
483 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
487 px
= *ptr4
& 0x00ffffff;
488 px
|= pixel4
[0] & 0xff000000;
490 px
= *ptr4
& 0xffff0000;
491 px
|= pixel4
[2] & 0x0000ffff;
496 px
= *ptr4
& 0x0000fffff;
497 px
|= pixel4
[1] & 0xffff0000;
499 px
= *ptr4
& 0xffffff00;
500 px
|= pixel4
[2] & 0x000000ff;
505 px
= *ptr4
& 0x000000ff;
506 px
|= pixel4
[2] & 0xffffff00;
523 px
= *ptr4
& 0xffffff00;
524 px
|= clearPixel
& 0xff;
530 px
= *ptr4
& 0xffff0000;
535 px
= *ptr4
& 0xff000000;
546 /* only clear subrect of color buffer */
548 /* same value for all three components (gray) */
550 for (j
=0;j
<height
;j
++) {
551 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
552 MEMSET(ptr3
, r
, 3 * width
);
556 /* non-gray clear color */
558 for (j
= 0; j
< height
; j
++) {
559 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
560 for (i
= 0; i
< width
; i
++) {
567 #if 0 /* this code might not always (seems ptr3 always == ptr4) */
570 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
571 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
572 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
573 for (j
=0;j
<height
;j
++) {
574 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
575 register GLuint
*ptr4
= (GLuint
*)ptr3
;
576 register GLuint
*p
, px
;
578 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
582 px
= *ptr4
& 0x00ffffff;
583 px
|= pixel4
[0] & 0xff000000;
585 px
= *ptr4
& 0xffff0000;
586 px
|= pixel4
[2] & 0x0000ffff;
591 px
= *ptr4
& 0x0000fffff;
592 px
|= pixel4
[1] & 0xffff0000;
594 px
= *ptr4
& 0xffffff00;
595 px
|= pixel4
[2] & 0x000000ff;
600 px
= *ptr4
& 0x000000ff;
601 px
|= pixel4
[2] & 0xffffff00;
618 px
= *ptr4
& 0xffffff00;
625 px
= *ptr4
& 0xffff0000;
630 px
= *ptr4
& 0xff000000;
631 px
|= pixel4
[0] & 0xffffff;
645 clear_32bit_ximage( GLcontext
*ctx
, GLboolean all
,
646 GLint x
, GLint y
, GLint width
, GLint height
)
648 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
649 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
650 if (xmesa
->swapbytes
) {
651 pixel
= ((pixel
>> 24) & 0x000000ff)
652 | ((pixel
>> 8) & 0x0000ff00)
653 | ((pixel
<< 8) & 0x00ff0000)
654 | ((pixel
<< 24) & 0xff000000);
657 register GLint n
= xmesa
->xm_buffer
->width
* xmesa
->xm_buffer
->height
;
658 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_buffer
->backimage
->data
;
660 MEMSET( ptr4
, pixel
, 4*n
);
671 for (j
=0;j
<height
;j
++) {
672 register GLuint
*ptr4
= PIXELADDR4( xmesa
->xm_buffer
, x
, y
+j
);
673 for (i
=0;i
<width
;i
++) {
682 clear_nbit_ximage( GLcontext
*ctx
, GLboolean all
,
683 GLint x
, GLint y
, GLint width
, GLint height
)
685 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
686 XMesaImage
*img
= xmesa
->xm_buffer
->backimage
;
689 width
= xmesa
->xm_buffer
->width
;
690 height
= xmesa
->xm_buffer
->height
;
691 for (j
=0;j
<height
;j
++) {
692 for (i
=0;i
<width
;i
++) {
693 XMesaPutPixel( img
, i
, j
, xmesa
->clearpixel
);
698 /* TODO: optimize this */
700 y
= FLIP(xmesa
->xm_buffer
, y
);
701 for (j
=0;j
<height
;j
++) {
702 for (i
=0;i
<width
;i
++) {
703 XMesaPutPixel( img
, x
+i
, y
-j
, xmesa
->clearpixel
);
712 clear_buffers( GLcontext
*ctx
, GLbitfield mask
,
713 GLboolean all
, GLint x
, GLint y
, GLint width
, GLint height
)
715 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
716 const GLuint
*colorMask
= (GLuint
*) &ctx
->Color
.ColorMask
;
718 if ((mask
& (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
)) &&
719 xmesa
->xm_buffer
->mesa_buffer
.UseSoftwareAlphaBuffers
&&
720 ctx
->Color
.ColorMask
[ACOMP
]) {
721 _mesa_clear_alpha_buffers(ctx
);
724 /* we can't handle color or index masking */
725 if (*colorMask
== 0xffffffff && ctx
->Color
.IndexMask
== 0xffffffff) {
726 if (mask
& DD_FRONT_LEFT_BIT
) {
727 ASSERT(xmesa
->xm_buffer
->front_clear_func
);
728 (*xmesa
->xm_buffer
->front_clear_func
)( ctx
, all
, x
, y
, width
, height
);
729 mask
&= ~DD_FRONT_LEFT_BIT
;
731 if (mask
& DD_BACK_LEFT_BIT
) {
732 ASSERT(xmesa
->xm_buffer
->back_clear_func
);
733 (*xmesa
->xm_buffer
->back_clear_func
)( ctx
, all
, x
, y
, width
, height
);
734 mask
&= ~DD_BACK_LEFT_BIT
;
739 _swrast_Clear( ctx
, mask
, all
, x
, y
, width
, height
);
744 * When we detect that the user has resized the window this function will
745 * get called. Here we'll reallocate the back buffer, depth buffer,
746 * stencil buffer etc. to match the new window size.
749 xmesa_resize_buffers( GLframebuffer
*buffer
)
751 int height
= (int) buffer
->Height
;
752 /* We can do this cast because the first field in the XMesaBuffer
753 * struct is a GLframebuffer struct. If this weren't true, we'd
754 * need a pointer from the GLframebuffer to the XMesaBuffer.
756 XMesaBuffer xmBuffer
= (XMesaBuffer
) buffer
;
758 xmBuffer
->width
= buffer
->Width
;
759 xmBuffer
->height
= buffer
->Height
;
760 xmesa_alloc_back_buffer( xmBuffer
);
762 /* Needed by FLIP macro */
763 xmBuffer
->bottom
= height
- 1;
765 if (xmBuffer
->backimage
) {
766 /* Needed by PIXELADDR1 macro */
767 xmBuffer
->ximage_width1
= xmBuffer
->backimage
->bytes_per_line
;
768 xmBuffer
->ximage_origin1
= (GLubyte
*) xmBuffer
->backimage
->data
769 + xmBuffer
->ximage_width1
* (height
-1);
771 /* Needed by PIXELADDR2 macro */
772 xmBuffer
->ximage_width2
= xmBuffer
->backimage
->bytes_per_line
/ 2;
773 xmBuffer
->ximage_origin2
= (GLushort
*) xmBuffer
->backimage
->data
774 + xmBuffer
->ximage_width2
* (height
-1);
776 /* Needed by PIXELADDR3 macro */
777 xmBuffer
->ximage_width3
= xmBuffer
->backimage
->bytes_per_line
;
778 xmBuffer
->ximage_origin3
= (GLubyte
*) xmBuffer
->backimage
->data
779 + xmBuffer
->ximage_width3
* (height
-1);
781 /* Needed by PIXELADDR4 macro */
782 xmBuffer
->ximage_width4
= xmBuffer
->backimage
->width
;
783 xmBuffer
->ximage_origin4
= (GLuint
*) xmBuffer
->backimage
->data
784 + xmBuffer
->ximage_width4
* (height
-1);
787 _swrast_alloc_buffers( buffer
);
792 * This function implements glDrawPixels() with an XPutImage call when
793 * drawing to the front buffer (X Window drawable).
794 * The image format must be GL_BGRA to match the PF_8R8G8B pixel format.
795 * XXX top/bottom edge clipping is broken!
798 drawpixels_8R8G8B( GLcontext
*ctx
,
799 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
800 GLenum format
, GLenum type
,
801 const struct gl_pixelstore_attrib
*unpack
,
802 const GLvoid
*pixels
)
804 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
805 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
806 XMesaDrawable buffer
= xmesa
->xm_buffer
->buffer
;
807 XMesaGC gc
= xmesa
->xm_buffer
->gc
;
812 /* XXX also check for pixel scale/bias/lookup/zooming! */
813 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
) {
818 int srcX
= unpack
->SkipPixels
;
819 int srcY
= unpack
->SkipRows
;
820 if (_mesa_clip_pixelrect(ctx
, &dstX
, &dstY
, &w
, &h
, &srcX
, &srcY
)) {
822 MEMSET(&ximage
, 0, sizeof(XMesaImage
));
823 ximage
.width
= width
;
824 ximage
.height
= height
;
825 ximage
.format
= ZPixmap
;
826 ximage
.data
= (char *) pixels
+ (height
- 1) * width
* 4;
827 ximage
.byte_order
= LSBFirst
;
828 ximage
.bitmap_unit
= 32;
829 ximage
.bitmap_bit_order
= LSBFirst
;
830 ximage
.bitmap_pad
= 32;
832 ximage
.bytes_per_line
= -width
* 4;
833 ximage
.bits_per_pixel
= 32;
834 ximage
.red_mask
= 0xff0000;
835 ximage
.green_mask
= 0x00ff00;
836 ximage
.blue_mask
= 0x0000ff;
837 dstY
= FLIP(xmesa
->xm_buffer
,dstY
) - height
+ 1;
838 XPutImage(dpy
, buffer
, gc
, &ximage
, srcX
, srcY
, dstX
, dstY
, w
, h
);
848 static const GLubyte
*
849 get_string( GLcontext
*ctx
, GLenum name
)
855 return (const GLubyte
*) "Mesa GLX Indirect";
857 return (const GLubyte
*) "Mesa X11";
861 return (const GLubyte
*) "Mesa project: www.mesa3d.org";
872 enable( GLcontext
*ctx
, GLenum pname
, GLboolean state
)
874 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
879 xmesa
->pixelformat
= xmesa
->xm_visual
->dithered_pf
;
881 xmesa
->pixelformat
= xmesa
->xm_visual
->undithered_pf
;
884 ; /* silence compiler warning */
889 void xmesa_update_state( GLcontext
*ctx
, GLuint new_state
)
891 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
893 /* Propogate statechange information to swrast and swrast_setup
894 * modules. The X11 driver has no internal GL-dependent state.
896 _swrast_InvalidateState( ctx
, new_state
);
897 _ac_InvalidateState( ctx
, new_state
);
898 _tnl_InvalidateState( ctx
, new_state
);
899 _swsetup_InvalidateState( ctx
, new_state
);
902 /* setup pointers to front and back buffer clear functions */
903 xmesa
->xm_buffer
->front_clear_func
= clear_front_pixmap
;
904 if (xmesa
->xm_buffer
->backpixmap
!= XIMAGE
) {
905 xmesa
->xm_buffer
->back_clear_func
= clear_back_pixmap
;
907 else if (sizeof(GLushort
)!=2 || sizeof(GLuint
)!=4) {
908 xmesa
->xm_buffer
->back_clear_func
= clear_nbit_ximage
;
910 else switch (xmesa
->xm_visual
->BitsPerPixel
) {
912 if (xmesa
->xm_visual
->hpcr_clear_flag
) {
913 xmesa
->xm_buffer
->back_clear_func
= clear_HPCR_ximage
;
916 xmesa
->xm_buffer
->back_clear_func
= clear_8bit_ximage
;
920 xmesa
->xm_buffer
->back_clear_func
= clear_16bit_ximage
;
923 xmesa
->xm_buffer
->back_clear_func
= clear_24bit_ximage
;
926 xmesa
->xm_buffer
->back_clear_func
= clear_32bit_ximage
;
929 xmesa
->xm_buffer
->back_clear_func
= clear_nbit_ximage
;
933 xmesa_update_span_funcs(ctx
);
938 /* Setup pointers and other driver state that is constant for the life
941 void xmesa_init_pointers( GLcontext
*ctx
)
945 ctx
->Driver
.GetString
= get_string
;
946 ctx
->Driver
.GetBufferSize
= get_buffer_size
;
947 ctx
->Driver
.Flush
= flush
;
948 ctx
->Driver
.Finish
= finish
;
950 /* Software rasterizer pixel paths:
952 ctx
->Driver
.Accum
= _swrast_Accum
;
953 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
954 ctx
->Driver
.Clear
= clear_buffers
;
955 ctx
->Driver
.ResizeBuffers
= xmesa_resize_buffers
;
956 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
957 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
958 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;
960 /* Software texture functions:
962 ctx
->Driver
.ChooseTextureFormat
= _mesa_choose_tex_format
;
963 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
964 ctx
->Driver
.TexImage2D
= _mesa_store_teximage2d
;
965 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
966 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
967 ctx
->Driver
.TexSubImage2D
= _mesa_store_texsubimage2d
;
968 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
969 ctx
->Driver
.TestProxyTexImage
= _mesa_test_proxy_teximage
;
971 ctx
->Driver
.CopyTexImage1D
= _swrast_copy_teximage1d
;
972 ctx
->Driver
.CopyTexImage2D
= _swrast_copy_teximage2d
;
973 ctx
->Driver
.CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
974 ctx
->Driver
.CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
975 ctx
->Driver
.CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
977 ctx
->Driver
.BaseCompressedTexFormat
= _mesa_base_compressed_texformat
;
978 ctx
->Driver
.CompressedTextureSize
= _mesa_compressed_texture_size
;
979 ctx
->Driver
.GetCompressedTexImage
= _mesa_get_compressed_teximage
;
981 /* Swrast hooks for imaging extensions:
983 ctx
->Driver
.CopyColorTable
= _swrast_CopyColorTable
;
984 ctx
->Driver
.CopyColorSubTable
= _swrast_CopyColorSubTable
;
985 ctx
->Driver
.CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
986 ctx
->Driver
.CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
989 /* Statechange callbacks:
991 ctx
->Driver
.SetDrawBuffer
= set_draw_buffer
;
992 ctx
->Driver
.ClearIndex
= clear_index
;
993 ctx
->Driver
.ClearColor
= clear_color
;
994 ctx
->Driver
.IndexMask
= index_mask
;
995 ctx
->Driver
.ColorMask
= color_mask
;
996 ctx
->Driver
.Enable
= enable
;
999 /* Initialize the TNL driver interface:
1001 tnl
= TNL_CONTEXT(ctx
);
1002 tnl
->Driver
.RunPipeline
= _tnl_run_pipeline
;
1004 /* Install swsetup for tnl->Driver.Render.*:
1006 _swsetup_Wakeup(ctx
);
1008 (void) DitherValues
; /* silenced unused var warning */
1015 #define XMESA_NEW_POINT (_NEW_POINT | \
1017 _SWRAST_NEW_RASTERMASK)
1019 #define XMESA_NEW_LINE (_NEW_LINE | \
1024 _SWRAST_NEW_RASTERMASK)
1026 #define XMESA_NEW_TRIANGLE (_NEW_POLYGON | \
1031 _SWRAST_NEW_RASTERMASK)
1034 /* Extend the software rasterizer with our line/point/triangle
1037 void xmesa_register_swrast_functions( GLcontext
*ctx
)
1039 SWcontext
*swrast
= SWRAST_CONTEXT( ctx
);
1041 swrast
->choose_point
= xmesa_choose_point
;
1042 swrast
->choose_line
= xmesa_choose_line
;
1043 swrast
->choose_triangle
= xmesa_choose_triangle
;
1045 swrast
->invalidate_point
|= XMESA_NEW_POINT
;
1046 swrast
->invalidate_line
|= XMESA_NEW_LINE
;
1047 swrast
->invalidate_triangle
|= XMESA_NEW_TRIANGLE
;