1 /* $Id: xm_dd.c,v 1.19 2001/03/19 02:25:36 keithw Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 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"
32 #include "extensions.h"
39 #include "array_cache/acache.h"
40 #include "swrast/swrast.h"
41 #include "swrast/s_alphabuf.h"
42 #include "swrast_setup/swrast_setup.h"
44 #include "tnl/t_context.h"
48 * Return the size (width,height of the current color buffer.
49 * This function should be called by the glViewport function because
50 * glViewport is often called when the window gets resized. We need to
51 * update some X/Mesa stuff when that happens.
52 * Output: width - width of buffer in pixels.
53 * height - height of buffer in pixels.
56 get_buffer_size( GLcontext
*ctx
, GLuint
*width
, GLuint
*height
)
58 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
59 unsigned int winwidth
, winheight
;
65 _glthread_LOCK_MUTEX(_xmesa_lock
);
66 XGetGeometry( xmesa
->display
, xmesa
->xm_buffer
->frontbuffer
, &root
,
67 &winx
, &winy
, &winwidth
, &winheight
, &bw
, &d
);
68 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
71 winwidth
= xmesa
->xm_buffer
->frontbuffer
->width
;
72 winheight
= xmesa
->xm_buffer
->frontbuffer
->height
;
78 if ( winwidth
!=xmesa
->xm_buffer
->width
79 || winheight
!=xmesa
->xm_buffer
->height
) {
80 xmesa
->xm_buffer
->width
= winwidth
;
81 xmesa
->xm_buffer
->height
= winheight
;
82 xmesa_alloc_back_buffer( xmesa
->xm_buffer
);
85 /* Needed by FLIP macro */
86 xmesa
->xm_buffer
->bottom
= (int) winheight
- 1;
88 if (xmesa
->xm_buffer
->backimage
) {
89 /* Needed by PIXELADDR1 macro */
90 xmesa
->xm_buffer
->ximage_width1
91 = xmesa
->xm_buffer
->backimage
->bytes_per_line
;
92 xmesa
->xm_buffer
->ximage_origin1
93 = (GLubyte
*) xmesa
->xm_buffer
->backimage
->data
94 + xmesa
->xm_buffer
->ximage_width1
* (winheight
-1);
96 /* Needed by PIXELADDR2 macro */
97 xmesa
->xm_buffer
->ximage_width2
98 = xmesa
->xm_buffer
->backimage
->bytes_per_line
/ 2;
99 xmesa
->xm_buffer
->ximage_origin2
100 = (GLushort
*) xmesa
->xm_buffer
->backimage
->data
101 + xmesa
->xm_buffer
->ximage_width2
* (winheight
-1);
103 /* Needed by PIXELADDR3 macro */
104 xmesa
->xm_buffer
->ximage_width3
105 = xmesa
->xm_buffer
->backimage
->bytes_per_line
;
106 xmesa
->xm_buffer
->ximage_origin3
107 = (GLubyte
*) xmesa
->xm_buffer
->backimage
->data
108 + xmesa
->xm_buffer
->ximage_width3
* (winheight
-1);
110 /* Needed by PIXELADDR4 macro */
111 xmesa
->xm_buffer
->ximage_width4
= xmesa
->xm_buffer
->backimage
->width
;
112 xmesa
->xm_buffer
->ximage_origin4
113 = (GLuint
*) xmesa
->xm_buffer
->backimage
->data
114 + xmesa
->xm_buffer
->ximage_width4
* (winheight
-1);
120 finish( GLcontext
*ctx
)
125 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
127 _glthread_LOCK_MUTEX(_xmesa_lock
);
128 XSync( xmesa
->display
, False
);
129 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
136 flush( GLcontext
*ctx
)
141 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
143 _glthread_LOCK_MUTEX(_xmesa_lock
);
144 XFlush( xmesa
->display
);
145 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
154 set_draw_buffer( GLcontext
*ctx
, GLenum mode
)
156 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
157 if (mode
== GL_FRONT_LEFT
) {
158 /* write to front buffer */
159 xmesa
->xm_buffer
->buffer
= xmesa
->xm_buffer
->frontbuffer
;
160 xmesa_update_span_funcs(ctx
);
163 else if (mode
==GL_BACK_LEFT
&& xmesa
->xm_buffer
->db_state
) {
164 /* write to back buffer */
165 if (xmesa
->xm_buffer
->backpixmap
) {
166 xmesa
->xm_buffer
->buffer
=
167 (XMesaDrawable
)xmesa
->xm_buffer
->backpixmap
;
169 else if (xmesa
->xm_buffer
->backimage
) {
170 xmesa
->xm_buffer
->buffer
= None
;
173 /* just in case there wasn't enough memory for back buffer */
174 xmesa
->xm_buffer
->buffer
= xmesa
->xm_buffer
->frontbuffer
;
176 xmesa_update_span_funcs(ctx
);
186 xmesa_set_read_buffer( GLcontext
*ctx
, GLframebuffer
*buffer
, GLenum mode
)
189 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
191 if (buffer
== ctx
->DrawBuffer
) {
192 target
= xmesa
->xm_buffer
;
193 xmesa
->use_read_buffer
= GL_FALSE
;
196 ASSERT(buffer
== ctx
->ReadBuffer
);
197 target
= xmesa
->xm_read_buffer
;
198 xmesa
->use_read_buffer
= GL_TRUE
;
201 if (mode
== GL_FRONT_LEFT
) {
202 target
->buffer
= target
->frontbuffer
;
203 xmesa_update_span_funcs(ctx
);
205 else if (mode
==GL_BACK_LEFT
&& xmesa
->xm_read_buffer
->db_state
) {
206 if (target
->backpixmap
) {
207 target
->buffer
= (XMesaDrawable
)xmesa
->xm_buffer
->backpixmap
;
209 else if (target
->backimage
) {
210 target
->buffer
= None
;
213 /* just in case there wasn't enough memory for back buffer */
214 target
->buffer
= target
->frontbuffer
;
216 xmesa_update_span_funcs(ctx
);
219 _mesa_problem(ctx
, "invalid buffer in set_read_buffer() in xmesa2.c");
226 clear_index( GLcontext
*ctx
, GLuint index
)
228 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
229 xmesa
->clearpixel
= (unsigned long) index
;
230 XMesaSetForeground( xmesa
->display
, xmesa
->xm_buffer
->cleargc
,
231 (unsigned long) index
);
236 clear_color( GLcontext
*ctx
, const GLchan color
[4] )
238 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
239 xmesa
->clearcolor
[0] = color
[0];
240 xmesa
->clearcolor
[1] = color
[1];
241 xmesa
->clearcolor
[2] = color
[2];
242 xmesa
->clearcolor
[3] = color
[3];
243 xmesa
->clearpixel
= xmesa_color_to_pixel( xmesa
, color
[0], color
[1],
245 xmesa
->xm_visual
->undithered_pf
);
246 _glthread_LOCK_MUTEX(_xmesa_lock
);
247 XMesaSetForeground( xmesa
->display
, xmesa
->xm_buffer
->cleargc
,
249 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
254 /* Set index mask ala glIndexMask */
256 index_mask( GLcontext
*ctx
, GLuint mask
)
258 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
259 if (xmesa
->xm_buffer
->buffer
!= XIMAGE
) {
261 if (mask
==0xffffffff) {
262 m
= ((unsigned long)~0L);
265 m
= (unsigned long) mask
;
267 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_buffer
->cleargc
, m
);
272 /* Implements glColorMask() */
274 color_mask(GLcontext
*ctx
,
275 GLboolean rmask
, GLboolean gmask
, GLboolean bmask
, GLboolean amask
)
277 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
278 int xclass
= GET_VISUAL_CLASS(xmesa
->xm_visual
);
281 if (xmesa
->xm_buffer
->buffer
!= XIMAGE
282 && (xclass
== TrueColor
|| xclass
== DirectColor
)) {
284 if (rmask
&& gmask
&& bmask
) {
285 m
= ((unsigned long)~0L);
289 if (rmask
) m
|= GET_REDMASK(xmesa
->xm_visual
);
290 if (gmask
) m
|= GET_GREENMASK(xmesa
->xm_visual
);
291 if (bmask
) m
|= GET_BLUEMASK(xmesa
->xm_visual
);
293 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_buffer
->cleargc
, m
);
299 /**********************************************************************/
300 /*** glClear implementations ***/
301 /**********************************************************************/
305 clear_front_pixmap( GLcontext
*ctx
, GLboolean all
,
306 GLint x
, GLint y
, GLint width
, GLint height
)
308 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
310 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->frontbuffer
,
311 xmesa
->xm_buffer
->cleargc
,
313 xmesa
->xm_buffer
->width
+1,
314 xmesa
->xm_buffer
->height
+1 );
317 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->frontbuffer
,
318 xmesa
->xm_buffer
->cleargc
,
319 x
, xmesa
->xm_buffer
->height
- y
- height
,
326 clear_back_pixmap( GLcontext
*ctx
, GLboolean all
,
327 GLint x
, GLint y
, GLint width
, GLint height
)
329 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
331 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->backpixmap
,
332 xmesa
->xm_buffer
->cleargc
,
334 xmesa
->xm_buffer
->width
+1,
335 xmesa
->xm_buffer
->height
+1 );
338 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->backpixmap
,
339 xmesa
->xm_buffer
->cleargc
,
340 x
, xmesa
->xm_buffer
->height
- y
- height
,
347 clear_8bit_ximage( GLcontext
*ctx
, GLboolean all
,
348 GLint x
, GLint y
, GLint width
, GLint height
)
350 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
352 size_t n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
353 * xmesa
->xm_buffer
->backimage
->height
;
354 MEMSET( xmesa
->xm_buffer
->backimage
->data
, xmesa
->clearpixel
, n
);
358 for (i
=0;i
<height
;i
++) {
359 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_buffer
, x
, y
+i
);
360 MEMSET( ptr
, xmesa
->clearpixel
, width
);
367 clear_HPCR_ximage( GLcontext
*ctx
, GLboolean all
,
368 GLint x
, GLint y
, GLint width
, GLint height
)
370 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
372 GLint i
, c16
= (xmesa
->xm_buffer
->backimage
->bytes_per_line
>>4)<<4;
373 GLubyte
*ptr
= (GLubyte
*)xmesa
->xm_buffer
->backimage
->data
;
374 for (i
=0; i
<xmesa
->xm_buffer
->backimage
->height
; i
++) {
376 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
380 for (j
=0; j
<c16
; j
+=16) {
399 for (; j
<xmesa
->xm_buffer
->backimage
->bytes_per_line
; j
++) {
407 for (i
=y
; i
<y
+height
; i
++) {
408 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_buffer
, x
, i
);
410 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
414 for (j
=x
; j
<x
+width
; j
++) {
424 clear_16bit_ximage( GLcontext
*ctx
, GLboolean all
,
425 GLint x
, GLint y
, GLint width
, GLint height
)
427 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
428 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
429 if (xmesa
->swapbytes
) {
430 pixel
= ((pixel
>> 8) & 0x00ff) | ((pixel
<< 8) & 0xff00);
434 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_buffer
->backimage
->data
;
435 if ((pixel
& 0xff) == ((pixel
>> 8) & 0xff)) {
436 /* low and high bytes are equal so use memset() */
437 n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
438 * xmesa
->xm_buffer
->height
;
439 MEMSET( ptr4
, pixel
& 0xff, n
);
442 pixel
= pixel
| (pixel
<<16);
443 n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
444 * xmesa
->xm_buffer
->height
/ 4;
450 if ((xmesa
->xm_buffer
->backimage
->bytes_per_line
*
451 xmesa
->xm_buffer
->height
) & 0x2)
452 *(GLushort
*)ptr4
= pixel
& 0xffff;
457 for (j
=0;j
<height
;j
++) {
458 register GLushort
*ptr2
= PIXELADDR2( xmesa
->xm_buffer
, x
, y
+j
);
459 for (i
=0;i
<width
;i
++) {
467 /* Optimized code provided by Nozomi Ytow <noz@xfree86.org> */
469 clear_24bit_ximage( GLcontext
*ctx
, GLboolean all
,
470 GLint x
, GLint y
, GLint width
, GLint height
)
472 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
473 const GLubyte r
= xmesa
->clearcolor
[0];
474 const GLubyte g
= xmesa
->clearcolor
[1];
475 const GLubyte b
= xmesa
->clearcolor
[2];
476 register GLuint clearPixel
;
477 if (xmesa
->swapbytes
) {
478 clearPixel
= (b
<< 16) | (g
<< 8) | r
;
481 clearPixel
= (r
<< 16) | (g
<< 8) | b
;
486 /* same value for all three components (gray) */
487 const GLint w3
= xmesa
->xm_buffer
->width
* 3;
488 const GLint h
= xmesa
->xm_buffer
->height
;
490 for (i
= 0; i
< h
; i
++) {
491 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_buffer
, 0, i
);
497 const GLint w
= xmesa
->xm_buffer
->width
;
498 const GLint h
= xmesa
->xm_buffer
->height
;
500 for (i
= 0; i
< h
; i
++) {
501 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_buffer
, 0, i
);
502 for (j
= 0; j
< w
; j
++) {
509 #if 0 /* this code doesn't work for all window widths */
510 register GLuint
*ptr4
= (GLuint
*) ptr3
;
513 register GLuint
*p
= pixel4
;
514 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
515 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
516 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
517 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
521 px
= *ptr4
& 0x00ffffff;
522 px
|= pixel4
[0] & 0xff000000;
524 px
= *ptr4
& 0xffff0000;
525 px
|= pixel4
[2] & 0x0000ffff;
530 px
= *ptr4
& 0x0000fffff;
531 px
|= pixel4
[1] & 0xffff0000;
533 px
= *ptr4
& 0xffffff00;
534 px
|= pixel4
[2] & 0x000000ff;
539 px
= *ptr4
& 0x000000ff;
540 px
|= pixel4
[2] & 0xffffff00;
557 px
= *ptr4
& 0xffffff00;
558 px
|= clearPixel
& 0xff;
564 px
= *ptr4
& 0xffff0000;
569 px
= *ptr4
& 0xff000000;
580 /* only clear subrect of color buffer */
582 /* same value for all three components (gray) */
584 for (j
=0;j
<height
;j
++) {
585 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
586 MEMSET(ptr3
, r
, 3 * width
);
590 /* non-gray clear color */
592 for (j
= 0; j
< height
; j
++) {
593 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
594 for (i
= 0; i
< width
; i
++) {
601 #if 0 /* this code might not always (seems ptr3 always == ptr4) */
604 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
605 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
606 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
607 for (j
=0;j
<height
;j
++) {
608 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
609 register GLuint
*ptr4
= (GLuint
*)ptr3
;
610 register GLuint
*p
, px
;
612 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
616 px
= *ptr4
& 0x00ffffff;
617 px
|= pixel4
[0] & 0xff000000;
619 px
= *ptr4
& 0xffff0000;
620 px
|= pixel4
[2] & 0x0000ffff;
625 px
= *ptr4
& 0x0000fffff;
626 px
|= pixel4
[1] & 0xffff0000;
628 px
= *ptr4
& 0xffffff00;
629 px
|= pixel4
[2] & 0x000000ff;
634 px
= *ptr4
& 0x000000ff;
635 px
|= pixel4
[2] & 0xffffff00;
652 px
= *ptr4
& 0xffffff00;
659 px
= *ptr4
& 0xffff0000;
664 px
= *ptr4
& 0xff000000;
665 px
|= pixel4
[0] & 0xffffff;
679 clear_32bit_ximage( GLcontext
*ctx
, GLboolean all
,
680 GLint x
, GLint y
, GLint width
, GLint height
)
682 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
684 register GLint n
= xmesa
->xm_buffer
->width
* xmesa
->xm_buffer
->height
;
685 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_buffer
->backimage
->data
;
686 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
687 if (xmesa
->swapbytes
) {
688 pixel
= ((pixel
>> 24) & 0x000000ff)
689 | ((pixel
>> 8) & 0x0000ff00)
690 | ((pixel
<< 8) & 0x00ff0000)
691 | ((pixel
<< 24) & 0xff000000);
694 MEMSET( ptr4
, pixel
, 4*n
);
705 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
706 for (j
=0;j
<height
;j
++) {
707 register GLuint
*ptr4
= PIXELADDR4( xmesa
->xm_buffer
, x
, y
+j
);
708 for (i
=0;i
<width
;i
++) {
717 clear_nbit_ximage( GLcontext
*ctx
, GLboolean all
,
718 GLint x
, GLint y
, GLint width
, GLint height
)
720 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
721 XMesaImage
*img
= xmesa
->xm_buffer
->backimage
;
724 width
= xmesa
->xm_buffer
->width
;
725 height
= xmesa
->xm_buffer
->height
;
726 for (j
=0;j
<height
;j
++) {
727 for (i
=0;i
<width
;i
++) {
728 XMesaPutPixel( img
, i
, j
, xmesa
->clearpixel
);
733 /* TODO: optimize this */
735 y
= FLIP(xmesa
->xm_buffer
, y
);
736 for (j
=0;j
<height
;j
++) {
737 for (i
=0;i
<width
;i
++) {
738 XMesaPutPixel( img
, x
+i
, y
-j
, xmesa
->clearpixel
);
747 clear_buffers( GLcontext
*ctx
, GLbitfield mask
,
748 GLboolean all
, GLint x
, GLint y
, GLint width
, GLint height
)
750 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
751 const GLuint
*colorMask
= (GLuint
*) &ctx
->Color
.ColorMask
;
753 if ((mask
& (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
)) &&
754 xmesa
->xm_buffer
->gl_buffer
->UseSoftwareAlphaBuffers
&&
755 ctx
->Color
.ColorMask
[ACOMP
]) {
756 _mesa_clear_alpha_buffers(ctx
);
759 /* we can't handle color or index masking */
760 if (*colorMask
== 0xffffffff && ctx
->Color
.IndexMask
== 0xffffffff) {
761 if (mask
& DD_FRONT_LEFT_BIT
) {
762 ASSERT(xmesa
->xm_buffer
->front_clear_func
);
763 (*xmesa
->xm_buffer
->front_clear_func
)( ctx
, all
, x
, y
, width
, height
);
764 mask
&= ~DD_FRONT_LEFT_BIT
;
766 if (mask
& DD_BACK_LEFT_BIT
) {
767 ASSERT(xmesa
->xm_buffer
->back_clear_func
);
768 (*xmesa
->xm_buffer
->back_clear_func
)( ctx
, all
, x
, y
, width
, height
);
769 mask
&= ~DD_BACK_LEFT_BIT
;
774 _swrast_Clear( ctx
, mask
, all
, x
, y
, width
, height
);
779 resize_buffers( GLcontext
*ctx
)
781 _swrast_alloc_buffers( ctx
);
786 * This function implements glDrawPixels() with an XPutImage call when
787 * drawing to the front buffer (X Window drawable).
788 * The image format must be GL_BGRA to match the PF_8R8G8B pixel format.
789 * XXX top/bottom edge clipping is broken!
792 drawpixels_8R8G8B( GLcontext
*ctx
,
793 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
794 GLenum format
, GLenum type
,
795 const struct gl_pixelstore_attrib
*unpack
,
796 const GLvoid
*pixels
)
798 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
799 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
800 XMesaDrawable buffer
= xmesa
->xm_buffer
->buffer
;
801 XMesaGC gc
= xmesa
->xm_buffer
->gc
;
806 /* XXX also check for pixel scale/bias/lookup/zooming! */
807 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
) {
812 int srcX
= unpack
->SkipPixels
;
813 int srcY
= unpack
->SkipRows
;
814 if (_mesa_clip_pixelrect(ctx
, &dstX
, &dstY
, &w
, &h
, &srcX
, &srcY
)) {
816 MEMSET(&ximage
, 0, sizeof(XMesaImage
));
817 ximage
.width
= width
;
818 ximage
.height
= height
;
819 ximage
.format
= ZPixmap
;
820 ximage
.data
= (char *) pixels
+ (height
- 1) * width
* 4;
821 ximage
.byte_order
= LSBFirst
;
822 ximage
.bitmap_unit
= 32;
823 ximage
.bitmap_bit_order
= LSBFirst
;
824 ximage
.bitmap_pad
= 32;
826 ximage
.bytes_per_line
= -width
* 4;
827 ximage
.bits_per_pixel
= 32;
828 ximage
.red_mask
= 0xff0000;
829 ximage
.green_mask
= 0x00ff00;
830 ximage
.blue_mask
= 0x0000ff;
831 dstY
= FLIP(xmesa
->xm_buffer
,dstY
) - height
+ 1;
832 XPutImage(dpy
, buffer
, gc
, &ximage
, srcX
, srcY
, dstX
, dstY
, w
, h
);
842 static const GLubyte
*
843 get_string( GLcontext
*ctx
, GLenum name
)
849 return (const GLubyte
*) "Mesa GLX Indirect";
851 return (const GLubyte
*) "Mesa X11";
855 return (const GLubyte
*) "VA Linux Systems, Inc.";
866 enable( GLcontext
*ctx
, GLenum pname
, GLboolean state
)
868 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
873 xmesa
->pixelformat
= xmesa
->xm_visual
->dithered_pf
;
875 xmesa
->pixelformat
= xmesa
->xm_visual
->undithered_pf
;
878 ; /* silence compiler warning */
883 void xmesa_update_state( GLcontext
*ctx
, GLuint new_state
)
885 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
887 /* Propogate statechange information to swrast and swrast_setup
888 * modules. The X11 driver has no internal GL-dependent state.
890 _swrast_InvalidateState( ctx
, new_state
);
891 _ac_InvalidateState( ctx
, new_state
);
892 _tnl_InvalidateState( ctx
, new_state
);
893 _swsetup_InvalidateState( ctx
, new_state
);
896 /* setup pointers to front and back buffer clear functions */
897 xmesa
->xm_buffer
->front_clear_func
= clear_front_pixmap
;
898 if (xmesa
->xm_buffer
->backpixmap
!= XIMAGE
) {
899 xmesa
->xm_buffer
->back_clear_func
= clear_back_pixmap
;
901 else if (sizeof(GLushort
)!=2 || sizeof(GLuint
)!=4) {
902 xmesa
->xm_buffer
->back_clear_func
= clear_nbit_ximage
;
904 else switch (xmesa
->xm_visual
->BitsPerPixel
) {
906 if (xmesa
->xm_visual
->hpcr_clear_flag
) {
907 xmesa
->xm_buffer
->back_clear_func
= clear_HPCR_ximage
;
910 xmesa
->xm_buffer
->back_clear_func
= clear_8bit_ximage
;
914 xmesa
->xm_buffer
->back_clear_func
= clear_16bit_ximage
;
917 xmesa
->xm_buffer
->back_clear_func
= clear_24bit_ximage
;
920 xmesa
->xm_buffer
->back_clear_func
= clear_32bit_ximage
;
923 xmesa
->xm_buffer
->back_clear_func
= clear_nbit_ximage
;
927 xmesa_update_span_funcs(ctx
);
932 /* Setup pointers and other driver state that is constant for the life
935 void xmesa_init_pointers( GLcontext
*ctx
)
939 ctx
->Driver
.GetString
= get_string
;
940 ctx
->Driver
.GetBufferSize
= get_buffer_size
;
941 ctx
->Driver
.Flush
= flush
;
942 ctx
->Driver
.Finish
= finish
;
944 /* Software rasterizer pixel paths:
946 ctx
->Driver
.Accum
= _swrast_Accum
;
947 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
948 ctx
->Driver
.Clear
= clear_buffers
;
949 ctx
->Driver
.ResizeBuffersMESA
= resize_buffers
;
950 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
951 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
952 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;
954 /* Software texture functions:
956 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
957 ctx
->Driver
.TexImage2D
= _mesa_store_teximage2d
;
958 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
959 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
960 ctx
->Driver
.TexSubImage2D
= _mesa_store_texsubimage2d
;
961 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
962 ctx
->Driver
.TestProxyTexImage
= _mesa_test_proxy_teximage
;
964 ctx
->Driver
.CopyTexImage1D
= _swrast_copy_teximage1d
;
965 ctx
->Driver
.CopyTexImage2D
= _swrast_copy_teximage2d
;
966 ctx
->Driver
.CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
967 ctx
->Driver
.CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
968 ctx
->Driver
.CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
971 /* Swrast hooks for imaging extensions:
973 ctx
->Driver
.CopyColorTable
= _swrast_CopyColorTable
;
974 ctx
->Driver
.CopyColorSubTable
= _swrast_CopyColorSubTable
;
975 ctx
->Driver
.CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
976 ctx
->Driver
.CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
979 /* Statechange callbacks:
981 ctx
->Driver
.SetDrawBuffer
= set_draw_buffer
;
982 ctx
->Driver
.ClearIndex
= clear_index
;
983 ctx
->Driver
.ClearColor
= clear_color
;
984 ctx
->Driver
.IndexMask
= index_mask
;
985 ctx
->Driver
.ColorMask
= color_mask
;
986 ctx
->Driver
.Enable
= enable
;
989 /* Initialize the TNL driver interface:
991 tnl
= TNL_CONTEXT(ctx
);
992 tnl
->Driver
.RenderStart
= _swsetup_RenderStart
;
993 tnl
->Driver
.RenderFinish
= _swsetup_RenderFinish
;
994 tnl
->Driver
.BuildProjectedVertices
= _swsetup_BuildProjectedVertices
;
995 tnl
->Driver
.RenderPrimitive
= _swsetup_RenderPrimitive
;
996 tnl
->Driver
.PointsFunc
= _swsetup_Points
;
997 tnl
->Driver
.LineFunc
= _swsetup_Line
;
998 tnl
->Driver
.TriangleFunc
= _swsetup_Triangle
;
999 tnl
->Driver
.QuadFunc
= _swsetup_Quad
;
1000 tnl
->Driver
.ResetLineStipple
= _swrast_ResetLineStipple
;
1001 tnl
->Driver
.RenderInterp
= _swsetup_RenderInterp
;
1002 tnl
->Driver
.RenderCopyPV
= _swsetup_RenderCopyPV
;
1003 tnl
->Driver
.RenderClippedLine
= _swsetup_RenderClippedLine
;
1004 tnl
->Driver
.RenderClippedPolygon
= _swsetup_RenderClippedPolygon
;
1006 (void) DitherValues
; /* silenced unused var warning */