1 /* $Id: xm_dd.c,v 1.5 2000/11/14 17:40:15 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 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.
28 #include "glxheader.h"
38 #include "extensions.h"
39 #include "swrast/swrast.h"
40 #include "swrast_setup/swrast_setup.h"
43 * Return the size (width,height of the current color buffer.
44 * This function should be called by the glViewport function because
45 * glViewport is often called when the window gets resized. We need to
46 * update some X/Mesa stuff when that happens.
47 * Output: width - width of buffer in pixels.
48 * height - height of buffer in pixels.
51 get_buffer_size( GLcontext
*ctx
, GLuint
*width
, GLuint
*height
)
53 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
54 unsigned int winwidth
, winheight
;
60 _glthread_LOCK_MUTEX(_xmesa_lock
);
61 XGetGeometry( xmesa
->display
, xmesa
->xm_buffer
->frontbuffer
, &root
,
62 &winx
, &winy
, &winwidth
, &winheight
, &bw
, &d
);
63 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
66 winwidth
= xmesa
->xm_buffer
->frontbuffer
->width
;
67 winheight
= xmesa
->xm_buffer
->frontbuffer
->height
;
73 if ( winwidth
!=xmesa
->xm_buffer
->width
74 || winheight
!=xmesa
->xm_buffer
->height
) {
75 xmesa
->xm_buffer
->width
= winwidth
;
76 xmesa
->xm_buffer
->height
= winheight
;
77 xmesa_alloc_back_buffer( xmesa
->xm_buffer
);
80 /* Needed by FLIP macro */
81 xmesa
->xm_buffer
->bottom
= (int) winheight
- 1;
83 if (xmesa
->xm_buffer
->backimage
) {
84 /* Needed by PIXELADDR1 macro */
85 xmesa
->xm_buffer
->ximage_width1
86 = xmesa
->xm_buffer
->backimage
->bytes_per_line
;
87 xmesa
->xm_buffer
->ximage_origin1
88 = (GLubyte
*) xmesa
->xm_buffer
->backimage
->data
89 + xmesa
->xm_buffer
->ximage_width1
* (winheight
-1);
91 /* Needed by PIXELADDR2 macro */
92 xmesa
->xm_buffer
->ximage_width2
93 = xmesa
->xm_buffer
->backimage
->bytes_per_line
/ 2;
94 xmesa
->xm_buffer
->ximage_origin2
95 = (GLushort
*) xmesa
->xm_buffer
->backimage
->data
96 + xmesa
->xm_buffer
->ximage_width2
* (winheight
-1);
98 /* Needed by PIXELADDR3 macro */
99 xmesa
->xm_buffer
->ximage_width3
100 = xmesa
->xm_buffer
->backimage
->bytes_per_line
;
101 xmesa
->xm_buffer
->ximage_origin3
102 = (GLubyte
*) xmesa
->xm_buffer
->backimage
->data
103 + xmesa
->xm_buffer
->ximage_width3
* (winheight
-1);
105 /* Needed by PIXELADDR4 macro */
106 xmesa
->xm_buffer
->ximage_width4
= xmesa
->xm_buffer
->backimage
->width
;
107 xmesa
->xm_buffer
->ximage_origin4
108 = (GLuint
*) xmesa
->xm_buffer
->backimage
->data
109 + xmesa
->xm_buffer
->ximage_width4
* (winheight
-1);
115 finish( GLcontext
*ctx
)
120 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
122 _glthread_LOCK_MUTEX(_xmesa_lock
);
123 XSync( xmesa
->display
, False
);
124 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
131 flush( GLcontext
*ctx
)
136 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
138 _glthread_LOCK_MUTEX(_xmesa_lock
);
139 XFlush( xmesa
->display
);
140 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
149 set_draw_buffer( GLcontext
*ctx
, GLenum mode
)
151 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
152 if (mode
== GL_FRONT_LEFT
) {
153 /* write to front buffer */
154 xmesa
->xm_buffer
->buffer
= xmesa
->xm_buffer
->frontbuffer
;
155 xmesa_update_span_funcs(ctx
);
158 else if (mode
==GL_BACK_LEFT
&& xmesa
->xm_buffer
->db_state
) {
159 /* write to back buffer */
160 if (xmesa
->xm_buffer
->backpixmap
) {
161 xmesa
->xm_buffer
->buffer
=
162 (XMesaDrawable
)xmesa
->xm_buffer
->backpixmap
;
164 else if (xmesa
->xm_buffer
->backimage
) {
165 xmesa
->xm_buffer
->buffer
= None
;
168 /* just in case there wasn't enough memory for back buffer */
169 xmesa
->xm_buffer
->buffer
= xmesa
->xm_buffer
->frontbuffer
;
171 xmesa_update_span_funcs(ctx
);
181 set_read_buffer( GLcontext
*ctx
, GLframebuffer
*buffer
, GLenum mode
)
184 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
186 if (buffer
== ctx
->DrawBuffer
) {
187 target
= xmesa
->xm_buffer
;
188 xmesa
->use_read_buffer
= GL_FALSE
;
191 ASSERT(buffer
== ctx
->ReadBuffer
);
192 target
= xmesa
->xm_read_buffer
;
193 xmesa
->use_read_buffer
= GL_TRUE
;
196 if (mode
== GL_FRONT_LEFT
) {
197 target
->buffer
= target
->frontbuffer
;
198 xmesa_update_span_funcs(ctx
);
200 else if (mode
==GL_BACK_LEFT
&& xmesa
->xm_read_buffer
->db_state
) {
201 if (target
->backpixmap
) {
202 target
->buffer
= (XMesaDrawable
)xmesa
->xm_buffer
->backpixmap
;
204 else if (target
->backimage
) {
205 target
->buffer
= None
;
208 /* just in case there wasn't enough memory for back buffer */
209 target
->buffer
= target
->frontbuffer
;
211 xmesa_update_span_funcs(ctx
);
214 gl_problem(ctx
, "invalid buffer in set_read_buffer() in xmesa2.c");
221 clear_index( GLcontext
*ctx
, GLuint index
)
223 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
224 xmesa
->clearpixel
= (unsigned long) index
;
225 XMesaSetForeground( xmesa
->display
, xmesa
->xm_buffer
->cleargc
,
226 (unsigned long) index
);
231 clear_color( GLcontext
*ctx
, GLubyte r
, GLubyte g
, GLubyte b
, GLubyte a
)
233 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
234 xmesa
->clearcolor
[0] = r
;
235 xmesa
->clearcolor
[1] = g
;
236 xmesa
->clearcolor
[2] = b
;
237 xmesa
->clearcolor
[3] = a
;
238 xmesa
->clearpixel
= xmesa_color_to_pixel( xmesa
, r
, g
, b
, a
,
239 xmesa
->xm_visual
->undithered_pf
);
240 _glthread_LOCK_MUTEX(_xmesa_lock
);
241 XMesaSetForeground( xmesa
->display
, xmesa
->xm_buffer
->cleargc
,
243 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
248 /* Set index mask ala glIndexMask */
250 index_mask( GLcontext
*ctx
, GLuint mask
)
252 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
253 if (xmesa
->xm_buffer
->buffer
!= XIMAGE
) {
255 if (mask
==0xffffffff) {
256 m
= ((unsigned long)~0L);
259 m
= (unsigned long) mask
;
261 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_buffer
->cleargc
, m
);
266 /* Implements glColorMask() */
268 color_mask(GLcontext
*ctx
,
269 GLboolean rmask
, GLboolean gmask
, GLboolean bmask
, GLboolean amask
)
271 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
272 int xclass
= GET_VISUAL_CLASS(xmesa
->xm_visual
);
275 if (xmesa
->xm_buffer
->buffer
!= XIMAGE
276 && (xclass
== TrueColor
|| xclass
== DirectColor
)) {
278 if (rmask
&& gmask
&& bmask
) {
279 m
= ((unsigned long)~0L);
283 if (rmask
) m
|= GET_REDMASK(xmesa
->xm_visual
);
284 if (gmask
) m
|= GET_GREENMASK(xmesa
->xm_visual
);
285 if (bmask
) m
|= GET_BLUEMASK(xmesa
->xm_visual
);
287 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_buffer
->cleargc
, m
);
293 /**********************************************************************/
294 /*** glClear implementations ***/
295 /**********************************************************************/
299 clear_front_pixmap( GLcontext
*ctx
, GLboolean all
,
300 GLint x
, GLint y
, GLint width
, GLint height
)
302 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
304 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->frontbuffer
,
305 xmesa
->xm_buffer
->cleargc
,
307 xmesa
->xm_buffer
->width
+1,
308 xmesa
->xm_buffer
->height
+1 );
311 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->frontbuffer
,
312 xmesa
->xm_buffer
->cleargc
,
313 x
, xmesa
->xm_buffer
->height
- y
- height
,
320 clear_back_pixmap( GLcontext
*ctx
, GLboolean all
,
321 GLint x
, GLint y
, GLint width
, GLint height
)
323 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
325 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->backpixmap
,
326 xmesa
->xm_buffer
->cleargc
,
328 xmesa
->xm_buffer
->width
+1,
329 xmesa
->xm_buffer
->height
+1 );
332 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->backpixmap
,
333 xmesa
->xm_buffer
->cleargc
,
334 x
, xmesa
->xm_buffer
->height
- y
- height
,
341 clear_8bit_ximage( GLcontext
*ctx
, GLboolean all
,
342 GLint x
, GLint y
, GLint width
, GLint height
)
344 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
346 size_t n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
347 * xmesa
->xm_buffer
->backimage
->height
;
348 MEMSET( xmesa
->xm_buffer
->backimage
->data
, xmesa
->clearpixel
, n
);
352 for (i
=0;i
<height
;i
++) {
353 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_buffer
, x
, y
+i
);
354 MEMSET( ptr
, xmesa
->clearpixel
, width
);
361 clear_HPCR_ximage( GLcontext
*ctx
, GLboolean all
,
362 GLint x
, GLint y
, GLint width
, GLint height
)
364 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
366 GLint i
, c16
= (xmesa
->xm_buffer
->backimage
->bytes_per_line
>>4)<<4;
367 GLubyte
*ptr
= (GLubyte
*)xmesa
->xm_buffer
->backimage
->data
;
368 for (i
=0; i
<xmesa
->xm_buffer
->backimage
->height
; i
++) {
370 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
374 for (j
=0; j
<c16
; j
+=16) {
393 for (; j
<xmesa
->xm_buffer
->backimage
->bytes_per_line
; j
++) {
401 for (i
=y
; i
<y
+height
; i
++) {
402 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_buffer
, x
, i
);
404 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
408 for (j
=x
; j
<x
+width
; j
++) {
418 clear_16bit_ximage( GLcontext
*ctx
, GLboolean all
,
419 GLint x
, GLint y
, GLint width
, GLint height
)
421 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
422 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
423 if (xmesa
->swapbytes
) {
424 pixel
= ((pixel
>> 8) & 0x00ff) | ((pixel
<< 8) & 0xff00);
428 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_buffer
->backimage
->data
;
429 if ((pixel
& 0xff) == ((pixel
>> 8) & 0xff)) {
430 /* low and high bytes are equal so use memset() */
431 n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
432 * xmesa
->xm_buffer
->height
;
433 MEMSET( ptr4
, pixel
& 0xff, n
);
436 pixel
= pixel
| (pixel
<<16);
437 n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
438 * xmesa
->xm_buffer
->height
/ 4;
444 if ((xmesa
->xm_buffer
->backimage
->bytes_per_line
*
445 xmesa
->xm_buffer
->height
) & 0x2)
446 *(GLushort
*)ptr4
= pixel
& 0xffff;
451 for (j
=0;j
<height
;j
++) {
452 register GLushort
*ptr2
= PIXELADDR2( xmesa
->xm_buffer
, x
, y
+j
);
453 for (i
=0;i
<width
;i
++) {
461 /* Optimized code provided by Nozomi Ytow <noz@xfree86.org> */
463 clear_24bit_ximage( GLcontext
*ctx
, GLboolean all
,
464 GLint x
, GLint y
, GLint width
, GLint height
)
466 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
467 const GLubyte r
= xmesa
->clearcolor
[0];
468 const GLubyte g
= xmesa
->clearcolor
[1];
469 const GLubyte b
= xmesa
->clearcolor
[2];
470 register GLuint clearPixel
;
471 if (xmesa
->swapbytes
) {
472 clearPixel
= (b
<< 16) | (g
<< 8) | r
;
475 clearPixel
= (r
<< 16) | (g
<< 8) | b
;
480 /* same value for all three components (gray) */
481 const GLint w3
= xmesa
->xm_buffer
->width
* 3;
482 const GLint h
= xmesa
->xm_buffer
->height
;
484 for (i
= 0; i
< h
; i
++) {
485 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_buffer
, 0, i
);
491 const GLint w
= xmesa
->xm_buffer
->width
;
492 const GLint h
= xmesa
->xm_buffer
->height
;
494 for (i
= 0; i
< h
; i
++) {
495 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_buffer
, 0, i
);
496 for (j
= 0; j
< w
; j
++) {
503 #if 0 /* this code doesn't work for all window widths */
504 register GLuint
*ptr4
= (GLuint
*) ptr3
;
507 register GLuint
*p
= pixel4
;
508 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
509 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
510 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
511 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
515 px
= *ptr4
& 0x00ffffff;
516 px
|= pixel4
[0] & 0xff000000;
518 px
= *ptr4
& 0xffff0000;
519 px
|= pixel4
[2] & 0x0000ffff;
524 px
= *ptr4
& 0x0000fffff;
525 px
|= pixel4
[1] & 0xffff0000;
527 px
= *ptr4
& 0xffffff00;
528 px
|= pixel4
[2] & 0x000000ff;
533 px
= *ptr4
& 0x000000ff;
534 px
|= pixel4
[2] & 0xffffff00;
551 px
= *ptr4
& 0xffffff00;
552 px
|= clearPixel
& 0xff;
558 px
= *ptr4
& 0xffff0000;
563 px
= *ptr4
& 0xff000000;
574 /* only clear subrect of color buffer */
576 /* same value for all three components (gray) */
578 for (j
=0;j
<height
;j
++) {
579 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
580 MEMSET(ptr3
, r
, 3 * width
);
584 /* non-gray clear color */
586 for (j
= 0; j
< height
; j
++) {
587 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
588 for (i
= 0; i
< width
; i
++) {
595 #if 0 /* this code might not always (seems ptr3 always == ptr4) */
598 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
599 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
600 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
601 for (j
=0;j
<height
;j
++) {
602 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
603 register GLuint
*ptr4
= (GLuint
*)ptr3
;
604 register GLuint
*p
, px
;
606 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
610 px
= *ptr4
& 0x00ffffff;
611 px
|= pixel4
[0] & 0xff000000;
613 px
= *ptr4
& 0xffff0000;
614 px
|= pixel4
[2] & 0x0000ffff;
619 px
= *ptr4
& 0x0000fffff;
620 px
|= pixel4
[1] & 0xffff0000;
622 px
= *ptr4
& 0xffffff00;
623 px
|= pixel4
[2] & 0x000000ff;
628 px
= *ptr4
& 0x000000ff;
629 px
|= pixel4
[2] & 0xffffff00;
646 px
= *ptr4
& 0xffffff00;
653 px
= *ptr4
& 0xffff0000;
658 px
= *ptr4
& 0xff000000;
659 px
|= pixel4
[0] & 0xffffff;
673 clear_32bit_ximage( GLcontext
*ctx
, GLboolean all
,
674 GLint x
, GLint y
, GLint width
, GLint height
)
676 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
678 register GLint n
= xmesa
->xm_buffer
->width
* xmesa
->xm_buffer
->height
;
679 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_buffer
->backimage
->data
;
680 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
681 if (xmesa
->swapbytes
) {
682 pixel
= ((pixel
>> 24) & 0x000000ff)
683 | ((pixel
>> 8) & 0x0000ff00)
684 | ((pixel
<< 8) & 0x00ff0000)
685 | ((pixel
<< 24) & 0xff000000);
688 MEMSET( ptr4
, pixel
, 4*n
);
699 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
700 for (j
=0;j
<height
;j
++) {
701 register GLuint
*ptr4
= PIXELADDR4( xmesa
->xm_buffer
, x
, y
+j
);
702 for (i
=0;i
<width
;i
++) {
711 clear_nbit_ximage( GLcontext
*ctx
, GLboolean all
,
712 GLint x
, GLint y
, GLint width
, GLint height
)
714 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
715 XMesaImage
*img
= xmesa
->xm_buffer
->backimage
;
718 width
= xmesa
->xm_buffer
->width
;
719 height
= xmesa
->xm_buffer
->height
;
720 for (j
=0;j
<height
;j
++) {
721 for (i
=0;i
<width
;i
++) {
722 XMesaPutPixel( img
, i
, j
, xmesa
->clearpixel
);
727 /* TODO: optimize this */
729 y
= FLIP(xmesa
->xm_buffer
, y
);
730 for (j
=0;j
<height
;j
++) {
731 for (i
=0;i
<width
;i
++) {
732 XMesaPutPixel( img
, x
+i
, y
-j
, xmesa
->clearpixel
);
741 clear_buffers( GLcontext
*ctx
, GLbitfield mask
,
742 GLboolean all
, GLint x
, GLint y
, GLint width
, GLint height
)
744 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
745 const GLuint
*colorMask
= (GLuint
*) &ctx
->Color
.ColorMask
;
747 /* we can't handle color or index masking */
748 if (mask
& (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
)) {
749 if (*colorMask
!= 0xffffffff || ctx
->Color
.IndexMask
!= 0xffffffff)
753 if (mask
& DD_FRONT_LEFT_BIT
) {
754 ASSERT(xmesa
->xm_buffer
->front_clear_func
);
755 (*xmesa
->xm_buffer
->front_clear_func
)( ctx
, all
, x
, y
, width
, height
);
757 if (mask
& DD_BACK_LEFT_BIT
) {
758 ASSERT(xmesa
->xm_buffer
->back_clear_func
);
759 (*xmesa
->xm_buffer
->back_clear_func
)( ctx
, all
, x
, y
, width
, height
);
761 return mask
& (~(DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
));
768 * This function implements glDrawPixels() with an XPutImage call when
769 * drawing to the front buffer (X Window drawable).
770 * The image format must be GL_BGRA to match the PF_8R8G8B pixel format.
771 * XXX top/bottom edge clipping is broken!
774 drawpixels_8R8G8B( GLcontext
*ctx
,
775 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
776 GLenum format
, GLenum type
,
777 const struct gl_pixelstore_attrib
*unpack
,
778 const GLvoid
*pixels
)
780 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
781 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
782 XMesaDrawable buffer
= xmesa
->xm_buffer
->buffer
;
783 XMesaGC gc
= xmesa
->xm_buffer
->gc
;
788 /* XXX also check for pixel scale/bias/lookup/zooming! */
789 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
) {
794 int srcX
= unpack
->SkipPixels
;
795 int srcY
= unpack
->SkipRows
;
796 if (_mesa_clip_pixelrect(ctx
, &dstX
, &dstY
, &w
, &h
, &srcX
, &srcY
)) {
798 MEMSET(&ximage
, 0, sizeof(XMesaImage
));
799 ximage
.width
= width
;
800 ximage
.height
= height
;
801 ximage
.format
= ZPixmap
;
802 ximage
.data
= (char *) pixels
+ (height
- 1) * width
* 4;
803 ximage
.byte_order
= LSBFirst
;
804 ximage
.bitmap_unit
= 32;
805 ximage
.bitmap_bit_order
= LSBFirst
;
806 ximage
.bitmap_pad
= 32;
808 ximage
.bytes_per_line
= -width
* 4;
809 ximage
.bits_per_pixel
= 32;
810 ximage
.red_mask
= 0xff0000;
811 ximage
.green_mask
= 0x00ff00;
812 ximage
.blue_mask
= 0x0000ff;
813 dstY
= FLIP(xmesa
->xm_buffer
,dstY
) - height
+ 1;
814 XPutImage(dpy
, buffer
, gc
, &ximage
, srcX
, srcY
, dstX
, dstY
, w
, h
);
824 static const GLubyte
*
825 get_string( GLcontext
*ctx
, GLenum name
)
831 return (const GLubyte
*) "Mesa GLX Indirect";
833 return (const GLubyte
*) "Mesa X11";
837 return (const GLubyte
*) "VA Linux Systems, Inc.";
848 enable( GLcontext
*ctx
, GLenum pname
, GLboolean state
)
850 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
855 xmesa
->pixelformat
= xmesa
->xm_visual
->dithered_pf
;
857 xmesa
->pixelformat
= xmesa
->xm_visual
->undithered_pf
;
860 ; /* silence compiler warning */
865 void xmesa_update_state( GLcontext
*ctx
)
867 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
869 /* Propogate statechange information to swrast and swrast_setup
870 * modules. The X11 driver has no internal GL-dependent state.
872 _swrast_InvalidateState( ctx
, ctx
->NewState
);
873 _swsetup_InvalidateState( ctx
, ctx
->NewState
);
876 /* setup pointers to front and back buffer clear functions */
877 xmesa
->xm_buffer
->front_clear_func
= clear_front_pixmap
;
878 if (xmesa
->xm_buffer
->backpixmap
!= XIMAGE
) {
879 xmesa
->xm_buffer
->back_clear_func
= clear_back_pixmap
;
881 else if (sizeof(GLushort
)!=2 || sizeof(GLuint
)!=4) {
882 xmesa
->xm_buffer
->back_clear_func
= clear_nbit_ximage
;
884 else switch (xmesa
->xm_visual
->BitsPerPixel
) {
886 if (xmesa
->xm_visual
->hpcr_clear_flag
) {
887 xmesa
->xm_buffer
->back_clear_func
= clear_HPCR_ximage
;
890 xmesa
->xm_buffer
->back_clear_func
= clear_8bit_ximage
;
894 xmesa
->xm_buffer
->back_clear_func
= clear_16bit_ximage
;
897 xmesa
->xm_buffer
->back_clear_func
= clear_24bit_ximage
;
900 xmesa
->xm_buffer
->back_clear_func
= clear_32bit_ximage
;
903 xmesa
->xm_buffer
->back_clear_func
= clear_nbit_ximage
;
907 xmesa_update_span_funcs(ctx
);
912 /* Setup pointers and other driver state that is constant for the life
915 void xmesa_init_pointers( GLcontext
*ctx
)
917 ctx
->Driver
.GetString
= get_string
;
918 ctx
->Driver
.GetBufferSize
= get_buffer_size
;
919 ctx
->Driver
.Flush
= flush
;
920 ctx
->Driver
.Finish
= finish
;
922 ctx
->Driver
.RenderStart
= 0;
923 ctx
->Driver
.RenderFinish
= _swrast_flush
;
925 ctx
->Driver
.SetDrawBuffer
= set_draw_buffer
;
926 ctx
->Driver
.SetReadBuffer
= set_read_buffer
;
928 ctx
->Driver
.ClearIndex
= clear_index
;
929 ctx
->Driver
.ClearColor
= clear_color
;
930 ctx
->Driver
.Clear
= clear_buffers
;
931 ctx
->Driver
.IndexMask
= index_mask
;
932 ctx
->Driver
.ColorMask
= color_mask
;
933 ctx
->Driver
.Enable
= enable
;
935 ctx
->Driver
.PointsFunc
= _swsetup_Points
;
936 ctx
->Driver
.LineFunc
= _swsetup_Line
;
937 ctx
->Driver
.TriangleFunc
= _swsetup_Triangle
;
938 ctx
->Driver
.QuadFunc
= _swsetup_Quad
;
939 ctx
->Driver
.RasterSetup
= _swsetup_RasterSetup
;
940 ctx
->Driver
.RegisterVB
= _swsetup_RegisterVB
;
941 ctx
->Driver
.UnregisterVB
= _swsetup_UnregisterVB
;
943 (void) DitherValues
; /* silenced unused var warning */