1 /* $Id: xm_dd.c,v 1.46 2003/04/01 16:41:58 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2003 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"
33 #include "extensions.h"
40 #include "texformat.h"
42 #include "array_cache/acache.h"
43 #include "swrast/s_context.h"
44 #include "swrast/swrast.h"
45 #include "swrast/s_alphabuf.h"
46 #include "swrast_setup/swrast_setup.h"
48 #include "tnl/t_context.h"
49 #include "tnl/t_pipeline.h"
53 * Return the size (width, height) of the X window for the given GLframebuffer.
54 * Output: width - width of buffer in pixels.
55 * height - height of buffer in pixels.
58 get_buffer_size( GLframebuffer
*buffer
, GLuint
*width
, GLuint
*height
)
60 /* We can do this cast because the first field in the XMesaBuffer
61 * struct is a GLframebuffer struct. If this weren't true, we'd
62 * need a pointer from the GLframebuffer to the XMesaBuffer.
64 const XMesaBuffer xmBuffer
= (XMesaBuffer
) buffer
;
65 unsigned int winwidth
, winheight
;
67 /* XFree86 GLX renderer */
68 if (xmBuffer
->frontbuffer
->width
> MAX_WIDTH
||
69 xmBuffer
->frontbuffer
->height
> MAX_HEIGHT
) {
70 winwidth
= buffer
->Width
;
71 winheight
= buffer
->Height
;
73 winwidth
= xmBuffer
->frontbuffer
->width
;
74 winheight
= xmBuffer
->frontbuffer
->height
;
81 _glthread_LOCK_MUTEX(_xmesa_lock
);
82 XSync(xmBuffer
->xm_visual
->display
, 0); /* added for Chromium */
83 XGetGeometry( xmBuffer
->xm_visual
->display
, xmBuffer
->frontbuffer
, &root
,
84 &winx
, &winy
, &winwidth
, &winheight
, &bw
, &d
);
85 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
88 (void)kernel8
; /* Muffle compiler */
96 finish( GLcontext
*ctx
)
101 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
103 _glthread_LOCK_MUTEX(_xmesa_lock
);
104 XSync( xmesa
->display
, False
);
105 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
112 flush( GLcontext
*ctx
)
117 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
119 _glthread_LOCK_MUTEX(_xmesa_lock
);
120 XFlush( xmesa
->display
);
121 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
129 * This chooses the color buffer for reading and writing spans, points,
130 * lines, and triangles.
133 set_buffer( GLcontext
*ctx
, GLframebuffer
*buffer
, GLuint bufferBit
)
135 /* We can make this cast since the XMesaBuffer wraps GLframebuffer.
136 * GLframebuffer is the first member in a XMesaBuffer struct.
138 XMesaBuffer target
= (XMesaBuffer
) buffer
;
139 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
141 /* This assignment tells the span/point/line/triangle functions
142 * which XMesaBuffer to use.
144 xmesa
->xm_buffer
= target
;
147 * Now determine front vs back color buffer.
149 if (bufferBit
== FRONT_LEFT_BIT
) {
150 target
->buffer
= target
->frontbuffer
;
152 else if (bufferBit
== BACK_LEFT_BIT
) {
153 ASSERT(target
->db_state
);
154 if (target
->backpixmap
) {
155 /* back buffer is a pixmape */
156 target
->buffer
= target
->backpixmap
; /* incompatible types? */
158 else if (target
->backimage
) {
159 /* back buffer is an XImage */
160 target
->buffer
= None
;
163 /* No back buffer!!!! Must be out of memory, use front buffer */
164 target
->buffer
= target
->frontbuffer
;
168 _mesa_problem(ctx
, "invalid buffer 0x%x in set_buffer() in xm_dd.c");
171 xmesa_update_span_funcs(ctx
);
177 clear_index( GLcontext
*ctx
, GLuint index
)
179 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
180 xmesa
->clearpixel
= (unsigned long) index
;
181 XMesaSetForeground( xmesa
->display
, xmesa
->xm_draw_buffer
->cleargc
,
182 (unsigned long) index
);
187 clear_color( GLcontext
*ctx
, const GLfloat color
[4] )
189 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
190 CLAMPED_FLOAT_TO_UBYTE(xmesa
->clearcolor
[0], color
[0]);
191 CLAMPED_FLOAT_TO_UBYTE(xmesa
->clearcolor
[1], color
[1]);
192 CLAMPED_FLOAT_TO_UBYTE(xmesa
->clearcolor
[2], color
[2]);
193 CLAMPED_FLOAT_TO_UBYTE(xmesa
->clearcolor
[3], color
[3]);
194 xmesa
->clearpixel
= xmesa_color_to_pixel( xmesa
,
195 xmesa
->clearcolor
[0],
196 xmesa
->clearcolor
[1],
197 xmesa
->clearcolor
[2],
198 xmesa
->clearcolor
[3],
199 xmesa
->xm_visual
->undithered_pf
);
200 _glthread_LOCK_MUTEX(_xmesa_lock
);
201 XMesaSetForeground( xmesa
->display
, xmesa
->xm_draw_buffer
->cleargc
,
203 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
208 /* Set index mask ala glIndexMask */
210 index_mask( GLcontext
*ctx
, GLuint mask
)
212 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
213 if (xmesa
->xm_draw_buffer
->buffer
!= XIMAGE
) {
215 if (mask
==0xffffffff) {
216 m
= ((unsigned long)~0L);
219 m
= (unsigned long) mask
;
221 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_draw_buffer
->cleargc
, m
);
222 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_draw_buffer
->gc
, m
);
227 /* Implements glColorMask() */
229 color_mask(GLcontext
*ctx
,
230 GLboolean rmask
, GLboolean gmask
, GLboolean bmask
, GLboolean amask
)
232 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
233 int xclass
= GET_VISUAL_CLASS(xmesa
->xm_visual
);
236 if (xclass
== TrueColor
|| xclass
== DirectColor
) {
238 if (rmask
&& gmask
&& bmask
) {
239 m
= ((unsigned long)~0L);
243 if (rmask
) m
|= GET_REDMASK(xmesa
->xm_visual
);
244 if (gmask
) m
|= GET_GREENMASK(xmesa
->xm_visual
);
245 if (bmask
) m
|= GET_BLUEMASK(xmesa
->xm_visual
);
247 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_draw_buffer
->cleargc
, m
);
248 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_draw_buffer
->gc
, m
);
254 /**********************************************************************/
255 /*** glClear implementations ***/
256 /**********************************************************************/
260 clear_front_pixmap( GLcontext
*ctx
, GLboolean all
,
261 GLint x
, GLint y
, GLint width
, GLint height
)
263 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
265 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_draw_buffer
->frontbuffer
,
266 xmesa
->xm_draw_buffer
->cleargc
,
268 xmesa
->xm_draw_buffer
->width
+1,
269 xmesa
->xm_draw_buffer
->height
+1 );
272 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_draw_buffer
->frontbuffer
,
273 xmesa
->xm_draw_buffer
->cleargc
,
274 x
, xmesa
->xm_draw_buffer
->height
- y
- height
,
281 clear_back_pixmap( GLcontext
*ctx
, GLboolean all
,
282 GLint x
, GLint y
, GLint width
, GLint height
)
284 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
286 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_draw_buffer
->backpixmap
,
287 xmesa
->xm_draw_buffer
->cleargc
,
289 xmesa
->xm_draw_buffer
->width
+1,
290 xmesa
->xm_draw_buffer
->height
+1 );
293 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_draw_buffer
->backpixmap
,
294 xmesa
->xm_draw_buffer
->cleargc
,
295 x
, xmesa
->xm_draw_buffer
->height
- y
- height
,
302 clear_8bit_ximage( GLcontext
*ctx
, GLboolean all
,
303 GLint x
, GLint y
, GLint width
, GLint height
)
305 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
307 size_t n
= xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
308 * xmesa
->xm_draw_buffer
->backimage
->height
;
309 MEMSET( xmesa
->xm_draw_buffer
->backimage
->data
, xmesa
->clearpixel
, n
);
313 for (i
=0;i
<height
;i
++) {
314 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_draw_buffer
, x
, y
+i
);
315 MEMSET( ptr
, xmesa
->clearpixel
, width
);
322 clear_HPCR_ximage( GLcontext
*ctx
, GLboolean all
,
323 GLint x
, GLint y
, GLint width
, GLint height
)
325 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
327 GLint i
, c16
= (xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
>>4)<<4;
328 GLubyte
*ptr
= (GLubyte
*)xmesa
->xm_draw_buffer
->backimage
->data
;
329 for (i
=0; i
<xmesa
->xm_draw_buffer
->backimage
->height
; i
++) {
331 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
335 for (j
=0; j
<c16
; j
+=16) {
354 for (; j
<xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
; j
++) {
362 for (i
=y
; i
<y
+height
; i
++) {
363 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_draw_buffer
, x
, i
);
365 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
369 for (j
=x
; j
<x
+width
; j
++) {
379 clear_16bit_ximage( GLcontext
*ctx
, GLboolean all
,
380 GLint x
, GLint y
, GLint width
, GLint height
)
382 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
383 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
384 if (xmesa
->swapbytes
) {
385 pixel
= ((pixel
>> 8) & 0x00ff) | ((pixel
<< 8) & 0xff00);
389 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_draw_buffer
->backimage
->data
;
390 if ((pixel
& 0xff) == ((pixel
>> 8) & 0xff)) {
391 /* low and high bytes are equal so use memset() */
392 n
= xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
393 * xmesa
->xm_draw_buffer
->height
;
394 MEMSET( ptr4
, pixel
& 0xff, n
);
397 pixel
= pixel
| (pixel
<<16);
398 n
= xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
399 * xmesa
->xm_draw_buffer
->height
/ 4;
405 if ((xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
*
406 xmesa
->xm_draw_buffer
->height
) & 0x2)
407 *(GLushort
*)ptr4
= pixel
& 0xffff;
412 for (j
=0;j
<height
;j
++) {
413 register GLushort
*ptr2
= PIXELADDR2( xmesa
->xm_draw_buffer
, x
, y
+j
);
414 for (i
=0;i
<width
;i
++) {
422 /* Optimized code provided by Nozomi Ytow <noz@xfree86.org> */
424 clear_24bit_ximage( GLcontext
*ctx
, GLboolean all
,
425 GLint x
, GLint y
, GLint width
, GLint height
)
427 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
428 const GLubyte r
= xmesa
->clearcolor
[0];
429 const GLubyte g
= xmesa
->clearcolor
[1];
430 const GLubyte b
= xmesa
->clearcolor
[2];
431 register GLuint clearPixel
;
432 if (xmesa
->swapbytes
) {
433 clearPixel
= (b
<< 16) | (g
<< 8) | r
;
436 clearPixel
= (r
<< 16) | (g
<< 8) | b
;
441 /* same value for all three components (gray) */
442 const GLint w3
= xmesa
->xm_draw_buffer
->width
* 3;
443 const GLint h
= xmesa
->xm_draw_buffer
->height
;
445 for (i
= 0; i
< h
; i
++) {
446 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_draw_buffer
, 0, i
);
452 const GLint w
= xmesa
->xm_draw_buffer
->width
;
453 const GLint h
= xmesa
->xm_draw_buffer
->height
;
455 for (i
= 0; i
< h
; i
++) {
456 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_draw_buffer
, 0, i
);
457 for (j
= 0; j
< w
; j
++) {
464 #if 0 /* this code doesn't work for all window widths */
465 register GLuint
*ptr4
= (GLuint
*) ptr3
;
468 register GLuint
*p
= pixel4
;
469 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
470 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
471 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
472 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
476 px
= *ptr4
& 0x00ffffff;
477 px
|= pixel4
[0] & 0xff000000;
479 px
= *ptr4
& 0xffff0000;
480 px
|= pixel4
[2] & 0x0000ffff;
485 px
= *ptr4
& 0x0000fffff;
486 px
|= pixel4
[1] & 0xffff0000;
488 px
= *ptr4
& 0xffffff00;
489 px
|= pixel4
[2] & 0x000000ff;
494 px
= *ptr4
& 0x000000ff;
495 px
|= pixel4
[2] & 0xffffff00;
512 px
= *ptr4
& 0xffffff00;
513 px
|= clearPixel
& 0xff;
519 px
= *ptr4
& 0xffff0000;
524 px
= *ptr4
& 0xff000000;
535 /* only clear subrect of color buffer */
537 /* same value for all three components (gray) */
539 for (j
=0;j
<height
;j
++) {
540 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_draw_buffer
, x
, y
+j
);
541 MEMSET(ptr3
, r
, 3 * width
);
545 /* non-gray clear color */
547 for (j
= 0; j
< height
; j
++) {
548 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_draw_buffer
, x
, y
+j
);
549 for (i
= 0; i
< width
; i
++) {
556 #if 0 /* this code might not always (seems ptr3 always == ptr4) */
559 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
560 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
561 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
562 for (j
=0;j
<height
;j
++) {
563 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_draw_buffer
, x
, y
+j
);
564 register GLuint
*ptr4
= (GLuint
*)ptr3
;
565 register GLuint
*p
, px
;
567 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
571 px
= *ptr4
& 0x00ffffff;
572 px
|= pixel4
[0] & 0xff000000;
574 px
= *ptr4
& 0xffff0000;
575 px
|= pixel4
[2] & 0x0000ffff;
580 px
= *ptr4
& 0x0000fffff;
581 px
|= pixel4
[1] & 0xffff0000;
583 px
= *ptr4
& 0xffffff00;
584 px
|= pixel4
[2] & 0x000000ff;
589 px
= *ptr4
& 0x000000ff;
590 px
|= pixel4
[2] & 0xffffff00;
607 px
= *ptr4
& 0xffffff00;
614 px
= *ptr4
& 0xffff0000;
619 px
= *ptr4
& 0xff000000;
620 px
|= pixel4
[0] & 0xffffff;
634 clear_32bit_ximage( GLcontext
*ctx
, GLboolean all
,
635 GLint x
, GLint y
, GLint width
, GLint height
)
637 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
638 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
639 if (xmesa
->swapbytes
) {
640 pixel
= ((pixel
>> 24) & 0x000000ff)
641 | ((pixel
>> 8) & 0x0000ff00)
642 | ((pixel
<< 8) & 0x00ff0000)
643 | ((pixel
<< 24) & 0xff000000);
646 register GLint n
= xmesa
->xm_draw_buffer
->width
* xmesa
->xm_draw_buffer
->height
;
647 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_draw_buffer
->backimage
->data
;
649 MEMSET( ptr4
, pixel
, 4*n
);
660 for (j
=0;j
<height
;j
++) {
661 register GLuint
*ptr4
= PIXELADDR4( xmesa
->xm_draw_buffer
, x
, y
+j
);
662 for (i
=0;i
<width
;i
++) {
671 clear_nbit_ximage( GLcontext
*ctx
, GLboolean all
,
672 GLint x
, GLint y
, GLint width
, GLint height
)
674 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
675 XMesaImage
*img
= xmesa
->xm_draw_buffer
->backimage
;
678 width
= xmesa
->xm_draw_buffer
->width
;
679 height
= xmesa
->xm_draw_buffer
->height
;
680 for (j
=0;j
<height
;j
++) {
681 for (i
=0;i
<width
;i
++) {
682 XMesaPutPixel( img
, i
, j
, xmesa
->clearpixel
);
687 /* TODO: optimize this */
689 y
= FLIP(xmesa
->xm_draw_buffer
, y
);
690 for (j
=0;j
<height
;j
++) {
691 for (i
=0;i
<width
;i
++) {
692 XMesaPutPixel( img
, x
+i
, y
-j
, xmesa
->clearpixel
);
701 clear_buffers( GLcontext
*ctx
, GLbitfield mask
,
702 GLboolean all
, GLint x
, GLint y
, GLint width
, GLint height
)
704 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
705 const GLuint
*colorMask
= (GLuint
*) &ctx
->Color
.ColorMask
;
707 if ((mask
& (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
)) &&
708 xmesa
->xm_draw_buffer
->mesa_buffer
.UseSoftwareAlphaBuffers
&&
709 ctx
->Color
.ColorMask
[ACOMP
]) {
710 _swrast_clear_alpha_buffers(ctx
);
713 /* we can't handle color or index masking */
714 if (*colorMask
== 0xffffffff && ctx
->Color
.IndexMask
== 0xffffffff) {
715 if (mask
& DD_FRONT_LEFT_BIT
) {
716 ASSERT(xmesa
->xm_draw_buffer
->front_clear_func
);
717 (*xmesa
->xm_draw_buffer
->front_clear_func
)( ctx
, all
, x
, y
, width
, height
);
718 mask
&= ~DD_FRONT_LEFT_BIT
;
720 if (mask
& DD_BACK_LEFT_BIT
) {
721 ASSERT(xmesa
->xm_draw_buffer
->back_clear_func
);
722 (*xmesa
->xm_draw_buffer
->back_clear_func
)( ctx
, all
, x
, y
, width
, height
);
723 mask
&= ~DD_BACK_LEFT_BIT
;
728 _swrast_Clear( ctx
, mask
, all
, x
, y
, width
, height
);
733 * When we detect that the user has resized the window this function will
734 * get called. Here we'll reallocate the back buffer, depth buffer,
735 * stencil buffer etc. to match the new window size.
738 xmesa_resize_buffers( GLframebuffer
*buffer
)
740 int height
= (int) buffer
->Height
;
741 /* We can do this cast because the first field in the XMesaBuffer
742 * struct is a GLframebuffer struct. If this weren't true, we'd
743 * need a pointer from the GLframebuffer to the XMesaBuffer.
745 XMesaBuffer xmBuffer
= (XMesaBuffer
) buffer
;
747 xmBuffer
->width
= buffer
->Width
;
748 xmBuffer
->height
= buffer
->Height
;
749 xmesa_alloc_back_buffer( xmBuffer
);
751 /* Needed by FLIP macro */
752 xmBuffer
->bottom
= height
- 1;
754 if (xmBuffer
->backimage
) {
755 /* Needed by PIXELADDR1 macro */
756 xmBuffer
->ximage_width1
= xmBuffer
->backimage
->bytes_per_line
;
757 xmBuffer
->ximage_origin1
= (GLubyte
*) xmBuffer
->backimage
->data
758 + xmBuffer
->ximage_width1
* (height
-1);
760 /* Needed by PIXELADDR2 macro */
761 xmBuffer
->ximage_width2
= xmBuffer
->backimage
->bytes_per_line
/ 2;
762 xmBuffer
->ximage_origin2
= (GLushort
*) xmBuffer
->backimage
->data
763 + xmBuffer
->ximage_width2
* (height
-1);
765 /* Needed by PIXELADDR3 macro */
766 xmBuffer
->ximage_width3
= xmBuffer
->backimage
->bytes_per_line
;
767 xmBuffer
->ximage_origin3
= (GLubyte
*) xmBuffer
->backimage
->data
768 + xmBuffer
->ximage_width3
* (height
-1);
770 /* Needed by PIXELADDR4 macro */
771 xmBuffer
->ximage_width4
= xmBuffer
->backimage
->width
;
772 xmBuffer
->ximage_origin4
= (GLuint
*) xmBuffer
->backimage
->data
773 + xmBuffer
->ximage_width4
* (height
-1);
776 _swrast_alloc_buffers( buffer
);
781 * This function implements glDrawPixels() with an XPutImage call when
782 * drawing to the front buffer (X Window drawable).
783 * The image format must be GL_BGRA to match the PF_8R8G8B pixel format.
784 * XXX top/bottom edge clipping is broken!
787 drawpixels_8R8G8B( GLcontext
*ctx
,
788 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
789 GLenum format
, GLenum type
,
790 const struct gl_pixelstore_attrib
*unpack
,
791 const GLvoid
*pixels
)
793 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
794 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
795 XMesaDrawable buffer
= xmesa
->xm_draw_buffer
->buffer
;
796 XMesaGC gc
= xmesa
->xm_draw_buffer
->gc
;
801 /* XXX also check for pixel scale/bias/lookup/zooming! */
802 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
) {
807 int srcX
= unpack
->SkipPixels
;
808 int srcY
= unpack
->SkipRows
;
809 if (_mesa_clip_pixelrect(ctx
, &dstX
, &dstY
, &w
, &h
, &srcX
, &srcY
)) {
811 MEMSET(&ximage
, 0, sizeof(XMesaImage
));
812 ximage
.width
= width
;
813 ximage
.height
= height
;
814 ximage
.format
= ZPixmap
;
815 ximage
.data
= (char *) pixels
+ (height
- 1) * width
* 4;
816 ximage
.byte_order
= LSBFirst
;
817 ximage
.bitmap_unit
= 32;
818 ximage
.bitmap_bit_order
= LSBFirst
;
819 ximage
.bitmap_pad
= 32;
821 ximage
.bytes_per_line
= -width
* 4;
822 ximage
.bits_per_pixel
= 32;
823 ximage
.red_mask
= 0xff0000;
824 ximage
.green_mask
= 0x00ff00;
825 ximage
.blue_mask
= 0x0000ff;
826 dstY
= FLIP(xmesa
->xm_draw_buffer
,dstY
) - height
+ 1;
827 XPutImage(dpy
, buffer
, gc
, &ximage
, srcX
, srcY
, dstX
, dstY
, w
, h
);
837 static const GLubyte
*
838 get_string( GLcontext
*ctx
, GLenum name
)
844 return (const GLubyte
*) "Mesa GLX Indirect";
846 return (const GLubyte
*) "Mesa X11";
850 return (const GLubyte
*) "Mesa project: www.mesa3d.org";
861 enable( GLcontext
*ctx
, GLenum pname
, GLboolean state
)
863 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
868 xmesa
->pixelformat
= xmesa
->xm_visual
->dithered_pf
;
870 xmesa
->pixelformat
= xmesa
->xm_visual
->undithered_pf
;
873 ; /* silence compiler warning */
878 void xmesa_update_state( GLcontext
*ctx
, GLuint new_state
)
880 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
882 /* Propogate statechange information to swrast and swrast_setup
883 * modules. The X11 driver has no internal GL-dependent state.
885 _swrast_InvalidateState( ctx
, new_state
);
886 _ac_InvalidateState( ctx
, new_state
);
887 _tnl_InvalidateState( ctx
, new_state
);
888 _swsetup_InvalidateState( ctx
, new_state
);
891 /* setup pointers to front and back buffer clear functions */
892 xmesa
->xm_draw_buffer
->front_clear_func
= clear_front_pixmap
;
893 if (xmesa
->xm_draw_buffer
->backpixmap
!= XIMAGE
) {
894 xmesa
->xm_draw_buffer
->back_clear_func
= clear_back_pixmap
;
896 else if (sizeof(GLushort
)!=2 || sizeof(GLuint
)!=4) {
897 xmesa
->xm_draw_buffer
->back_clear_func
= clear_nbit_ximage
;
899 else switch (xmesa
->xm_visual
->BitsPerPixel
) {
901 if (xmesa
->xm_visual
->hpcr_clear_flag
) {
902 xmesa
->xm_draw_buffer
->back_clear_func
= clear_HPCR_ximage
;
905 xmesa
->xm_draw_buffer
->back_clear_func
= clear_8bit_ximage
;
909 xmesa
->xm_draw_buffer
->back_clear_func
= clear_16bit_ximage
;
912 xmesa
->xm_draw_buffer
->back_clear_func
= clear_24bit_ximage
;
915 xmesa
->xm_draw_buffer
->back_clear_func
= clear_32bit_ximage
;
918 xmesa
->xm_draw_buffer
->back_clear_func
= clear_nbit_ximage
;
922 xmesa_update_span_funcs(ctx
);
927 /* Setup pointers and other driver state that is constant for the life
930 void xmesa_init_pointers( GLcontext
*ctx
)
933 struct swrast_device_driver
*dd
= _swrast_GetDeviceDriverReference( ctx
);
935 ctx
->Driver
.GetString
= get_string
;
936 ctx
->Driver
.GetBufferSize
= get_buffer_size
;
937 ctx
->Driver
.Flush
= flush
;
938 ctx
->Driver
.Finish
= finish
;
940 /* Software rasterizer pixel paths:
942 ctx
->Driver
.Accum
= _swrast_Accum
;
943 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
944 ctx
->Driver
.Clear
= clear_buffers
;
945 ctx
->Driver
.ResizeBuffers
= xmesa_resize_buffers
;
946 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
947 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
948 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;
949 ctx
->Driver
.DrawBuffer
= _swrast_DrawBuffer
;
951 /* Software texture functions:
953 ctx
->Driver
.ChooseTextureFormat
= _mesa_choose_tex_format
;
954 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
955 ctx
->Driver
.TexImage2D
= _mesa_store_teximage2d
;
956 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
957 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
958 ctx
->Driver
.TexSubImage2D
= _mesa_store_texsubimage2d
;
959 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
960 ctx
->Driver
.TestProxyTexImage
= _mesa_test_proxy_teximage
;
962 ctx
->Driver
.CopyTexImage1D
= _swrast_copy_teximage1d
;
963 ctx
->Driver
.CopyTexImage2D
= _swrast_copy_teximage2d
;
964 ctx
->Driver
.CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
965 ctx
->Driver
.CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
966 ctx
->Driver
.CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
968 ctx
->Driver
.NewTextureObject
= _mesa_new_texture_object
;
969 ctx
->Driver
.DeleteTexture
= _mesa_delete_texture_object
;
971 ctx
->Driver
.CompressedTexImage1D
= _mesa_store_compressed_teximage1d
;
972 ctx
->Driver
.CompressedTexImage2D
= _mesa_store_compressed_teximage2d
;
973 ctx
->Driver
.CompressedTexImage3D
= _mesa_store_compressed_teximage3d
;
974 ctx
->Driver
.CompressedTexSubImage1D
= _mesa_store_compressed_texsubimage1d
;
975 ctx
->Driver
.CompressedTexSubImage2D
= _mesa_store_compressed_texsubimage2d
;
976 ctx
->Driver
.CompressedTexSubImage3D
= _mesa_store_compressed_texsubimage3d
;
978 /* Swrast hooks for imaging extensions:
980 ctx
->Driver
.CopyColorTable
= _swrast_CopyColorTable
;
981 ctx
->Driver
.CopyColorSubTable
= _swrast_CopyColorSubTable
;
982 ctx
->Driver
.CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
983 ctx
->Driver
.CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
986 /* Statechange callbacks:
988 ctx
->Driver
.ClearIndex
= clear_index
;
989 ctx
->Driver
.ClearColor
= clear_color
;
990 ctx
->Driver
.IndexMask
= index_mask
;
991 ctx
->Driver
.ColorMask
= color_mask
;
992 ctx
->Driver
.Enable
= enable
;
995 /* Initialize the TNL driver interface:
997 tnl
= TNL_CONTEXT(ctx
);
998 tnl
->Driver
.RunPipeline
= _tnl_run_pipeline
;
1000 dd
->SetBuffer
= set_buffer
;
1002 /* Install swsetup for tnl->Driver.Render.*:
1004 _swsetup_Wakeup(ctx
);
1006 (void) DitherValues
; /* silenced unused var warning */
1013 #define XMESA_NEW_POINT (_NEW_POINT | \
1015 _SWRAST_NEW_RASTERMASK)
1017 #define XMESA_NEW_LINE (_NEW_LINE | \
1022 _SWRAST_NEW_RASTERMASK)
1024 #define XMESA_NEW_TRIANGLE (_NEW_POLYGON | \
1029 _SWRAST_NEW_RASTERMASK)
1032 /* Extend the software rasterizer with our line/point/triangle
1035 void xmesa_register_swrast_functions( GLcontext
*ctx
)
1037 SWcontext
*swrast
= SWRAST_CONTEXT( ctx
);
1039 swrast
->choose_point
= xmesa_choose_point
;
1040 swrast
->choose_line
= xmesa_choose_line
;
1041 swrast
->choose_triangle
= xmesa_choose_triangle
;
1043 swrast
->invalidate_point
|= XMESA_NEW_POINT
;
1044 swrast
->invalidate_line
|= XMESA_NEW_LINE
;
1045 swrast
->invalidate_triangle
|= XMESA_NEW_TRIANGLE
;