2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 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"
27 #include "bufferobj.h"
32 #include "extensions.h"
40 #include "texformat.h"
42 #include "array_cache/acache.h"
43 #include "swrast/swrast.h"
44 #include "swrast/s_context.h"
45 #include "swrast/s_drawpix.h"
46 #include "swrast/s_alphabuf.h"
47 #include "swrast_setup/swrast_setup.h"
49 #include "tnl/t_context.h"
52 #include <GL/glxtokens.h>
56 * Return the size (width, height) of the X window for the given GLframebuffer.
57 * Output: width - width of buffer in pixels.
58 * height - height of buffer in pixels.
61 get_buffer_size( GLframebuffer
*buffer
, GLuint
*width
, GLuint
*height
)
63 /* We can do this cast because the first field in the XMesaBuffer
64 * struct is a GLframebuffer struct. If this weren't true, we'd
65 * need a pointer from the GLframebuffer to the XMesaBuffer.
67 const XMesaBuffer xmBuffer
= (XMesaBuffer
) buffer
;
68 unsigned int winwidth
, winheight
;
70 /* XFree86 GLX renderer */
71 if (xmBuffer
->frontbuffer
->width
> MAX_WIDTH
||
72 xmBuffer
->frontbuffer
->height
> MAX_HEIGHT
) {
73 winwidth
= buffer
->Width
;
74 winheight
= buffer
->Height
;
76 winwidth
= xmBuffer
->frontbuffer
->width
;
77 winheight
= xmBuffer
->frontbuffer
->height
;
84 _glthread_LOCK_MUTEX(_xmesa_lock
);
85 XSync(xmBuffer
->xm_visual
->display
, 0); /* added for Chromium */
86 XGetGeometry( xmBuffer
->xm_visual
->display
, xmBuffer
->frontbuffer
, &root
,
87 &winx
, &winy
, &winwidth
, &winheight
, &bw
, &d
);
88 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
91 (void)kernel8
; /* Muffle compiler */
99 finish_or_flush( GLcontext
*ctx
)
104 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
106 _glthread_LOCK_MUTEX(_xmesa_lock
);
107 XSync( xmesa
->display
, False
);
108 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
116 * This chooses the color buffer for reading and writing spans, points,
117 * lines, and triangles.
120 xmesa_set_buffer( GLcontext
*ctx
, GLframebuffer
*buffer
, GLuint bufferBit
)
122 /* We can make this cast since the XMesaBuffer wraps GLframebuffer.
123 * GLframebuffer is the first member in a XMesaBuffer struct.
125 XMesaBuffer target
= (XMesaBuffer
) buffer
;
126 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
128 /* This assignment tells the span/point/line/triangle functions
129 * which XMesaBuffer to use.
131 xmesa
->xm_buffer
= target
;
134 * Now determine front vs back color buffer.
136 if (bufferBit
== FRONT_LEFT_BIT
) {
137 target
->buffer
= target
->frontbuffer
;
139 else if (bufferBit
== BACK_LEFT_BIT
) {
140 ASSERT(target
->db_state
);
141 if (target
->backpixmap
) {
142 /* back buffer is a pixmap */
143 target
->buffer
= (XMesaDrawable
) target
->backpixmap
;
145 else if (target
->backimage
) {
146 /* back buffer is an XImage */
147 target
->buffer
= None
;
150 /* No back buffer!!!! Must be out of memory, use front buffer */
151 target
->buffer
= target
->frontbuffer
;
155 _mesa_problem(ctx
, "invalid buffer 0x%x in set_buffer() in xm_dd.c");
158 xmesa_update_span_funcs(ctx
);
164 clear_index( GLcontext
*ctx
, GLuint index
)
166 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
167 xmesa
->clearpixel
= (unsigned long) index
;
168 XMesaSetForeground( xmesa
->display
, xmesa
->xm_draw_buffer
->cleargc
,
169 (unsigned long) index
);
174 clear_color( GLcontext
*ctx
, const GLfloat color
[4] )
176 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
177 CLAMPED_FLOAT_TO_UBYTE(xmesa
->clearcolor
[0], color
[0]);
178 CLAMPED_FLOAT_TO_UBYTE(xmesa
->clearcolor
[1], color
[1]);
179 CLAMPED_FLOAT_TO_UBYTE(xmesa
->clearcolor
[2], color
[2]);
180 CLAMPED_FLOAT_TO_UBYTE(xmesa
->clearcolor
[3], color
[3]);
181 xmesa
->clearpixel
= xmesa_color_to_pixel( xmesa
,
182 xmesa
->clearcolor
[0],
183 xmesa
->clearcolor
[1],
184 xmesa
->clearcolor
[2],
185 xmesa
->clearcolor
[3],
186 xmesa
->xm_visual
->undithered_pf
);
187 _glthread_LOCK_MUTEX(_xmesa_lock
);
188 XMesaSetForeground( xmesa
->display
, xmesa
->xm_draw_buffer
->cleargc
,
190 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
195 /* Set index mask ala glIndexMask */
197 index_mask( GLcontext
*ctx
, GLuint mask
)
199 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
200 if (xmesa
->xm_draw_buffer
->buffer
!= XIMAGE
) {
202 if (mask
==0xffffffff) {
203 m
= ((unsigned long)~0L);
206 m
= (unsigned long) mask
;
208 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_draw_buffer
->cleargc
, m
);
209 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_draw_buffer
->gc
, m
);
214 /* Implements glColorMask() */
216 color_mask(GLcontext
*ctx
,
217 GLboolean rmask
, GLboolean gmask
, GLboolean bmask
, GLboolean amask
)
219 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
220 const int xclass
= xmesa
->xm_visual
->mesa_visual
.visualType
;
223 if (xclass
== GLX_TRUE_COLOR
|| xclass
== GLX_DIRECT_COLOR
) {
225 if (rmask
&& gmask
&& bmask
) {
226 m
= ((unsigned long)~0L);
230 if (rmask
) m
|= GET_REDMASK(xmesa
->xm_visual
);
231 if (gmask
) m
|= GET_GREENMASK(xmesa
->xm_visual
);
232 if (bmask
) m
|= GET_BLUEMASK(xmesa
->xm_visual
);
234 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_draw_buffer
->cleargc
, m
);
235 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_draw_buffer
->gc
, m
);
241 /**********************************************************************/
242 /*** glClear implementations ***/
243 /**********************************************************************/
247 clear_front_pixmap( GLcontext
*ctx
, GLboolean all
,
248 GLint x
, GLint y
, GLint width
, GLint height
)
250 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
252 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_draw_buffer
->frontbuffer
,
253 xmesa
->xm_draw_buffer
->cleargc
,
255 xmesa
->xm_draw_buffer
->width
+1,
256 xmesa
->xm_draw_buffer
->height
+1 );
259 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_draw_buffer
->frontbuffer
,
260 xmesa
->xm_draw_buffer
->cleargc
,
261 x
, xmesa
->xm_draw_buffer
->height
- y
- height
,
268 clear_back_pixmap( GLcontext
*ctx
, GLboolean all
,
269 GLint x
, GLint y
, GLint width
, GLint height
)
271 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
273 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_draw_buffer
->backpixmap
,
274 xmesa
->xm_draw_buffer
->cleargc
,
276 xmesa
->xm_draw_buffer
->width
+1,
277 xmesa
->xm_draw_buffer
->height
+1 );
280 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_draw_buffer
->backpixmap
,
281 xmesa
->xm_draw_buffer
->cleargc
,
282 x
, xmesa
->xm_draw_buffer
->height
- y
- height
,
289 clear_8bit_ximage( GLcontext
*ctx
, GLboolean all
,
290 GLint x
, GLint y
, GLint width
, GLint height
)
292 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
294 size_t n
= xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
295 * xmesa
->xm_draw_buffer
->backimage
->height
;
296 MEMSET( xmesa
->xm_draw_buffer
->backimage
->data
, xmesa
->clearpixel
, n
);
300 for (i
=0;i
<height
;i
++) {
301 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_draw_buffer
, x
, y
+i
);
302 MEMSET( ptr
, xmesa
->clearpixel
, width
);
309 clear_HPCR_ximage( GLcontext
*ctx
, GLboolean all
,
310 GLint x
, GLint y
, GLint width
, GLint height
)
312 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
314 GLint i
, c16
= (xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
>>4)<<4;
315 GLubyte
*ptr
= (GLubyte
*)xmesa
->xm_draw_buffer
->backimage
->data
;
316 for (i
=0; i
<xmesa
->xm_draw_buffer
->backimage
->height
; i
++) {
318 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
322 for (j
=0; j
<c16
; j
+=16) {
341 for (; j
<xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
; j
++) {
349 for (i
=y
; i
<y
+height
; i
++) {
350 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_draw_buffer
, x
, i
);
352 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
356 for (j
=x
; j
<x
+width
; j
++) {
366 clear_16bit_ximage( GLcontext
*ctx
, GLboolean all
,
367 GLint x
, GLint y
, GLint width
, GLint height
)
369 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
370 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
371 if (xmesa
->swapbytes
) {
372 pixel
= ((pixel
>> 8) & 0x00ff) | ((pixel
<< 8) & 0xff00);
376 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_draw_buffer
->backimage
->data
;
377 if ((pixel
& 0xff) == ((pixel
>> 8) & 0xff)) {
378 /* low and high bytes are equal so use memset() */
379 n
= xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
380 * xmesa
->xm_draw_buffer
->height
;
381 MEMSET( ptr4
, pixel
& 0xff, n
);
384 pixel
= pixel
| (pixel
<<16);
385 n
= xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
386 * xmesa
->xm_draw_buffer
->height
/ 4;
392 if ((xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
*
393 xmesa
->xm_draw_buffer
->height
) & 0x2)
394 *(GLushort
*)ptr4
= pixel
& 0xffff;
399 for (j
=0;j
<height
;j
++) {
400 register GLushort
*ptr2
= PIXELADDR2( xmesa
->xm_draw_buffer
, x
, y
+j
);
401 for (i
=0;i
<width
;i
++) {
409 /* Optimized code provided by Nozomi Ytow <noz@xfree86.org> */
411 clear_24bit_ximage( GLcontext
*ctx
, GLboolean all
,
412 GLint x
, GLint y
, GLint width
, GLint height
)
414 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
415 const GLubyte r
= xmesa
->clearcolor
[0];
416 const GLubyte g
= xmesa
->clearcolor
[1];
417 const GLubyte b
= xmesa
->clearcolor
[2];
418 #if 0 /* See below */
419 register GLuint clearPixel
;
420 if (xmesa
->swapbytes
) {
421 clearPixel
= (b
<< 16) | (g
<< 8) | r
;
424 clearPixel
= (r
<< 16) | (g
<< 8) | b
;
430 /* same value for all three components (gray) */
431 const GLint w3
= xmesa
->xm_draw_buffer
->width
* 3;
432 const GLint h
= xmesa
->xm_draw_buffer
->height
;
434 for (i
= 0; i
< h
; i
++) {
435 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_draw_buffer
, 0, i
);
441 const GLint w
= xmesa
->xm_draw_buffer
->width
;
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
);
446 for (j
= 0; j
< w
; j
++) {
453 #if 0 /* this code doesn't work for all window widths */
454 register GLuint
*ptr4
= (GLuint
*) ptr3
;
457 register GLuint
*p
= pixel4
;
458 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
459 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
460 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
461 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
465 px
= *ptr4
& 0x00ffffff;
466 px
|= pixel4
[0] & 0xff000000;
468 px
= *ptr4
& 0xffff0000;
469 px
|= pixel4
[2] & 0x0000ffff;
474 px
= *ptr4
& 0x0000fffff;
475 px
|= pixel4
[1] & 0xffff0000;
477 px
= *ptr4
& 0xffffff00;
478 px
|= pixel4
[2] & 0x000000ff;
483 px
= *ptr4
& 0x000000ff;
484 px
|= pixel4
[2] & 0xffffff00;
501 px
= *ptr4
& 0xffffff00;
502 px
|= clearPixel
& 0xff;
508 px
= *ptr4
& 0xffff0000;
513 px
= *ptr4
& 0xff000000;
524 /* only clear subrect of color buffer */
526 /* same value for all three components (gray) */
528 for (j
=0;j
<height
;j
++) {
529 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_draw_buffer
, x
, y
+j
);
530 MEMSET(ptr3
, r
, 3 * width
);
534 /* non-gray clear color */
536 for (j
= 0; j
< height
; j
++) {
537 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_draw_buffer
, x
, y
+j
);
538 for (i
= 0; i
< width
; i
++) {
545 #if 0 /* this code might not always (seems ptr3 always == ptr4) */
548 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
549 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
550 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
551 for (j
=0;j
<height
;j
++) {
552 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_draw_buffer
, x
, y
+j
);
553 register GLuint
*ptr4
= (GLuint
*)ptr3
;
554 register GLuint
*p
, px
;
556 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
560 px
= *ptr4
& 0x00ffffff;
561 px
|= pixel4
[0] & 0xff000000;
563 px
= *ptr4
& 0xffff0000;
564 px
|= pixel4
[2] & 0x0000ffff;
569 px
= *ptr4
& 0x0000fffff;
570 px
|= pixel4
[1] & 0xffff0000;
572 px
= *ptr4
& 0xffffff00;
573 px
|= pixel4
[2] & 0x000000ff;
578 px
= *ptr4
& 0x000000ff;
579 px
|= pixel4
[2] & 0xffffff00;
596 px
= *ptr4
& 0xffffff00;
603 px
= *ptr4
& 0xffff0000;
608 px
= *ptr4
& 0xff000000;
609 px
|= pixel4
[0] & 0xffffff;
623 clear_32bit_ximage( GLcontext
*ctx
, GLboolean all
,
624 GLint x
, GLint y
, GLint width
, GLint height
)
626 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
627 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
628 if (xmesa
->swapbytes
) {
629 pixel
= ((pixel
>> 24) & 0x000000ff)
630 | ((pixel
>> 8) & 0x0000ff00)
631 | ((pixel
<< 8) & 0x00ff0000)
632 | ((pixel
<< 24) & 0xff000000);
635 register GLint n
= xmesa
->xm_draw_buffer
->width
* xmesa
->xm_draw_buffer
->height
;
636 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_draw_buffer
->backimage
->data
;
638 MEMSET( ptr4
, pixel
, 4*n
);
649 for (j
=0;j
<height
;j
++) {
650 register GLuint
*ptr4
= PIXELADDR4( xmesa
->xm_draw_buffer
, x
, y
+j
);
651 for (i
=0;i
<width
;i
++) {
660 clear_nbit_ximage( GLcontext
*ctx
, GLboolean all
,
661 GLint x
, GLint y
, GLint width
, GLint height
)
663 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
664 XMesaImage
*img
= xmesa
->xm_draw_buffer
->backimage
;
667 width
= xmesa
->xm_draw_buffer
->width
;
668 height
= xmesa
->xm_draw_buffer
->height
;
669 for (j
=0;j
<height
;j
++) {
670 for (i
=0;i
<width
;i
++) {
671 XMesaPutPixel( img
, i
, j
, xmesa
->clearpixel
);
676 /* TODO: optimize this */
678 y
= FLIP(xmesa
->xm_draw_buffer
, y
);
679 for (j
=0;j
<height
;j
++) {
680 for (i
=0;i
<width
;i
++) {
681 XMesaPutPixel( img
, x
+i
, y
-j
, xmesa
->clearpixel
);
690 clear_buffers( GLcontext
*ctx
, GLbitfield mask
,
691 GLboolean all
, GLint x
, GLint y
, GLint width
, GLint height
)
693 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
694 const GLuint
*colorMask
= (GLuint
*) &ctx
->Color
.ColorMask
;
696 if ((mask
& (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
)) &&
697 xmesa
->xm_draw_buffer
->mesa_buffer
.UseSoftwareAlphaBuffers
&&
698 ctx
->Color
.ColorMask
[ACOMP
]) {
699 _swrast_clear_alpha_buffers(ctx
);
702 /* we can't handle color or index masking */
703 if (*colorMask
== 0xffffffff && ctx
->Color
.IndexMask
== 0xffffffff) {
704 if (mask
& DD_FRONT_LEFT_BIT
) {
705 ASSERT(xmesa
->xm_draw_buffer
->front_clear_func
);
706 (*xmesa
->xm_draw_buffer
->front_clear_func
)( ctx
, all
, x
, y
, width
, height
);
707 mask
&= ~DD_FRONT_LEFT_BIT
;
709 if (mask
& DD_BACK_LEFT_BIT
) {
710 ASSERT(xmesa
->xm_draw_buffer
->back_clear_func
);
711 (*xmesa
->xm_draw_buffer
->back_clear_func
)( ctx
, all
, x
, y
, width
, height
);
712 mask
&= ~DD_BACK_LEFT_BIT
;
717 _swrast_Clear( ctx
, mask
, all
, x
, y
, width
, height
);
722 * When we detect that the user has resized the window this function will
723 * get called. Here we'll reallocate the back buffer, depth buffer,
724 * stencil buffer etc. to match the new window size.
727 xmesa_resize_buffers( GLframebuffer
*buffer
)
729 int height
= (int) buffer
->Height
;
730 /* We can do this cast because the first field in the XMesaBuffer
731 * struct is a GLframebuffer struct. If this weren't true, we'd
732 * need a pointer from the GLframebuffer to the XMesaBuffer.
734 XMesaBuffer xmBuffer
= (XMesaBuffer
) buffer
;
736 xmBuffer
->width
= buffer
->Width
;
737 xmBuffer
->height
= buffer
->Height
;
738 xmesa_alloc_back_buffer( xmBuffer
);
740 /* Needed by FLIP macro */
741 xmBuffer
->bottom
= height
- 1;
743 if (xmBuffer
->backimage
) {
744 /* Needed by PIXELADDR1 macro */
745 xmBuffer
->ximage_width1
= xmBuffer
->backimage
->bytes_per_line
;
746 xmBuffer
->ximage_origin1
= (GLubyte
*) xmBuffer
->backimage
->data
747 + xmBuffer
->ximage_width1
* (height
-1);
749 /* Needed by PIXELADDR2 macro */
750 xmBuffer
->ximage_width2
= xmBuffer
->backimage
->bytes_per_line
/ 2;
751 xmBuffer
->ximage_origin2
= (GLushort
*) xmBuffer
->backimage
->data
752 + xmBuffer
->ximage_width2
* (height
-1);
754 /* Needed by PIXELADDR3 macro */
755 xmBuffer
->ximage_width3
= xmBuffer
->backimage
->bytes_per_line
;
756 xmBuffer
->ximage_origin3
= (GLubyte
*) xmBuffer
->backimage
->data
757 + xmBuffer
->ximage_width3
* (height
-1);
759 /* Needed by PIXELADDR4 macro */
760 xmBuffer
->ximage_width4
= xmBuffer
->backimage
->width
;
761 xmBuffer
->ximage_origin4
= (GLuint
*) xmBuffer
->backimage
->data
762 + xmBuffer
->ximage_width4
* (height
-1);
765 _swrast_alloc_buffers( buffer
);
769 #ifndef XFree86Server
770 /* XXX this was never tested in the Xserver environment */
773 * This function implements glDrawPixels() with an XPutImage call when
774 * drawing to the front buffer (X Window drawable).
775 * The image format must be GL_BGRA to match the PF_8R8G8B pixel format.
778 xmesa_DrawPixels_8R8G8B( GLcontext
*ctx
,
779 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
780 GLenum format
, GLenum type
,
781 const struct gl_pixelstore_attrib
*unpack
,
782 const GLvoid
*pixels
)
784 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
785 const SWcontext
*swrast
= SWRAST_CONTEXT( ctx
);
786 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
787 const XMesaDrawable buffer
= xmesa
->xm_draw_buffer
->buffer
;
788 const XMesaGC gc
= xmesa
->xm_draw_buffer
->gc
;
792 ASSERT(xmesa
->xm_visual
->dithered_pf
== PF_8R8G8B
);
793 ASSERT(xmesa
->xm_visual
->undithered_pf
== PF_8R8G8B
);
795 if (swrast
->NewState
)
796 _swrast_validate_derived( ctx
);
798 if (buffer
&& /* buffer != 0 means it's a Window or Pixmap */
800 type
== GL_UNSIGNED_BYTE
&&
801 (swrast
->_RasterMask
& ~CLIP_BIT
) == 0 && /* no blend, z-test, etc */
802 ctx
->_ImageTransferState
== 0 && /* no color tables, scale/bias, etc */
803 ctx
->Pixel
.ZoomX
== 1.0 && /* no zooming */
804 ctx
->Pixel
.ZoomY
== 1.0) {
809 int srcX
= unpack
->SkipPixels
;
810 int srcY
= unpack
->SkipRows
;
811 int rowLength
= unpack
->RowLength
? unpack
->RowLength
: width
;
812 if (_swrast_clip_pixelrect(ctx
, &dstX
, &dstY
, &w
, &h
, &srcX
, &srcY
)) {
813 /* This is a little tricky since all coordinates up to now have
814 * been in the OpenGL bottom-to-top orientation. X is top-to-bottom
815 * so we have to carefully compute the Y coordinates/addresses here.
818 MEMSET(&ximage
, 0, sizeof(XMesaImage
));
819 ximage
.width
= width
;
820 ximage
.height
= height
;
821 ximage
.format
= ZPixmap
;
822 ximage
.data
= (char *) pixels
823 + ((srcY
+ h
- 1) * rowLength
+ srcX
) * 4;
824 ximage
.byte_order
= LSBFirst
;
825 ximage
.bitmap_unit
= 32;
826 ximage
.bitmap_bit_order
= LSBFirst
;
827 ximage
.bitmap_pad
= 32;
829 ximage
.bytes_per_line
= -rowLength
* 4; /* negative to flip image */
830 ximage
.bits_per_pixel
= 32;
831 /* it seems we don't need to set the ximage.red/green/blue_mask fields */
832 /* flip Y axis for dest position */
833 dstY
= FLIP(xmesa
->xm_draw_buffer
, dstY
) - h
+ 1;
834 XPutImage(dpy
, buffer
, gc
, &ximage
, 0, 0, dstX
, dstY
, w
, h
);
838 /* software fallback */
839 _swrast_DrawPixels(ctx
, x
, y
, width
, height
,
840 format
, type
, unpack
, pixels
);
847 * This function implements glDrawPixels() with an XPutImage call when
848 * drawing to the front buffer (X Window drawable). The image format
849 * must be GL_RGB and image type must be GL_UNSIGNED_SHORT_5_6_5 to
850 * match the PF_5R6G5B pixel format.
853 xmesa_DrawPixels_5R6G5B( GLcontext
*ctx
,
854 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
855 GLenum format
, GLenum type
,
856 const struct gl_pixelstore_attrib
*unpack
,
857 const GLvoid
*pixels
)
859 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
860 const SWcontext
*swrast
= SWRAST_CONTEXT( ctx
);
861 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
862 const XMesaDrawable buffer
= xmesa
->xm_draw_buffer
->buffer
;
863 const XMesaGC gc
= xmesa
->xm_draw_buffer
->gc
;
867 ASSERT(xmesa
->xm_visual
->undithered_pf
== PF_5R6G5B
);
869 if (swrast
->NewState
)
870 _swrast_validate_derived( ctx
);
872 if (buffer
&& /* buffer != 0 means it's a Window or Pixmap */
874 type
== GL_UNSIGNED_SHORT_5_6_5
&&
875 !ctx
->Color
.DitherFlag
&& /* no dithering */
876 (swrast
->_RasterMask
& ~CLIP_BIT
) == 0 && /* no blend, z-test, etc */
877 ctx
->_ImageTransferState
== 0 && /* no color tables, scale/bias, etc */
878 ctx
->Pixel
.ZoomX
== 1.0 && /* no zooming */
879 ctx
->Pixel
.ZoomY
== 1.0) {
884 int srcX
= unpack
->SkipPixels
;
885 int srcY
= unpack
->SkipRows
;
886 int rowLength
= unpack
->RowLength
? unpack
->RowLength
: width
;
887 if (_swrast_clip_pixelrect(ctx
, &dstX
, &dstY
, &w
, &h
, &srcX
, &srcY
)) {
888 /* This is a little tricky since all coordinates up to now have
889 * been in the OpenGL bottom-to-top orientation. X is top-to-bottom
890 * so we have to carefully compute the Y coordinates/addresses here.
893 MEMSET(&ximage
, 0, sizeof(XMesaImage
));
894 ximage
.width
= width
;
895 ximage
.height
= height
;
896 ximage
.format
= ZPixmap
;
897 ximage
.data
= (char *) pixels
898 + ((srcY
+ h
- 1) * rowLength
+ srcX
) * 2;
899 ximage
.byte_order
= LSBFirst
;
900 ximage
.bitmap_unit
= 16;
901 ximage
.bitmap_bit_order
= LSBFirst
;
902 ximage
.bitmap_pad
= 16;
904 ximage
.bytes_per_line
= -rowLength
* 2; /* negative to flip image */
905 ximage
.bits_per_pixel
= 16;
906 /* it seems we don't need to set the ximage.red/green/blue_mask fields */
907 /* flip Y axis for dest position */
908 dstY
= FLIP(xmesa
->xm_draw_buffer
, dstY
) - h
+ 1;
909 XPutImage(dpy
, buffer
, gc
, &ximage
, 0, 0, dstX
, dstY
, w
, h
);
913 /* software fallback */
914 _swrast_DrawPixels(ctx
, x
, y
, width
, height
,
915 format
, type
, unpack
, pixels
);
922 * Implement glCopyPixels for the front color buffer (or back buffer Pixmap)
923 * for the color buffer. Don't support zooming, pixel transfer, etc.
924 * We do support copying from one window to another, ala glXMakeCurrentRead.
927 xmesa_CopyPixels( GLcontext
*ctx
,
928 GLint srcx
, GLint srcy
, GLsizei width
, GLsizei height
,
929 GLint destx
, GLint desty
, GLenum type
)
931 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
932 const SWcontext
*swrast
= SWRAST_CONTEXT( ctx
);
933 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
934 const XMesaDrawable drawBuffer
= xmesa
->xm_draw_buffer
->buffer
;
935 const XMesaDrawable readBuffer
= xmesa
->xm_read_buffer
->buffer
;
936 const XMesaGC gc
= xmesa
->xm_draw_buffer
->gc
;
941 if (swrast
->NewState
)
942 _swrast_validate_derived( ctx
);
944 if (ctx
->Color
.DrawBuffer
== GL_FRONT
&&
945 ctx
->Pixel
.ReadBuffer
== GL_FRONT
&&
946 drawBuffer
&& /* buffer != 0 means it's a Window or Pixmap */
949 (swrast
->_RasterMask
& ~CLIP_BIT
) == 0 && /* no blend, z-test, etc */
950 ctx
->_ImageTransferState
== 0 && /* no color tables, scale/bias, etc */
951 ctx
->Pixel
.ZoomX
== 1.0 && /* no zooming */
952 ctx
->Pixel
.ZoomY
== 1.0) {
953 /* Note: we don't do any special clipping work here. We could,
954 * but X will do it for us.
956 srcy
= FLIP(xmesa
->xm_read_buffer
, srcy
) - height
+ 1;
957 desty
= FLIP(xmesa
->xm_draw_buffer
, desty
) - height
+ 1;
958 XCopyArea(dpy
, readBuffer
, drawBuffer
, gc
,
959 srcx
, srcy
, width
, height
, destx
, desty
);
962 _swrast_CopyPixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
);
965 #endif /* XFree86Server */
970 * Every driver should implement a GetString function in order to
971 * return a meaningful GL_RENDERER string.
973 static const GLubyte
*
974 get_string( GLcontext
*ctx
, GLenum name
)
980 return (const GLubyte
*) "Mesa GLX Indirect";
982 return (const GLubyte
*) "Mesa X11";
986 return (const GLubyte
*) "Mesa project: www.mesa3d.org";
997 * We implement the glEnable function only because we care about
998 * dither enable/disable.
1001 enable( GLcontext
*ctx
, GLenum pname
, GLboolean state
)
1003 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1008 xmesa
->pixelformat
= xmesa
->xm_visual
->dithered_pf
;
1010 xmesa
->pixelformat
= xmesa
->xm_visual
->undithered_pf
;
1013 ; /* silence compiler warning */
1018 void xmesa_update_state( GLcontext
*ctx
, GLuint new_state
)
1020 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1022 /* Propogate statechange information to swrast and swrast_setup
1023 * modules. The X11 driver has no internal GL-dependent state.
1025 _swrast_InvalidateState( ctx
, new_state
);
1026 _ac_InvalidateState( ctx
, new_state
);
1027 _tnl_InvalidateState( ctx
, new_state
);
1028 _swsetup_InvalidateState( ctx
, new_state
);
1031 /* setup pointers to front and back buffer clear functions */
1032 xmesa
->xm_draw_buffer
->front_clear_func
= clear_front_pixmap
;
1033 if (xmesa
->xm_draw_buffer
->backpixmap
!= XIMAGE
) {
1034 xmesa
->xm_draw_buffer
->back_clear_func
= clear_back_pixmap
;
1036 else if (sizeof(GLushort
)!=2 || sizeof(GLuint
)!=4) {
1037 xmesa
->xm_draw_buffer
->back_clear_func
= clear_nbit_ximage
;
1039 else switch (xmesa
->xm_visual
->BitsPerPixel
) {
1041 if (xmesa
->xm_visual
->hpcr_clear_flag
) {
1042 xmesa
->xm_draw_buffer
->back_clear_func
= clear_HPCR_ximage
;
1045 xmesa
->xm_draw_buffer
->back_clear_func
= clear_8bit_ximage
;
1049 xmesa
->xm_draw_buffer
->back_clear_func
= clear_16bit_ximage
;
1052 xmesa
->xm_draw_buffer
->back_clear_func
= clear_24bit_ximage
;
1055 xmesa
->xm_draw_buffer
->back_clear_func
= clear_32bit_ximage
;
1058 xmesa
->xm_draw_buffer
->back_clear_func
= clear_nbit_ximage
;
1062 xmesa_update_span_funcs(ctx
);
1068 * Called via ctx->Driver.TestProxyTeximage(). Normally, we'd just use
1069 * the _mesa_test_proxy_teximage() fallback function, but we're going to
1070 * special-case the 3D texture case to allow textures up to 512x512x32
1074 test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1075 GLint internalFormat
, GLenum format
, GLenum type
,
1076 GLint width
, GLint height
, GLint depth
, GLint border
)
1078 if (target
== GL_PROXY_TEXTURE_3D
) {
1079 /* special case for 3D textures */
1080 if (width
* height
* depth
> 512 * 512 * 64 ||
1081 width
< 2 * border
||
1082 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1083 _mesa_bitcount(width
- 2 * border
) != 1) ||
1084 height
< 2 * border
||
1085 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1086 _mesa_bitcount(height
- 2 * border
) != 1) ||
1087 depth
< 2 * border
||
1088 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1089 _mesa_bitcount(depth
- 2 * border
) != 1)) {
1090 /* Bad size, or too many texels */
1096 /* use the fallback routine for 1D, 2D, cube and rect targets */
1097 return _mesa_test_proxy_teximage(ctx
, target
, level
, internalFormat
,
1098 format
, type
, width
, height
, depth
,
1105 * Initialize the device driver function table with the functions
1106 * we implement in this driver.
1108 void xmesa_init_driver_functions( XMesaVisual xmvisual
,
1109 struct dd_function_table
*driver
)
1111 driver
->GetString
= get_string
;
1112 driver
->UpdateState
= xmesa_update_state
;
1113 driver
->GetBufferSize
= get_buffer_size
;
1114 driver
->Flush
= finish_or_flush
;
1115 driver
->Finish
= finish_or_flush
;
1116 driver
->ClearIndex
= clear_index
;
1117 driver
->ClearColor
= clear_color
;
1118 driver
->IndexMask
= index_mask
;
1119 driver
->ColorMask
= color_mask
;
1120 driver
->Enable
= enable
;
1121 driver
->Clear
= clear_buffers
;
1122 driver
->ResizeBuffers
= xmesa_resize_buffers
;
1123 #ifndef XFree86Server
1124 driver
->CopyPixels
= /*_swrast_CopyPixels;*/xmesa_CopyPixels
;
1125 if (xmvisual
->undithered_pf
== PF_8R8G8B
&&
1126 xmvisual
->dithered_pf
== PF_8R8G8B
) {
1127 driver
->DrawPixels
= xmesa_DrawPixels_8R8G8B
;
1129 else if (xmvisual
->undithered_pf
== PF_5R6G5B
) {
1130 driver
->DrawPixels
= xmesa_DrawPixels_5R6G5B
;
1133 driver
->TestProxyTexImage
= test_proxy_teximage
;
1137 #define XMESA_NEW_POINT (_NEW_POINT | \
1139 _SWRAST_NEW_RASTERMASK)
1141 #define XMESA_NEW_LINE (_NEW_LINE | \
1146 _SWRAST_NEW_RASTERMASK)
1148 #define XMESA_NEW_TRIANGLE (_NEW_POLYGON | \
1153 _SWRAST_NEW_RASTERMASK)
1156 /* Extend the software rasterizer with our line/point/triangle
1159 void xmesa_register_swrast_functions( GLcontext
*ctx
)
1161 SWcontext
*swrast
= SWRAST_CONTEXT( ctx
);
1162 struct swrast_device_driver
*dd
= _swrast_GetDeviceDriverReference(ctx
);
1164 dd
->SetBuffer
= xmesa_set_buffer
;
1166 swrast
->choose_point
= xmesa_choose_point
;
1167 swrast
->choose_line
= xmesa_choose_line
;
1168 swrast
->choose_triangle
= xmesa_choose_triangle
;
1170 swrast
->invalidate_point
|= XMESA_NEW_POINT
;
1171 swrast
->invalidate_line
|= XMESA_NEW_LINE
;
1172 swrast
->invalidate_triangle
|= XMESA_NEW_TRIANGLE
;