2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 #include "glxheader.h"
31 #include "extensions.h"
39 #include "texformat.h"
41 #include "array_cache/acache.h"
42 #include "swrast/s_context.h"
43 #include "swrast/swrast.h"
44 #include "swrast/s_alphabuf.h"
45 #include "swrast_setup/swrast_setup.h"
47 #include "tnl/t_context.h"
48 #include "tnl/t_pipeline.h"
52 * Return the size (width, height) of the X window for the given GLframebuffer.
53 * Output: width - width of buffer in pixels.
54 * height - height of buffer in pixels.
57 get_buffer_size( GLframebuffer
*buffer
, GLuint
*width
, GLuint
*height
)
59 /* We can do this cast because the first field in the XMesaBuffer
60 * struct is a GLframebuffer struct. If this weren't true, we'd
61 * need a pointer from the GLframebuffer to the XMesaBuffer.
63 const XMesaBuffer xmBuffer
= (XMesaBuffer
) buffer
;
64 unsigned int winwidth
, winheight
;
66 /* XFree86 GLX renderer */
67 if (xmBuffer
->frontbuffer
->width
> MAX_WIDTH
||
68 xmBuffer
->frontbuffer
->height
> MAX_HEIGHT
) {
69 winwidth
= buffer
->Width
;
70 winheight
= buffer
->Height
;
72 winwidth
= xmBuffer
->frontbuffer
->width
;
73 winheight
= xmBuffer
->frontbuffer
->height
;
80 _glthread_LOCK_MUTEX(_xmesa_lock
);
81 XSync(xmBuffer
->xm_visual
->display
, 0); /* added for Chromium */
82 XGetGeometry( xmBuffer
->xm_visual
->display
, xmBuffer
->frontbuffer
, &root
,
83 &winx
, &winy
, &winwidth
, &winheight
, &bw
, &d
);
84 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
87 (void)kernel8
; /* Muffle compiler */
95 finish( GLcontext
*ctx
)
100 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
102 _glthread_LOCK_MUTEX(_xmesa_lock
);
103 XSync( xmesa
->display
, False
);
104 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
111 flush( GLcontext
*ctx
)
116 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
118 _glthread_LOCK_MUTEX(_xmesa_lock
);
119 XFlush( xmesa
->display
);
120 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
128 * This chooses the color buffer for reading and writing spans, points,
129 * lines, and triangles.
132 set_buffer( GLcontext
*ctx
, GLframebuffer
*buffer
, GLuint bufferBit
)
134 /* We can make this cast since the XMesaBuffer wraps GLframebuffer.
135 * GLframebuffer is the first member in a XMesaBuffer struct.
137 XMesaBuffer target
= (XMesaBuffer
) buffer
;
138 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
140 /* This assignment tells the span/point/line/triangle functions
141 * which XMesaBuffer to use.
143 xmesa
->xm_buffer
= target
;
146 * Now determine front vs back color buffer.
148 if (bufferBit
== FRONT_LEFT_BIT
) {
149 target
->buffer
= target
->frontbuffer
;
151 else if (bufferBit
== BACK_LEFT_BIT
) {
152 ASSERT(target
->db_state
);
153 if (target
->backpixmap
) {
154 /* back buffer is a pixmape */
155 target
->buffer
= target
->backpixmap
; /* incompatible types? */
157 else if (target
->backimage
) {
158 /* back buffer is an XImage */
159 target
->buffer
= None
;
162 /* No back buffer!!!! Must be out of memory, use front buffer */
163 target
->buffer
= target
->frontbuffer
;
167 _mesa_problem(ctx
, "invalid buffer 0x%x in set_buffer() in xm_dd.c");
170 xmesa_update_span_funcs(ctx
);
176 clear_index( GLcontext
*ctx
, GLuint index
)
178 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
179 xmesa
->clearpixel
= (unsigned long) index
;
180 XMesaSetForeground( xmesa
->display
, xmesa
->xm_draw_buffer
->cleargc
,
181 (unsigned long) index
);
186 clear_color( GLcontext
*ctx
, const GLfloat color
[4] )
188 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
189 CLAMPED_FLOAT_TO_UBYTE(xmesa
->clearcolor
[0], color
[0]);
190 CLAMPED_FLOAT_TO_UBYTE(xmesa
->clearcolor
[1], color
[1]);
191 CLAMPED_FLOAT_TO_UBYTE(xmesa
->clearcolor
[2], color
[2]);
192 CLAMPED_FLOAT_TO_UBYTE(xmesa
->clearcolor
[3], color
[3]);
193 xmesa
->clearpixel
= xmesa_color_to_pixel( xmesa
,
194 xmesa
->clearcolor
[0],
195 xmesa
->clearcolor
[1],
196 xmesa
->clearcolor
[2],
197 xmesa
->clearcolor
[3],
198 xmesa
->xm_visual
->undithered_pf
);
199 _glthread_LOCK_MUTEX(_xmesa_lock
);
200 XMesaSetForeground( xmesa
->display
, xmesa
->xm_draw_buffer
->cleargc
,
202 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
207 /* Set index mask ala glIndexMask */
209 index_mask( GLcontext
*ctx
, GLuint mask
)
211 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
212 if (xmesa
->xm_draw_buffer
->buffer
!= XIMAGE
) {
214 if (mask
==0xffffffff) {
215 m
= ((unsigned long)~0L);
218 m
= (unsigned long) mask
;
220 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_draw_buffer
->cleargc
, m
);
221 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_draw_buffer
->gc
, m
);
226 /* Implements glColorMask() */
228 color_mask(GLcontext
*ctx
,
229 GLboolean rmask
, GLboolean gmask
, GLboolean bmask
, GLboolean amask
)
231 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
232 int xclass
= GET_VISUAL_CLASS(xmesa
->xm_visual
);
235 if (xclass
== TrueColor
|| xclass
== DirectColor
) {
237 if (rmask
&& gmask
&& bmask
) {
238 m
= ((unsigned long)~0L);
242 if (rmask
) m
|= GET_REDMASK(xmesa
->xm_visual
);
243 if (gmask
) m
|= GET_GREENMASK(xmesa
->xm_visual
);
244 if (bmask
) m
|= GET_BLUEMASK(xmesa
->xm_visual
);
246 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_draw_buffer
->cleargc
, m
);
247 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_draw_buffer
->gc
, m
);
253 /**********************************************************************/
254 /*** glClear implementations ***/
255 /**********************************************************************/
259 clear_front_pixmap( GLcontext
*ctx
, GLboolean all
,
260 GLint x
, GLint y
, GLint width
, GLint height
)
262 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
264 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_draw_buffer
->frontbuffer
,
265 xmesa
->xm_draw_buffer
->cleargc
,
267 xmesa
->xm_draw_buffer
->width
+1,
268 xmesa
->xm_draw_buffer
->height
+1 );
271 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_draw_buffer
->frontbuffer
,
272 xmesa
->xm_draw_buffer
->cleargc
,
273 x
, xmesa
->xm_draw_buffer
->height
- y
- height
,
280 clear_back_pixmap( GLcontext
*ctx
, GLboolean all
,
281 GLint x
, GLint y
, GLint width
, GLint height
)
283 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
285 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_draw_buffer
->backpixmap
,
286 xmesa
->xm_draw_buffer
->cleargc
,
288 xmesa
->xm_draw_buffer
->width
+1,
289 xmesa
->xm_draw_buffer
->height
+1 );
292 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_draw_buffer
->backpixmap
,
293 xmesa
->xm_draw_buffer
->cleargc
,
294 x
, xmesa
->xm_draw_buffer
->height
- y
- height
,
301 clear_8bit_ximage( GLcontext
*ctx
, GLboolean all
,
302 GLint x
, GLint y
, GLint width
, GLint height
)
304 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
306 size_t n
= xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
307 * xmesa
->xm_draw_buffer
->backimage
->height
;
308 MEMSET( xmesa
->xm_draw_buffer
->backimage
->data
, xmesa
->clearpixel
, n
);
312 for (i
=0;i
<height
;i
++) {
313 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_draw_buffer
, x
, y
+i
);
314 MEMSET( ptr
, xmesa
->clearpixel
, width
);
321 clear_HPCR_ximage( GLcontext
*ctx
, GLboolean all
,
322 GLint x
, GLint y
, GLint width
, GLint height
)
324 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
326 GLint i
, c16
= (xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
>>4)<<4;
327 GLubyte
*ptr
= (GLubyte
*)xmesa
->xm_draw_buffer
->backimage
->data
;
328 for (i
=0; i
<xmesa
->xm_draw_buffer
->backimage
->height
; i
++) {
330 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
334 for (j
=0; j
<c16
; j
+=16) {
353 for (; j
<xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
; j
++) {
361 for (i
=y
; i
<y
+height
; i
++) {
362 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_draw_buffer
, x
, i
);
364 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
368 for (j
=x
; j
<x
+width
; j
++) {
378 clear_16bit_ximage( GLcontext
*ctx
, GLboolean all
,
379 GLint x
, GLint y
, GLint width
, GLint height
)
381 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
382 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
383 if (xmesa
->swapbytes
) {
384 pixel
= ((pixel
>> 8) & 0x00ff) | ((pixel
<< 8) & 0xff00);
388 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_draw_buffer
->backimage
->data
;
389 if ((pixel
& 0xff) == ((pixel
>> 8) & 0xff)) {
390 /* low and high bytes are equal so use memset() */
391 n
= xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
392 * xmesa
->xm_draw_buffer
->height
;
393 MEMSET( ptr4
, pixel
& 0xff, n
);
396 pixel
= pixel
| (pixel
<<16);
397 n
= xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
398 * xmesa
->xm_draw_buffer
->height
/ 4;
404 if ((xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
*
405 xmesa
->xm_draw_buffer
->height
) & 0x2)
406 *(GLushort
*)ptr4
= pixel
& 0xffff;
411 for (j
=0;j
<height
;j
++) {
412 register GLushort
*ptr2
= PIXELADDR2( xmesa
->xm_draw_buffer
, x
, y
+j
);
413 for (i
=0;i
<width
;i
++) {
421 /* Optimized code provided by Nozomi Ytow <noz@xfree86.org> */
423 clear_24bit_ximage( GLcontext
*ctx
, GLboolean all
,
424 GLint x
, GLint y
, GLint width
, GLint height
)
426 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
427 const GLubyte r
= xmesa
->clearcolor
[0];
428 const GLubyte g
= xmesa
->clearcolor
[1];
429 const GLubyte b
= xmesa
->clearcolor
[2];
430 register GLuint clearPixel
;
431 if (xmesa
->swapbytes
) {
432 clearPixel
= (b
<< 16) | (g
<< 8) | r
;
435 clearPixel
= (r
<< 16) | (g
<< 8) | b
;
440 /* same value for all three components (gray) */
441 const GLint w3
= xmesa
->xm_draw_buffer
->width
* 3;
442 const GLint h
= xmesa
->xm_draw_buffer
->height
;
444 for (i
= 0; i
< h
; i
++) {
445 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_draw_buffer
, 0, i
);
451 const GLint w
= xmesa
->xm_draw_buffer
->width
;
452 const GLint h
= xmesa
->xm_draw_buffer
->height
;
454 for (i
= 0; i
< h
; i
++) {
455 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_draw_buffer
, 0, i
);
456 for (j
= 0; j
< w
; j
++) {
463 #if 0 /* this code doesn't work for all window widths */
464 register GLuint
*ptr4
= (GLuint
*) ptr3
;
467 register GLuint
*p
= pixel4
;
468 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
469 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
470 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
471 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
475 px
= *ptr4
& 0x00ffffff;
476 px
|= pixel4
[0] & 0xff000000;
478 px
= *ptr4
& 0xffff0000;
479 px
|= pixel4
[2] & 0x0000ffff;
484 px
= *ptr4
& 0x0000fffff;
485 px
|= pixel4
[1] & 0xffff0000;
487 px
= *ptr4
& 0xffffff00;
488 px
|= pixel4
[2] & 0x000000ff;
493 px
= *ptr4
& 0x000000ff;
494 px
|= pixel4
[2] & 0xffffff00;
511 px
= *ptr4
& 0xffffff00;
512 px
|= clearPixel
& 0xff;
518 px
= *ptr4
& 0xffff0000;
523 px
= *ptr4
& 0xff000000;
534 /* only clear subrect of color buffer */
536 /* same value for all three components (gray) */
538 for (j
=0;j
<height
;j
++) {
539 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_draw_buffer
, x
, y
+j
);
540 MEMSET(ptr3
, r
, 3 * width
);
544 /* non-gray clear color */
546 for (j
= 0; j
< height
; j
++) {
547 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_draw_buffer
, x
, y
+j
);
548 for (i
= 0; i
< width
; i
++) {
555 #if 0 /* this code might not always (seems ptr3 always == ptr4) */
558 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
559 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
560 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
561 for (j
=0;j
<height
;j
++) {
562 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_draw_buffer
, x
, y
+j
);
563 register GLuint
*ptr4
= (GLuint
*)ptr3
;
564 register GLuint
*p
, px
;
566 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
570 px
= *ptr4
& 0x00ffffff;
571 px
|= pixel4
[0] & 0xff000000;
573 px
= *ptr4
& 0xffff0000;
574 px
|= pixel4
[2] & 0x0000ffff;
579 px
= *ptr4
& 0x0000fffff;
580 px
|= pixel4
[1] & 0xffff0000;
582 px
= *ptr4
& 0xffffff00;
583 px
|= pixel4
[2] & 0x000000ff;
588 px
= *ptr4
& 0x000000ff;
589 px
|= pixel4
[2] & 0xffffff00;
606 px
= *ptr4
& 0xffffff00;
613 px
= *ptr4
& 0xffff0000;
618 px
= *ptr4
& 0xff000000;
619 px
|= pixel4
[0] & 0xffffff;
633 clear_32bit_ximage( GLcontext
*ctx
, GLboolean all
,
634 GLint x
, GLint y
, GLint width
, GLint height
)
636 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
637 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
638 if (xmesa
->swapbytes
) {
639 pixel
= ((pixel
>> 24) & 0x000000ff)
640 | ((pixel
>> 8) & 0x0000ff00)
641 | ((pixel
<< 8) & 0x00ff0000)
642 | ((pixel
<< 24) & 0xff000000);
645 register GLint n
= xmesa
->xm_draw_buffer
->width
* xmesa
->xm_draw_buffer
->height
;
646 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_draw_buffer
->backimage
->data
;
648 MEMSET( ptr4
, pixel
, 4*n
);
659 for (j
=0;j
<height
;j
++) {
660 register GLuint
*ptr4
= PIXELADDR4( xmesa
->xm_draw_buffer
, x
, y
+j
);
661 for (i
=0;i
<width
;i
++) {
670 clear_nbit_ximage( GLcontext
*ctx
, GLboolean all
,
671 GLint x
, GLint y
, GLint width
, GLint height
)
673 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
674 XMesaImage
*img
= xmesa
->xm_draw_buffer
->backimage
;
677 width
= xmesa
->xm_draw_buffer
->width
;
678 height
= xmesa
->xm_draw_buffer
->height
;
679 for (j
=0;j
<height
;j
++) {
680 for (i
=0;i
<width
;i
++) {
681 XMesaPutPixel( img
, i
, j
, xmesa
->clearpixel
);
686 /* TODO: optimize this */
688 y
= FLIP(xmesa
->xm_draw_buffer
, y
);
689 for (j
=0;j
<height
;j
++) {
690 for (i
=0;i
<width
;i
++) {
691 XMesaPutPixel( img
, x
+i
, y
-j
, xmesa
->clearpixel
);
700 clear_buffers( GLcontext
*ctx
, GLbitfield mask
,
701 GLboolean all
, GLint x
, GLint y
, GLint width
, GLint height
)
703 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
704 const GLuint
*colorMask
= (GLuint
*) &ctx
->Color
.ColorMask
;
706 if ((mask
& (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
)) &&
707 xmesa
->xm_draw_buffer
->mesa_buffer
.UseSoftwareAlphaBuffers
&&
708 ctx
->Color
.ColorMask
[ACOMP
]) {
709 _swrast_clear_alpha_buffers(ctx
);
712 /* we can't handle color or index masking */
713 if (*colorMask
== 0xffffffff && ctx
->Color
.IndexMask
== 0xffffffff) {
714 if (mask
& DD_FRONT_LEFT_BIT
) {
715 ASSERT(xmesa
->xm_draw_buffer
->front_clear_func
);
716 (*xmesa
->xm_draw_buffer
->front_clear_func
)( ctx
, all
, x
, y
, width
, height
);
717 mask
&= ~DD_FRONT_LEFT_BIT
;
719 if (mask
& DD_BACK_LEFT_BIT
) {
720 ASSERT(xmesa
->xm_draw_buffer
->back_clear_func
);
721 (*xmesa
->xm_draw_buffer
->back_clear_func
)( ctx
, all
, x
, y
, width
, height
);
722 mask
&= ~DD_BACK_LEFT_BIT
;
727 _swrast_Clear( ctx
, mask
, all
, x
, y
, width
, height
);
732 * When we detect that the user has resized the window this function will
733 * get called. Here we'll reallocate the back buffer, depth buffer,
734 * stencil buffer etc. to match the new window size.
737 xmesa_resize_buffers( GLframebuffer
*buffer
)
739 int height
= (int) buffer
->Height
;
740 /* We can do this cast because the first field in the XMesaBuffer
741 * struct is a GLframebuffer struct. If this weren't true, we'd
742 * need a pointer from the GLframebuffer to the XMesaBuffer.
744 XMesaBuffer xmBuffer
= (XMesaBuffer
) buffer
;
746 xmBuffer
->width
= buffer
->Width
;
747 xmBuffer
->height
= buffer
->Height
;
748 xmesa_alloc_back_buffer( xmBuffer
);
750 /* Needed by FLIP macro */
751 xmBuffer
->bottom
= height
- 1;
753 if (xmBuffer
->backimage
) {
754 /* Needed by PIXELADDR1 macro */
755 xmBuffer
->ximage_width1
= xmBuffer
->backimage
->bytes_per_line
;
756 xmBuffer
->ximage_origin1
= (GLubyte
*) xmBuffer
->backimage
->data
757 + xmBuffer
->ximage_width1
* (height
-1);
759 /* Needed by PIXELADDR2 macro */
760 xmBuffer
->ximage_width2
= xmBuffer
->backimage
->bytes_per_line
/ 2;
761 xmBuffer
->ximage_origin2
= (GLushort
*) xmBuffer
->backimage
->data
762 + xmBuffer
->ximage_width2
* (height
-1);
764 /* Needed by PIXELADDR3 macro */
765 xmBuffer
->ximage_width3
= xmBuffer
->backimage
->bytes_per_line
;
766 xmBuffer
->ximage_origin3
= (GLubyte
*) xmBuffer
->backimage
->data
767 + xmBuffer
->ximage_width3
* (height
-1);
769 /* Needed by PIXELADDR4 macro */
770 xmBuffer
->ximage_width4
= xmBuffer
->backimage
->width
;
771 xmBuffer
->ximage_origin4
= (GLuint
*) xmBuffer
->backimage
->data
772 + xmBuffer
->ximage_width4
* (height
-1);
775 _swrast_alloc_buffers( buffer
);
780 * This function implements glDrawPixels() with an XPutImage call when
781 * drawing to the front buffer (X Window drawable).
782 * The image format must be GL_BGRA to match the PF_8R8G8B pixel format.
783 * XXX top/bottom edge clipping is broken!
786 drawpixels_8R8G8B( GLcontext
*ctx
,
787 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
788 GLenum format
, GLenum type
,
789 const struct gl_pixelstore_attrib
*unpack
,
790 const GLvoid
*pixels
)
792 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
793 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
794 XMesaDrawable buffer
= xmesa
->xm_draw_buffer
->buffer
;
795 XMesaGC gc
= xmesa
->xm_draw_buffer
->gc
;
800 /* XXX also check for pixel scale/bias/lookup/zooming! */
801 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
) {
806 int srcX
= unpack
->SkipPixels
;
807 int srcY
= unpack
->SkipRows
;
808 if (_mesa_clip_pixelrect(ctx
, &dstX
, &dstY
, &w
, &h
, &srcX
, &srcY
)) {
810 MEMSET(&ximage
, 0, sizeof(XMesaImage
));
811 ximage
.width
= width
;
812 ximage
.height
= height
;
813 ximage
.format
= ZPixmap
;
814 ximage
.data
= (char *) pixels
+ (height
- 1) * width
* 4;
815 ximage
.byte_order
= LSBFirst
;
816 ximage
.bitmap_unit
= 32;
817 ximage
.bitmap_bit_order
= LSBFirst
;
818 ximage
.bitmap_pad
= 32;
820 ximage
.bytes_per_line
= -width
* 4;
821 ximage
.bits_per_pixel
= 32;
822 ximage
.red_mask
= 0xff0000;
823 ximage
.green_mask
= 0x00ff00;
824 ximage
.blue_mask
= 0x0000ff;
825 dstY
= FLIP(xmesa
->xm_draw_buffer
,dstY
) - height
+ 1;
826 XPutImage(dpy
, buffer
, gc
, &ximage
, srcX
, srcY
, dstX
, dstY
, w
, h
);
836 static const GLubyte
*
837 get_string( GLcontext
*ctx
, GLenum name
)
843 return (const GLubyte
*) "Mesa GLX Indirect";
845 return (const GLubyte
*) "Mesa X11";
849 return (const GLubyte
*) "Mesa project: www.mesa3d.org";
860 enable( GLcontext
*ctx
, GLenum pname
, GLboolean state
)
862 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
867 xmesa
->pixelformat
= xmesa
->xm_visual
->dithered_pf
;
869 xmesa
->pixelformat
= xmesa
->xm_visual
->undithered_pf
;
872 ; /* silence compiler warning */
877 void xmesa_update_state( GLcontext
*ctx
, GLuint new_state
)
879 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
881 /* Propogate statechange information to swrast and swrast_setup
882 * modules. The X11 driver has no internal GL-dependent state.
884 _swrast_InvalidateState( ctx
, new_state
);
885 _ac_InvalidateState( ctx
, new_state
);
886 _tnl_InvalidateState( ctx
, new_state
);
887 _swsetup_InvalidateState( ctx
, new_state
);
890 /* setup pointers to front and back buffer clear functions */
891 xmesa
->xm_draw_buffer
->front_clear_func
= clear_front_pixmap
;
892 if (xmesa
->xm_draw_buffer
->backpixmap
!= XIMAGE
) {
893 xmesa
->xm_draw_buffer
->back_clear_func
= clear_back_pixmap
;
895 else if (sizeof(GLushort
)!=2 || sizeof(GLuint
)!=4) {
896 xmesa
->xm_draw_buffer
->back_clear_func
= clear_nbit_ximage
;
898 else switch (xmesa
->xm_visual
->BitsPerPixel
) {
900 if (xmesa
->xm_visual
->hpcr_clear_flag
) {
901 xmesa
->xm_draw_buffer
->back_clear_func
= clear_HPCR_ximage
;
904 xmesa
->xm_draw_buffer
->back_clear_func
= clear_8bit_ximage
;
908 xmesa
->xm_draw_buffer
->back_clear_func
= clear_16bit_ximage
;
911 xmesa
->xm_draw_buffer
->back_clear_func
= clear_24bit_ximage
;
914 xmesa
->xm_draw_buffer
->back_clear_func
= clear_32bit_ximage
;
917 xmesa
->xm_draw_buffer
->back_clear_func
= clear_nbit_ximage
;
921 xmesa_update_span_funcs(ctx
);
927 * Called via ctx->Driver.TestProxyTeximage(). Normally, we'd just use
928 * the _mesa_test_proxy_teximage() fallback function, but we're going to
929 * special-case the 3D texture case to allow textures up to 512x512x32
933 test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
934 GLint internalFormat
, GLenum format
, GLenum type
,
935 GLint width
, GLint height
, GLint depth
, GLint border
)
937 if (target
== GL_PROXY_TEXTURE_3D
) {
938 /* special case for 3D textures */
939 if (width
* height
* depth
> 512 * 512 * 64 ||
940 width
< 2 * border
||
941 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
942 _mesa_bitcount(width
- 2 * border
) != 1) ||
943 height
< 2 * border
||
944 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
945 _mesa_bitcount(height
- 2 * border
) != 1) ||
946 depth
< 2 * border
||
947 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
948 _mesa_bitcount(depth
- 2 * border
) != 1)) {
949 /* Bad size, or too many texels */
955 /* use the fallback routine for 1D, 2D, cube and rect targets */
956 return _mesa_test_proxy_teximage(ctx
, target
, level
, internalFormat
,
957 format
, type
, width
, height
, depth
,
965 /* Setup pointers and other driver state that is constant for the life
968 void xmesa_init_pointers( GLcontext
*ctx
)
971 struct swrast_device_driver
*dd
= _swrast_GetDeviceDriverReference( ctx
);
973 ctx
->Driver
.GetString
= get_string
;
974 ctx
->Driver
.GetBufferSize
= get_buffer_size
;
975 ctx
->Driver
.Flush
= flush
;
976 ctx
->Driver
.Finish
= finish
;
978 /* Software rasterizer pixel paths:
980 ctx
->Driver
.Accum
= _swrast_Accum
;
981 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
982 ctx
->Driver
.Clear
= clear_buffers
;
983 ctx
->Driver
.ResizeBuffers
= xmesa_resize_buffers
;
984 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
985 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
986 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;
987 ctx
->Driver
.DrawBuffer
= _swrast_DrawBuffer
;
989 /* Software texture functions:
991 ctx
->Driver
.ChooseTextureFormat
= _mesa_choose_tex_format
;
992 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
993 ctx
->Driver
.TexImage2D
= _mesa_store_teximage2d
;
994 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
995 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
996 ctx
->Driver
.TexSubImage2D
= _mesa_store_texsubimage2d
;
997 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
998 ctx
->Driver
.TestProxyTexImage
= test_proxy_teximage
;
1000 ctx
->Driver
.CopyTexImage1D
= _swrast_copy_teximage1d
;
1001 ctx
->Driver
.CopyTexImage2D
= _swrast_copy_teximage2d
;
1002 ctx
->Driver
.CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
1003 ctx
->Driver
.CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
1004 ctx
->Driver
.CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
1006 ctx
->Driver
.CompressedTexImage1D
= _mesa_store_compressed_teximage1d
;
1007 ctx
->Driver
.CompressedTexImage2D
= _mesa_store_compressed_teximage2d
;
1008 ctx
->Driver
.CompressedTexImage3D
= _mesa_store_compressed_teximage3d
;
1009 ctx
->Driver
.CompressedTexSubImage1D
= _mesa_store_compressed_texsubimage1d
;
1010 ctx
->Driver
.CompressedTexSubImage2D
= _mesa_store_compressed_texsubimage2d
;
1011 ctx
->Driver
.CompressedTexSubImage3D
= _mesa_store_compressed_texsubimage3d
;
1013 /* Swrast hooks for imaging extensions:
1015 ctx
->Driver
.CopyColorTable
= _swrast_CopyColorTable
;
1016 ctx
->Driver
.CopyColorSubTable
= _swrast_CopyColorSubTable
;
1017 ctx
->Driver
.CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
1018 ctx
->Driver
.CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
1021 /* Statechange callbacks:
1023 ctx
->Driver
.ClearIndex
= clear_index
;
1024 ctx
->Driver
.ClearColor
= clear_color
;
1025 ctx
->Driver
.IndexMask
= index_mask
;
1026 ctx
->Driver
.ColorMask
= color_mask
;
1027 ctx
->Driver
.Enable
= enable
;
1030 /* Initialize the TNL driver interface:
1032 tnl
= TNL_CONTEXT(ctx
);
1033 tnl
->Driver
.RunPipeline
= _tnl_run_pipeline
;
1035 dd
->SetBuffer
= set_buffer
;
1037 /* Install swsetup for tnl->Driver.Render.*:
1039 _swsetup_Wakeup(ctx
);
1041 (void) DitherValues
; /* silenced unused var warning */
1048 #define XMESA_NEW_POINT (_NEW_POINT | \
1050 _SWRAST_NEW_RASTERMASK)
1052 #define XMESA_NEW_LINE (_NEW_LINE | \
1057 _SWRAST_NEW_RASTERMASK)
1059 #define XMESA_NEW_TRIANGLE (_NEW_POLYGON | \
1064 _SWRAST_NEW_RASTERMASK)
1067 /* Extend the software rasterizer with our line/point/triangle
1070 void xmesa_register_swrast_functions( GLcontext
*ctx
)
1072 SWcontext
*swrast
= SWRAST_CONTEXT( ctx
);
1074 swrast
->choose_point
= xmesa_choose_point
;
1075 swrast
->choose_line
= xmesa_choose_line
;
1076 swrast
->choose_triangle
= xmesa_choose_triangle
;
1078 swrast
->invalidate_point
|= XMESA_NEW_POINT
;
1079 swrast
->invalidate_line
|= XMESA_NEW_LINE
;
1080 swrast
->invalidate_triangle
|= XMESA_NEW_TRIANGLE
;