1 /* $Id: xm_dd.c,v 1.23 2001/04/27 21:18:25 brianp 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"
38 #include "texformat.h"
40 #include "array_cache/acache.h"
41 #include "swrast/swrast.h"
42 #include "swrast/s_alphabuf.h"
43 #include "swrast_setup/swrast_setup.h"
45 #include "tnl/t_context.h"
49 * Return the size (width,height of the current color buffer.
50 * This function should be called by the glViewport function because
51 * glViewport is often called when the window gets resized. We need to
52 * update some X/Mesa stuff when that happens.
53 * Output: width - width of buffer in pixels.
54 * height - height of buffer in pixels.
57 get_buffer_size( GLcontext
*ctx
, GLuint
*width
, GLuint
*height
)
59 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
60 unsigned int winwidth
, winheight
;
66 _glthread_LOCK_MUTEX(_xmesa_lock
);
67 XGetGeometry( xmesa
->display
, xmesa
->xm_buffer
->frontbuffer
, &root
,
68 &winx
, &winy
, &winwidth
, &winheight
, &bw
, &d
);
69 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
72 winwidth
= xmesa
->xm_buffer
->frontbuffer
->width
;
73 winheight
= xmesa
->xm_buffer
->frontbuffer
->height
;
79 if ( winwidth
!=xmesa
->xm_buffer
->width
80 || winheight
!=xmesa
->xm_buffer
->height
) {
81 xmesa
->xm_buffer
->width
= winwidth
;
82 xmesa
->xm_buffer
->height
= winheight
;
83 xmesa_alloc_back_buffer( xmesa
->xm_buffer
);
86 /* Needed by FLIP macro */
87 xmesa
->xm_buffer
->bottom
= (int) winheight
- 1;
89 if (xmesa
->xm_buffer
->backimage
) {
90 /* Needed by PIXELADDR1 macro */
91 xmesa
->xm_buffer
->ximage_width1
92 = xmesa
->xm_buffer
->backimage
->bytes_per_line
;
93 xmesa
->xm_buffer
->ximage_origin1
94 = (GLubyte
*) xmesa
->xm_buffer
->backimage
->data
95 + xmesa
->xm_buffer
->ximage_width1
* (winheight
-1);
97 /* Needed by PIXELADDR2 macro */
98 xmesa
->xm_buffer
->ximage_width2
99 = xmesa
->xm_buffer
->backimage
->bytes_per_line
/ 2;
100 xmesa
->xm_buffer
->ximage_origin2
101 = (GLushort
*) xmesa
->xm_buffer
->backimage
->data
102 + xmesa
->xm_buffer
->ximage_width2
* (winheight
-1);
104 /* Needed by PIXELADDR3 macro */
105 xmesa
->xm_buffer
->ximage_width3
106 = xmesa
->xm_buffer
->backimage
->bytes_per_line
;
107 xmesa
->xm_buffer
->ximage_origin3
108 = (GLubyte
*) xmesa
->xm_buffer
->backimage
->data
109 + xmesa
->xm_buffer
->ximage_width3
* (winheight
-1);
111 /* Needed by PIXELADDR4 macro */
112 xmesa
->xm_buffer
->ximage_width4
= xmesa
->xm_buffer
->backimage
->width
;
113 xmesa
->xm_buffer
->ximage_origin4
114 = (GLuint
*) xmesa
->xm_buffer
->backimage
->data
115 + xmesa
->xm_buffer
->ximage_width4
* (winheight
-1);
121 finish( GLcontext
*ctx
)
126 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
128 _glthread_LOCK_MUTEX(_xmesa_lock
);
129 XSync( xmesa
->display
, False
);
130 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
137 flush( GLcontext
*ctx
)
142 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
144 _glthread_LOCK_MUTEX(_xmesa_lock
);
145 XFlush( xmesa
->display
);
146 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
155 set_draw_buffer( GLcontext
*ctx
, GLenum mode
)
157 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
158 if (mode
== GL_FRONT_LEFT
) {
159 /* write to front buffer */
160 xmesa
->xm_buffer
->buffer
= xmesa
->xm_buffer
->frontbuffer
;
161 xmesa_update_span_funcs(ctx
);
164 else if (mode
==GL_BACK_LEFT
&& xmesa
->xm_buffer
->db_state
) {
165 /* write to back buffer */
166 if (xmesa
->xm_buffer
->backpixmap
) {
167 xmesa
->xm_buffer
->buffer
=
168 (XMesaDrawable
)xmesa
->xm_buffer
->backpixmap
;
170 else if (xmesa
->xm_buffer
->backimage
) {
171 xmesa
->xm_buffer
->buffer
= None
;
174 /* just in case there wasn't enough memory for back buffer */
175 xmesa
->xm_buffer
->buffer
= xmesa
->xm_buffer
->frontbuffer
;
177 xmesa_update_span_funcs(ctx
);
187 xmesa_set_read_buffer( GLcontext
*ctx
, GLframebuffer
*buffer
, GLenum mode
)
190 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
192 if (buffer
== ctx
->DrawBuffer
) {
193 target
= xmesa
->xm_buffer
;
194 xmesa
->use_read_buffer
= GL_FALSE
;
197 ASSERT(buffer
== ctx
->ReadBuffer
);
198 target
= xmesa
->xm_read_buffer
;
199 xmesa
->use_read_buffer
= GL_TRUE
;
202 if (mode
== GL_FRONT_LEFT
) {
203 target
->buffer
= target
->frontbuffer
;
204 xmesa_update_span_funcs(ctx
);
206 else if (mode
==GL_BACK_LEFT
&& xmesa
->xm_read_buffer
->db_state
) {
207 if (target
->backpixmap
) {
208 target
->buffer
= (XMesaDrawable
)xmesa
->xm_buffer
->backpixmap
;
210 else if (target
->backimage
) {
211 target
->buffer
= None
;
214 /* just in case there wasn't enough memory for back buffer */
215 target
->buffer
= target
->frontbuffer
;
217 xmesa_update_span_funcs(ctx
);
220 _mesa_problem(ctx
, "invalid buffer in set_read_buffer() in xmesa2.c");
227 clear_index( GLcontext
*ctx
, GLuint index
)
229 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
230 xmesa
->clearpixel
= (unsigned long) index
;
231 XMesaSetForeground( xmesa
->display
, xmesa
->xm_buffer
->cleargc
,
232 (unsigned long) index
);
237 clear_color( GLcontext
*ctx
, const GLchan color
[4] )
239 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
240 xmesa
->clearcolor
[0] = color
[0];
241 xmesa
->clearcolor
[1] = color
[1];
242 xmesa
->clearcolor
[2] = color
[2];
243 xmesa
->clearcolor
[3] = color
[3];
244 xmesa
->clearpixel
= xmesa_color_to_pixel( xmesa
, color
[0], color
[1],
246 xmesa
->xm_visual
->undithered_pf
);
247 _glthread_LOCK_MUTEX(_xmesa_lock
);
248 XMesaSetForeground( xmesa
->display
, xmesa
->xm_buffer
->cleargc
,
250 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
255 /* Set index mask ala glIndexMask */
257 index_mask( GLcontext
*ctx
, GLuint mask
)
259 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
260 if (xmesa
->xm_buffer
->buffer
!= XIMAGE
) {
262 if (mask
==0xffffffff) {
263 m
= ((unsigned long)~0L);
266 m
= (unsigned long) mask
;
268 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_buffer
->cleargc
, m
);
273 /* Implements glColorMask() */
275 color_mask(GLcontext
*ctx
,
276 GLboolean rmask
, GLboolean gmask
, GLboolean bmask
, GLboolean amask
)
278 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
279 int xclass
= GET_VISUAL_CLASS(xmesa
->xm_visual
);
282 if (xmesa
->xm_buffer
->buffer
!= XIMAGE
283 && (xclass
== TrueColor
|| xclass
== DirectColor
)) {
285 if (rmask
&& gmask
&& bmask
) {
286 m
= ((unsigned long)~0L);
290 if (rmask
) m
|= GET_REDMASK(xmesa
->xm_visual
);
291 if (gmask
) m
|= GET_GREENMASK(xmesa
->xm_visual
);
292 if (bmask
) m
|= GET_BLUEMASK(xmesa
->xm_visual
);
294 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_buffer
->cleargc
, m
);
300 /**********************************************************************/
301 /*** glClear implementations ***/
302 /**********************************************************************/
306 clear_front_pixmap( GLcontext
*ctx
, GLboolean all
,
307 GLint x
, GLint y
, GLint width
, GLint height
)
309 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
311 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->frontbuffer
,
312 xmesa
->xm_buffer
->cleargc
,
314 xmesa
->xm_buffer
->width
+1,
315 xmesa
->xm_buffer
->height
+1 );
318 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->frontbuffer
,
319 xmesa
->xm_buffer
->cleargc
,
320 x
, xmesa
->xm_buffer
->height
- y
- height
,
327 clear_back_pixmap( GLcontext
*ctx
, GLboolean all
,
328 GLint x
, GLint y
, GLint width
, GLint height
)
330 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
332 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->backpixmap
,
333 xmesa
->xm_buffer
->cleargc
,
335 xmesa
->xm_buffer
->width
+1,
336 xmesa
->xm_buffer
->height
+1 );
339 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->backpixmap
,
340 xmesa
->xm_buffer
->cleargc
,
341 x
, xmesa
->xm_buffer
->height
- y
- height
,
348 clear_8bit_ximage( GLcontext
*ctx
, GLboolean all
,
349 GLint x
, GLint y
, GLint width
, GLint height
)
351 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
353 size_t n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
354 * xmesa
->xm_buffer
->backimage
->height
;
355 MEMSET( xmesa
->xm_buffer
->backimage
->data
, xmesa
->clearpixel
, n
);
359 for (i
=0;i
<height
;i
++) {
360 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_buffer
, x
, y
+i
);
361 MEMSET( ptr
, xmesa
->clearpixel
, width
);
368 clear_HPCR_ximage( GLcontext
*ctx
, GLboolean all
,
369 GLint x
, GLint y
, GLint width
, GLint height
)
371 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
373 GLint i
, c16
= (xmesa
->xm_buffer
->backimage
->bytes_per_line
>>4)<<4;
374 GLubyte
*ptr
= (GLubyte
*)xmesa
->xm_buffer
->backimage
->data
;
375 for (i
=0; i
<xmesa
->xm_buffer
->backimage
->height
; i
++) {
377 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
381 for (j
=0; j
<c16
; j
+=16) {
400 for (; j
<xmesa
->xm_buffer
->backimage
->bytes_per_line
; j
++) {
408 for (i
=y
; i
<y
+height
; i
++) {
409 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_buffer
, x
, i
);
411 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
415 for (j
=x
; j
<x
+width
; j
++) {
425 clear_16bit_ximage( GLcontext
*ctx
, GLboolean all
,
426 GLint x
, GLint y
, GLint width
, GLint height
)
428 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
429 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
430 if (xmesa
->swapbytes
) {
431 pixel
= ((pixel
>> 8) & 0x00ff) | ((pixel
<< 8) & 0xff00);
435 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_buffer
->backimage
->data
;
436 if ((pixel
& 0xff) == ((pixel
>> 8) & 0xff)) {
437 /* low and high bytes are equal so use memset() */
438 n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
439 * xmesa
->xm_buffer
->height
;
440 MEMSET( ptr4
, pixel
& 0xff, n
);
443 pixel
= pixel
| (pixel
<<16);
444 n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
445 * xmesa
->xm_buffer
->height
/ 4;
451 if ((xmesa
->xm_buffer
->backimage
->bytes_per_line
*
452 xmesa
->xm_buffer
->height
) & 0x2)
453 *(GLushort
*)ptr4
= pixel
& 0xffff;
458 for (j
=0;j
<height
;j
++) {
459 register GLushort
*ptr2
= PIXELADDR2( xmesa
->xm_buffer
, x
, y
+j
);
460 for (i
=0;i
<width
;i
++) {
468 /* Optimized code provided by Nozomi Ytow <noz@xfree86.org> */
470 clear_24bit_ximage( GLcontext
*ctx
, GLboolean all
,
471 GLint x
, GLint y
, GLint width
, GLint height
)
473 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
474 const GLubyte r
= xmesa
->clearcolor
[0];
475 const GLubyte g
= xmesa
->clearcolor
[1];
476 const GLubyte b
= xmesa
->clearcolor
[2];
477 register GLuint clearPixel
;
478 if (xmesa
->swapbytes
) {
479 clearPixel
= (b
<< 16) | (g
<< 8) | r
;
482 clearPixel
= (r
<< 16) | (g
<< 8) | b
;
487 /* same value for all three components (gray) */
488 const GLint w3
= xmesa
->xm_buffer
->width
* 3;
489 const GLint h
= xmesa
->xm_buffer
->height
;
491 for (i
= 0; i
< h
; i
++) {
492 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_buffer
, 0, i
);
498 const GLint w
= xmesa
->xm_buffer
->width
;
499 const GLint h
= xmesa
->xm_buffer
->height
;
501 for (i
= 0; i
< h
; i
++) {
502 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_buffer
, 0, i
);
503 for (j
= 0; j
< w
; j
++) {
510 #if 0 /* this code doesn't work for all window widths */
511 register GLuint
*ptr4
= (GLuint
*) ptr3
;
514 register GLuint
*p
= pixel4
;
515 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
516 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
517 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
518 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
522 px
= *ptr4
& 0x00ffffff;
523 px
|= pixel4
[0] & 0xff000000;
525 px
= *ptr4
& 0xffff0000;
526 px
|= pixel4
[2] & 0x0000ffff;
531 px
= *ptr4
& 0x0000fffff;
532 px
|= pixel4
[1] & 0xffff0000;
534 px
= *ptr4
& 0xffffff00;
535 px
|= pixel4
[2] & 0x000000ff;
540 px
= *ptr4
& 0x000000ff;
541 px
|= pixel4
[2] & 0xffffff00;
558 px
= *ptr4
& 0xffffff00;
559 px
|= clearPixel
& 0xff;
565 px
= *ptr4
& 0xffff0000;
570 px
= *ptr4
& 0xff000000;
581 /* only clear subrect of color buffer */
583 /* same value for all three components (gray) */
585 for (j
=0;j
<height
;j
++) {
586 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
587 MEMSET(ptr3
, r
, 3 * width
);
591 /* non-gray clear color */
593 for (j
= 0; j
< height
; j
++) {
594 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
595 for (i
= 0; i
< width
; i
++) {
602 #if 0 /* this code might not always (seems ptr3 always == ptr4) */
605 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
606 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
607 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
608 for (j
=0;j
<height
;j
++) {
609 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
610 register GLuint
*ptr4
= (GLuint
*)ptr3
;
611 register GLuint
*p
, px
;
613 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
617 px
= *ptr4
& 0x00ffffff;
618 px
|= pixel4
[0] & 0xff000000;
620 px
= *ptr4
& 0xffff0000;
621 px
|= pixel4
[2] & 0x0000ffff;
626 px
= *ptr4
& 0x0000fffff;
627 px
|= pixel4
[1] & 0xffff0000;
629 px
= *ptr4
& 0xffffff00;
630 px
|= pixel4
[2] & 0x000000ff;
635 px
= *ptr4
& 0x000000ff;
636 px
|= pixel4
[2] & 0xffffff00;
653 px
= *ptr4
& 0xffffff00;
660 px
= *ptr4
& 0xffff0000;
665 px
= *ptr4
& 0xff000000;
666 px
|= pixel4
[0] & 0xffffff;
680 clear_32bit_ximage( GLcontext
*ctx
, GLboolean all
,
681 GLint x
, GLint y
, GLint width
, GLint height
)
683 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
684 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
685 if (xmesa
->swapbytes
) {
686 pixel
= ((pixel
>> 24) & 0x000000ff)
687 | ((pixel
>> 8) & 0x0000ff00)
688 | ((pixel
<< 8) & 0x00ff0000)
689 | ((pixel
<< 24) & 0xff000000);
692 register GLint n
= xmesa
->xm_buffer
->width
* xmesa
->xm_buffer
->height
;
693 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_buffer
->backimage
->data
;
695 MEMSET( ptr4
, pixel
, 4*n
);
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
->mesa_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
.ChooseTextureFormat
= _mesa_choose_tex_format
;
957 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
958 ctx
->Driver
.TexImage2D
= _mesa_store_teximage2d
;
959 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
960 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
961 ctx
->Driver
.TexSubImage2D
= _mesa_store_texsubimage2d
;
962 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
963 ctx
->Driver
.TestProxyTexImage
= _mesa_test_proxy_teximage
;
965 ctx
->Driver
.CopyTexImage1D
= _swrast_copy_teximage1d
;
966 ctx
->Driver
.CopyTexImage2D
= _swrast_copy_teximage2d
;
967 ctx
->Driver
.CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
968 ctx
->Driver
.CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
969 ctx
->Driver
.CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
972 /* Swrast hooks for imaging extensions:
974 ctx
->Driver
.CopyColorTable
= _swrast_CopyColorTable
;
975 ctx
->Driver
.CopyColorSubTable
= _swrast_CopyColorSubTable
;
976 ctx
->Driver
.CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
977 ctx
->Driver
.CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
980 /* Statechange callbacks:
982 ctx
->Driver
.SetDrawBuffer
= set_draw_buffer
;
983 ctx
->Driver
.ClearIndex
= clear_index
;
984 ctx
->Driver
.ClearColor
= clear_color
;
985 ctx
->Driver
.IndexMask
= index_mask
;
986 ctx
->Driver
.ColorMask
= color_mask
;
987 ctx
->Driver
.Enable
= enable
;
990 /* Initialize the TNL driver interface:
992 tnl
= TNL_CONTEXT(ctx
);
993 tnl
->Driver
.RenderStart
= _swsetup_RenderStart
;
994 tnl
->Driver
.RenderFinish
= _swsetup_RenderFinish
;
995 tnl
->Driver
.BuildProjectedVertices
= _swsetup_BuildProjectedVertices
;
996 tnl
->Driver
.RenderPrimitive
= _swsetup_RenderPrimitive
;
997 tnl
->Driver
.PointsFunc
= _swsetup_Points
;
998 tnl
->Driver
.LineFunc
= _swsetup_Line
;
999 tnl
->Driver
.TriangleFunc
= _swsetup_Triangle
;
1000 tnl
->Driver
.QuadFunc
= _swsetup_Quad
;
1001 tnl
->Driver
.ResetLineStipple
= _swrast_ResetLineStipple
;
1002 tnl
->Driver
.RenderInterp
= _swsetup_RenderInterp
;
1003 tnl
->Driver
.RenderCopyPV
= _swsetup_RenderCopyPV
;
1004 tnl
->Driver
.RenderClippedLine
= _swsetup_RenderClippedLine
;
1005 tnl
->Driver
.RenderClippedPolygon
= _swsetup_RenderClippedPolygon
;
1007 (void) DitherValues
; /* silenced unused var warning */