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"
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"
50 #include "tnl/t_pipeline.h"
54 * Return the size (width, height) of the X window for the given GLframebuffer.
55 * Output: width - width of buffer in pixels.
56 * height - height of buffer in pixels.
59 get_buffer_size( GLframebuffer
*buffer
, GLuint
*width
, GLuint
*height
)
61 /* We can do this cast because the first field in the XMesaBuffer
62 * struct is a GLframebuffer struct. If this weren't true, we'd
63 * need a pointer from the GLframebuffer to the XMesaBuffer.
65 const XMesaBuffer xmBuffer
= (XMesaBuffer
) buffer
;
66 unsigned int winwidth
, winheight
;
68 /* XFree86 GLX renderer */
69 if (xmBuffer
->frontbuffer
->width
> MAX_WIDTH
||
70 xmBuffer
->frontbuffer
->height
> MAX_HEIGHT
) {
71 winwidth
= buffer
->Width
;
72 winheight
= buffer
->Height
;
74 winwidth
= xmBuffer
->frontbuffer
->width
;
75 winheight
= xmBuffer
->frontbuffer
->height
;
82 _glthread_LOCK_MUTEX(_xmesa_lock
);
83 XSync(xmBuffer
->xm_visual
->display
, 0); /* added for Chromium */
84 XGetGeometry( xmBuffer
->xm_visual
->display
, xmBuffer
->frontbuffer
, &root
,
85 &winx
, &winy
, &winwidth
, &winheight
, &bw
, &d
);
86 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
89 (void)kernel8
; /* Muffle compiler */
97 finish_or_flush( GLcontext
*ctx
)
102 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
104 _glthread_LOCK_MUTEX(_xmesa_lock
);
105 XSync( xmesa
->display
, False
);
106 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
114 * This chooses the color buffer for reading and writing spans, points,
115 * lines, and triangles.
118 set_buffer( GLcontext
*ctx
, GLframebuffer
*buffer
, GLuint bufferBit
)
120 /* We can make this cast since the XMesaBuffer wraps GLframebuffer.
121 * GLframebuffer is the first member in a XMesaBuffer struct.
123 XMesaBuffer target
= (XMesaBuffer
) buffer
;
124 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
126 /* This assignment tells the span/point/line/triangle functions
127 * which XMesaBuffer to use.
129 xmesa
->xm_buffer
= target
;
132 * Now determine front vs back color buffer.
134 if (bufferBit
== FRONT_LEFT_BIT
) {
135 target
->buffer
= target
->frontbuffer
;
137 else if (bufferBit
== BACK_LEFT_BIT
) {
138 ASSERT(target
->db_state
);
139 if (target
->backpixmap
) {
140 /* back buffer is a pixmap */
141 target
->buffer
= (XMesaDrawable
) target
->backpixmap
;
143 else if (target
->backimage
) {
144 /* back buffer is an XImage */
145 target
->buffer
= None
;
148 /* No back buffer!!!! Must be out of memory, use front buffer */
149 target
->buffer
= target
->frontbuffer
;
153 _mesa_problem(ctx
, "invalid buffer 0x%x in set_buffer() in xm_dd.c");
156 xmesa_update_span_funcs(ctx
);
162 clear_index( GLcontext
*ctx
, GLuint index
)
164 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
165 xmesa
->clearpixel
= (unsigned long) index
;
166 XMesaSetForeground( xmesa
->display
, xmesa
->xm_draw_buffer
->cleargc
,
167 (unsigned long) index
);
172 clear_color( GLcontext
*ctx
, const GLfloat color
[4] )
174 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
175 CLAMPED_FLOAT_TO_UBYTE(xmesa
->clearcolor
[0], color
[0]);
176 CLAMPED_FLOAT_TO_UBYTE(xmesa
->clearcolor
[1], color
[1]);
177 CLAMPED_FLOAT_TO_UBYTE(xmesa
->clearcolor
[2], color
[2]);
178 CLAMPED_FLOAT_TO_UBYTE(xmesa
->clearcolor
[3], color
[3]);
179 xmesa
->clearpixel
= xmesa_color_to_pixel( xmesa
,
180 xmesa
->clearcolor
[0],
181 xmesa
->clearcolor
[1],
182 xmesa
->clearcolor
[2],
183 xmesa
->clearcolor
[3],
184 xmesa
->xm_visual
->undithered_pf
);
185 _glthread_LOCK_MUTEX(_xmesa_lock
);
186 XMesaSetForeground( xmesa
->display
, xmesa
->xm_draw_buffer
->cleargc
,
188 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
193 /* Set index mask ala glIndexMask */
195 index_mask( GLcontext
*ctx
, GLuint mask
)
197 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
198 if (xmesa
->xm_draw_buffer
->buffer
!= XIMAGE
) {
200 if (mask
==0xffffffff) {
201 m
= ((unsigned long)~0L);
204 m
= (unsigned long) mask
;
206 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_draw_buffer
->cleargc
, m
);
207 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_draw_buffer
->gc
, m
);
212 /* Implements glColorMask() */
214 color_mask(GLcontext
*ctx
,
215 GLboolean rmask
, GLboolean gmask
, GLboolean bmask
, GLboolean amask
)
217 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
218 int xclass
= GET_VISUAL_CLASS(xmesa
->xm_visual
);
221 if (xclass
== TrueColor
|| xclass
== DirectColor
) {
223 if (rmask
&& gmask
&& bmask
) {
224 m
= ((unsigned long)~0L);
228 if (rmask
) m
|= GET_REDMASK(xmesa
->xm_visual
);
229 if (gmask
) m
|= GET_GREENMASK(xmesa
->xm_visual
);
230 if (bmask
) m
|= GET_BLUEMASK(xmesa
->xm_visual
);
232 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_draw_buffer
->cleargc
, m
);
233 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_draw_buffer
->gc
, m
);
239 /**********************************************************************/
240 /*** glClear implementations ***/
241 /**********************************************************************/
245 clear_front_pixmap( GLcontext
*ctx
, GLboolean all
,
246 GLint x
, GLint y
, GLint width
, GLint height
)
248 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
250 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_draw_buffer
->frontbuffer
,
251 xmesa
->xm_draw_buffer
->cleargc
,
253 xmesa
->xm_draw_buffer
->width
+1,
254 xmesa
->xm_draw_buffer
->height
+1 );
257 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_draw_buffer
->frontbuffer
,
258 xmesa
->xm_draw_buffer
->cleargc
,
259 x
, xmesa
->xm_draw_buffer
->height
- y
- height
,
266 clear_back_pixmap( GLcontext
*ctx
, GLboolean all
,
267 GLint x
, GLint y
, GLint width
, GLint height
)
269 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
271 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_draw_buffer
->backpixmap
,
272 xmesa
->xm_draw_buffer
->cleargc
,
274 xmesa
->xm_draw_buffer
->width
+1,
275 xmesa
->xm_draw_buffer
->height
+1 );
278 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_draw_buffer
->backpixmap
,
279 xmesa
->xm_draw_buffer
->cleargc
,
280 x
, xmesa
->xm_draw_buffer
->height
- y
- height
,
287 clear_8bit_ximage( GLcontext
*ctx
, GLboolean all
,
288 GLint x
, GLint y
, GLint width
, GLint height
)
290 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
292 size_t n
= xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
293 * xmesa
->xm_draw_buffer
->backimage
->height
;
294 MEMSET( xmesa
->xm_draw_buffer
->backimage
->data
, xmesa
->clearpixel
, n
);
298 for (i
=0;i
<height
;i
++) {
299 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_draw_buffer
, x
, y
+i
);
300 MEMSET( ptr
, xmesa
->clearpixel
, width
);
307 clear_HPCR_ximage( GLcontext
*ctx
, GLboolean all
,
308 GLint x
, GLint y
, GLint width
, GLint height
)
310 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
312 GLint i
, c16
= (xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
>>4)<<4;
313 GLubyte
*ptr
= (GLubyte
*)xmesa
->xm_draw_buffer
->backimage
->data
;
314 for (i
=0; i
<xmesa
->xm_draw_buffer
->backimage
->height
; i
++) {
316 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
320 for (j
=0; j
<c16
; j
+=16) {
339 for (; j
<xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
; j
++) {
347 for (i
=y
; i
<y
+height
; i
++) {
348 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_draw_buffer
, x
, i
);
350 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
354 for (j
=x
; j
<x
+width
; j
++) {
364 clear_16bit_ximage( GLcontext
*ctx
, GLboolean all
,
365 GLint x
, GLint y
, GLint width
, GLint height
)
367 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
368 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
369 if (xmesa
->swapbytes
) {
370 pixel
= ((pixel
>> 8) & 0x00ff) | ((pixel
<< 8) & 0xff00);
374 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_draw_buffer
->backimage
->data
;
375 if ((pixel
& 0xff) == ((pixel
>> 8) & 0xff)) {
376 /* low and high bytes are equal so use memset() */
377 n
= xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
378 * xmesa
->xm_draw_buffer
->height
;
379 MEMSET( ptr4
, pixel
& 0xff, n
);
382 pixel
= pixel
| (pixel
<<16);
383 n
= xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
384 * xmesa
->xm_draw_buffer
->height
/ 4;
390 if ((xmesa
->xm_draw_buffer
->backimage
->bytes_per_line
*
391 xmesa
->xm_draw_buffer
->height
) & 0x2)
392 *(GLushort
*)ptr4
= pixel
& 0xffff;
397 for (j
=0;j
<height
;j
++) {
398 register GLushort
*ptr2
= PIXELADDR2( xmesa
->xm_draw_buffer
, x
, y
+j
);
399 for (i
=0;i
<width
;i
++) {
407 /* Optimized code provided by Nozomi Ytow <noz@xfree86.org> */
409 clear_24bit_ximage( GLcontext
*ctx
, GLboolean all
,
410 GLint x
, GLint y
, GLint width
, GLint height
)
412 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
413 const GLubyte r
= xmesa
->clearcolor
[0];
414 const GLubyte g
= xmesa
->clearcolor
[1];
415 const GLubyte b
= xmesa
->clearcolor
[2];
416 #if 0 /* See below */
417 register GLuint clearPixel
;
418 if (xmesa
->swapbytes
) {
419 clearPixel
= (b
<< 16) | (g
<< 8) | r
;
422 clearPixel
= (r
<< 16) | (g
<< 8) | b
;
428 /* same value for all three components (gray) */
429 const GLint w3
= xmesa
->xm_draw_buffer
->width
* 3;
430 const GLint h
= xmesa
->xm_draw_buffer
->height
;
432 for (i
= 0; i
< h
; i
++) {
433 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_draw_buffer
, 0, i
);
439 const GLint w
= xmesa
->xm_draw_buffer
->width
;
440 const GLint h
= xmesa
->xm_draw_buffer
->height
;
442 for (i
= 0; i
< h
; i
++) {
443 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_draw_buffer
, 0, i
);
444 for (j
= 0; j
< w
; j
++) {
451 #if 0 /* this code doesn't work for all window widths */
452 register GLuint
*ptr4
= (GLuint
*) ptr3
;
455 register GLuint
*p
= pixel4
;
456 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
457 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
458 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
459 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
463 px
= *ptr4
& 0x00ffffff;
464 px
|= pixel4
[0] & 0xff000000;
466 px
= *ptr4
& 0xffff0000;
467 px
|= pixel4
[2] & 0x0000ffff;
472 px
= *ptr4
& 0x0000fffff;
473 px
|= pixel4
[1] & 0xffff0000;
475 px
= *ptr4
& 0xffffff00;
476 px
|= pixel4
[2] & 0x000000ff;
481 px
= *ptr4
& 0x000000ff;
482 px
|= pixel4
[2] & 0xffffff00;
499 px
= *ptr4
& 0xffffff00;
500 px
|= clearPixel
& 0xff;
506 px
= *ptr4
& 0xffff0000;
511 px
= *ptr4
& 0xff000000;
522 /* only clear subrect of color buffer */
524 /* same value for all three components (gray) */
526 for (j
=0;j
<height
;j
++) {
527 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_draw_buffer
, x
, y
+j
);
528 MEMSET(ptr3
, r
, 3 * width
);
532 /* non-gray clear color */
534 for (j
= 0; j
< height
; j
++) {
535 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_draw_buffer
, x
, y
+j
);
536 for (i
= 0; i
< width
; i
++) {
543 #if 0 /* this code might not always (seems ptr3 always == ptr4) */
546 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
547 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
548 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
549 for (j
=0;j
<height
;j
++) {
550 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_draw_buffer
, x
, y
+j
);
551 register GLuint
*ptr4
= (GLuint
*)ptr3
;
552 register GLuint
*p
, px
;
554 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
558 px
= *ptr4
& 0x00ffffff;
559 px
|= pixel4
[0] & 0xff000000;
561 px
= *ptr4
& 0xffff0000;
562 px
|= pixel4
[2] & 0x0000ffff;
567 px
= *ptr4
& 0x0000fffff;
568 px
|= pixel4
[1] & 0xffff0000;
570 px
= *ptr4
& 0xffffff00;
571 px
|= pixel4
[2] & 0x000000ff;
576 px
= *ptr4
& 0x000000ff;
577 px
|= pixel4
[2] & 0xffffff00;
594 px
= *ptr4
& 0xffffff00;
601 px
= *ptr4
& 0xffff0000;
606 px
= *ptr4
& 0xff000000;
607 px
|= pixel4
[0] & 0xffffff;
621 clear_32bit_ximage( GLcontext
*ctx
, GLboolean all
,
622 GLint x
, GLint y
, GLint width
, GLint height
)
624 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
625 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
626 if (xmesa
->swapbytes
) {
627 pixel
= ((pixel
>> 24) & 0x000000ff)
628 | ((pixel
>> 8) & 0x0000ff00)
629 | ((pixel
<< 8) & 0x00ff0000)
630 | ((pixel
<< 24) & 0xff000000);
633 register GLint n
= xmesa
->xm_draw_buffer
->width
* xmesa
->xm_draw_buffer
->height
;
634 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_draw_buffer
->backimage
->data
;
636 MEMSET( ptr4
, pixel
, 4*n
);
647 for (j
=0;j
<height
;j
++) {
648 register GLuint
*ptr4
= PIXELADDR4( xmesa
->xm_draw_buffer
, x
, y
+j
);
649 for (i
=0;i
<width
;i
++) {
658 clear_nbit_ximage( GLcontext
*ctx
, GLboolean all
,
659 GLint x
, GLint y
, GLint width
, GLint height
)
661 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
662 XMesaImage
*img
= xmesa
->xm_draw_buffer
->backimage
;
665 width
= xmesa
->xm_draw_buffer
->width
;
666 height
= xmesa
->xm_draw_buffer
->height
;
667 for (j
=0;j
<height
;j
++) {
668 for (i
=0;i
<width
;i
++) {
669 XMesaPutPixel( img
, i
, j
, xmesa
->clearpixel
);
674 /* TODO: optimize this */
676 y
= FLIP(xmesa
->xm_draw_buffer
, y
);
677 for (j
=0;j
<height
;j
++) {
678 for (i
=0;i
<width
;i
++) {
679 XMesaPutPixel( img
, x
+i
, y
-j
, xmesa
->clearpixel
);
688 clear_buffers( GLcontext
*ctx
, GLbitfield mask
,
689 GLboolean all
, GLint x
, GLint y
, GLint width
, GLint height
)
691 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
692 const GLuint
*colorMask
= (GLuint
*) &ctx
->Color
.ColorMask
;
694 if ((mask
& (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
)) &&
695 xmesa
->xm_draw_buffer
->mesa_buffer
.UseSoftwareAlphaBuffers
&&
696 ctx
->Color
.ColorMask
[ACOMP
]) {
697 _swrast_clear_alpha_buffers(ctx
);
700 /* we can't handle color or index masking */
701 if (*colorMask
== 0xffffffff && ctx
->Color
.IndexMask
== 0xffffffff) {
702 if (mask
& DD_FRONT_LEFT_BIT
) {
703 ASSERT(xmesa
->xm_draw_buffer
->front_clear_func
);
704 (*xmesa
->xm_draw_buffer
->front_clear_func
)( ctx
, all
, x
, y
, width
, height
);
705 mask
&= ~DD_FRONT_LEFT_BIT
;
707 if (mask
& DD_BACK_LEFT_BIT
) {
708 ASSERT(xmesa
->xm_draw_buffer
->back_clear_func
);
709 (*xmesa
->xm_draw_buffer
->back_clear_func
)( ctx
, all
, x
, y
, width
, height
);
710 mask
&= ~DD_BACK_LEFT_BIT
;
715 _swrast_Clear( ctx
, mask
, all
, x
, y
, width
, height
);
720 * When we detect that the user has resized the window this function will
721 * get called. Here we'll reallocate the back buffer, depth buffer,
722 * stencil buffer etc. to match the new window size.
725 xmesa_resize_buffers( GLframebuffer
*buffer
)
727 int height
= (int) buffer
->Height
;
728 /* We can do this cast because the first field in the XMesaBuffer
729 * struct is a GLframebuffer struct. If this weren't true, we'd
730 * need a pointer from the GLframebuffer to the XMesaBuffer.
732 XMesaBuffer xmBuffer
= (XMesaBuffer
) buffer
;
734 xmBuffer
->width
= buffer
->Width
;
735 xmBuffer
->height
= buffer
->Height
;
736 xmesa_alloc_back_buffer( xmBuffer
);
738 /* Needed by FLIP macro */
739 xmBuffer
->bottom
= height
- 1;
741 if (xmBuffer
->backimage
) {
742 /* Needed by PIXELADDR1 macro */
743 xmBuffer
->ximage_width1
= xmBuffer
->backimage
->bytes_per_line
;
744 xmBuffer
->ximage_origin1
= (GLubyte
*) xmBuffer
->backimage
->data
745 + xmBuffer
->ximage_width1
* (height
-1);
747 /* Needed by PIXELADDR2 macro */
748 xmBuffer
->ximage_width2
= xmBuffer
->backimage
->bytes_per_line
/ 2;
749 xmBuffer
->ximage_origin2
= (GLushort
*) xmBuffer
->backimage
->data
750 + xmBuffer
->ximage_width2
* (height
-1);
752 /* Needed by PIXELADDR3 macro */
753 xmBuffer
->ximage_width3
= xmBuffer
->backimage
->bytes_per_line
;
754 xmBuffer
->ximage_origin3
= (GLubyte
*) xmBuffer
->backimage
->data
755 + xmBuffer
->ximage_width3
* (height
-1);
757 /* Needed by PIXELADDR4 macro */
758 xmBuffer
->ximage_width4
= xmBuffer
->backimage
->width
;
759 xmBuffer
->ximage_origin4
= (GLuint
*) xmBuffer
->backimage
->data
760 + xmBuffer
->ximage_width4
* (height
-1);
763 _swrast_alloc_buffers( buffer
);
767 #ifndef XFree86Server
768 /* XXX this was never tested in the Xserver environment */
771 * This function implements glDrawPixels() with an XPutImage call when
772 * drawing to the front buffer (X Window drawable).
773 * The image format must be GL_BGRA to match the PF_8R8G8B pixel format.
776 xmesa_DrawPixels_8R8G8B( GLcontext
*ctx
,
777 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
778 GLenum format
, GLenum type
,
779 const struct gl_pixelstore_attrib
*unpack
,
780 const GLvoid
*pixels
)
782 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
783 const SWcontext
*swrast
= SWRAST_CONTEXT( ctx
);
784 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
785 const XMesaDrawable buffer
= xmesa
->xm_draw_buffer
->buffer
;
786 const XMesaGC gc
= xmesa
->xm_draw_buffer
->gc
;
790 ASSERT(xmesa
->xm_visual
->dithered_pf
== PF_8R8G8B
);
791 ASSERT(xmesa
->xm_visual
->undithered_pf
== PF_8R8G8B
);
793 if (swrast
->NewState
)
794 _swrast_validate_derived( ctx
);
796 if (buffer
&& /* buffer != 0 means it's a Window or Pixmap */
798 type
== GL_UNSIGNED_BYTE
&&
799 (swrast
->_RasterMask
& ~CLIP_BIT
) == 0 && /* no blend, z-test, etc */
800 ctx
->_ImageTransferState
== 0 && /* no color tables, scale/bias, etc */
801 ctx
->Pixel
.ZoomX
== 1.0 && /* no zooming */
802 ctx
->Pixel
.ZoomY
== 1.0) {
807 int srcX
= unpack
->SkipPixels
;
808 int srcY
= unpack
->SkipRows
;
809 int rowLength
= unpack
->RowLength
? unpack
->RowLength
: width
;
810 if (_swrast_clip_pixelrect(ctx
, &dstX
, &dstY
, &w
, &h
, &srcX
, &srcY
)) {
811 /* This is a little tricky since all coordinates up to now have
812 * been in the OpenGL bottom-to-top orientation. X is top-to-bottom
813 * so we have to carefully compute the Y coordinates/addresses here.
816 MEMSET(&ximage
, 0, sizeof(XMesaImage
));
817 ximage
.width
= width
;
818 ximage
.height
= height
;
819 ximage
.format
= ZPixmap
;
820 ximage
.data
= (char *) pixels
821 + ((srcY
+ h
- 1) * rowLength
+ srcX
) * 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
= -rowLength
* 4; /* negative to flip image */
828 ximage
.bits_per_pixel
= 32;
829 /* it seems we don't need to set the ximage.red/green/blue_mask fields */
830 /* flip Y axis for dest position */
831 dstY
= FLIP(xmesa
->xm_draw_buffer
, dstY
) - h
+ 1;
832 XPutImage(dpy
, buffer
, gc
, &ximage
, 0, 0, dstX
, dstY
, w
, h
);
836 /* software fallback */
837 _swrast_DrawPixels(ctx
, x
, y
, width
, height
,
838 format
, type
, unpack
, pixels
);
845 * This function implements glDrawPixels() with an XPutImage call when
846 * drawing to the front buffer (X Window drawable). The image format
847 * must be GL_RGB and image type must be GL_UNSIGNED_SHORT_5_6_5 to
848 * match the PF_5R6G5B pixel format.
851 xmesa_DrawPixels_5R6G5B( GLcontext
*ctx
,
852 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
853 GLenum format
, GLenum type
,
854 const struct gl_pixelstore_attrib
*unpack
,
855 const GLvoid
*pixels
)
857 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
858 const SWcontext
*swrast
= SWRAST_CONTEXT( ctx
);
859 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
860 const XMesaDrawable buffer
= xmesa
->xm_draw_buffer
->buffer
;
861 const XMesaGC gc
= xmesa
->xm_draw_buffer
->gc
;
865 ASSERT(xmesa
->xm_visual
->undithered_pf
== PF_5R6G5B
);
867 if (swrast
->NewState
)
868 _swrast_validate_derived( ctx
);
870 if (buffer
&& /* buffer != 0 means it's a Window or Pixmap */
872 type
== GL_UNSIGNED_SHORT_5_6_5
&&
873 !ctx
->Color
.DitherFlag
&& /* no dithering */
874 (swrast
->_RasterMask
& ~CLIP_BIT
) == 0 && /* no blend, z-test, etc */
875 ctx
->_ImageTransferState
== 0 && /* no color tables, scale/bias, etc */
876 ctx
->Pixel
.ZoomX
== 1.0 && /* no zooming */
877 ctx
->Pixel
.ZoomY
== 1.0) {
882 int srcX
= unpack
->SkipPixels
;
883 int srcY
= unpack
->SkipRows
;
884 int rowLength
= unpack
->RowLength
? unpack
->RowLength
: width
;
885 if (_swrast_clip_pixelrect(ctx
, &dstX
, &dstY
, &w
, &h
, &srcX
, &srcY
)) {
886 /* This is a little tricky since all coordinates up to now have
887 * been in the OpenGL bottom-to-top orientation. X is top-to-bottom
888 * so we have to carefully compute the Y coordinates/addresses here.
891 MEMSET(&ximage
, 0, sizeof(XMesaImage
));
892 ximage
.width
= width
;
893 ximage
.height
= height
;
894 ximage
.format
= ZPixmap
;
895 ximage
.data
= (char *) pixels
896 + ((srcY
+ h
- 1) * rowLength
+ srcX
) * 2;
897 ximage
.byte_order
= LSBFirst
;
898 ximage
.bitmap_unit
= 16;
899 ximage
.bitmap_bit_order
= LSBFirst
;
900 ximage
.bitmap_pad
= 16;
902 ximage
.bytes_per_line
= -rowLength
* 2; /* negative to flip image */
903 ximage
.bits_per_pixel
= 16;
904 /* it seems we don't need to set the ximage.red/green/blue_mask fields */
905 /* flip Y axis for dest position */
906 dstY
= FLIP(xmesa
->xm_draw_buffer
, dstY
) - h
+ 1;
907 XPutImage(dpy
, buffer
, gc
, &ximage
, 0, 0, dstX
, dstY
, w
, h
);
911 /* software fallback */
912 _swrast_DrawPixels(ctx
, x
, y
, width
, height
,
913 format
, type
, unpack
, pixels
);
920 * Implement glCopyPixels for the front color buffer (or back buffer Pixmap)
921 * for the color buffer. Don't support zooming, pixel transfer, etc.
922 * We do support copying from one window to another, ala glXMakeCurrentRead.
925 xmesa_CopyPixels( GLcontext
*ctx
,
926 GLint srcx
, GLint srcy
, GLsizei width
, GLsizei height
,
927 GLint destx
, GLint desty
, GLenum type
)
929 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
930 const SWcontext
*swrast
= SWRAST_CONTEXT( ctx
);
931 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
932 const XMesaDrawable drawBuffer
= xmesa
->xm_draw_buffer
->buffer
;
933 const XMesaDrawable readBuffer
= xmesa
->xm_read_buffer
->buffer
;
934 const XMesaGC gc
= xmesa
->xm_draw_buffer
->gc
;
939 if (swrast
->NewState
)
940 _swrast_validate_derived( ctx
);
942 if (ctx
->Color
.DrawBuffer
== GL_FRONT
&&
943 ctx
->Pixel
.ReadBuffer
== GL_FRONT
&&
944 drawBuffer
&& /* buffer != 0 means it's a Window or Pixmap */
947 (swrast
->_RasterMask
& ~CLIP_BIT
) == 0 && /* no blend, z-test, etc */
948 ctx
->_ImageTransferState
== 0 && /* no color tables, scale/bias, etc */
949 ctx
->Pixel
.ZoomX
== 1.0 && /* no zooming */
950 ctx
->Pixel
.ZoomY
== 1.0) {
951 /* Note: we don't do any special clipping work here. We could,
952 * but X will do it for us.
954 srcy
= FLIP(xmesa
->xm_read_buffer
, srcy
) - height
+ 1;
955 desty
= FLIP(xmesa
->xm_draw_buffer
, desty
) - height
+ 1;
956 XCopyArea(dpy
, readBuffer
, drawBuffer
, gc
,
957 srcx
, srcy
, width
, height
, destx
, desty
);
960 _swrast_CopyPixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
);
963 #endif /* XFree86Server */
968 * Every driver should implement a GetString function in order to
969 * return a meaningful GL_RENDERER string.
971 static const GLubyte
*
972 get_string( GLcontext
*ctx
, GLenum name
)
978 return (const GLubyte
*) "Mesa GLX Indirect";
980 return (const GLubyte
*) "Mesa X11";
984 return (const GLubyte
*) "Mesa project: www.mesa3d.org";
995 * We implement the glEnable function only because we care about
996 * dither enable/disable.
999 enable( GLcontext
*ctx
, GLenum pname
, GLboolean state
)
1001 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1006 xmesa
->pixelformat
= xmesa
->xm_visual
->dithered_pf
;
1008 xmesa
->pixelformat
= xmesa
->xm_visual
->undithered_pf
;
1011 ; /* silence compiler warning */
1016 void xmesa_update_state( GLcontext
*ctx
, GLuint new_state
)
1018 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1020 /* Propogate statechange information to swrast and swrast_setup
1021 * modules. The X11 driver has no internal GL-dependent state.
1023 _swrast_InvalidateState( ctx
, new_state
);
1024 _ac_InvalidateState( ctx
, new_state
);
1025 _tnl_InvalidateState( ctx
, new_state
);
1026 _swsetup_InvalidateState( ctx
, new_state
);
1029 /* setup pointers to front and back buffer clear functions */
1030 xmesa
->xm_draw_buffer
->front_clear_func
= clear_front_pixmap
;
1031 if (xmesa
->xm_draw_buffer
->backpixmap
!= XIMAGE
) {
1032 xmesa
->xm_draw_buffer
->back_clear_func
= clear_back_pixmap
;
1034 else if (sizeof(GLushort
)!=2 || sizeof(GLuint
)!=4) {
1035 xmesa
->xm_draw_buffer
->back_clear_func
= clear_nbit_ximage
;
1037 else switch (xmesa
->xm_visual
->BitsPerPixel
) {
1039 if (xmesa
->xm_visual
->hpcr_clear_flag
) {
1040 xmesa
->xm_draw_buffer
->back_clear_func
= clear_HPCR_ximage
;
1043 xmesa
->xm_draw_buffer
->back_clear_func
= clear_8bit_ximage
;
1047 xmesa
->xm_draw_buffer
->back_clear_func
= clear_16bit_ximage
;
1050 xmesa
->xm_draw_buffer
->back_clear_func
= clear_24bit_ximage
;
1053 xmesa
->xm_draw_buffer
->back_clear_func
= clear_32bit_ximage
;
1056 xmesa
->xm_draw_buffer
->back_clear_func
= clear_nbit_ximage
;
1060 xmesa_update_span_funcs(ctx
);
1066 * Called via ctx->Driver.TestProxyTeximage(). Normally, we'd just use
1067 * the _mesa_test_proxy_teximage() fallback function, but we're going to
1068 * special-case the 3D texture case to allow textures up to 512x512x32
1072 test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1073 GLint internalFormat
, GLenum format
, GLenum type
,
1074 GLint width
, GLint height
, GLint depth
, GLint border
)
1076 if (target
== GL_PROXY_TEXTURE_3D
) {
1077 /* special case for 3D textures */
1078 if (width
* height
* depth
> 512 * 512 * 64 ||
1079 width
< 2 * border
||
1080 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1081 _mesa_bitcount(width
- 2 * border
) != 1) ||
1082 height
< 2 * border
||
1083 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1084 _mesa_bitcount(height
- 2 * border
) != 1) ||
1085 depth
< 2 * border
||
1086 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1087 _mesa_bitcount(depth
- 2 * border
) != 1)) {
1088 /* Bad size, or too many texels */
1094 /* use the fallback routine for 1D, 2D, cube and rect targets */
1095 return _mesa_test_proxy_teximage(ctx
, target
, level
, internalFormat
,
1096 format
, type
, width
, height
, depth
,
1104 /* Setup pointers and other driver state that is constant for the life
1107 void xmesa_init_pointers( GLcontext
*ctx
)
1110 struct swrast_device_driver
*dd
= _swrast_GetDeviceDriverReference( ctx
);
1111 const XMesaContext xmesa
= XMESA_CONTEXT(ctx
);
1113 /* Plug in our driver-specific functions here */
1114 ctx
->Driver
.GetString
= get_string
;
1115 ctx
->Driver
.GetBufferSize
= get_buffer_size
;
1116 ctx
->Driver
.Flush
= finish_or_flush
;
1117 ctx
->Driver
.Finish
= finish_or_flush
;
1118 ctx
->Driver
.ClearIndex
= clear_index
;
1119 ctx
->Driver
.ClearColor
= clear_color
;
1120 ctx
->Driver
.IndexMask
= index_mask
;
1121 ctx
->Driver
.ColorMask
= color_mask
;
1122 ctx
->Driver
.Enable
= enable
;
1124 /* Software rasterizer pixel paths:
1126 ctx
->Driver
.Accum
= _swrast_Accum
;
1127 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
1128 ctx
->Driver
.Clear
= clear_buffers
;
1129 ctx
->Driver
.ResizeBuffers
= xmesa_resize_buffers
;
1130 #ifdef XFree86Server
1131 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
1132 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
1134 ctx
->Driver
.CopyPixels
= /*_swrast_CopyPixels;*/xmesa_CopyPixels
;
1135 if (xmesa
->xm_visual
->undithered_pf
== PF_8R8G8B
&&
1136 xmesa
->xm_visual
->dithered_pf
== PF_8R8G8B
) {
1137 ctx
->Driver
.DrawPixels
= xmesa_DrawPixels_8R8G8B
;
1139 else if (xmesa
->xm_visual
->undithered_pf
== PF_5R6G5B
) {
1140 ctx
->Driver
.DrawPixels
= xmesa_DrawPixels_5R6G5B
;
1143 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
1146 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;
1147 ctx
->Driver
.DrawBuffer
= _swrast_DrawBuffer
;
1149 /* Software texture functions:
1151 ctx
->Driver
.ChooseTextureFormat
= _mesa_choose_tex_format
;
1152 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
1153 ctx
->Driver
.TexImage2D
= _mesa_store_teximage2d
;
1154 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
1155 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
1156 ctx
->Driver
.TexSubImage2D
= _mesa_store_texsubimage2d
;
1157 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
1158 ctx
->Driver
.TestProxyTexImage
= test_proxy_teximage
;
1160 ctx
->Driver
.CopyTexImage1D
= _swrast_copy_teximage1d
;
1161 ctx
->Driver
.CopyTexImage2D
= _swrast_copy_teximage2d
;
1162 ctx
->Driver
.CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
1163 ctx
->Driver
.CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
1164 ctx
->Driver
.CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
1166 ctx
->Driver
.CompressedTexImage1D
= _mesa_store_compressed_teximage1d
;
1167 ctx
->Driver
.CompressedTexImage2D
= _mesa_store_compressed_teximage2d
;
1168 ctx
->Driver
.CompressedTexImage3D
= _mesa_store_compressed_teximage3d
;
1169 ctx
->Driver
.CompressedTexSubImage1D
= _mesa_store_compressed_texsubimage1d
;
1170 ctx
->Driver
.CompressedTexSubImage2D
= _mesa_store_compressed_texsubimage2d
;
1171 ctx
->Driver
.CompressedTexSubImage3D
= _mesa_store_compressed_texsubimage3d
;
1173 /* Swrast hooks for imaging extensions:
1175 ctx
->Driver
.CopyColorTable
= _swrast_CopyColorTable
;
1176 ctx
->Driver
.CopyColorSubTable
= _swrast_CopyColorSubTable
;
1177 ctx
->Driver
.CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
1178 ctx
->Driver
.CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
1180 /* Initialize the TNL driver interface:
1182 tnl
= TNL_CONTEXT(ctx
);
1183 tnl
->Driver
.RunPipeline
= _tnl_run_pipeline
;
1185 dd
->SetBuffer
= set_buffer
;
1187 /* Install swsetup for tnl->Driver.Render.*:
1189 _swsetup_Wakeup(ctx
);
1191 (void) DitherValues
; /* silenced unused var warning */
1198 #define XMESA_NEW_POINT (_NEW_POINT | \
1200 _SWRAST_NEW_RASTERMASK)
1202 #define XMESA_NEW_LINE (_NEW_LINE | \
1207 _SWRAST_NEW_RASTERMASK)
1209 #define XMESA_NEW_TRIANGLE (_NEW_POLYGON | \
1214 _SWRAST_NEW_RASTERMASK)
1217 /* Extend the software rasterizer with our line/point/triangle
1220 void xmesa_register_swrast_functions( GLcontext
*ctx
)
1222 SWcontext
*swrast
= SWRAST_CONTEXT( ctx
);
1224 swrast
->choose_point
= xmesa_choose_point
;
1225 swrast
->choose_line
= xmesa_choose_line
;
1226 swrast
->choose_triangle
= xmesa_choose_triangle
;
1228 swrast
->invalidate_point
|= XMESA_NEW_POINT
;
1229 swrast
->invalidate_line
|= XMESA_NEW_LINE
;
1230 swrast
->invalidate_triangle
|= XMESA_NEW_TRIANGLE
;