1 /* $Id: xm_dd.c,v 1.34 2002/07/09 01:22:52 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
;
65 /* XFree86 GLX renderer */
66 winwidth
= xmBuffer
->frontbuffer
->width
;
67 winheight
= xmBuffer
->frontbuffer
->height
;
73 _glthread_LOCK_MUTEX(_xmesa_lock
);
74 XSync(xmBuffer
->xm_visual
->display
, 0); /* added for Chromium */
75 XGetGeometry( xmBuffer
->xm_visual
->display
, xmBuffer
->frontbuffer
, &root
,
76 &winx
, &winy
, &winwidth
, &winheight
, &bw
, &d
);
77 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
80 (void)kernel8
; /* Muffle compiler */
88 finish( GLcontext
*ctx
)
93 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
95 _glthread_LOCK_MUTEX(_xmesa_lock
);
96 XSync( xmesa
->display
, False
);
97 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
104 flush( GLcontext
*ctx
)
109 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
111 _glthread_LOCK_MUTEX(_xmesa_lock
);
112 XFlush( xmesa
->display
);
113 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
121 * This chooses the color buffer for reading and writing spans, points,
122 * lines, and triangles.
125 set_buffer( GLcontext
*ctx
, GLframebuffer
*buffer
, GLenum mode
)
127 /* We can make this cast since the XMesaBuffer wraps GLframebuffer.
128 * GLframebuffer is the first member in a XMesaBuffer struct.
130 XMesaBuffer target
= (XMesaBuffer
) buffer
;
131 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
133 /* This assignment tells the span/point/line/triangle functions
134 * which XMesaBuffer to use.
136 xmesa
->xm_buffer
= target
;
139 * Now determine front vs back color buffer.
141 if (mode
== GL_FRONT_LEFT
) {
142 target
->buffer
= target
->frontbuffer
;
144 else if (mode
== GL_BACK_LEFT
) {
145 ASSERT(target
->db_state
);
146 if (target
->backpixmap
) {
147 /* back buffer is a pixmape */
148 target
->buffer
= target
->backpixmap
;
150 else if (target
->backimage
) {
151 /* back buffer is an XImage */
152 target
->buffer
= None
;
155 /* No back buffer!!!! Must be out of memory, use front buffer */
156 target
->buffer
= target
->frontbuffer
;
160 _mesa_problem(ctx
, "invalid buffer in set_buffer() in xmesa2.c");
163 xmesa_update_span_funcs(ctx
);
169 clear_index( GLcontext
*ctx
, GLuint index
)
171 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
172 xmesa
->clearpixel
= (unsigned long) index
;
173 XMesaSetForeground( xmesa
->display
, xmesa
->xm_draw_buffer
->cleargc
,
174 (unsigned long) index
);
179 clear_color( GLcontext
*ctx
, const GLchan color
[4] )
181 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
182 xmesa
->clearcolor
[0] = color
[0];
183 xmesa
->clearcolor
[1] = color
[1];
184 xmesa
->clearcolor
[2] = color
[2];
185 xmesa
->clearcolor
[3] = color
[3];
186 xmesa
->clearpixel
= xmesa_color_to_pixel( xmesa
, color
[0], color
[1],
188 xmesa
->xm_visual
->undithered_pf
);
189 _glthread_LOCK_MUTEX(_xmesa_lock
);
190 XMesaSetForeground( xmesa
->display
, xmesa
->xm_draw_buffer
->cleargc
,
192 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
197 /* Set index mask ala glIndexMask */
199 index_mask( GLcontext
*ctx
, GLuint mask
)
201 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
202 if (xmesa
->xm_draw_buffer
->buffer
!= XIMAGE
) {
204 if (mask
==0xffffffff) {
205 m
= ((unsigned long)~0L);
208 m
= (unsigned long) mask
;
210 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_draw_buffer
->cleargc
, m
);
215 /* Implements glColorMask() */
217 color_mask(GLcontext
*ctx
,
218 GLboolean rmask
, GLboolean gmask
, GLboolean bmask
, GLboolean amask
)
220 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
221 int xclass
= GET_VISUAL_CLASS(xmesa
->xm_visual
);
224 if (xclass
== TrueColor
|| xclass
== DirectColor
) {
226 if (rmask
&& gmask
&& bmask
) {
227 m
= ((unsigned long)~0L);
231 if (rmask
) m
|= GET_REDMASK(xmesa
->xm_visual
);
232 if (gmask
) m
|= GET_GREENMASK(xmesa
->xm_visual
);
233 if (bmask
) m
|= GET_BLUEMASK(xmesa
->xm_visual
);
235 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_draw_buffer
->cleargc
, m
);
241 /**********************************************************************/
242 /*** glClear implementations ***/
243 /**********************************************************************/
247 clear_front_pixmap( GLcontext
*ctx
, GLboolean all
,
248 GLint x
, GLint y
, GLint width
, GLint height
)
250 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
252 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_draw_buffer
->frontbuffer
,
253 xmesa
->xm_draw_buffer
->cleargc
,
255 xmesa
->xm_draw_buffer
->width
+1,
256 xmesa
->xm_draw_buffer
->height
+1 );
259 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_draw_buffer
->frontbuffer
,
260 xmesa
->xm_draw_buffer
->cleargc
,
261 x
, xmesa
->xm_draw_buffer
->height
- y
- height
,
268 clear_back_pixmap( GLcontext
*ctx
, GLboolean all
,
269 GLint x
, GLint y
, GLint width
, GLint height
)
271 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
273 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_draw_buffer
->backpixmap
,
274 xmesa
->xm_draw_buffer
->cleargc
,
276 xmesa
->xm_draw_buffer
->width
+1,
277 xmesa
->xm_draw_buffer
->height
+1 );
280 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_draw_buffer
->backpixmap
,
281 xmesa
->xm_draw_buffer
->cleargc
,
282 x
, xmesa
->xm_draw_buffer
->height
- y
- height
,
289 clear_8bit_ximage( GLcontext
*ctx
, GLboolean all
,
290 GLint x
, GLint y
, GLint width
, GLint height
)
292 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
294 size_t n
= xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
295 * xmesa
->xm_draw_buffer
->backimage
->height
;
296 MEMSET( xmesa
->xm_draw_buffer
->backimage
->data
, xmesa
->clearpixel
, n
);
300 for (i
=0;i
<height
;i
++) {
301 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_draw_buffer
, x
, y
+i
);
302 MEMSET( ptr
, xmesa
->clearpixel
, width
);
309 clear_HPCR_ximage( GLcontext
*ctx
, GLboolean all
,
310 GLint x
, GLint y
, GLint width
, GLint height
)
312 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
314 GLint i
, c16
= (xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
>>4)<<4;
315 GLubyte
*ptr
= (GLubyte
*)xmesa
->xm_draw_buffer
->backimage
->data
;
316 for (i
=0; i
<xmesa
->xm_draw_buffer
->backimage
->height
; i
++) {
318 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
322 for (j
=0; j
<c16
; j
+=16) {
341 for (; j
<xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
; j
++) {
349 for (i
=y
; i
<y
+height
; i
++) {
350 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_draw_buffer
, x
, i
);
352 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
356 for (j
=x
; j
<x
+width
; j
++) {
366 clear_16bit_ximage( GLcontext
*ctx
, GLboolean all
,
367 GLint x
, GLint y
, GLint width
, GLint height
)
369 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
370 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
371 if (xmesa
->swapbytes
) {
372 pixel
= ((pixel
>> 8) & 0x00ff) | ((pixel
<< 8) & 0xff00);
376 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_draw_buffer
->backimage
->data
;
377 if ((pixel
& 0xff) == ((pixel
>> 8) & 0xff)) {
378 /* low and high bytes are equal so use memset() */
379 n
= xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
380 * xmesa
->xm_draw_buffer
->height
;
381 MEMSET( ptr4
, pixel
& 0xff, n
);
384 pixel
= pixel
| (pixel
<<16);
385 n
= xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
386 * xmesa
->xm_draw_buffer
->height
/ 4;
392 if ((xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
*
393 xmesa
->xm_draw_buffer
->height
) & 0x2)
394 *(GLushort
*)ptr4
= pixel
& 0xffff;
399 for (j
=0;j
<height
;j
++) {
400 register GLushort
*ptr2
= PIXELADDR2( xmesa
->xm_draw_buffer
, x
, y
+j
);
401 for (i
=0;i
<width
;i
++) {
409 /* Optimized code provided by Nozomi Ytow <noz@xfree86.org> */
411 clear_24bit_ximage( GLcontext
*ctx
, GLboolean all
,
412 GLint x
, GLint y
, GLint width
, GLint height
)
414 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
415 const GLubyte r
= xmesa
->clearcolor
[0];
416 const GLubyte g
= xmesa
->clearcolor
[1];
417 const GLubyte b
= xmesa
->clearcolor
[2];
418 register GLuint clearPixel
;
419 if (xmesa
->swapbytes
) {
420 clearPixel
= (b
<< 16) | (g
<< 8) | r
;
423 clearPixel
= (r
<< 16) | (g
<< 8) | b
;
428 /* same value for all three components (gray) */
429 const GLint w3
= xmesa
->xm_draw_buffer
->width
* 3;
430 const GLint h
= xmesa
->xm_draw_buffer
->height
;
432 for (i
= 0; i
< h
; i
++) {
433 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_draw_buffer
, 0, i
);
439 const GLint w
= xmesa
->xm_draw_buffer
->width
;
440 const GLint h
= xmesa
->xm_draw_buffer
->height
;
442 for (i
= 0; i
< h
; i
++) {
443 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_draw_buffer
, 0, i
);
444 for (j
= 0; j
< w
; j
++) {
451 #if 0 /* this code doesn't work for all window widths */
452 register GLuint
*ptr4
= (GLuint
*) ptr3
;
455 register GLuint
*p
= pixel4
;
456 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
457 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
458 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
459 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
463 px
= *ptr4
& 0x00ffffff;
464 px
|= pixel4
[0] & 0xff000000;
466 px
= *ptr4
& 0xffff0000;
467 px
|= pixel4
[2] & 0x0000ffff;
472 px
= *ptr4
& 0x0000fffff;
473 px
|= pixel4
[1] & 0xffff0000;
475 px
= *ptr4
& 0xffffff00;
476 px
|= pixel4
[2] & 0x000000ff;
481 px
= *ptr4
& 0x000000ff;
482 px
|= pixel4
[2] & 0xffffff00;
499 px
= *ptr4
& 0xffffff00;
500 px
|= clearPixel
& 0xff;
506 px
= *ptr4
& 0xffff0000;
511 px
= *ptr4
& 0xff000000;
522 /* only clear subrect of color buffer */
524 /* same value for all three components (gray) */
526 for (j
=0;j
<height
;j
++) {
527 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_draw_buffer
, x
, y
+j
);
528 MEMSET(ptr3
, r
, 3 * width
);
532 /* non-gray clear color */
534 for (j
= 0; j
< height
; j
++) {
535 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_draw_buffer
, x
, y
+j
);
536 for (i
= 0; i
< width
; i
++) {
543 #if 0 /* this code might not always (seems ptr3 always == ptr4) */
546 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
547 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
548 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
549 for (j
=0;j
<height
;j
++) {
550 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_draw_buffer
, x
, y
+j
);
551 register GLuint
*ptr4
= (GLuint
*)ptr3
;
552 register GLuint
*p
, px
;
554 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
558 px
= *ptr4
& 0x00ffffff;
559 px
|= pixel4
[0] & 0xff000000;
561 px
= *ptr4
& 0xffff0000;
562 px
|= pixel4
[2] & 0x0000ffff;
567 px
= *ptr4
& 0x0000fffff;
568 px
|= pixel4
[1] & 0xffff0000;
570 px
= *ptr4
& 0xffffff00;
571 px
|= pixel4
[2] & 0x000000ff;
576 px
= *ptr4
& 0x000000ff;
577 px
|= pixel4
[2] & 0xffffff00;
594 px
= *ptr4
& 0xffffff00;
601 px
= *ptr4
& 0xffff0000;
606 px
= *ptr4
& 0xff000000;
607 px
|= pixel4
[0] & 0xffffff;
621 clear_32bit_ximage( GLcontext
*ctx
, GLboolean all
,
622 GLint x
, GLint y
, GLint width
, GLint height
)
624 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
625 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
626 if (xmesa
->swapbytes
) {
627 pixel
= ((pixel
>> 24) & 0x000000ff)
628 | ((pixel
>> 8) & 0x0000ff00)
629 | ((pixel
<< 8) & 0x00ff0000)
630 | ((pixel
<< 24) & 0xff000000);
633 register GLint n
= xmesa
->xm_draw_buffer
->width
* xmesa
->xm_draw_buffer
->height
;
634 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_draw_buffer
->backimage
->data
;
636 MEMSET( ptr4
, pixel
, 4*n
);
647 for (j
=0;j
<height
;j
++) {
648 register GLuint
*ptr4
= PIXELADDR4( xmesa
->xm_draw_buffer
, x
, y
+j
);
649 for (i
=0;i
<width
;i
++) {
658 clear_nbit_ximage( GLcontext
*ctx
, GLboolean all
,
659 GLint x
, GLint y
, GLint width
, GLint height
)
661 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
662 XMesaImage
*img
= xmesa
->xm_draw_buffer
->backimage
;
665 width
= xmesa
->xm_draw_buffer
->width
;
666 height
= xmesa
->xm_draw_buffer
->height
;
667 for (j
=0;j
<height
;j
++) {
668 for (i
=0;i
<width
;i
++) {
669 XMesaPutPixel( img
, i
, j
, xmesa
->clearpixel
);
674 /* TODO: optimize this */
676 y
= FLIP(xmesa
->xm_draw_buffer
, y
);
677 for (j
=0;j
<height
;j
++) {
678 for (i
=0;i
<width
;i
++) {
679 XMesaPutPixel( img
, x
+i
, y
-j
, xmesa
->clearpixel
);
688 clear_buffers( GLcontext
*ctx
, GLbitfield mask
,
689 GLboolean all
, GLint x
, GLint y
, GLint width
, GLint height
)
691 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
692 const GLuint
*colorMask
= (GLuint
*) &ctx
->Color
.ColorMask
;
694 if ((mask
& (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
)) &&
695 xmesa
->xm_draw_buffer
->mesa_buffer
.UseSoftwareAlphaBuffers
&&
696 ctx
->Color
.ColorMask
[ACOMP
]) {
697 _mesa_clear_alpha_buffers(ctx
);
700 /* we can't handle color or index masking */
701 if (*colorMask
== 0xffffffff && ctx
->Color
.IndexMask
== 0xffffffff) {
702 if (mask
& DD_FRONT_LEFT_BIT
) {
703 ASSERT(xmesa
->xm_draw_buffer
->front_clear_func
);
704 (*xmesa
->xm_draw_buffer
->front_clear_func
)( ctx
, all
, x
, y
, width
, height
);
705 mask
&= ~DD_FRONT_LEFT_BIT
;
707 if (mask
& DD_BACK_LEFT_BIT
) {
708 ASSERT(xmesa
->xm_draw_buffer
->back_clear_func
);
709 (*xmesa
->xm_draw_buffer
->back_clear_func
)( ctx
, all
, x
, y
, width
, height
);
710 mask
&= ~DD_BACK_LEFT_BIT
;
715 _swrast_Clear( ctx
, mask
, all
, x
, y
, width
, height
);
720 * When we detect that the user has resized the window this function will
721 * get called. Here we'll reallocate the back buffer, depth buffer,
722 * stencil buffer etc. to match the new window size.
725 xmesa_resize_buffers( GLframebuffer
*buffer
)
727 int height
= (int) buffer
->Height
;
728 /* We can do this cast because the first field in the XMesaBuffer
729 * struct is a GLframebuffer struct. If this weren't true, we'd
730 * need a pointer from the GLframebuffer to the XMesaBuffer.
732 XMesaBuffer xmBuffer
= (XMesaBuffer
) buffer
;
734 xmBuffer
->width
= buffer
->Width
;
735 xmBuffer
->height
= buffer
->Height
;
736 xmesa_alloc_back_buffer( xmBuffer
);
738 /* Needed by FLIP macro */
739 xmBuffer
->bottom
= height
- 1;
741 if (xmBuffer
->backimage
) {
742 /* Needed by PIXELADDR1 macro */
743 xmBuffer
->ximage_width1
= xmBuffer
->backimage
->bytes_per_line
;
744 xmBuffer
->ximage_origin1
= (GLubyte
*) xmBuffer
->backimage
->data
745 + xmBuffer
->ximage_width1
* (height
-1);
747 /* Needed by PIXELADDR2 macro */
748 xmBuffer
->ximage_width2
= xmBuffer
->backimage
->bytes_per_line
/ 2;
749 xmBuffer
->ximage_origin2
= (GLushort
*) xmBuffer
->backimage
->data
750 + xmBuffer
->ximage_width2
* (height
-1);
752 /* Needed by PIXELADDR3 macro */
753 xmBuffer
->ximage_width3
= xmBuffer
->backimage
->bytes_per_line
;
754 xmBuffer
->ximage_origin3
= (GLubyte
*) xmBuffer
->backimage
->data
755 + xmBuffer
->ximage_width3
* (height
-1);
757 /* Needed by PIXELADDR4 macro */
758 xmBuffer
->ximage_width4
= xmBuffer
->backimage
->width
;
759 xmBuffer
->ximage_origin4
= (GLuint
*) xmBuffer
->backimage
->data
760 + xmBuffer
->ximage_width4
* (height
-1);
763 _swrast_alloc_buffers( buffer
);
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_draw_buffer
->buffer
;
783 XMesaGC gc
= xmesa
->xm_draw_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_draw_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
*) "Mesa project: www.mesa3d.org";
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
, GLuint new_state
)
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
, new_state
);
873 _ac_InvalidateState( ctx
, new_state
);
874 _tnl_InvalidateState( ctx
, new_state
);
875 _swsetup_InvalidateState( ctx
, new_state
);
878 /* setup pointers to front and back buffer clear functions */
879 xmesa
->xm_draw_buffer
->front_clear_func
= clear_front_pixmap
;
880 if (xmesa
->xm_draw_buffer
->backpixmap
!= XIMAGE
) {
881 xmesa
->xm_draw_buffer
->back_clear_func
= clear_back_pixmap
;
883 else if (sizeof(GLushort
)!=2 || sizeof(GLuint
)!=4) {
884 xmesa
->xm_draw_buffer
->back_clear_func
= clear_nbit_ximage
;
886 else switch (xmesa
->xm_visual
->BitsPerPixel
) {
888 if (xmesa
->xm_visual
->hpcr_clear_flag
) {
889 xmesa
->xm_draw_buffer
->back_clear_func
= clear_HPCR_ximage
;
892 xmesa
->xm_draw_buffer
->back_clear_func
= clear_8bit_ximage
;
896 xmesa
->xm_draw_buffer
->back_clear_func
= clear_16bit_ximage
;
899 xmesa
->xm_draw_buffer
->back_clear_func
= clear_24bit_ximage
;
902 xmesa
->xm_draw_buffer
->back_clear_func
= clear_32bit_ximage
;
905 xmesa
->xm_draw_buffer
->back_clear_func
= clear_nbit_ximage
;
909 xmesa_update_span_funcs(ctx
);
914 /* Setup pointers and other driver state that is constant for the life
917 void xmesa_init_pointers( GLcontext
*ctx
)
920 struct swrast_device_driver
*dd
= _swrast_GetDeviceDriverReference( ctx
);
922 ctx
->Driver
.GetString
= get_string
;
923 ctx
->Driver
.GetBufferSize
= get_buffer_size
;
924 ctx
->Driver
.Flush
= flush
;
925 ctx
->Driver
.Finish
= finish
;
927 /* Software rasterizer pixel paths:
929 ctx
->Driver
.Accum
= _swrast_Accum
;
930 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
931 ctx
->Driver
.Clear
= clear_buffers
;
932 ctx
->Driver
.ResizeBuffers
= xmesa_resize_buffers
;
933 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
934 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
935 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;
936 ctx
->Driver
.DrawBuffer
= _swrast_DrawBuffer
;
938 /* Software texture functions:
940 ctx
->Driver
.ChooseTextureFormat
= _mesa_choose_tex_format
;
941 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
942 ctx
->Driver
.TexImage2D
= _mesa_store_teximage2d
;
943 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
944 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
945 ctx
->Driver
.TexSubImage2D
= _mesa_store_texsubimage2d
;
946 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
947 ctx
->Driver
.TestProxyTexImage
= _mesa_test_proxy_teximage
;
949 ctx
->Driver
.CopyTexImage1D
= _swrast_copy_teximage1d
;
950 ctx
->Driver
.CopyTexImage2D
= _swrast_copy_teximage2d
;
951 ctx
->Driver
.CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
952 ctx
->Driver
.CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
953 ctx
->Driver
.CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
955 ctx
->Driver
.BaseCompressedTexFormat
= _mesa_base_compressed_texformat
;
956 ctx
->Driver
.CompressedTextureSize
= _mesa_compressed_texture_size
;
957 ctx
->Driver
.GetCompressedTexImage
= _mesa_get_compressed_teximage
;
959 /* Swrast hooks for imaging extensions:
961 ctx
->Driver
.CopyColorTable
= _swrast_CopyColorTable
;
962 ctx
->Driver
.CopyColorSubTable
= _swrast_CopyColorSubTable
;
963 ctx
->Driver
.CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
964 ctx
->Driver
.CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
967 /* Statechange callbacks:
969 ctx
->Driver
.ClearIndex
= clear_index
;
970 ctx
->Driver
.ClearColor
= clear_color
;
971 ctx
->Driver
.IndexMask
= index_mask
;
972 ctx
->Driver
.ColorMask
= color_mask
;
973 ctx
->Driver
.Enable
= enable
;
976 /* Initialize the TNL driver interface:
978 tnl
= TNL_CONTEXT(ctx
);
979 tnl
->Driver
.RunPipeline
= _tnl_run_pipeline
;
981 dd
->SetBuffer
= set_buffer
;
983 /* Install swsetup for tnl->Driver.Render.*:
985 _swsetup_Wakeup(ctx
);
987 (void) DitherValues
; /* silenced unused var warning */
994 #define XMESA_NEW_POINT (_NEW_POINT | \
996 _SWRAST_NEW_RASTERMASK)
998 #define XMESA_NEW_LINE (_NEW_LINE | \
1003 _SWRAST_NEW_RASTERMASK)
1005 #define XMESA_NEW_TRIANGLE (_NEW_POLYGON | \
1010 _SWRAST_NEW_RASTERMASK)
1013 /* Extend the software rasterizer with our line/point/triangle
1016 void xmesa_register_swrast_functions( GLcontext
*ctx
)
1018 SWcontext
*swrast
= SWRAST_CONTEXT( ctx
);
1020 swrast
->choose_point
= xmesa_choose_point
;
1021 swrast
->choose_line
= xmesa_choose_line
;
1022 swrast
->choose_triangle
= xmesa_choose_triangle
;
1024 swrast
->invalidate_point
|= XMESA_NEW_POINT
;
1025 swrast
->invalidate_line
|= XMESA_NEW_LINE
;
1026 swrast
->invalidate_triangle
|= XMESA_NEW_TRIANGLE
;