1 /* $Id: xm_dd.c,v 1.24 2001/05/10 12:22:32 keithw 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/swrast.h"
42 #include "swrast/s_alphabuf.h"
43 #include "swrast_setup/swrast_setup.h"
45 #include "tnl/t_context.h"
46 #include "tnl/t_pipeline.h"
50 * Return the size (width,height of the current color buffer.
51 * This function should be called by the glViewport function because
52 * glViewport is often called when the window gets resized. We need to
53 * update some X/Mesa stuff when that happens.
54 * Output: width - width of buffer in pixels.
55 * height - height of buffer in pixels.
58 get_buffer_size( GLcontext
*ctx
, GLuint
*width
, GLuint
*height
)
60 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
61 unsigned int winwidth
, winheight
;
67 _glthread_LOCK_MUTEX(_xmesa_lock
);
68 XGetGeometry( xmesa
->display
, xmesa
->xm_buffer
->frontbuffer
, &root
,
69 &winx
, &winy
, &winwidth
, &winheight
, &bw
, &d
);
70 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
73 winwidth
= xmesa
->xm_buffer
->frontbuffer
->width
;
74 winheight
= xmesa
->xm_buffer
->frontbuffer
->height
;
80 if ( winwidth
!=xmesa
->xm_buffer
->width
81 || winheight
!=xmesa
->xm_buffer
->height
) {
82 xmesa
->xm_buffer
->width
= winwidth
;
83 xmesa
->xm_buffer
->height
= winheight
;
84 xmesa_alloc_back_buffer( xmesa
->xm_buffer
);
87 /* Needed by FLIP macro */
88 xmesa
->xm_buffer
->bottom
= (int) winheight
- 1;
90 if (xmesa
->xm_buffer
->backimage
) {
91 /* Needed by PIXELADDR1 macro */
92 xmesa
->xm_buffer
->ximage_width1
93 = xmesa
->xm_buffer
->backimage
->bytes_per_line
;
94 xmesa
->xm_buffer
->ximage_origin1
95 = (GLubyte
*) xmesa
->xm_buffer
->backimage
->data
96 + xmesa
->xm_buffer
->ximage_width1
* (winheight
-1);
98 /* Needed by PIXELADDR2 macro */
99 xmesa
->xm_buffer
->ximage_width2
100 = xmesa
->xm_buffer
->backimage
->bytes_per_line
/ 2;
101 xmesa
->xm_buffer
->ximage_origin2
102 = (GLushort
*) xmesa
->xm_buffer
->backimage
->data
103 + xmesa
->xm_buffer
->ximage_width2
* (winheight
-1);
105 /* Needed by PIXELADDR3 macro */
106 xmesa
->xm_buffer
->ximage_width3
107 = xmesa
->xm_buffer
->backimage
->bytes_per_line
;
108 xmesa
->xm_buffer
->ximage_origin3
109 = (GLubyte
*) xmesa
->xm_buffer
->backimage
->data
110 + xmesa
->xm_buffer
->ximage_width3
* (winheight
-1);
112 /* Needed by PIXELADDR4 macro */
113 xmesa
->xm_buffer
->ximage_width4
= xmesa
->xm_buffer
->backimage
->width
;
114 xmesa
->xm_buffer
->ximage_origin4
115 = (GLuint
*) xmesa
->xm_buffer
->backimage
->data
116 + xmesa
->xm_buffer
->ximage_width4
* (winheight
-1);
122 finish( GLcontext
*ctx
)
127 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
129 _glthread_LOCK_MUTEX(_xmesa_lock
);
130 XSync( xmesa
->display
, False
);
131 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
138 flush( GLcontext
*ctx
)
143 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
145 _glthread_LOCK_MUTEX(_xmesa_lock
);
146 XFlush( xmesa
->display
);
147 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
156 set_draw_buffer( GLcontext
*ctx
, GLenum mode
)
158 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
159 if (mode
== GL_FRONT_LEFT
) {
160 /* write to front buffer */
161 xmesa
->xm_buffer
->buffer
= xmesa
->xm_buffer
->frontbuffer
;
162 xmesa_update_span_funcs(ctx
);
165 else if (mode
==GL_BACK_LEFT
&& xmesa
->xm_buffer
->db_state
) {
166 /* write to back buffer */
167 if (xmesa
->xm_buffer
->backpixmap
) {
168 xmesa
->xm_buffer
->buffer
=
169 (XMesaDrawable
)xmesa
->xm_buffer
->backpixmap
;
171 else if (xmesa
->xm_buffer
->backimage
) {
172 xmesa
->xm_buffer
->buffer
= None
;
175 /* just in case there wasn't enough memory for back buffer */
176 xmesa
->xm_buffer
->buffer
= xmesa
->xm_buffer
->frontbuffer
;
178 xmesa_update_span_funcs(ctx
);
188 xmesa_set_read_buffer( GLcontext
*ctx
, GLframebuffer
*buffer
, GLenum mode
)
191 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
193 if (buffer
== ctx
->DrawBuffer
) {
194 target
= xmesa
->xm_buffer
;
195 xmesa
->use_read_buffer
= GL_FALSE
;
198 ASSERT(buffer
== ctx
->ReadBuffer
);
199 target
= xmesa
->xm_read_buffer
;
200 xmesa
->use_read_buffer
= GL_TRUE
;
203 if (mode
== GL_FRONT_LEFT
) {
204 target
->buffer
= target
->frontbuffer
;
205 xmesa_update_span_funcs(ctx
);
207 else if (mode
==GL_BACK_LEFT
&& xmesa
->xm_read_buffer
->db_state
) {
208 if (target
->backpixmap
) {
209 target
->buffer
= (XMesaDrawable
)xmesa
->xm_buffer
->backpixmap
;
211 else if (target
->backimage
) {
212 target
->buffer
= None
;
215 /* just in case there wasn't enough memory for back buffer */
216 target
->buffer
= target
->frontbuffer
;
218 xmesa_update_span_funcs(ctx
);
221 _mesa_problem(ctx
, "invalid buffer in set_read_buffer() in xmesa2.c");
228 clear_index( GLcontext
*ctx
, GLuint index
)
230 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
231 xmesa
->clearpixel
= (unsigned long) index
;
232 XMesaSetForeground( xmesa
->display
, xmesa
->xm_buffer
->cleargc
,
233 (unsigned long) index
);
238 clear_color( GLcontext
*ctx
, const GLchan color
[4] )
240 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
241 xmesa
->clearcolor
[0] = color
[0];
242 xmesa
->clearcolor
[1] = color
[1];
243 xmesa
->clearcolor
[2] = color
[2];
244 xmesa
->clearcolor
[3] = color
[3];
245 xmesa
->clearpixel
= xmesa_color_to_pixel( xmesa
, color
[0], color
[1],
247 xmesa
->xm_visual
->undithered_pf
);
248 _glthread_LOCK_MUTEX(_xmesa_lock
);
249 XMesaSetForeground( xmesa
->display
, xmesa
->xm_buffer
->cleargc
,
251 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
256 /* Set index mask ala glIndexMask */
258 index_mask( GLcontext
*ctx
, GLuint mask
)
260 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
261 if (xmesa
->xm_buffer
->buffer
!= XIMAGE
) {
263 if (mask
==0xffffffff) {
264 m
= ((unsigned long)~0L);
267 m
= (unsigned long) mask
;
269 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_buffer
->cleargc
, m
);
274 /* Implements glColorMask() */
276 color_mask(GLcontext
*ctx
,
277 GLboolean rmask
, GLboolean gmask
, GLboolean bmask
, GLboolean amask
)
279 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
280 int xclass
= GET_VISUAL_CLASS(xmesa
->xm_visual
);
283 if (xmesa
->xm_buffer
->buffer
!= XIMAGE
284 && (xclass
== TrueColor
|| xclass
== DirectColor
)) {
286 if (rmask
&& gmask
&& bmask
) {
287 m
= ((unsigned long)~0L);
291 if (rmask
) m
|= GET_REDMASK(xmesa
->xm_visual
);
292 if (gmask
) m
|= GET_GREENMASK(xmesa
->xm_visual
);
293 if (bmask
) m
|= GET_BLUEMASK(xmesa
->xm_visual
);
295 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_buffer
->cleargc
, m
);
301 /**********************************************************************/
302 /*** glClear implementations ***/
303 /**********************************************************************/
307 clear_front_pixmap( GLcontext
*ctx
, GLboolean all
,
308 GLint x
, GLint y
, GLint width
, GLint height
)
310 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
312 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->frontbuffer
,
313 xmesa
->xm_buffer
->cleargc
,
315 xmesa
->xm_buffer
->width
+1,
316 xmesa
->xm_buffer
->height
+1 );
319 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->frontbuffer
,
320 xmesa
->xm_buffer
->cleargc
,
321 x
, xmesa
->xm_buffer
->height
- y
- height
,
328 clear_back_pixmap( GLcontext
*ctx
, GLboolean all
,
329 GLint x
, GLint y
, GLint width
, GLint height
)
331 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
333 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->backpixmap
,
334 xmesa
->xm_buffer
->cleargc
,
336 xmesa
->xm_buffer
->width
+1,
337 xmesa
->xm_buffer
->height
+1 );
340 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->backpixmap
,
341 xmesa
->xm_buffer
->cleargc
,
342 x
, xmesa
->xm_buffer
->height
- y
- height
,
349 clear_8bit_ximage( GLcontext
*ctx
, GLboolean all
,
350 GLint x
, GLint y
, GLint width
, GLint height
)
352 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
354 size_t n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
355 * xmesa
->xm_buffer
->backimage
->height
;
356 MEMSET( xmesa
->xm_buffer
->backimage
->data
, xmesa
->clearpixel
, n
);
360 for (i
=0;i
<height
;i
++) {
361 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_buffer
, x
, y
+i
);
362 MEMSET( ptr
, xmesa
->clearpixel
, width
);
369 clear_HPCR_ximage( GLcontext
*ctx
, GLboolean all
,
370 GLint x
, GLint y
, GLint width
, GLint height
)
372 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
374 GLint i
, c16
= (xmesa
->xm_buffer
->backimage
->bytes_per_line
>>4)<<4;
375 GLubyte
*ptr
= (GLubyte
*)xmesa
->xm_buffer
->backimage
->data
;
376 for (i
=0; i
<xmesa
->xm_buffer
->backimage
->height
; i
++) {
378 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
382 for (j
=0; j
<c16
; j
+=16) {
401 for (; j
<xmesa
->xm_buffer
->backimage
->bytes_per_line
; j
++) {
409 for (i
=y
; i
<y
+height
; i
++) {
410 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_buffer
, x
, i
);
412 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
416 for (j
=x
; j
<x
+width
; j
++) {
426 clear_16bit_ximage( GLcontext
*ctx
, GLboolean all
,
427 GLint x
, GLint y
, GLint width
, GLint height
)
429 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
430 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
431 if (xmesa
->swapbytes
) {
432 pixel
= ((pixel
>> 8) & 0x00ff) | ((pixel
<< 8) & 0xff00);
436 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_buffer
->backimage
->data
;
437 if ((pixel
& 0xff) == ((pixel
>> 8) & 0xff)) {
438 /* low and high bytes are equal so use memset() */
439 n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
440 * xmesa
->xm_buffer
->height
;
441 MEMSET( ptr4
, pixel
& 0xff, n
);
444 pixel
= pixel
| (pixel
<<16);
445 n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
446 * xmesa
->xm_buffer
->height
/ 4;
452 if ((xmesa
->xm_buffer
->backimage
->bytes_per_line
*
453 xmesa
->xm_buffer
->height
) & 0x2)
454 *(GLushort
*)ptr4
= pixel
& 0xffff;
459 for (j
=0;j
<height
;j
++) {
460 register GLushort
*ptr2
= PIXELADDR2( xmesa
->xm_buffer
, x
, y
+j
);
461 for (i
=0;i
<width
;i
++) {
469 /* Optimized code provided by Nozomi Ytow <noz@xfree86.org> */
471 clear_24bit_ximage( GLcontext
*ctx
, GLboolean all
,
472 GLint x
, GLint y
, GLint width
, GLint height
)
474 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
475 const GLubyte r
= xmesa
->clearcolor
[0];
476 const GLubyte g
= xmesa
->clearcolor
[1];
477 const GLubyte b
= xmesa
->clearcolor
[2];
478 register GLuint clearPixel
;
479 if (xmesa
->swapbytes
) {
480 clearPixel
= (b
<< 16) | (g
<< 8) | r
;
483 clearPixel
= (r
<< 16) | (g
<< 8) | b
;
488 /* same value for all three components (gray) */
489 const GLint w3
= xmesa
->xm_buffer
->width
* 3;
490 const GLint h
= xmesa
->xm_buffer
->height
;
492 for (i
= 0; i
< h
; i
++) {
493 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_buffer
, 0, i
);
499 const GLint w
= xmesa
->xm_buffer
->width
;
500 const GLint h
= xmesa
->xm_buffer
->height
;
502 for (i
= 0; i
< h
; i
++) {
503 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_buffer
, 0, i
);
504 for (j
= 0; j
< w
; j
++) {
511 #if 0 /* this code doesn't work for all window widths */
512 register GLuint
*ptr4
= (GLuint
*) ptr3
;
515 register GLuint
*p
= pixel4
;
516 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
517 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
518 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
519 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
523 px
= *ptr4
& 0x00ffffff;
524 px
|= pixel4
[0] & 0xff000000;
526 px
= *ptr4
& 0xffff0000;
527 px
|= pixel4
[2] & 0x0000ffff;
532 px
= *ptr4
& 0x0000fffff;
533 px
|= pixel4
[1] & 0xffff0000;
535 px
= *ptr4
& 0xffffff00;
536 px
|= pixel4
[2] & 0x000000ff;
541 px
= *ptr4
& 0x000000ff;
542 px
|= pixel4
[2] & 0xffffff00;
559 px
= *ptr4
& 0xffffff00;
560 px
|= clearPixel
& 0xff;
566 px
= *ptr4
& 0xffff0000;
571 px
= *ptr4
& 0xff000000;
582 /* only clear subrect of color buffer */
584 /* same value for all three components (gray) */
586 for (j
=0;j
<height
;j
++) {
587 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
588 MEMSET(ptr3
, r
, 3 * width
);
592 /* non-gray clear color */
594 for (j
= 0; j
< height
; j
++) {
595 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
596 for (i
= 0; i
< width
; i
++) {
603 #if 0 /* this code might not always (seems ptr3 always == ptr4) */
606 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
607 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
608 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
609 for (j
=0;j
<height
;j
++) {
610 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
611 register GLuint
*ptr4
= (GLuint
*)ptr3
;
612 register GLuint
*p
, px
;
614 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
618 px
= *ptr4
& 0x00ffffff;
619 px
|= pixel4
[0] & 0xff000000;
621 px
= *ptr4
& 0xffff0000;
622 px
|= pixel4
[2] & 0x0000ffff;
627 px
= *ptr4
& 0x0000fffff;
628 px
|= pixel4
[1] & 0xffff0000;
630 px
= *ptr4
& 0xffffff00;
631 px
|= pixel4
[2] & 0x000000ff;
636 px
= *ptr4
& 0x000000ff;
637 px
|= pixel4
[2] & 0xffffff00;
654 px
= *ptr4
& 0xffffff00;
661 px
= *ptr4
& 0xffff0000;
666 px
= *ptr4
& 0xff000000;
667 px
|= pixel4
[0] & 0xffffff;
681 clear_32bit_ximage( GLcontext
*ctx
, GLboolean all
,
682 GLint x
, GLint y
, GLint width
, GLint height
)
684 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
685 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
686 if (xmesa
->swapbytes
) {
687 pixel
= ((pixel
>> 24) & 0x000000ff)
688 | ((pixel
>> 8) & 0x0000ff00)
689 | ((pixel
<< 8) & 0x00ff0000)
690 | ((pixel
<< 24) & 0xff000000);
693 register GLint n
= xmesa
->xm_buffer
->width
* xmesa
->xm_buffer
->height
;
694 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_buffer
->backimage
->data
;
696 MEMSET( ptr4
, pixel
, 4*n
);
707 for (j
=0;j
<height
;j
++) {
708 register GLuint
*ptr4
= PIXELADDR4( xmesa
->xm_buffer
, x
, y
+j
);
709 for (i
=0;i
<width
;i
++) {
718 clear_nbit_ximage( GLcontext
*ctx
, GLboolean all
,
719 GLint x
, GLint y
, GLint width
, GLint height
)
721 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
722 XMesaImage
*img
= xmesa
->xm_buffer
->backimage
;
725 width
= xmesa
->xm_buffer
->width
;
726 height
= xmesa
->xm_buffer
->height
;
727 for (j
=0;j
<height
;j
++) {
728 for (i
=0;i
<width
;i
++) {
729 XMesaPutPixel( img
, i
, j
, xmesa
->clearpixel
);
734 /* TODO: optimize this */
736 y
= FLIP(xmesa
->xm_buffer
, y
);
737 for (j
=0;j
<height
;j
++) {
738 for (i
=0;i
<width
;i
++) {
739 XMesaPutPixel( img
, x
+i
, y
-j
, xmesa
->clearpixel
);
748 clear_buffers( GLcontext
*ctx
, GLbitfield mask
,
749 GLboolean all
, GLint x
, GLint y
, GLint width
, GLint height
)
751 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
752 const GLuint
*colorMask
= (GLuint
*) &ctx
->Color
.ColorMask
;
754 if ((mask
& (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
)) &&
755 xmesa
->xm_buffer
->mesa_buffer
.UseSoftwareAlphaBuffers
&&
756 ctx
->Color
.ColorMask
[ACOMP
]) {
757 _mesa_clear_alpha_buffers(ctx
);
760 /* we can't handle color or index masking */
761 if (*colorMask
== 0xffffffff && ctx
->Color
.IndexMask
== 0xffffffff) {
762 if (mask
& DD_FRONT_LEFT_BIT
) {
763 ASSERT(xmesa
->xm_buffer
->front_clear_func
);
764 (*xmesa
->xm_buffer
->front_clear_func
)( ctx
, all
, x
, y
, width
, height
);
765 mask
&= ~DD_FRONT_LEFT_BIT
;
767 if (mask
& DD_BACK_LEFT_BIT
) {
768 ASSERT(xmesa
->xm_buffer
->back_clear_func
);
769 (*xmesa
->xm_buffer
->back_clear_func
)( ctx
, all
, x
, y
, width
, height
);
770 mask
&= ~DD_BACK_LEFT_BIT
;
775 _swrast_Clear( ctx
, mask
, all
, x
, y
, width
, height
);
780 resize_buffers( GLcontext
*ctx
)
782 _swrast_alloc_buffers( ctx
);
787 * This function implements glDrawPixels() with an XPutImage call when
788 * drawing to the front buffer (X Window drawable).
789 * The image format must be GL_BGRA to match the PF_8R8G8B pixel format.
790 * XXX top/bottom edge clipping is broken!
793 drawpixels_8R8G8B( GLcontext
*ctx
,
794 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
795 GLenum format
, GLenum type
,
796 const struct gl_pixelstore_attrib
*unpack
,
797 const GLvoid
*pixels
)
799 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
800 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
801 XMesaDrawable buffer
= xmesa
->xm_buffer
->buffer
;
802 XMesaGC gc
= xmesa
->xm_buffer
->gc
;
807 /* XXX also check for pixel scale/bias/lookup/zooming! */
808 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
) {
813 int srcX
= unpack
->SkipPixels
;
814 int srcY
= unpack
->SkipRows
;
815 if (_mesa_clip_pixelrect(ctx
, &dstX
, &dstY
, &w
, &h
, &srcX
, &srcY
)) {
817 MEMSET(&ximage
, 0, sizeof(XMesaImage
));
818 ximage
.width
= width
;
819 ximage
.height
= height
;
820 ximage
.format
= ZPixmap
;
821 ximage
.data
= (char *) pixels
+ (height
- 1) * width
* 4;
822 ximage
.byte_order
= LSBFirst
;
823 ximage
.bitmap_unit
= 32;
824 ximage
.bitmap_bit_order
= LSBFirst
;
825 ximage
.bitmap_pad
= 32;
827 ximage
.bytes_per_line
= -width
* 4;
828 ximage
.bits_per_pixel
= 32;
829 ximage
.red_mask
= 0xff0000;
830 ximage
.green_mask
= 0x00ff00;
831 ximage
.blue_mask
= 0x0000ff;
832 dstY
= FLIP(xmesa
->xm_buffer
,dstY
) - height
+ 1;
833 XPutImage(dpy
, buffer
, gc
, &ximage
, srcX
, srcY
, dstX
, dstY
, w
, h
);
843 static const GLubyte
*
844 get_string( GLcontext
*ctx
, GLenum name
)
850 return (const GLubyte
*) "Mesa GLX Indirect";
852 return (const GLubyte
*) "Mesa X11";
856 return (const GLubyte
*) "VA Linux Systems, Inc.";
867 enable( GLcontext
*ctx
, GLenum pname
, GLboolean state
)
869 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
874 xmesa
->pixelformat
= xmesa
->xm_visual
->dithered_pf
;
876 xmesa
->pixelformat
= xmesa
->xm_visual
->undithered_pf
;
879 ; /* silence compiler warning */
884 void xmesa_update_state( GLcontext
*ctx
, GLuint new_state
)
886 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
888 /* Propogate statechange information to swrast and swrast_setup
889 * modules. The X11 driver has no internal GL-dependent state.
891 _swrast_InvalidateState( ctx
, new_state
);
892 _ac_InvalidateState( ctx
, new_state
);
893 _tnl_InvalidateState( ctx
, new_state
);
894 _swsetup_InvalidateState( ctx
, new_state
);
897 /* setup pointers to front and back buffer clear functions */
898 xmesa
->xm_buffer
->front_clear_func
= clear_front_pixmap
;
899 if (xmesa
->xm_buffer
->backpixmap
!= XIMAGE
) {
900 xmesa
->xm_buffer
->back_clear_func
= clear_back_pixmap
;
902 else if (sizeof(GLushort
)!=2 || sizeof(GLuint
)!=4) {
903 xmesa
->xm_buffer
->back_clear_func
= clear_nbit_ximage
;
905 else switch (xmesa
->xm_visual
->BitsPerPixel
) {
907 if (xmesa
->xm_visual
->hpcr_clear_flag
) {
908 xmesa
->xm_buffer
->back_clear_func
= clear_HPCR_ximage
;
911 xmesa
->xm_buffer
->back_clear_func
= clear_8bit_ximage
;
915 xmesa
->xm_buffer
->back_clear_func
= clear_16bit_ximage
;
918 xmesa
->xm_buffer
->back_clear_func
= clear_24bit_ximage
;
921 xmesa
->xm_buffer
->back_clear_func
= clear_32bit_ximage
;
924 xmesa
->xm_buffer
->back_clear_func
= clear_nbit_ximage
;
928 xmesa_update_span_funcs(ctx
);
933 /* Setup pointers and other driver state that is constant for the life
936 void xmesa_init_pointers( GLcontext
*ctx
)
940 ctx
->Driver
.GetString
= get_string
;
941 ctx
->Driver
.GetBufferSize
= get_buffer_size
;
942 ctx
->Driver
.Flush
= flush
;
943 ctx
->Driver
.Finish
= finish
;
945 /* Software rasterizer pixel paths:
947 ctx
->Driver
.Accum
= _swrast_Accum
;
948 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
949 ctx
->Driver
.Clear
= clear_buffers
;
950 ctx
->Driver
.ResizeBuffersMESA
= resize_buffers
;
951 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
952 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
953 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;
955 /* Software texture functions:
957 ctx
->Driver
.ChooseTextureFormat
= _mesa_choose_tex_format
;
958 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
959 ctx
->Driver
.TexImage2D
= _mesa_store_teximage2d
;
960 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
961 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
962 ctx
->Driver
.TexSubImage2D
= _mesa_store_texsubimage2d
;
963 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
964 ctx
->Driver
.TestProxyTexImage
= _mesa_test_proxy_teximage
;
966 ctx
->Driver
.CopyTexImage1D
= _swrast_copy_teximage1d
;
967 ctx
->Driver
.CopyTexImage2D
= _swrast_copy_teximage2d
;
968 ctx
->Driver
.CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
969 ctx
->Driver
.CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
970 ctx
->Driver
.CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
973 /* Swrast hooks for imaging extensions:
975 ctx
->Driver
.CopyColorTable
= _swrast_CopyColorTable
;
976 ctx
->Driver
.CopyColorSubTable
= _swrast_CopyColorSubTable
;
977 ctx
->Driver
.CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
978 ctx
->Driver
.CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
981 /* Statechange callbacks:
983 ctx
->Driver
.SetDrawBuffer
= set_draw_buffer
;
984 ctx
->Driver
.ClearIndex
= clear_index
;
985 ctx
->Driver
.ClearColor
= clear_color
;
986 ctx
->Driver
.IndexMask
= index_mask
;
987 ctx
->Driver
.ColorMask
= color_mask
;
988 ctx
->Driver
.Enable
= enable
;
991 /* Initialize the TNL driver interface:
993 tnl
= TNL_CONTEXT(ctx
);
994 tnl
->Driver
.RunPipeline
= _tnl_run_pipeline
;
995 tnl
->Driver
.RenderStart
= _swsetup_RenderStart
;
996 tnl
->Driver
.RenderFinish
= _swsetup_RenderFinish
;
997 tnl
->Driver
.BuildProjectedVertices
= _swsetup_BuildProjectedVertices
;
998 tnl
->Driver
.RenderPrimitive
= _swsetup_RenderPrimitive
;
999 tnl
->Driver
.PointsFunc
= _swsetup_Points
;
1000 tnl
->Driver
.LineFunc
= _swsetup_Line
;
1001 tnl
->Driver
.TriangleFunc
= _swsetup_Triangle
;
1002 tnl
->Driver
.QuadFunc
= _swsetup_Quad
;
1003 tnl
->Driver
.ResetLineStipple
= _swrast_ResetLineStipple
;
1004 tnl
->Driver
.RenderInterp
= _swsetup_RenderInterp
;
1005 tnl
->Driver
.RenderCopyPV
= _swsetup_RenderCopyPV
;
1006 tnl
->Driver
.RenderClippedLine
= _swsetup_RenderClippedLine
;
1007 tnl
->Driver
.RenderClippedPolygon
= _swsetup_RenderClippedPolygon
;
1009 (void) DitherValues
; /* silenced unused var warning */