1 /* $Id: xm_dd.c,v 1.26 2001/09/12 03:32:29 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include "glxheader.h"
32 #include "extensions.h"
38 #include "texformat.h"
40 #include "array_cache/acache.h"
41 #include "swrast/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
;
81 if ( winwidth
!=xmesa
->xm_buffer
->width
82 || winheight
!=xmesa
->xm_buffer
->height
) {
83 xmesa
->xm_buffer
->width
= winwidth
;
84 xmesa
->xm_buffer
->height
= winheight
;
85 xmesa_alloc_back_buffer( xmesa
->xm_buffer
);
88 /* Needed by FLIP macro */
89 xmesa
->xm_buffer
->bottom
= (int) winheight
- 1;
91 if (xmesa
->xm_buffer
->backimage
) {
92 /* Needed by PIXELADDR1 macro */
93 xmesa
->xm_buffer
->ximage_width1
94 = xmesa
->xm_buffer
->backimage
->bytes_per_line
;
95 xmesa
->xm_buffer
->ximage_origin1
96 = (GLubyte
*) xmesa
->xm_buffer
->backimage
->data
97 + xmesa
->xm_buffer
->ximage_width1
* (winheight
-1);
99 /* Needed by PIXELADDR2 macro */
100 xmesa
->xm_buffer
->ximage_width2
101 = xmesa
->xm_buffer
->backimage
->bytes_per_line
/ 2;
102 xmesa
->xm_buffer
->ximage_origin2
103 = (GLushort
*) xmesa
->xm_buffer
->backimage
->data
104 + xmesa
->xm_buffer
->ximage_width2
* (winheight
-1);
106 /* Needed by PIXELADDR3 macro */
107 xmesa
->xm_buffer
->ximage_width3
108 = xmesa
->xm_buffer
->backimage
->bytes_per_line
;
109 xmesa
->xm_buffer
->ximage_origin3
110 = (GLubyte
*) xmesa
->xm_buffer
->backimage
->data
111 + xmesa
->xm_buffer
->ximage_width3
* (winheight
-1);
113 /* Needed by PIXELADDR4 macro */
114 xmesa
->xm_buffer
->ximage_width4
= xmesa
->xm_buffer
->backimage
->width
;
115 xmesa
->xm_buffer
->ximage_origin4
116 = (GLuint
*) xmesa
->xm_buffer
->backimage
->data
117 + xmesa
->xm_buffer
->ximage_width4
* (winheight
-1);
123 finish( GLcontext
*ctx
)
128 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
130 _glthread_LOCK_MUTEX(_xmesa_lock
);
131 XSync( xmesa
->display
, False
);
132 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
139 flush( GLcontext
*ctx
)
144 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
146 _glthread_LOCK_MUTEX(_xmesa_lock
);
147 XFlush( xmesa
->display
);
148 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
157 set_draw_buffer( GLcontext
*ctx
, GLenum mode
)
159 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
160 if (mode
== GL_FRONT_LEFT
) {
161 /* write to front buffer */
162 xmesa
->xm_buffer
->buffer
= xmesa
->xm_buffer
->frontbuffer
;
163 xmesa_update_span_funcs(ctx
);
166 else if (mode
==GL_BACK_LEFT
&& xmesa
->xm_buffer
->db_state
) {
167 /* write to back buffer */
168 if (xmesa
->xm_buffer
->backpixmap
) {
169 xmesa
->xm_buffer
->buffer
=
170 (XMesaDrawable
)xmesa
->xm_buffer
->backpixmap
;
172 else if (xmesa
->xm_buffer
->backimage
) {
173 xmesa
->xm_buffer
->buffer
= None
;
176 /* just in case there wasn't enough memory for back buffer */
177 xmesa
->xm_buffer
->buffer
= xmesa
->xm_buffer
->frontbuffer
;
179 xmesa_update_span_funcs(ctx
);
189 xmesa_set_read_buffer( GLcontext
*ctx
, GLframebuffer
*buffer
, GLenum mode
)
192 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
194 if (buffer
== ctx
->DrawBuffer
) {
195 target
= xmesa
->xm_buffer
;
196 xmesa
->use_read_buffer
= GL_FALSE
;
199 ASSERT(buffer
== ctx
->ReadBuffer
);
200 target
= xmesa
->xm_read_buffer
;
201 xmesa
->use_read_buffer
= GL_TRUE
;
204 if (mode
== GL_FRONT_LEFT
) {
205 target
->buffer
= target
->frontbuffer
;
206 xmesa_update_span_funcs(ctx
);
208 else if (mode
==GL_BACK_LEFT
&& xmesa
->xm_read_buffer
->db_state
) {
209 if (target
->backpixmap
) {
210 target
->buffer
= (XMesaDrawable
)xmesa
->xm_buffer
->backpixmap
;
212 else if (target
->backimage
) {
213 target
->buffer
= None
;
216 /* just in case there wasn't enough memory for back buffer */
217 target
->buffer
= target
->frontbuffer
;
219 xmesa_update_span_funcs(ctx
);
222 _mesa_problem(ctx
, "invalid buffer in set_read_buffer() in xmesa2.c");
229 clear_index( GLcontext
*ctx
, GLuint index
)
231 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
232 xmesa
->clearpixel
= (unsigned long) index
;
233 XMesaSetForeground( xmesa
->display
, xmesa
->xm_buffer
->cleargc
,
234 (unsigned long) index
);
239 clear_color( GLcontext
*ctx
, const GLchan color
[4] )
241 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
242 xmesa
->clearcolor
[0] = color
[0];
243 xmesa
->clearcolor
[1] = color
[1];
244 xmesa
->clearcolor
[2] = color
[2];
245 xmesa
->clearcolor
[3] = color
[3];
246 xmesa
->clearpixel
= xmesa_color_to_pixel( xmesa
, color
[0], color
[1],
248 xmesa
->xm_visual
->undithered_pf
);
249 _glthread_LOCK_MUTEX(_xmesa_lock
);
250 XMesaSetForeground( xmesa
->display
, xmesa
->xm_buffer
->cleargc
,
252 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
257 /* Set index mask ala glIndexMask */
259 index_mask( GLcontext
*ctx
, GLuint mask
)
261 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
262 if (xmesa
->xm_buffer
->buffer
!= XIMAGE
) {
264 if (mask
==0xffffffff) {
265 m
= ((unsigned long)~0L);
268 m
= (unsigned long) mask
;
270 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_buffer
->cleargc
, m
);
275 /* Implements glColorMask() */
277 color_mask(GLcontext
*ctx
,
278 GLboolean rmask
, GLboolean gmask
, GLboolean bmask
, GLboolean amask
)
280 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
281 int xclass
= GET_VISUAL_CLASS(xmesa
->xm_visual
);
284 if (xmesa
->xm_buffer
->buffer
!= XIMAGE
285 && (xclass
== TrueColor
|| xclass
== DirectColor
)) {
287 if (rmask
&& gmask
&& bmask
) {
288 m
= ((unsigned long)~0L);
292 if (rmask
) m
|= GET_REDMASK(xmesa
->xm_visual
);
293 if (gmask
) m
|= GET_GREENMASK(xmesa
->xm_visual
);
294 if (bmask
) m
|= GET_BLUEMASK(xmesa
->xm_visual
);
296 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_buffer
->cleargc
, m
);
302 /**********************************************************************/
303 /*** glClear implementations ***/
304 /**********************************************************************/
308 clear_front_pixmap( GLcontext
*ctx
, GLboolean all
,
309 GLint x
, GLint y
, GLint width
, GLint height
)
311 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
313 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->frontbuffer
,
314 xmesa
->xm_buffer
->cleargc
,
316 xmesa
->xm_buffer
->width
+1,
317 xmesa
->xm_buffer
->height
+1 );
320 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->frontbuffer
,
321 xmesa
->xm_buffer
->cleargc
,
322 x
, xmesa
->xm_buffer
->height
- y
- height
,
329 clear_back_pixmap( GLcontext
*ctx
, GLboolean all
,
330 GLint x
, GLint y
, GLint width
, GLint height
)
332 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
334 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->backpixmap
,
335 xmesa
->xm_buffer
->cleargc
,
337 xmesa
->xm_buffer
->width
+1,
338 xmesa
->xm_buffer
->height
+1 );
341 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->backpixmap
,
342 xmesa
->xm_buffer
->cleargc
,
343 x
, xmesa
->xm_buffer
->height
- y
- height
,
350 clear_8bit_ximage( GLcontext
*ctx
, GLboolean all
,
351 GLint x
, GLint y
, GLint width
, GLint height
)
353 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
355 size_t n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
356 * xmesa
->xm_buffer
->backimage
->height
;
357 MEMSET( xmesa
->xm_buffer
->backimage
->data
, xmesa
->clearpixel
, n
);
361 for (i
=0;i
<height
;i
++) {
362 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_buffer
, x
, y
+i
);
363 MEMSET( ptr
, xmesa
->clearpixel
, width
);
370 clear_HPCR_ximage( GLcontext
*ctx
, GLboolean all
,
371 GLint x
, GLint y
, GLint width
, GLint height
)
373 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
375 GLint i
, c16
= (xmesa
->xm_buffer
->backimage
->bytes_per_line
>>4)<<4;
376 GLubyte
*ptr
= (GLubyte
*)xmesa
->xm_buffer
->backimage
->data
;
377 for (i
=0; i
<xmesa
->xm_buffer
->backimage
->height
; i
++) {
379 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
383 for (j
=0; j
<c16
; j
+=16) {
402 for (; j
<xmesa
->xm_buffer
->backimage
->bytes_per_line
; j
++) {
410 for (i
=y
; i
<y
+height
; i
++) {
411 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_buffer
, x
, i
);
413 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
417 for (j
=x
; j
<x
+width
; j
++) {
427 clear_16bit_ximage( GLcontext
*ctx
, GLboolean all
,
428 GLint x
, GLint y
, GLint width
, GLint height
)
430 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
431 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
432 if (xmesa
->swapbytes
) {
433 pixel
= ((pixel
>> 8) & 0x00ff) | ((pixel
<< 8) & 0xff00);
437 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_buffer
->backimage
->data
;
438 if ((pixel
& 0xff) == ((pixel
>> 8) & 0xff)) {
439 /* low and high bytes are equal so use memset() */
440 n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
441 * xmesa
->xm_buffer
->height
;
442 MEMSET( ptr4
, pixel
& 0xff, n
);
445 pixel
= pixel
| (pixel
<<16);
446 n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
447 * xmesa
->xm_buffer
->height
/ 4;
453 if ((xmesa
->xm_buffer
->backimage
->bytes_per_line
*
454 xmesa
->xm_buffer
->height
) & 0x2)
455 *(GLushort
*)ptr4
= pixel
& 0xffff;
460 for (j
=0;j
<height
;j
++) {
461 register GLushort
*ptr2
= PIXELADDR2( xmesa
->xm_buffer
, x
, y
+j
);
462 for (i
=0;i
<width
;i
++) {
470 /* Optimized code provided by Nozomi Ytow <noz@xfree86.org> */
472 clear_24bit_ximage( GLcontext
*ctx
, GLboolean all
,
473 GLint x
, GLint y
, GLint width
, GLint height
)
475 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
476 const GLubyte r
= xmesa
->clearcolor
[0];
477 const GLubyte g
= xmesa
->clearcolor
[1];
478 const GLubyte b
= xmesa
->clearcolor
[2];
479 register GLuint clearPixel
;
480 if (xmesa
->swapbytes
) {
481 clearPixel
= (b
<< 16) | (g
<< 8) | r
;
484 clearPixel
= (r
<< 16) | (g
<< 8) | b
;
489 /* same value for all three components (gray) */
490 const GLint w3
= xmesa
->xm_buffer
->width
* 3;
491 const GLint h
= xmesa
->xm_buffer
->height
;
493 for (i
= 0; i
< h
; i
++) {
494 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_buffer
, 0, i
);
500 const GLint w
= xmesa
->xm_buffer
->width
;
501 const GLint h
= xmesa
->xm_buffer
->height
;
503 for (i
= 0; i
< h
; i
++) {
504 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_buffer
, 0, i
);
505 for (j
= 0; j
< w
; j
++) {
512 #if 0 /* this code doesn't work for all window widths */
513 register GLuint
*ptr4
= (GLuint
*) ptr3
;
516 register GLuint
*p
= pixel4
;
517 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
518 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
519 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
520 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
524 px
= *ptr4
& 0x00ffffff;
525 px
|= pixel4
[0] & 0xff000000;
527 px
= *ptr4
& 0xffff0000;
528 px
|= pixel4
[2] & 0x0000ffff;
533 px
= *ptr4
& 0x0000fffff;
534 px
|= pixel4
[1] & 0xffff0000;
536 px
= *ptr4
& 0xffffff00;
537 px
|= pixel4
[2] & 0x000000ff;
542 px
= *ptr4
& 0x000000ff;
543 px
|= pixel4
[2] & 0xffffff00;
560 px
= *ptr4
& 0xffffff00;
561 px
|= clearPixel
& 0xff;
567 px
= *ptr4
& 0xffff0000;
572 px
= *ptr4
& 0xff000000;
583 /* only clear subrect of color buffer */
585 /* same value for all three components (gray) */
587 for (j
=0;j
<height
;j
++) {
588 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
589 MEMSET(ptr3
, r
, 3 * width
);
593 /* non-gray clear color */
595 for (j
= 0; j
< height
; j
++) {
596 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
597 for (i
= 0; i
< width
; i
++) {
604 #if 0 /* this code might not always (seems ptr3 always == ptr4) */
607 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
608 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
609 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
610 for (j
=0;j
<height
;j
++) {
611 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
612 register GLuint
*ptr4
= (GLuint
*)ptr3
;
613 register GLuint
*p
, px
;
615 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
619 px
= *ptr4
& 0x00ffffff;
620 px
|= pixel4
[0] & 0xff000000;
622 px
= *ptr4
& 0xffff0000;
623 px
|= pixel4
[2] & 0x0000ffff;
628 px
= *ptr4
& 0x0000fffff;
629 px
|= pixel4
[1] & 0xffff0000;
631 px
= *ptr4
& 0xffffff00;
632 px
|= pixel4
[2] & 0x000000ff;
637 px
= *ptr4
& 0x000000ff;
638 px
|= pixel4
[2] & 0xffffff00;
655 px
= *ptr4
& 0xffffff00;
662 px
= *ptr4
& 0xffff0000;
667 px
= *ptr4
& 0xff000000;
668 px
|= pixel4
[0] & 0xffffff;
682 clear_32bit_ximage( GLcontext
*ctx
, GLboolean all
,
683 GLint x
, GLint y
, GLint width
, GLint height
)
685 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
686 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
687 if (xmesa
->swapbytes
) {
688 pixel
= ((pixel
>> 24) & 0x000000ff)
689 | ((pixel
>> 8) & 0x0000ff00)
690 | ((pixel
<< 8) & 0x00ff0000)
691 | ((pixel
<< 24) & 0xff000000);
694 register GLint n
= xmesa
->xm_buffer
->width
* xmesa
->xm_buffer
->height
;
695 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_buffer
->backimage
->data
;
697 MEMSET( ptr4
, pixel
, 4*n
);
708 for (j
=0;j
<height
;j
++) {
709 register GLuint
*ptr4
= PIXELADDR4( xmesa
->xm_buffer
, x
, y
+j
);
710 for (i
=0;i
<width
;i
++) {
719 clear_nbit_ximage( GLcontext
*ctx
, GLboolean all
,
720 GLint x
, GLint y
, GLint width
, GLint height
)
722 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
723 XMesaImage
*img
= xmesa
->xm_buffer
->backimage
;
726 width
= xmesa
->xm_buffer
->width
;
727 height
= xmesa
->xm_buffer
->height
;
728 for (j
=0;j
<height
;j
++) {
729 for (i
=0;i
<width
;i
++) {
730 XMesaPutPixel( img
, i
, j
, xmesa
->clearpixel
);
735 /* TODO: optimize this */
737 y
= FLIP(xmesa
->xm_buffer
, y
);
738 for (j
=0;j
<height
;j
++) {
739 for (i
=0;i
<width
;i
++) {
740 XMesaPutPixel( img
, x
+i
, y
-j
, xmesa
->clearpixel
);
749 clear_buffers( GLcontext
*ctx
, GLbitfield mask
,
750 GLboolean all
, GLint x
, GLint y
, GLint width
, GLint height
)
752 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
753 const GLuint
*colorMask
= (GLuint
*) &ctx
->Color
.ColorMask
;
755 if ((mask
& (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
)) &&
756 xmesa
->xm_buffer
->mesa_buffer
.UseSoftwareAlphaBuffers
&&
757 ctx
->Color
.ColorMask
[ACOMP
]) {
758 _mesa_clear_alpha_buffers(ctx
);
761 /* we can't handle color or index masking */
762 if (*colorMask
== 0xffffffff && ctx
->Color
.IndexMask
== 0xffffffff) {
763 if (mask
& DD_FRONT_LEFT_BIT
) {
764 ASSERT(xmesa
->xm_buffer
->front_clear_func
);
765 (*xmesa
->xm_buffer
->front_clear_func
)( ctx
, all
, x
, y
, width
, height
);
766 mask
&= ~DD_FRONT_LEFT_BIT
;
768 if (mask
& DD_BACK_LEFT_BIT
) {
769 ASSERT(xmesa
->xm_buffer
->back_clear_func
);
770 (*xmesa
->xm_buffer
->back_clear_func
)( ctx
, all
, x
, y
, width
, height
);
771 mask
&= ~DD_BACK_LEFT_BIT
;
776 _swrast_Clear( ctx
, mask
, all
, x
, y
, width
, height
);
781 resize_buffers( GLcontext
*ctx
)
783 _swrast_alloc_buffers( ctx
);
788 * This function implements glDrawPixels() with an XPutImage call when
789 * drawing to the front buffer (X Window drawable).
790 * The image format must be GL_BGRA to match the PF_8R8G8B pixel format.
791 * XXX top/bottom edge clipping is broken!
794 drawpixels_8R8G8B( GLcontext
*ctx
,
795 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
796 GLenum format
, GLenum type
,
797 const struct gl_pixelstore_attrib
*unpack
,
798 const GLvoid
*pixels
)
800 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
801 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
802 XMesaDrawable buffer
= xmesa
->xm_buffer
->buffer
;
803 XMesaGC gc
= xmesa
->xm_buffer
->gc
;
808 /* XXX also check for pixel scale/bias/lookup/zooming! */
809 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
) {
814 int srcX
= unpack
->SkipPixels
;
815 int srcY
= unpack
->SkipRows
;
816 if (_mesa_clip_pixelrect(ctx
, &dstX
, &dstY
, &w
, &h
, &srcX
, &srcY
)) {
818 MEMSET(&ximage
, 0, sizeof(XMesaImage
));
819 ximage
.width
= width
;
820 ximage
.height
= height
;
821 ximage
.format
= ZPixmap
;
822 ximage
.data
= (char *) pixels
+ (height
- 1) * width
* 4;
823 ximage
.byte_order
= LSBFirst
;
824 ximage
.bitmap_unit
= 32;
825 ximage
.bitmap_bit_order
= LSBFirst
;
826 ximage
.bitmap_pad
= 32;
828 ximage
.bytes_per_line
= -width
* 4;
829 ximage
.bits_per_pixel
= 32;
830 ximage
.red_mask
= 0xff0000;
831 ximage
.green_mask
= 0x00ff00;
832 ximage
.blue_mask
= 0x0000ff;
833 dstY
= FLIP(xmesa
->xm_buffer
,dstY
) - height
+ 1;
834 XPutImage(dpy
, buffer
, gc
, &ximage
, srcX
, srcY
, dstX
, dstY
, w
, h
);
844 static const GLubyte
*
845 get_string( GLcontext
*ctx
, GLenum name
)
851 return (const GLubyte
*) "Mesa GLX Indirect";
853 return (const GLubyte
*) "Mesa X11";
857 return (const GLubyte
*) "VA Linux Systems, Inc.";
868 enable( GLcontext
*ctx
, GLenum pname
, GLboolean state
)
870 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
875 xmesa
->pixelformat
= xmesa
->xm_visual
->dithered_pf
;
877 xmesa
->pixelformat
= xmesa
->xm_visual
->undithered_pf
;
880 ; /* silence compiler warning */
885 void xmesa_update_state( GLcontext
*ctx
, GLuint new_state
)
887 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
889 /* Propogate statechange information to swrast and swrast_setup
890 * modules. The X11 driver has no internal GL-dependent state.
892 _swrast_InvalidateState( ctx
, new_state
);
893 _ac_InvalidateState( ctx
, new_state
);
894 _tnl_InvalidateState( ctx
, new_state
);
895 _swsetup_InvalidateState( ctx
, new_state
);
898 /* setup pointers to front and back buffer clear functions */
899 xmesa
->xm_buffer
->front_clear_func
= clear_front_pixmap
;
900 if (xmesa
->xm_buffer
->backpixmap
!= XIMAGE
) {
901 xmesa
->xm_buffer
->back_clear_func
= clear_back_pixmap
;
903 else if (sizeof(GLushort
)!=2 || sizeof(GLuint
)!=4) {
904 xmesa
->xm_buffer
->back_clear_func
= clear_nbit_ximage
;
906 else switch (xmesa
->xm_visual
->BitsPerPixel
) {
908 if (xmesa
->xm_visual
->hpcr_clear_flag
) {
909 xmesa
->xm_buffer
->back_clear_func
= clear_HPCR_ximage
;
912 xmesa
->xm_buffer
->back_clear_func
= clear_8bit_ximage
;
916 xmesa
->xm_buffer
->back_clear_func
= clear_16bit_ximage
;
919 xmesa
->xm_buffer
->back_clear_func
= clear_24bit_ximage
;
922 xmesa
->xm_buffer
->back_clear_func
= clear_32bit_ximage
;
925 xmesa
->xm_buffer
->back_clear_func
= clear_nbit_ximage
;
929 xmesa_update_span_funcs(ctx
);
934 /* Setup pointers and other driver state that is constant for the life
937 void xmesa_init_pointers( GLcontext
*ctx
)
941 ctx
->Driver
.GetString
= get_string
;
942 ctx
->Driver
.GetBufferSize
= get_buffer_size
;
943 ctx
->Driver
.Flush
= flush
;
944 ctx
->Driver
.Finish
= finish
;
946 /* Software rasterizer pixel paths:
948 ctx
->Driver
.Accum
= _swrast_Accum
;
949 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
950 ctx
->Driver
.Clear
= clear_buffers
;
951 ctx
->Driver
.ResizeBuffersMESA
= resize_buffers
;
952 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
953 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
954 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;
956 /* Software texture functions:
958 ctx
->Driver
.ChooseTextureFormat
= _mesa_choose_tex_format
;
959 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
960 ctx
->Driver
.TexImage2D
= _mesa_store_teximage2d
;
961 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
962 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
963 ctx
->Driver
.TexSubImage2D
= _mesa_store_texsubimage2d
;
964 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
965 ctx
->Driver
.TestProxyTexImage
= _mesa_test_proxy_teximage
;
967 ctx
->Driver
.CopyTexImage1D
= _swrast_copy_teximage1d
;
968 ctx
->Driver
.CopyTexImage2D
= _swrast_copy_teximage2d
;
969 ctx
->Driver
.CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
970 ctx
->Driver
.CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
971 ctx
->Driver
.CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
973 ctx
->Driver
.BaseCompressedTexFormat
= _mesa_base_compressed_texformat
;
974 ctx
->Driver
.CompressedTextureSize
= _mesa_compressed_texture_size
;
975 ctx
->Driver
.GetCompressedTexImage
= _mesa_get_compressed_teximage
;
977 /* Swrast hooks for imaging extensions:
979 ctx
->Driver
.CopyColorTable
= _swrast_CopyColorTable
;
980 ctx
->Driver
.CopyColorSubTable
= _swrast_CopyColorSubTable
;
981 ctx
->Driver
.CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
982 ctx
->Driver
.CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
985 /* Statechange callbacks:
987 ctx
->Driver
.SetDrawBuffer
= set_draw_buffer
;
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 /* Install swsetup for tnl->Driver.Render.*:
1002 _swsetup_Wakeup(ctx
);
1004 (void) DitherValues
; /* silenced unused var warning */
1011 #define XMESA_NEW_POINT (_NEW_POINT | \
1013 _SWRAST_NEW_RASTERMASK)
1015 #define XMESA_NEW_LINE (_NEW_LINE | \
1020 _SWRAST_NEW_RASTERMASK)
1022 #define XMESA_NEW_TRIANGLE (_NEW_POLYGON | \
1027 _SWRAST_NEW_RASTERMASK)
1030 /* Extend the software rasterizer with our line/point/triangle
1033 void xmesa_register_swrast_functions( GLcontext
*ctx
)
1035 SWcontext
*swrast
= SWRAST_CONTEXT( ctx
);
1037 swrast
->choose_point
= xmesa_choose_point
;
1038 swrast
->choose_line
= xmesa_choose_line
;
1039 swrast
->choose_triangle
= xmesa_choose_triangle
;
1041 swrast
->invalidate_point
|= XMESA_NEW_POINT
;
1042 swrast
->invalidate_line
|= XMESA_NEW_LINE
;
1043 swrast
->invalidate_triangle
|= XMESA_NEW_TRIANGLE
;