1 /* $Id: xm_dd.c,v 1.30 2002/03/16 00:53:15 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
;
69 _glthread_LOCK_MUTEX(_xmesa_lock
);
70 XGetGeometry( xmBuffer
->xm_visual
->display
, xmBuffer
->frontbuffer
, &root
,
71 &winx
, &winy
, &winwidth
, &winheight
, &bw
, &d
);
72 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
74 /* XFree86 GLX renderer */
75 winwidth
= xmBuffer
->frontbuffer
->width
;
76 winheight
= xmBuffer
->frontbuffer
->height
;
79 (void)kernel8
; /* Muffle compiler */
87 finish( GLcontext
*ctx
)
92 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
94 _glthread_LOCK_MUTEX(_xmesa_lock
);
95 XSync( xmesa
->display
, False
);
96 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
103 flush( GLcontext
*ctx
)
108 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
110 _glthread_LOCK_MUTEX(_xmesa_lock
);
111 XFlush( xmesa
->display
);
112 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
121 set_draw_buffer( GLcontext
*ctx
, GLenum mode
)
123 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
124 if (mode
== GL_FRONT_LEFT
) {
125 /* write to front buffer */
126 xmesa
->xm_buffer
->buffer
= xmesa
->xm_buffer
->frontbuffer
;
127 xmesa_update_span_funcs(ctx
);
130 else if (mode
==GL_BACK_LEFT
&& xmesa
->xm_buffer
->db_state
) {
131 /* write to back buffer */
132 if (xmesa
->xm_buffer
->backpixmap
) {
133 xmesa
->xm_buffer
->buffer
=
134 (XMesaDrawable
)xmesa
->xm_buffer
->backpixmap
;
136 else if (xmesa
->xm_buffer
->backimage
) {
137 xmesa
->xm_buffer
->buffer
= None
;
140 /* just in case there wasn't enough memory for back buffer */
141 xmesa
->xm_buffer
->buffer
= xmesa
->xm_buffer
->frontbuffer
;
143 xmesa_update_span_funcs(ctx
);
153 xmesa_set_read_buffer( GLcontext
*ctx
, GLframebuffer
*buffer
, GLenum mode
)
156 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
158 if (buffer
== ctx
->DrawBuffer
) {
159 target
= xmesa
->xm_buffer
;
160 xmesa
->use_read_buffer
= GL_FALSE
;
163 ASSERT(buffer
== ctx
->ReadBuffer
);
164 target
= xmesa
->xm_read_buffer
;
165 xmesa
->use_read_buffer
= GL_TRUE
;
168 if (mode
== GL_FRONT_LEFT
) {
169 target
->buffer
= target
->frontbuffer
;
170 xmesa_update_span_funcs(ctx
);
172 else if (mode
==GL_BACK_LEFT
&& xmesa
->xm_read_buffer
->db_state
) {
173 if (target
->backpixmap
) {
174 target
->buffer
= (XMesaDrawable
)xmesa
->xm_buffer
->backpixmap
;
176 else if (target
->backimage
) {
177 target
->buffer
= None
;
180 /* just in case there wasn't enough memory for back buffer */
181 target
->buffer
= target
->frontbuffer
;
183 xmesa_update_span_funcs(ctx
);
186 _mesa_problem(ctx
, "invalid buffer in set_read_buffer() in xmesa2.c");
193 clear_index( GLcontext
*ctx
, GLuint index
)
195 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
196 xmesa
->clearpixel
= (unsigned long) index
;
197 XMesaSetForeground( xmesa
->display
, xmesa
->xm_buffer
->cleargc
,
198 (unsigned long) index
);
203 clear_color( GLcontext
*ctx
, const GLchan color
[4] )
205 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
206 xmesa
->clearcolor
[0] = color
[0];
207 xmesa
->clearcolor
[1] = color
[1];
208 xmesa
->clearcolor
[2] = color
[2];
209 xmesa
->clearcolor
[3] = color
[3];
210 xmesa
->clearpixel
= xmesa_color_to_pixel( xmesa
, color
[0], color
[1],
212 xmesa
->xm_visual
->undithered_pf
);
213 _glthread_LOCK_MUTEX(_xmesa_lock
);
214 XMesaSetForeground( xmesa
->display
, xmesa
->xm_buffer
->cleargc
,
216 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
221 /* Set index mask ala glIndexMask */
223 index_mask( GLcontext
*ctx
, GLuint mask
)
225 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
226 if (xmesa
->xm_buffer
->buffer
!= XIMAGE
) {
228 if (mask
==0xffffffff) {
229 m
= ((unsigned long)~0L);
232 m
= (unsigned long) mask
;
234 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_buffer
->gc
, m
);
235 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_buffer
->cleargc
, m
);
240 /* Implements glColorMask() */
242 color_mask(GLcontext
*ctx
,
243 GLboolean rmask
, GLboolean gmask
, GLboolean bmask
, GLboolean amask
)
245 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
246 int xclass
= GET_VISUAL_CLASS(xmesa
->xm_visual
);
249 if (xclass
== TrueColor
|| xclass
== DirectColor
) {
251 if (rmask
&& gmask
&& bmask
) {
252 m
= ((unsigned long)~0L);
256 if (rmask
) m
|= GET_REDMASK(xmesa
->xm_visual
);
257 if (gmask
) m
|= GET_GREENMASK(xmesa
->xm_visual
);
258 if (bmask
) m
|= GET_BLUEMASK(xmesa
->xm_visual
);
260 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_buffer
->gc
, m
);
261 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_buffer
->cleargc
, m
);
267 /**********************************************************************/
268 /*** glClear implementations ***/
269 /**********************************************************************/
273 clear_front_pixmap( GLcontext
*ctx
, GLboolean all
,
274 GLint x
, GLint y
, GLint width
, GLint height
)
276 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
278 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->frontbuffer
,
279 xmesa
->xm_buffer
->cleargc
,
281 xmesa
->xm_buffer
->width
+1,
282 xmesa
->xm_buffer
->height
+1 );
285 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->frontbuffer
,
286 xmesa
->xm_buffer
->cleargc
,
287 x
, xmesa
->xm_buffer
->height
- y
- height
,
294 clear_back_pixmap( GLcontext
*ctx
, GLboolean all
,
295 GLint x
, GLint y
, GLint width
, GLint height
)
297 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
299 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->backpixmap
,
300 xmesa
->xm_buffer
->cleargc
,
302 xmesa
->xm_buffer
->width
+1,
303 xmesa
->xm_buffer
->height
+1 );
306 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->backpixmap
,
307 xmesa
->xm_buffer
->cleargc
,
308 x
, xmesa
->xm_buffer
->height
- y
- height
,
315 clear_8bit_ximage( GLcontext
*ctx
, GLboolean all
,
316 GLint x
, GLint y
, GLint width
, GLint height
)
318 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
320 size_t n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
321 * xmesa
->xm_buffer
->backimage
->height
;
322 MEMSET( xmesa
->xm_buffer
->backimage
->data
, xmesa
->clearpixel
, n
);
326 for (i
=0;i
<height
;i
++) {
327 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_buffer
, x
, y
+i
);
328 MEMSET( ptr
, xmesa
->clearpixel
, width
);
335 clear_HPCR_ximage( GLcontext
*ctx
, GLboolean all
,
336 GLint x
, GLint y
, GLint width
, GLint height
)
338 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
340 GLint i
, c16
= (xmesa
->xm_buffer
->backimage
->bytes_per_line
>>4)<<4;
341 GLubyte
*ptr
= (GLubyte
*)xmesa
->xm_buffer
->backimage
->data
;
342 for (i
=0; i
<xmesa
->xm_buffer
->backimage
->height
; i
++) {
344 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
348 for (j
=0; j
<c16
; j
+=16) {
367 for (; j
<xmesa
->xm_buffer
->backimage
->bytes_per_line
; j
++) {
375 for (i
=y
; i
<y
+height
; i
++) {
376 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_buffer
, x
, i
);
378 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
382 for (j
=x
; j
<x
+width
; j
++) {
392 clear_16bit_ximage( GLcontext
*ctx
, GLboolean all
,
393 GLint x
, GLint y
, GLint width
, GLint height
)
395 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
396 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
397 if (xmesa
->swapbytes
) {
398 pixel
= ((pixel
>> 8) & 0x00ff) | ((pixel
<< 8) & 0xff00);
402 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_buffer
->backimage
->data
;
403 if ((pixel
& 0xff) == ((pixel
>> 8) & 0xff)) {
404 /* low and high bytes are equal so use memset() */
405 n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
406 * xmesa
->xm_buffer
->height
;
407 MEMSET( ptr4
, pixel
& 0xff, n
);
410 pixel
= pixel
| (pixel
<<16);
411 n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
412 * xmesa
->xm_buffer
->height
/ 4;
418 if ((xmesa
->xm_buffer
->backimage
->bytes_per_line
*
419 xmesa
->xm_buffer
->height
) & 0x2)
420 *(GLushort
*)ptr4
= pixel
& 0xffff;
425 for (j
=0;j
<height
;j
++) {
426 register GLushort
*ptr2
= PIXELADDR2( xmesa
->xm_buffer
, x
, y
+j
);
427 for (i
=0;i
<width
;i
++) {
435 /* Optimized code provided by Nozomi Ytow <noz@xfree86.org> */
437 clear_24bit_ximage( GLcontext
*ctx
, GLboolean all
,
438 GLint x
, GLint y
, GLint width
, GLint height
)
440 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
441 const GLubyte r
= xmesa
->clearcolor
[0];
442 const GLubyte g
= xmesa
->clearcolor
[1];
443 const GLubyte b
= xmesa
->clearcolor
[2];
444 register GLuint clearPixel
;
445 if (xmesa
->swapbytes
) {
446 clearPixel
= (b
<< 16) | (g
<< 8) | r
;
449 clearPixel
= (r
<< 16) | (g
<< 8) | b
;
454 /* same value for all three components (gray) */
455 const GLint w3
= xmesa
->xm_buffer
->width
* 3;
456 const GLint h
= xmesa
->xm_buffer
->height
;
458 for (i
= 0; i
< h
; i
++) {
459 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_buffer
, 0, i
);
465 const GLint w
= xmesa
->xm_buffer
->width
;
466 const GLint h
= xmesa
->xm_buffer
->height
;
468 for (i
= 0; i
< h
; i
++) {
469 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_buffer
, 0, i
);
470 for (j
= 0; j
< w
; j
++) {
477 #if 0 /* this code doesn't work for all window widths */
478 register GLuint
*ptr4
= (GLuint
*) ptr3
;
481 register GLuint
*p
= pixel4
;
482 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
483 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
484 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
485 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
489 px
= *ptr4
& 0x00ffffff;
490 px
|= pixel4
[0] & 0xff000000;
492 px
= *ptr4
& 0xffff0000;
493 px
|= pixel4
[2] & 0x0000ffff;
498 px
= *ptr4
& 0x0000fffff;
499 px
|= pixel4
[1] & 0xffff0000;
501 px
= *ptr4
& 0xffffff00;
502 px
|= pixel4
[2] & 0x000000ff;
507 px
= *ptr4
& 0x000000ff;
508 px
|= pixel4
[2] & 0xffffff00;
525 px
= *ptr4
& 0xffffff00;
526 px
|= clearPixel
& 0xff;
532 px
= *ptr4
& 0xffff0000;
537 px
= *ptr4
& 0xff000000;
548 /* only clear subrect of color buffer */
550 /* same value for all three components (gray) */
552 for (j
=0;j
<height
;j
++) {
553 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
554 MEMSET(ptr3
, r
, 3 * width
);
558 /* non-gray clear color */
560 for (j
= 0; j
< height
; j
++) {
561 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
562 for (i
= 0; i
< width
; i
++) {
569 #if 0 /* this code might not always (seems ptr3 always == ptr4) */
572 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
573 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
574 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
575 for (j
=0;j
<height
;j
++) {
576 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
577 register GLuint
*ptr4
= (GLuint
*)ptr3
;
578 register GLuint
*p
, px
;
580 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
584 px
= *ptr4
& 0x00ffffff;
585 px
|= pixel4
[0] & 0xff000000;
587 px
= *ptr4
& 0xffff0000;
588 px
|= pixel4
[2] & 0x0000ffff;
593 px
= *ptr4
& 0x0000fffff;
594 px
|= pixel4
[1] & 0xffff0000;
596 px
= *ptr4
& 0xffffff00;
597 px
|= pixel4
[2] & 0x000000ff;
602 px
= *ptr4
& 0x000000ff;
603 px
|= pixel4
[2] & 0xffffff00;
620 px
= *ptr4
& 0xffffff00;
627 px
= *ptr4
& 0xffff0000;
632 px
= *ptr4
& 0xff000000;
633 px
|= pixel4
[0] & 0xffffff;
647 clear_32bit_ximage( GLcontext
*ctx
, GLboolean all
,
648 GLint x
, GLint y
, GLint width
, GLint height
)
650 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
651 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
652 if (xmesa
->swapbytes
) {
653 pixel
= ((pixel
>> 24) & 0x000000ff)
654 | ((pixel
>> 8) & 0x0000ff00)
655 | ((pixel
<< 8) & 0x00ff0000)
656 | ((pixel
<< 24) & 0xff000000);
659 register GLint n
= xmesa
->xm_buffer
->width
* xmesa
->xm_buffer
->height
;
660 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_buffer
->backimage
->data
;
662 MEMSET( ptr4
, pixel
, 4*n
);
673 for (j
=0;j
<height
;j
++) {
674 register GLuint
*ptr4
= PIXELADDR4( xmesa
->xm_buffer
, x
, y
+j
);
675 for (i
=0;i
<width
;i
++) {
684 clear_nbit_ximage( GLcontext
*ctx
, GLboolean all
,
685 GLint x
, GLint y
, GLint width
, GLint height
)
687 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
688 XMesaImage
*img
= xmesa
->xm_buffer
->backimage
;
691 width
= xmesa
->xm_buffer
->width
;
692 height
= xmesa
->xm_buffer
->height
;
693 for (j
=0;j
<height
;j
++) {
694 for (i
=0;i
<width
;i
++) {
695 XMesaPutPixel( img
, i
, j
, xmesa
->clearpixel
);
700 /* TODO: optimize this */
702 y
= FLIP(xmesa
->xm_buffer
, y
);
703 for (j
=0;j
<height
;j
++) {
704 for (i
=0;i
<width
;i
++) {
705 XMesaPutPixel( img
, x
+i
, y
-j
, xmesa
->clearpixel
);
714 clear_buffers( GLcontext
*ctx
, GLbitfield mask
,
715 GLboolean all
, GLint x
, GLint y
, GLint width
, GLint height
)
717 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
718 const GLuint
*colorMask
= (GLuint
*) &ctx
->Color
.ColorMask
;
720 if ((mask
& (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
)) &&
721 xmesa
->xm_buffer
->mesa_buffer
.UseSoftwareAlphaBuffers
&&
722 ctx
->Color
.ColorMask
[ACOMP
]) {
723 _mesa_clear_alpha_buffers(ctx
);
726 /* we can't handle color or index masking */
727 if (*colorMask
== 0xffffffff && ctx
->Color
.IndexMask
== 0xffffffff) {
728 if (mask
& DD_FRONT_LEFT_BIT
) {
729 ASSERT(xmesa
->xm_buffer
->front_clear_func
);
730 (*xmesa
->xm_buffer
->front_clear_func
)( ctx
, all
, x
, y
, width
, height
);
731 mask
&= ~DD_FRONT_LEFT_BIT
;
733 if (mask
& DD_BACK_LEFT_BIT
) {
734 ASSERT(xmesa
->xm_buffer
->back_clear_func
);
735 (*xmesa
->xm_buffer
->back_clear_func
)( ctx
, all
, x
, y
, width
, height
);
736 mask
&= ~DD_BACK_LEFT_BIT
;
741 _swrast_Clear( ctx
, mask
, all
, x
, y
, width
, height
);
746 * When we detect that the user has resized the window this function will
747 * get called. Here we'll reallocate the back buffer, depth buffer,
748 * stencil buffer etc. to match the new window size.
751 xmesa_resize_buffers( GLframebuffer
*buffer
)
753 int height
= (int) buffer
->Height
;
754 /* We can do this cast because the first field in the XMesaBuffer
755 * struct is a GLframebuffer struct. If this weren't true, we'd
756 * need a pointer from the GLframebuffer to the XMesaBuffer.
758 XMesaBuffer xmBuffer
= (XMesaBuffer
) buffer
;
760 xmBuffer
->width
= buffer
->Width
;
761 xmBuffer
->height
= buffer
->Height
;
762 xmesa_alloc_back_buffer( xmBuffer
);
764 /* Needed by FLIP macro */
765 xmBuffer
->bottom
= height
- 1;
767 if (xmBuffer
->backimage
) {
768 /* Needed by PIXELADDR1 macro */
769 xmBuffer
->ximage_width1
= xmBuffer
->backimage
->bytes_per_line
;
770 xmBuffer
->ximage_origin1
= (GLubyte
*) xmBuffer
->backimage
->data
771 + xmBuffer
->ximage_width1
* (height
-1);
773 /* Needed by PIXELADDR2 macro */
774 xmBuffer
->ximage_width2
= xmBuffer
->backimage
->bytes_per_line
/ 2;
775 xmBuffer
->ximage_origin2
= (GLushort
*) xmBuffer
->backimage
->data
776 + xmBuffer
->ximage_width2
* (height
-1);
778 /* Needed by PIXELADDR3 macro */
779 xmBuffer
->ximage_width3
= xmBuffer
->backimage
->bytes_per_line
;
780 xmBuffer
->ximage_origin3
= (GLubyte
*) xmBuffer
->backimage
->data
781 + xmBuffer
->ximage_width3
* (height
-1);
783 /* Needed by PIXELADDR4 macro */
784 xmBuffer
->ximage_width4
= xmBuffer
->backimage
->width
;
785 xmBuffer
->ximage_origin4
= (GLuint
*) xmBuffer
->backimage
->data
786 + xmBuffer
->ximage_width4
* (height
-1);
789 _swrast_alloc_buffers( buffer
);
794 * This function implements glDrawPixels() with an XPutImage call when
795 * drawing to the front buffer (X Window drawable).
796 * The image format must be GL_BGRA to match the PF_8R8G8B pixel format.
797 * XXX top/bottom edge clipping is broken!
800 drawpixels_8R8G8B( GLcontext
*ctx
,
801 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
802 GLenum format
, GLenum type
,
803 const struct gl_pixelstore_attrib
*unpack
,
804 const GLvoid
*pixels
)
806 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
807 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
808 XMesaDrawable buffer
= xmesa
->xm_buffer
->buffer
;
809 XMesaGC gc
= xmesa
->xm_buffer
->gc
;
814 /* XXX also check for pixel scale/bias/lookup/zooming! */
815 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
) {
820 int srcX
= unpack
->SkipPixels
;
821 int srcY
= unpack
->SkipRows
;
822 if (_mesa_clip_pixelrect(ctx
, &dstX
, &dstY
, &w
, &h
, &srcX
, &srcY
)) {
824 MEMSET(&ximage
, 0, sizeof(XMesaImage
));
825 ximage
.width
= width
;
826 ximage
.height
= height
;
827 ximage
.format
= ZPixmap
;
828 ximage
.data
= (char *) pixels
+ (height
- 1) * width
* 4;
829 ximage
.byte_order
= LSBFirst
;
830 ximage
.bitmap_unit
= 32;
831 ximage
.bitmap_bit_order
= LSBFirst
;
832 ximage
.bitmap_pad
= 32;
834 ximage
.bytes_per_line
= -width
* 4;
835 ximage
.bits_per_pixel
= 32;
836 ximage
.red_mask
= 0xff0000;
837 ximage
.green_mask
= 0x00ff00;
838 ximage
.blue_mask
= 0x0000ff;
839 dstY
= FLIP(xmesa
->xm_buffer
,dstY
) - height
+ 1;
840 XPutImage(dpy
, buffer
, gc
, &ximage
, srcX
, srcY
, dstX
, dstY
, w
, h
);
850 static const GLubyte
*
851 get_string( GLcontext
*ctx
, GLenum name
)
857 return (const GLubyte
*) "Mesa GLX Indirect";
859 return (const GLubyte
*) "Mesa X11";
863 return (const GLubyte
*) "Mesa project: www.mesa3d.org";
874 enable( GLcontext
*ctx
, GLenum pname
, GLboolean state
)
876 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
881 xmesa
->pixelformat
= xmesa
->xm_visual
->dithered_pf
;
883 xmesa
->pixelformat
= xmesa
->xm_visual
->undithered_pf
;
886 ; /* silence compiler warning */
891 void xmesa_update_state( GLcontext
*ctx
, GLuint new_state
)
893 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
895 /* Propogate statechange information to swrast and swrast_setup
896 * modules. The X11 driver has no internal GL-dependent state.
898 _swrast_InvalidateState( ctx
, new_state
);
899 _ac_InvalidateState( ctx
, new_state
);
900 _tnl_InvalidateState( ctx
, new_state
);
901 _swsetup_InvalidateState( ctx
, new_state
);
904 /* setup pointers to front and back buffer clear functions */
905 xmesa
->xm_buffer
->front_clear_func
= clear_front_pixmap
;
906 if (xmesa
->xm_buffer
->backpixmap
!= XIMAGE
) {
907 xmesa
->xm_buffer
->back_clear_func
= clear_back_pixmap
;
909 else if (sizeof(GLushort
)!=2 || sizeof(GLuint
)!=4) {
910 xmesa
->xm_buffer
->back_clear_func
= clear_nbit_ximage
;
912 else switch (xmesa
->xm_visual
->BitsPerPixel
) {
914 if (xmesa
->xm_visual
->hpcr_clear_flag
) {
915 xmesa
->xm_buffer
->back_clear_func
= clear_HPCR_ximage
;
918 xmesa
->xm_buffer
->back_clear_func
= clear_8bit_ximage
;
922 xmesa
->xm_buffer
->back_clear_func
= clear_16bit_ximage
;
925 xmesa
->xm_buffer
->back_clear_func
= clear_24bit_ximage
;
928 xmesa
->xm_buffer
->back_clear_func
= clear_32bit_ximage
;
931 xmesa
->xm_buffer
->back_clear_func
= clear_nbit_ximage
;
935 xmesa_update_span_funcs(ctx
);
940 /* Setup pointers and other driver state that is constant for the life
943 void xmesa_init_pointers( GLcontext
*ctx
)
947 ctx
->Driver
.GetString
= get_string
;
948 ctx
->Driver
.GetBufferSize
= get_buffer_size
;
949 ctx
->Driver
.Flush
= flush
;
950 ctx
->Driver
.Finish
= finish
;
952 /* Software rasterizer pixel paths:
954 ctx
->Driver
.Accum
= _swrast_Accum
;
955 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
956 ctx
->Driver
.Clear
= clear_buffers
;
957 ctx
->Driver
.ResizeBuffers
= xmesa_resize_buffers
;
958 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
959 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
960 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;
962 /* Software texture functions:
964 ctx
->Driver
.ChooseTextureFormat
= _mesa_choose_tex_format
;
965 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
966 ctx
->Driver
.TexImage2D
= _mesa_store_teximage2d
;
967 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
968 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
969 ctx
->Driver
.TexSubImage2D
= _mesa_store_texsubimage2d
;
970 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
971 ctx
->Driver
.TestProxyTexImage
= _mesa_test_proxy_teximage
;
973 ctx
->Driver
.CopyTexImage1D
= _swrast_copy_teximage1d
;
974 ctx
->Driver
.CopyTexImage2D
= _swrast_copy_teximage2d
;
975 ctx
->Driver
.CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
976 ctx
->Driver
.CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
977 ctx
->Driver
.CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
979 ctx
->Driver
.BaseCompressedTexFormat
= _mesa_base_compressed_texformat
;
980 ctx
->Driver
.CompressedTextureSize
= _mesa_compressed_texture_size
;
981 ctx
->Driver
.GetCompressedTexImage
= _mesa_get_compressed_teximage
;
983 /* Swrast hooks for imaging extensions:
985 ctx
->Driver
.CopyColorTable
= _swrast_CopyColorTable
;
986 ctx
->Driver
.CopyColorSubTable
= _swrast_CopyColorSubTable
;
987 ctx
->Driver
.CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
988 ctx
->Driver
.CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
991 /* Statechange callbacks:
993 ctx
->Driver
.SetDrawBuffer
= set_draw_buffer
;
994 ctx
->Driver
.ClearIndex
= clear_index
;
995 ctx
->Driver
.ClearColor
= clear_color
;
996 ctx
->Driver
.IndexMask
= index_mask
;
997 ctx
->Driver
.ColorMask
= color_mask
;
998 ctx
->Driver
.Enable
= enable
;
1001 /* Initialize the TNL driver interface:
1003 tnl
= TNL_CONTEXT(ctx
);
1004 tnl
->Driver
.RunPipeline
= _tnl_run_pipeline
;
1006 /* Install swsetup for tnl->Driver.Render.*:
1008 _swsetup_Wakeup(ctx
);
1010 (void) DitherValues
; /* silenced unused var warning */
1017 #define XMESA_NEW_POINT (_NEW_POINT | \
1019 _SWRAST_NEW_RASTERMASK)
1021 #define XMESA_NEW_LINE (_NEW_LINE | \
1026 _SWRAST_NEW_RASTERMASK)
1028 #define XMESA_NEW_TRIANGLE (_NEW_POLYGON | \
1033 _SWRAST_NEW_RASTERMASK)
1036 /* Extend the software rasterizer with our line/point/triangle
1039 void xmesa_register_swrast_functions( GLcontext
*ctx
)
1041 SWcontext
*swrast
= SWRAST_CONTEXT( ctx
);
1043 swrast
->choose_point
= xmesa_choose_point
;
1044 swrast
->choose_line
= xmesa_choose_line
;
1045 swrast
->choose_triangle
= xmesa_choose_triangle
;
1047 swrast
->invalidate_point
|= XMESA_NEW_POINT
;
1048 swrast
->invalidate_line
|= XMESA_NEW_LINE
;
1049 swrast
->invalidate_triangle
|= XMESA_NEW_TRIANGLE
;