1 /* $Id: xm_dd.c,v 1.29 2002/03/01 04:28:32 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 current color buffer.
52 * This function should be called by the glViewport function because
53 * glViewport is often called when the window gets resized. We need to
54 * update some X/Mesa stuff when that happens.
55 * Output: width - width of buffer in pixels.
56 * height - height of buffer in pixels.
59 get_buffer_size( GLcontext
*ctx
, GLuint
*width
, GLuint
*height
)
61 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
62 unsigned int winwidth
, winheight
;
68 _glthread_LOCK_MUTEX(_xmesa_lock
);
69 XGetGeometry( xmesa
->display
, xmesa
->xm_buffer
->frontbuffer
, &root
,
70 &winx
, &winy
, &winwidth
, &winheight
, &bw
, &d
);
71 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
74 winwidth
= xmesa
->xm_buffer
->frontbuffer
->width
;
75 winheight
= xmesa
->xm_buffer
->frontbuffer
->height
;
78 (void)kernel8
; /* Muffle compiler */
83 if ( winwidth
!=xmesa
->xm_buffer
->width
84 || winheight
!=xmesa
->xm_buffer
->height
) {
85 xmesa
->xm_buffer
->width
= winwidth
;
86 xmesa
->xm_buffer
->height
= winheight
;
87 xmesa_alloc_back_buffer( xmesa
->xm_buffer
);
90 /* Needed by FLIP macro */
91 xmesa
->xm_buffer
->bottom
= (int) winheight
- 1;
93 if (xmesa
->xm_buffer
->backimage
) {
94 /* Needed by PIXELADDR1 macro */
95 xmesa
->xm_buffer
->ximage_width1
96 = xmesa
->xm_buffer
->backimage
->bytes_per_line
;
97 xmesa
->xm_buffer
->ximage_origin1
98 = (GLubyte
*) xmesa
->xm_buffer
->backimage
->data
99 + xmesa
->xm_buffer
->ximage_width1
* (winheight
-1);
101 /* Needed by PIXELADDR2 macro */
102 xmesa
->xm_buffer
->ximage_width2
103 = xmesa
->xm_buffer
->backimage
->bytes_per_line
/ 2;
104 xmesa
->xm_buffer
->ximage_origin2
105 = (GLushort
*) xmesa
->xm_buffer
->backimage
->data
106 + xmesa
->xm_buffer
->ximage_width2
* (winheight
-1);
108 /* Needed by PIXELADDR3 macro */
109 xmesa
->xm_buffer
->ximage_width3
110 = xmesa
->xm_buffer
->backimage
->bytes_per_line
;
111 xmesa
->xm_buffer
->ximage_origin3
112 = (GLubyte
*) xmesa
->xm_buffer
->backimage
->data
113 + xmesa
->xm_buffer
->ximage_width3
* (winheight
-1);
115 /* Needed by PIXELADDR4 macro */
116 xmesa
->xm_buffer
->ximage_width4
= xmesa
->xm_buffer
->backimage
->width
;
117 xmesa
->xm_buffer
->ximage_origin4
118 = (GLuint
*) xmesa
->xm_buffer
->backimage
->data
119 + xmesa
->xm_buffer
->ximage_width4
* (winheight
-1);
125 finish( GLcontext
*ctx
)
130 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
132 _glthread_LOCK_MUTEX(_xmesa_lock
);
133 XSync( xmesa
->display
, False
);
134 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
141 flush( GLcontext
*ctx
)
146 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
148 _glthread_LOCK_MUTEX(_xmesa_lock
);
149 XFlush( xmesa
->display
);
150 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
159 set_draw_buffer( GLcontext
*ctx
, GLenum mode
)
161 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
162 if (mode
== GL_FRONT_LEFT
) {
163 /* write to front buffer */
164 xmesa
->xm_buffer
->buffer
= xmesa
->xm_buffer
->frontbuffer
;
165 xmesa_update_span_funcs(ctx
);
168 else if (mode
==GL_BACK_LEFT
&& xmesa
->xm_buffer
->db_state
) {
169 /* write to back buffer */
170 if (xmesa
->xm_buffer
->backpixmap
) {
171 xmesa
->xm_buffer
->buffer
=
172 (XMesaDrawable
)xmesa
->xm_buffer
->backpixmap
;
174 else if (xmesa
->xm_buffer
->backimage
) {
175 xmesa
->xm_buffer
->buffer
= None
;
178 /* just in case there wasn't enough memory for back buffer */
179 xmesa
->xm_buffer
->buffer
= xmesa
->xm_buffer
->frontbuffer
;
181 xmesa_update_span_funcs(ctx
);
191 xmesa_set_read_buffer( GLcontext
*ctx
, GLframebuffer
*buffer
, GLenum mode
)
194 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
196 if (buffer
== ctx
->DrawBuffer
) {
197 target
= xmesa
->xm_buffer
;
198 xmesa
->use_read_buffer
= GL_FALSE
;
201 ASSERT(buffer
== ctx
->ReadBuffer
);
202 target
= xmesa
->xm_read_buffer
;
203 xmesa
->use_read_buffer
= GL_TRUE
;
206 if (mode
== GL_FRONT_LEFT
) {
207 target
->buffer
= target
->frontbuffer
;
208 xmesa_update_span_funcs(ctx
);
210 else if (mode
==GL_BACK_LEFT
&& xmesa
->xm_read_buffer
->db_state
) {
211 if (target
->backpixmap
) {
212 target
->buffer
= (XMesaDrawable
)xmesa
->xm_buffer
->backpixmap
;
214 else if (target
->backimage
) {
215 target
->buffer
= None
;
218 /* just in case there wasn't enough memory for back buffer */
219 target
->buffer
= target
->frontbuffer
;
221 xmesa_update_span_funcs(ctx
);
224 _mesa_problem(ctx
, "invalid buffer in set_read_buffer() in xmesa2.c");
231 clear_index( GLcontext
*ctx
, GLuint index
)
233 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
234 xmesa
->clearpixel
= (unsigned long) index
;
235 XMesaSetForeground( xmesa
->display
, xmesa
->xm_buffer
->cleargc
,
236 (unsigned long) index
);
241 clear_color( GLcontext
*ctx
, const GLchan color
[4] )
243 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
244 xmesa
->clearcolor
[0] = color
[0];
245 xmesa
->clearcolor
[1] = color
[1];
246 xmesa
->clearcolor
[2] = color
[2];
247 xmesa
->clearcolor
[3] = color
[3];
248 xmesa
->clearpixel
= xmesa_color_to_pixel( xmesa
, color
[0], color
[1],
250 xmesa
->xm_visual
->undithered_pf
);
251 _glthread_LOCK_MUTEX(_xmesa_lock
);
252 XMesaSetForeground( xmesa
->display
, xmesa
->xm_buffer
->cleargc
,
254 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
259 /* Set index mask ala glIndexMask */
261 index_mask( GLcontext
*ctx
, GLuint mask
)
263 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
264 if (xmesa
->xm_buffer
->buffer
!= XIMAGE
) {
266 if (mask
==0xffffffff) {
267 m
= ((unsigned long)~0L);
270 m
= (unsigned long) mask
;
272 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_buffer
->gc
, m
);
273 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_buffer
->cleargc
, m
);
278 /* Implements glColorMask() */
280 color_mask(GLcontext
*ctx
,
281 GLboolean rmask
, GLboolean gmask
, GLboolean bmask
, GLboolean amask
)
283 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
284 int xclass
= GET_VISUAL_CLASS(xmesa
->xm_visual
);
287 if (xclass
== TrueColor
|| xclass
== DirectColor
) {
289 if (rmask
&& gmask
&& bmask
) {
290 m
= ((unsigned long)~0L);
294 if (rmask
) m
|= GET_REDMASK(xmesa
->xm_visual
);
295 if (gmask
) m
|= GET_GREENMASK(xmesa
->xm_visual
);
296 if (bmask
) m
|= GET_BLUEMASK(xmesa
->xm_visual
);
298 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_buffer
->gc
, m
);
299 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_buffer
->cleargc
, m
);
305 /**********************************************************************/
306 /*** glClear implementations ***/
307 /**********************************************************************/
311 clear_front_pixmap( GLcontext
*ctx
, GLboolean all
,
312 GLint x
, GLint y
, GLint width
, GLint height
)
314 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
316 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->frontbuffer
,
317 xmesa
->xm_buffer
->cleargc
,
319 xmesa
->xm_buffer
->width
+1,
320 xmesa
->xm_buffer
->height
+1 );
323 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->frontbuffer
,
324 xmesa
->xm_buffer
->cleargc
,
325 x
, xmesa
->xm_buffer
->height
- y
- height
,
332 clear_back_pixmap( GLcontext
*ctx
, GLboolean all
,
333 GLint x
, GLint y
, GLint width
, GLint height
)
335 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
337 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->backpixmap
,
338 xmesa
->xm_buffer
->cleargc
,
340 xmesa
->xm_buffer
->width
+1,
341 xmesa
->xm_buffer
->height
+1 );
344 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->backpixmap
,
345 xmesa
->xm_buffer
->cleargc
,
346 x
, xmesa
->xm_buffer
->height
- y
- height
,
353 clear_8bit_ximage( GLcontext
*ctx
, GLboolean all
,
354 GLint x
, GLint y
, GLint width
, GLint height
)
356 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
358 size_t n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
359 * xmesa
->xm_buffer
->backimage
->height
;
360 MEMSET( xmesa
->xm_buffer
->backimage
->data
, xmesa
->clearpixel
, n
);
364 for (i
=0;i
<height
;i
++) {
365 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_buffer
, x
, y
+i
);
366 MEMSET( ptr
, xmesa
->clearpixel
, width
);
373 clear_HPCR_ximage( GLcontext
*ctx
, GLboolean all
,
374 GLint x
, GLint y
, GLint width
, GLint height
)
376 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
378 GLint i
, c16
= (xmesa
->xm_buffer
->backimage
->bytes_per_line
>>4)<<4;
379 GLubyte
*ptr
= (GLubyte
*)xmesa
->xm_buffer
->backimage
->data
;
380 for (i
=0; i
<xmesa
->xm_buffer
->backimage
->height
; i
++) {
382 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
386 for (j
=0; j
<c16
; j
+=16) {
405 for (; j
<xmesa
->xm_buffer
->backimage
->bytes_per_line
; j
++) {
413 for (i
=y
; i
<y
+height
; i
++) {
414 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_buffer
, x
, i
);
416 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
420 for (j
=x
; j
<x
+width
; j
++) {
430 clear_16bit_ximage( GLcontext
*ctx
, GLboolean all
,
431 GLint x
, GLint y
, GLint width
, GLint height
)
433 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
434 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
435 if (xmesa
->swapbytes
) {
436 pixel
= ((pixel
>> 8) & 0x00ff) | ((pixel
<< 8) & 0xff00);
440 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_buffer
->backimage
->data
;
441 if ((pixel
& 0xff) == ((pixel
>> 8) & 0xff)) {
442 /* low and high bytes are equal so use memset() */
443 n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
444 * xmesa
->xm_buffer
->height
;
445 MEMSET( ptr4
, pixel
& 0xff, n
);
448 pixel
= pixel
| (pixel
<<16);
449 n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
450 * xmesa
->xm_buffer
->height
/ 4;
456 if ((xmesa
->xm_buffer
->backimage
->bytes_per_line
*
457 xmesa
->xm_buffer
->height
) & 0x2)
458 *(GLushort
*)ptr4
= pixel
& 0xffff;
463 for (j
=0;j
<height
;j
++) {
464 register GLushort
*ptr2
= PIXELADDR2( xmesa
->xm_buffer
, x
, y
+j
);
465 for (i
=0;i
<width
;i
++) {
473 /* Optimized code provided by Nozomi Ytow <noz@xfree86.org> */
475 clear_24bit_ximage( GLcontext
*ctx
, GLboolean all
,
476 GLint x
, GLint y
, GLint width
, GLint height
)
478 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
479 const GLubyte r
= xmesa
->clearcolor
[0];
480 const GLubyte g
= xmesa
->clearcolor
[1];
481 const GLubyte b
= xmesa
->clearcolor
[2];
482 register GLuint clearPixel
;
483 if (xmesa
->swapbytes
) {
484 clearPixel
= (b
<< 16) | (g
<< 8) | r
;
487 clearPixel
= (r
<< 16) | (g
<< 8) | b
;
492 /* same value for all three components (gray) */
493 const GLint w3
= xmesa
->xm_buffer
->width
* 3;
494 const GLint h
= xmesa
->xm_buffer
->height
;
496 for (i
= 0; i
< h
; i
++) {
497 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_buffer
, 0, i
);
503 const GLint w
= xmesa
->xm_buffer
->width
;
504 const GLint h
= xmesa
->xm_buffer
->height
;
506 for (i
= 0; i
< h
; i
++) {
507 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_buffer
, 0, i
);
508 for (j
= 0; j
< w
; j
++) {
515 #if 0 /* this code doesn't work for all window widths */
516 register GLuint
*ptr4
= (GLuint
*) ptr3
;
519 register GLuint
*p
= pixel4
;
520 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
521 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
522 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
523 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
527 px
= *ptr4
& 0x00ffffff;
528 px
|= pixel4
[0] & 0xff000000;
530 px
= *ptr4
& 0xffff0000;
531 px
|= pixel4
[2] & 0x0000ffff;
536 px
= *ptr4
& 0x0000fffff;
537 px
|= pixel4
[1] & 0xffff0000;
539 px
= *ptr4
& 0xffffff00;
540 px
|= pixel4
[2] & 0x000000ff;
545 px
= *ptr4
& 0x000000ff;
546 px
|= pixel4
[2] & 0xffffff00;
563 px
= *ptr4
& 0xffffff00;
564 px
|= clearPixel
& 0xff;
570 px
= *ptr4
& 0xffff0000;
575 px
= *ptr4
& 0xff000000;
586 /* only clear subrect of color buffer */
588 /* same value for all three components (gray) */
590 for (j
=0;j
<height
;j
++) {
591 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
592 MEMSET(ptr3
, r
, 3 * width
);
596 /* non-gray clear color */
598 for (j
= 0; j
< height
; j
++) {
599 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
600 for (i
= 0; i
< width
; i
++) {
607 #if 0 /* this code might not always (seems ptr3 always == ptr4) */
610 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
611 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
612 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
613 for (j
=0;j
<height
;j
++) {
614 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
615 register GLuint
*ptr4
= (GLuint
*)ptr3
;
616 register GLuint
*p
, px
;
618 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
622 px
= *ptr4
& 0x00ffffff;
623 px
|= pixel4
[0] & 0xff000000;
625 px
= *ptr4
& 0xffff0000;
626 px
|= pixel4
[2] & 0x0000ffff;
631 px
= *ptr4
& 0x0000fffff;
632 px
|= pixel4
[1] & 0xffff0000;
634 px
= *ptr4
& 0xffffff00;
635 px
|= pixel4
[2] & 0x000000ff;
640 px
= *ptr4
& 0x000000ff;
641 px
|= pixel4
[2] & 0xffffff00;
658 px
= *ptr4
& 0xffffff00;
665 px
= *ptr4
& 0xffff0000;
670 px
= *ptr4
& 0xff000000;
671 px
|= pixel4
[0] & 0xffffff;
685 clear_32bit_ximage( GLcontext
*ctx
, GLboolean all
,
686 GLint x
, GLint y
, GLint width
, GLint height
)
688 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
689 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
690 if (xmesa
->swapbytes
) {
691 pixel
= ((pixel
>> 24) & 0x000000ff)
692 | ((pixel
>> 8) & 0x0000ff00)
693 | ((pixel
<< 8) & 0x00ff0000)
694 | ((pixel
<< 24) & 0xff000000);
697 register GLint n
= xmesa
->xm_buffer
->width
* xmesa
->xm_buffer
->height
;
698 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_buffer
->backimage
->data
;
700 MEMSET( ptr4
, pixel
, 4*n
);
711 for (j
=0;j
<height
;j
++) {
712 register GLuint
*ptr4
= PIXELADDR4( xmesa
->xm_buffer
, x
, y
+j
);
713 for (i
=0;i
<width
;i
++) {
722 clear_nbit_ximage( GLcontext
*ctx
, GLboolean all
,
723 GLint x
, GLint y
, GLint width
, GLint height
)
725 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
726 XMesaImage
*img
= xmesa
->xm_buffer
->backimage
;
729 width
= xmesa
->xm_buffer
->width
;
730 height
= xmesa
->xm_buffer
->height
;
731 for (j
=0;j
<height
;j
++) {
732 for (i
=0;i
<width
;i
++) {
733 XMesaPutPixel( img
, i
, j
, xmesa
->clearpixel
);
738 /* TODO: optimize this */
740 y
= FLIP(xmesa
->xm_buffer
, y
);
741 for (j
=0;j
<height
;j
++) {
742 for (i
=0;i
<width
;i
++) {
743 XMesaPutPixel( img
, x
+i
, y
-j
, xmesa
->clearpixel
);
752 clear_buffers( GLcontext
*ctx
, GLbitfield mask
,
753 GLboolean all
, GLint x
, GLint y
, GLint width
, GLint height
)
755 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
756 const GLuint
*colorMask
= (GLuint
*) &ctx
->Color
.ColorMask
;
758 if ((mask
& (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
)) &&
759 xmesa
->xm_buffer
->mesa_buffer
.UseSoftwareAlphaBuffers
&&
760 ctx
->Color
.ColorMask
[ACOMP
]) {
761 _mesa_clear_alpha_buffers(ctx
);
764 /* we can't handle color or index masking */
765 if (*colorMask
== 0xffffffff && ctx
->Color
.IndexMask
== 0xffffffff) {
766 if (mask
& DD_FRONT_LEFT_BIT
) {
767 ASSERT(xmesa
->xm_buffer
->front_clear_func
);
768 (*xmesa
->xm_buffer
->front_clear_func
)( ctx
, all
, x
, y
, width
, height
);
769 mask
&= ~DD_FRONT_LEFT_BIT
;
771 if (mask
& DD_BACK_LEFT_BIT
) {
772 ASSERT(xmesa
->xm_buffer
->back_clear_func
);
773 (*xmesa
->xm_buffer
->back_clear_func
)( ctx
, all
, x
, y
, width
, height
);
774 mask
&= ~DD_BACK_LEFT_BIT
;
779 _swrast_Clear( ctx
, mask
, all
, x
, y
, width
, height
);
784 resize_buffers( GLcontext
*ctx
)
786 _swrast_alloc_buffers( ctx
);
791 * This function implements glDrawPixels() with an XPutImage call when
792 * drawing to the front buffer (X Window drawable).
793 * The image format must be GL_BGRA to match the PF_8R8G8B pixel format.
794 * XXX top/bottom edge clipping is broken!
797 drawpixels_8R8G8B( GLcontext
*ctx
,
798 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
799 GLenum format
, GLenum type
,
800 const struct gl_pixelstore_attrib
*unpack
,
801 const GLvoid
*pixels
)
803 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
804 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
805 XMesaDrawable buffer
= xmesa
->xm_buffer
->buffer
;
806 XMesaGC gc
= xmesa
->xm_buffer
->gc
;
811 /* XXX also check for pixel scale/bias/lookup/zooming! */
812 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
) {
817 int srcX
= unpack
->SkipPixels
;
818 int srcY
= unpack
->SkipRows
;
819 if (_mesa_clip_pixelrect(ctx
, &dstX
, &dstY
, &w
, &h
, &srcX
, &srcY
)) {
821 MEMSET(&ximage
, 0, sizeof(XMesaImage
));
822 ximage
.width
= width
;
823 ximage
.height
= height
;
824 ximage
.format
= ZPixmap
;
825 ximage
.data
= (char *) pixels
+ (height
- 1) * width
* 4;
826 ximage
.byte_order
= LSBFirst
;
827 ximage
.bitmap_unit
= 32;
828 ximage
.bitmap_bit_order
= LSBFirst
;
829 ximage
.bitmap_pad
= 32;
831 ximage
.bytes_per_line
= -width
* 4;
832 ximage
.bits_per_pixel
= 32;
833 ximage
.red_mask
= 0xff0000;
834 ximage
.green_mask
= 0x00ff00;
835 ximage
.blue_mask
= 0x0000ff;
836 dstY
= FLIP(xmesa
->xm_buffer
,dstY
) - height
+ 1;
837 XPutImage(dpy
, buffer
, gc
, &ximage
, srcX
, srcY
, dstX
, dstY
, w
, h
);
847 static const GLubyte
*
848 get_string( GLcontext
*ctx
, GLenum name
)
854 return (const GLubyte
*) "Mesa GLX Indirect";
856 return (const GLubyte
*) "Mesa X11";
860 return (const GLubyte
*) "Mesa project: www.mesa3d.org";
871 enable( GLcontext
*ctx
, GLenum pname
, GLboolean state
)
873 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
878 xmesa
->pixelformat
= xmesa
->xm_visual
->dithered_pf
;
880 xmesa
->pixelformat
= xmesa
->xm_visual
->undithered_pf
;
883 ; /* silence compiler warning */
888 void xmesa_update_state( GLcontext
*ctx
, GLuint new_state
)
890 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
892 /* Propogate statechange information to swrast and swrast_setup
893 * modules. The X11 driver has no internal GL-dependent state.
895 _swrast_InvalidateState( ctx
, new_state
);
896 _ac_InvalidateState( ctx
, new_state
);
897 _tnl_InvalidateState( ctx
, new_state
);
898 _swsetup_InvalidateState( ctx
, new_state
);
901 /* setup pointers to front and back buffer clear functions */
902 xmesa
->xm_buffer
->front_clear_func
= clear_front_pixmap
;
903 if (xmesa
->xm_buffer
->backpixmap
!= XIMAGE
) {
904 xmesa
->xm_buffer
->back_clear_func
= clear_back_pixmap
;
906 else if (sizeof(GLushort
)!=2 || sizeof(GLuint
)!=4) {
907 xmesa
->xm_buffer
->back_clear_func
= clear_nbit_ximage
;
909 else switch (xmesa
->xm_visual
->BitsPerPixel
) {
911 if (xmesa
->xm_visual
->hpcr_clear_flag
) {
912 xmesa
->xm_buffer
->back_clear_func
= clear_HPCR_ximage
;
915 xmesa
->xm_buffer
->back_clear_func
= clear_8bit_ximage
;
919 xmesa
->xm_buffer
->back_clear_func
= clear_16bit_ximage
;
922 xmesa
->xm_buffer
->back_clear_func
= clear_24bit_ximage
;
925 xmesa
->xm_buffer
->back_clear_func
= clear_32bit_ximage
;
928 xmesa
->xm_buffer
->back_clear_func
= clear_nbit_ximage
;
932 xmesa_update_span_funcs(ctx
);
937 /* Setup pointers and other driver state that is constant for the life
940 void xmesa_init_pointers( GLcontext
*ctx
)
944 ctx
->Driver
.GetString
= get_string
;
945 ctx
->Driver
.GetBufferSize
= get_buffer_size
;
946 ctx
->Driver
.Flush
= flush
;
947 ctx
->Driver
.Finish
= finish
;
949 /* Software rasterizer pixel paths:
951 ctx
->Driver
.Accum
= _swrast_Accum
;
952 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
953 ctx
->Driver
.Clear
= clear_buffers
;
954 ctx
->Driver
.ResizeBuffersMESA
= resize_buffers
;
955 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
956 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
957 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;
959 /* Software texture functions:
961 ctx
->Driver
.ChooseTextureFormat
= _mesa_choose_tex_format
;
962 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
963 ctx
->Driver
.TexImage2D
= _mesa_store_teximage2d
;
964 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
965 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
966 ctx
->Driver
.TexSubImage2D
= _mesa_store_texsubimage2d
;
967 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
968 ctx
->Driver
.TestProxyTexImage
= _mesa_test_proxy_teximage
;
970 ctx
->Driver
.CopyTexImage1D
= _swrast_copy_teximage1d
;
971 ctx
->Driver
.CopyTexImage2D
= _swrast_copy_teximage2d
;
972 ctx
->Driver
.CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
973 ctx
->Driver
.CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
974 ctx
->Driver
.CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
976 ctx
->Driver
.BaseCompressedTexFormat
= _mesa_base_compressed_texformat
;
977 ctx
->Driver
.CompressedTextureSize
= _mesa_compressed_texture_size
;
978 ctx
->Driver
.GetCompressedTexImage
= _mesa_get_compressed_teximage
;
980 /* Swrast hooks for imaging extensions:
982 ctx
->Driver
.CopyColorTable
= _swrast_CopyColorTable
;
983 ctx
->Driver
.CopyColorSubTable
= _swrast_CopyColorSubTable
;
984 ctx
->Driver
.CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
985 ctx
->Driver
.CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
988 /* Statechange callbacks:
990 ctx
->Driver
.SetDrawBuffer
= set_draw_buffer
;
991 ctx
->Driver
.ClearIndex
= clear_index
;
992 ctx
->Driver
.ClearColor
= clear_color
;
993 ctx
->Driver
.IndexMask
= index_mask
;
994 ctx
->Driver
.ColorMask
= color_mask
;
995 ctx
->Driver
.Enable
= enable
;
998 /* Initialize the TNL driver interface:
1000 tnl
= TNL_CONTEXT(ctx
);
1001 tnl
->Driver
.RunPipeline
= _tnl_run_pipeline
;
1003 /* Install swsetup for tnl->Driver.Render.*:
1005 _swsetup_Wakeup(ctx
);
1007 (void) DitherValues
; /* silenced unused var warning */
1014 #define XMESA_NEW_POINT (_NEW_POINT | \
1016 _SWRAST_NEW_RASTERMASK)
1018 #define XMESA_NEW_LINE (_NEW_LINE | \
1023 _SWRAST_NEW_RASTERMASK)
1025 #define XMESA_NEW_TRIANGLE (_NEW_POLYGON | \
1030 _SWRAST_NEW_RASTERMASK)
1033 /* Extend the software rasterizer with our line/point/triangle
1036 void xmesa_register_swrast_functions( GLcontext
*ctx
)
1038 SWcontext
*swrast
= SWRAST_CONTEXT( ctx
);
1040 swrast
->choose_point
= xmesa_choose_point
;
1041 swrast
->choose_line
= xmesa_choose_line
;
1042 swrast
->choose_triangle
= xmesa_choose_triangle
;
1044 swrast
->invalidate_point
|= XMESA_NEW_POINT
;
1045 swrast
->invalidate_line
|= XMESA_NEW_LINE
;
1046 swrast
->invalidate_triangle
|= XMESA_NEW_TRIANGLE
;