1 /* $Id: xm_dd.c,v 1.33 2002/06/19 21:49:37 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 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.
26 /* $XFree86: xc/extras/Mesa/src/X/xm_dd.c,v 1.2 2002/02/26 23:37:31 tsi Exp $ */
28 #include "glxheader.h"
32 #include "extensions.h"
38 #include "texformat.h"
40 #include "array_cache/acache.h"
41 #include "swrast/s_context.h"
42 #include "swrast/swrast.h"
43 #include "swrast/s_alphabuf.h"
44 #include "swrast_setup/swrast_setup.h"
46 #include "tnl/t_context.h"
47 #include "tnl/t_pipeline.h"
51 * Return the size (width, height) of the X window for the given GLframebuffer.
52 * Output: width - width of buffer in pixels.
53 * height - height of buffer in pixels.
56 get_buffer_size( GLframebuffer
*buffer
, GLuint
*width
, GLuint
*height
)
58 /* We can do this cast because the first field in the XMesaBuffer
59 * struct is a GLframebuffer struct. If this weren't true, we'd
60 * need a pointer from the GLframebuffer to the XMesaBuffer.
62 const XMesaBuffer xmBuffer
= (XMesaBuffer
) buffer
;
63 unsigned int winwidth
, winheight
;
65 /* XFree86 GLX renderer */
66 winwidth
= xmBuffer
->frontbuffer
->width
;
67 winheight
= xmBuffer
->frontbuffer
->height
;
73 _glthread_LOCK_MUTEX(_xmesa_lock
);
74 XSync(xmBuffer
->xm_visual
->display
, 0); /* added for Chromium */
75 XGetGeometry( xmBuffer
->xm_visual
->display
, xmBuffer
->frontbuffer
, &root
,
76 &winx
, &winy
, &winwidth
, &winheight
, &bw
, &d
);
77 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
80 (void)kernel8
; /* Muffle compiler */
88 finish( GLcontext
*ctx
)
93 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
95 _glthread_LOCK_MUTEX(_xmesa_lock
);
96 XSync( xmesa
->display
, False
);
97 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
104 flush( GLcontext
*ctx
)
109 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
111 _glthread_LOCK_MUTEX(_xmesa_lock
);
112 XFlush( xmesa
->display
);
113 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
120 set_draw_buffer( GLcontext
*ctx
, GLenum mode
)
122 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
123 if (mode
== GL_FRONT_LEFT
) {
124 /* write to front buffer */
125 xmesa
->xm_buffer
->buffer
= xmesa
->xm_buffer
->frontbuffer
;
126 xmesa_update_span_funcs(ctx
);
128 else if (mode
==GL_BACK_LEFT
&& xmesa
->xm_buffer
->db_state
) {
129 /* write to back buffer */
130 if (xmesa
->xm_buffer
->backpixmap
) {
131 xmesa
->xm_buffer
->buffer
=
132 (XMesaDrawable
)xmesa
->xm_buffer
->backpixmap
;
134 else if (xmesa
->xm_buffer
->backimage
) {
135 xmesa
->xm_buffer
->buffer
= None
;
138 /* just in case there wasn't enough memory for back buffer */
139 xmesa
->xm_buffer
->buffer
= xmesa
->xm_buffer
->frontbuffer
;
141 xmesa_update_span_funcs(ctx
);
144 /* the swrast->_RasterMask MULTI_DRAW_BIT will be set and
145 * we'll fall back to swrast to draw points/lines/triangles.
152 xmesa_set_read_buffer( GLcontext
*ctx
, GLframebuffer
*buffer
, GLenum mode
)
155 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
157 if (buffer
== ctx
->DrawBuffer
) {
158 target
= xmesa
->xm_buffer
;
159 xmesa
->use_read_buffer
= GL_FALSE
;
162 ASSERT(buffer
== ctx
->ReadBuffer
);
163 target
= xmesa
->xm_read_buffer
;
164 xmesa
->use_read_buffer
= GL_TRUE
;
167 if (mode
== GL_FRONT_LEFT
) {
168 target
->buffer
= target
->frontbuffer
;
169 xmesa_update_span_funcs(ctx
);
171 else if (mode
==GL_BACK_LEFT
&& xmesa
->xm_read_buffer
->db_state
) {
172 if (target
->backpixmap
) {
173 target
->buffer
= (XMesaDrawable
)xmesa
->xm_buffer
->backpixmap
;
175 else if (target
->backimage
) {
176 target
->buffer
= None
;
179 /* just in case there wasn't enough memory for back buffer */
180 target
->buffer
= target
->frontbuffer
;
182 xmesa_update_span_funcs(ctx
);
185 _mesa_problem(ctx
, "invalid buffer in set_read_buffer() in xmesa2.c");
192 clear_index( GLcontext
*ctx
, GLuint index
)
194 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
195 xmesa
->clearpixel
= (unsigned long) index
;
196 XMesaSetForeground( xmesa
->display
, xmesa
->xm_buffer
->cleargc
,
197 (unsigned long) index
);
202 clear_color( GLcontext
*ctx
, const GLchan color
[4] )
204 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
205 xmesa
->clearcolor
[0] = color
[0];
206 xmesa
->clearcolor
[1] = color
[1];
207 xmesa
->clearcolor
[2] = color
[2];
208 xmesa
->clearcolor
[3] = color
[3];
209 xmesa
->clearpixel
= xmesa_color_to_pixel( xmesa
, color
[0], color
[1],
211 xmesa
->xm_visual
->undithered_pf
);
212 _glthread_LOCK_MUTEX(_xmesa_lock
);
213 XMesaSetForeground( xmesa
->display
, xmesa
->xm_buffer
->cleargc
,
215 _glthread_UNLOCK_MUTEX(_xmesa_lock
);
220 /* Set index mask ala glIndexMask */
222 index_mask( GLcontext
*ctx
, GLuint mask
)
224 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
225 if (xmesa
->xm_buffer
->buffer
!= XIMAGE
) {
227 if (mask
==0xffffffff) {
228 m
= ((unsigned long)~0L);
231 m
= (unsigned long) mask
;
233 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_buffer
->cleargc
, m
);
238 /* Implements glColorMask() */
240 color_mask(GLcontext
*ctx
,
241 GLboolean rmask
, GLboolean gmask
, GLboolean bmask
, GLboolean amask
)
243 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
244 int xclass
= GET_VISUAL_CLASS(xmesa
->xm_visual
);
247 if (xclass
== TrueColor
|| xclass
== DirectColor
) {
249 if (rmask
&& gmask
&& bmask
) {
250 m
= ((unsigned long)~0L);
254 if (rmask
) m
|= GET_REDMASK(xmesa
->xm_visual
);
255 if (gmask
) m
|= GET_GREENMASK(xmesa
->xm_visual
);
256 if (bmask
) m
|= GET_BLUEMASK(xmesa
->xm_visual
);
258 XMesaSetPlaneMask( xmesa
->display
, xmesa
->xm_buffer
->cleargc
, m
);
264 /**********************************************************************/
265 /*** glClear implementations ***/
266 /**********************************************************************/
270 clear_front_pixmap( GLcontext
*ctx
, GLboolean all
,
271 GLint x
, GLint y
, GLint width
, GLint height
)
273 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
275 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->frontbuffer
,
276 xmesa
->xm_buffer
->cleargc
,
278 xmesa
->xm_buffer
->width
+1,
279 xmesa
->xm_buffer
->height
+1 );
282 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->frontbuffer
,
283 xmesa
->xm_buffer
->cleargc
,
284 x
, xmesa
->xm_buffer
->height
- y
- height
,
291 clear_back_pixmap( GLcontext
*ctx
, GLboolean all
,
292 GLint x
, GLint y
, GLint width
, GLint height
)
294 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
296 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->backpixmap
,
297 xmesa
->xm_buffer
->cleargc
,
299 xmesa
->xm_buffer
->width
+1,
300 xmesa
->xm_buffer
->height
+1 );
303 XMesaFillRectangle( xmesa
->display
, xmesa
->xm_buffer
->backpixmap
,
304 xmesa
->xm_buffer
->cleargc
,
305 x
, xmesa
->xm_buffer
->height
- y
- height
,
312 clear_8bit_ximage( GLcontext
*ctx
, GLboolean all
,
313 GLint x
, GLint y
, GLint width
, GLint height
)
315 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
317 size_t n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
318 * xmesa
->xm_buffer
->backimage
->height
;
319 MEMSET( xmesa
->xm_buffer
->backimage
->data
, xmesa
->clearpixel
, n
);
323 for (i
=0;i
<height
;i
++) {
324 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_buffer
, x
, y
+i
);
325 MEMSET( ptr
, xmesa
->clearpixel
, width
);
332 clear_HPCR_ximage( GLcontext
*ctx
, GLboolean all
,
333 GLint x
, GLint y
, GLint width
, GLint height
)
335 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
337 GLint i
, c16
= (xmesa
->xm_buffer
->backimage
->bytes_per_line
>>4)<<4;
338 GLubyte
*ptr
= (GLubyte
*)xmesa
->xm_buffer
->backimage
->data
;
339 for (i
=0; i
<xmesa
->xm_buffer
->backimage
->height
; i
++) {
341 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
345 for (j
=0; j
<c16
; j
+=16) {
364 for (; j
<xmesa
->xm_buffer
->backimage
->bytes_per_line
; j
++) {
372 for (i
=y
; i
<y
+height
; i
++) {
373 GLubyte
*ptr
= PIXELADDR1( xmesa
->xm_buffer
, x
, i
);
375 GLubyte
*sptr
= xmesa
->xm_visual
->hpcr_clear_ximage_pattern
[0];
379 for (j
=x
; j
<x
+width
; j
++) {
389 clear_16bit_ximage( GLcontext
*ctx
, GLboolean all
,
390 GLint x
, GLint y
, GLint width
, GLint height
)
392 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
393 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
394 if (xmesa
->swapbytes
) {
395 pixel
= ((pixel
>> 8) & 0x00ff) | ((pixel
<< 8) & 0xff00);
399 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_buffer
->backimage
->data
;
400 if ((pixel
& 0xff) == ((pixel
>> 8) & 0xff)) {
401 /* low and high bytes are equal so use memset() */
402 n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
403 * xmesa
->xm_buffer
->height
;
404 MEMSET( ptr4
, pixel
& 0xff, n
);
407 pixel
= pixel
| (pixel
<<16);
408 n
= xmesa
->xm_buffer
->backimage
->bytes_per_line
409 * xmesa
->xm_buffer
->height
/ 4;
415 if ((xmesa
->xm_buffer
->backimage
->bytes_per_line
*
416 xmesa
->xm_buffer
->height
) & 0x2)
417 *(GLushort
*)ptr4
= pixel
& 0xffff;
422 for (j
=0;j
<height
;j
++) {
423 register GLushort
*ptr2
= PIXELADDR2( xmesa
->xm_buffer
, x
, y
+j
);
424 for (i
=0;i
<width
;i
++) {
432 /* Optimized code provided by Nozomi Ytow <noz@xfree86.org> */
434 clear_24bit_ximage( GLcontext
*ctx
, GLboolean all
,
435 GLint x
, GLint y
, GLint width
, GLint height
)
437 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
438 const GLubyte r
= xmesa
->clearcolor
[0];
439 const GLubyte g
= xmesa
->clearcolor
[1];
440 const GLubyte b
= xmesa
->clearcolor
[2];
441 register GLuint clearPixel
;
442 if (xmesa
->swapbytes
) {
443 clearPixel
= (b
<< 16) | (g
<< 8) | r
;
446 clearPixel
= (r
<< 16) | (g
<< 8) | b
;
451 /* same value for all three components (gray) */
452 const GLint w3
= xmesa
->xm_buffer
->width
* 3;
453 const GLint h
= xmesa
->xm_buffer
->height
;
455 for (i
= 0; i
< h
; i
++) {
456 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_buffer
, 0, i
);
462 const GLint w
= xmesa
->xm_buffer
->width
;
463 const GLint h
= xmesa
->xm_buffer
->height
;
465 for (i
= 0; i
< h
; i
++) {
466 bgr_t
*ptr3
= PIXELADDR3(xmesa
->xm_buffer
, 0, i
);
467 for (j
= 0; j
< w
; j
++) {
474 #if 0 /* this code doesn't work for all window widths */
475 register GLuint
*ptr4
= (GLuint
*) ptr3
;
478 register GLuint
*p
= pixel4
;
479 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
480 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
481 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
482 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
486 px
= *ptr4
& 0x00ffffff;
487 px
|= pixel4
[0] & 0xff000000;
489 px
= *ptr4
& 0xffff0000;
490 px
|= pixel4
[2] & 0x0000ffff;
495 px
= *ptr4
& 0x0000fffff;
496 px
|= pixel4
[1] & 0xffff0000;
498 px
= *ptr4
& 0xffffff00;
499 px
|= pixel4
[2] & 0x000000ff;
504 px
= *ptr4
& 0x000000ff;
505 px
|= pixel4
[2] & 0xffffff00;
522 px
= *ptr4
& 0xffffff00;
523 px
|= clearPixel
& 0xff;
529 px
= *ptr4
& 0xffff0000;
534 px
= *ptr4
& 0xff000000;
545 /* only clear subrect of color buffer */
547 /* same value for all three components (gray) */
549 for (j
=0;j
<height
;j
++) {
550 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
551 MEMSET(ptr3
, r
, 3 * width
);
555 /* non-gray clear color */
557 for (j
= 0; j
< height
; j
++) {
558 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
559 for (i
= 0; i
< width
; i
++) {
566 #if 0 /* this code might not always (seems ptr3 always == ptr4) */
569 pixel4
[0] = clearPixel
| (clearPixel
<< 24);
570 pixel4
[1] = (clearPixel
<< 16) | (clearPixel
>> 8);
571 pixel4
[2] = (clearPixel
<< 8) | (clearPixel
>> 16);
572 for (j
=0;j
<height
;j
++) {
573 bgr_t
*ptr3
= PIXELADDR3( xmesa
->xm_buffer
, x
, y
+j
);
574 register GLuint
*ptr4
= (GLuint
*)ptr3
;
575 register GLuint
*p
, px
;
577 switch (3 & (int)(ptr3
- (bgr_t
*) ptr4
)){
581 px
= *ptr4
& 0x00ffffff;
582 px
|= pixel4
[0] & 0xff000000;
584 px
= *ptr4
& 0xffff0000;
585 px
|= pixel4
[2] & 0x0000ffff;
590 px
= *ptr4
& 0x0000fffff;
591 px
|= pixel4
[1] & 0xffff0000;
593 px
= *ptr4
& 0xffffff00;
594 px
|= pixel4
[2] & 0x000000ff;
599 px
= *ptr4
& 0x000000ff;
600 px
|= pixel4
[2] & 0xffffff00;
617 px
= *ptr4
& 0xffffff00;
624 px
= *ptr4
& 0xffff0000;
629 px
= *ptr4
& 0xff000000;
630 px
|= pixel4
[0] & 0xffffff;
644 clear_32bit_ximage( GLcontext
*ctx
, GLboolean all
,
645 GLint x
, GLint y
, GLint width
, GLint height
)
647 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
648 register GLuint pixel
= (GLuint
) xmesa
->clearpixel
;
649 if (xmesa
->swapbytes
) {
650 pixel
= ((pixel
>> 24) & 0x000000ff)
651 | ((pixel
>> 8) & 0x0000ff00)
652 | ((pixel
<< 8) & 0x00ff0000)
653 | ((pixel
<< 24) & 0xff000000);
656 register GLint n
= xmesa
->xm_buffer
->width
* xmesa
->xm_buffer
->height
;
657 register GLuint
*ptr4
= (GLuint
*) xmesa
->xm_buffer
->backimage
->data
;
659 MEMSET( ptr4
, pixel
, 4*n
);
670 for (j
=0;j
<height
;j
++) {
671 register GLuint
*ptr4
= PIXELADDR4( xmesa
->xm_buffer
, x
, y
+j
);
672 for (i
=0;i
<width
;i
++) {
681 clear_nbit_ximage( GLcontext
*ctx
, GLboolean all
,
682 GLint x
, GLint y
, GLint width
, GLint height
)
684 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
685 XMesaImage
*img
= xmesa
->xm_buffer
->backimage
;
688 width
= xmesa
->xm_buffer
->width
;
689 height
= xmesa
->xm_buffer
->height
;
690 for (j
=0;j
<height
;j
++) {
691 for (i
=0;i
<width
;i
++) {
692 XMesaPutPixel( img
, i
, j
, xmesa
->clearpixel
);
697 /* TODO: optimize this */
699 y
= FLIP(xmesa
->xm_buffer
, y
);
700 for (j
=0;j
<height
;j
++) {
701 for (i
=0;i
<width
;i
++) {
702 XMesaPutPixel( img
, x
+i
, y
-j
, xmesa
->clearpixel
);
711 clear_buffers( GLcontext
*ctx
, GLbitfield mask
,
712 GLboolean all
, GLint x
, GLint y
, GLint width
, GLint height
)
714 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
715 const GLuint
*colorMask
= (GLuint
*) &ctx
->Color
.ColorMask
;
717 if ((mask
& (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
)) &&
718 xmesa
->xm_buffer
->mesa_buffer
.UseSoftwareAlphaBuffers
&&
719 ctx
->Color
.ColorMask
[ACOMP
]) {
720 _mesa_clear_alpha_buffers(ctx
);
723 /* we can't handle color or index masking */
724 if (*colorMask
== 0xffffffff && ctx
->Color
.IndexMask
== 0xffffffff) {
725 if (mask
& DD_FRONT_LEFT_BIT
) {
726 ASSERT(xmesa
->xm_buffer
->front_clear_func
);
727 (*xmesa
->xm_buffer
->front_clear_func
)( ctx
, all
, x
, y
, width
, height
);
728 mask
&= ~DD_FRONT_LEFT_BIT
;
730 if (mask
& DD_BACK_LEFT_BIT
) {
731 ASSERT(xmesa
->xm_buffer
->back_clear_func
);
732 (*xmesa
->xm_buffer
->back_clear_func
)( ctx
, all
, x
, y
, width
, height
);
733 mask
&= ~DD_BACK_LEFT_BIT
;
738 _swrast_Clear( ctx
, mask
, all
, x
, y
, width
, height
);
743 * When we detect that the user has resized the window this function will
744 * get called. Here we'll reallocate the back buffer, depth buffer,
745 * stencil buffer etc. to match the new window size.
748 xmesa_resize_buffers( GLframebuffer
*buffer
)
750 int height
= (int) buffer
->Height
;
751 /* We can do this cast because the first field in the XMesaBuffer
752 * struct is a GLframebuffer struct. If this weren't true, we'd
753 * need a pointer from the GLframebuffer to the XMesaBuffer.
755 XMesaBuffer xmBuffer
= (XMesaBuffer
) buffer
;
757 xmBuffer
->width
= buffer
->Width
;
758 xmBuffer
->height
= buffer
->Height
;
759 xmesa_alloc_back_buffer( xmBuffer
);
761 /* Needed by FLIP macro */
762 xmBuffer
->bottom
= height
- 1;
764 if (xmBuffer
->backimage
) {
765 /* Needed by PIXELADDR1 macro */
766 xmBuffer
->ximage_width1
= xmBuffer
->backimage
->bytes_per_line
;
767 xmBuffer
->ximage_origin1
= (GLubyte
*) xmBuffer
->backimage
->data
768 + xmBuffer
->ximage_width1
* (height
-1);
770 /* Needed by PIXELADDR2 macro */
771 xmBuffer
->ximage_width2
= xmBuffer
->backimage
->bytes_per_line
/ 2;
772 xmBuffer
->ximage_origin2
= (GLushort
*) xmBuffer
->backimage
->data
773 + xmBuffer
->ximage_width2
* (height
-1);
775 /* Needed by PIXELADDR3 macro */
776 xmBuffer
->ximage_width3
= xmBuffer
->backimage
->bytes_per_line
;
777 xmBuffer
->ximage_origin3
= (GLubyte
*) xmBuffer
->backimage
->data
778 + xmBuffer
->ximage_width3
* (height
-1);
780 /* Needed by PIXELADDR4 macro */
781 xmBuffer
->ximage_width4
= xmBuffer
->backimage
->width
;
782 xmBuffer
->ximage_origin4
= (GLuint
*) xmBuffer
->backimage
->data
783 + xmBuffer
->ximage_width4
* (height
-1);
786 _swrast_alloc_buffers( buffer
);
791 * This function implements glDrawPixels() with an XPutImage call when
792 * drawing to the front buffer (X Window drawable).
793 * The image format must be GL_BGRA to match the PF_8R8G8B pixel format.
794 * XXX top/bottom edge clipping is broken!
797 drawpixels_8R8G8B( GLcontext
*ctx
,
798 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
799 GLenum format
, GLenum type
,
800 const struct gl_pixelstore_attrib
*unpack
,
801 const GLvoid
*pixels
)
803 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
804 XMesaDisplay
*dpy
= xmesa
->xm_visual
->display
;
805 XMesaDrawable buffer
= xmesa
->xm_buffer
->buffer
;
806 XMesaGC gc
= xmesa
->xm_buffer
->gc
;
811 /* XXX also check for pixel scale/bias/lookup/zooming! */
812 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
) {
817 int srcX
= unpack
->SkipPixels
;
818 int srcY
= unpack
->SkipRows
;
819 if (_mesa_clip_pixelrect(ctx
, &dstX
, &dstY
, &w
, &h
, &srcX
, &srcY
)) {
821 MEMSET(&ximage
, 0, sizeof(XMesaImage
));
822 ximage
.width
= width
;
823 ximage
.height
= height
;
824 ximage
.format
= ZPixmap
;
825 ximage
.data
= (char *) pixels
+ (height
- 1) * width
* 4;
826 ximage
.byte_order
= LSBFirst
;
827 ximage
.bitmap_unit
= 32;
828 ximage
.bitmap_bit_order
= LSBFirst
;
829 ximage
.bitmap_pad
= 32;
831 ximage
.bytes_per_line
= -width
* 4;
832 ximage
.bits_per_pixel
= 32;
833 ximage
.red_mask
= 0xff0000;
834 ximage
.green_mask
= 0x00ff00;
835 ximage
.blue_mask
= 0x0000ff;
836 dstY
= FLIP(xmesa
->xm_buffer
,dstY
) - height
+ 1;
837 XPutImage(dpy
, buffer
, gc
, &ximage
, srcX
, srcY
, dstX
, dstY
, w
, h
);
847 static const GLubyte
*
848 get_string( GLcontext
*ctx
, GLenum name
)
854 return (const GLubyte
*) "Mesa GLX Indirect";
856 return (const GLubyte
*) "Mesa X11";
860 return (const GLubyte
*) "Mesa project: www.mesa3d.org";
871 enable( GLcontext
*ctx
, GLenum pname
, GLboolean state
)
873 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
878 xmesa
->pixelformat
= xmesa
->xm_visual
->dithered_pf
;
880 xmesa
->pixelformat
= xmesa
->xm_visual
->undithered_pf
;
883 ; /* silence compiler warning */
888 void xmesa_update_state( GLcontext
*ctx
, GLuint new_state
)
890 const XMesaContext xmesa
= (XMesaContext
) ctx
->DriverCtx
;
892 /* Propogate statechange information to swrast and swrast_setup
893 * modules. The X11 driver has no internal GL-dependent state.
895 _swrast_InvalidateState( ctx
, new_state
);
896 _ac_InvalidateState( ctx
, new_state
);
897 _tnl_InvalidateState( ctx
, new_state
);
898 _swsetup_InvalidateState( ctx
, new_state
);
901 /* setup pointers to front and back buffer clear functions */
902 xmesa
->xm_buffer
->front_clear_func
= clear_front_pixmap
;
903 if (xmesa
->xm_buffer
->backpixmap
!= XIMAGE
) {
904 xmesa
->xm_buffer
->back_clear_func
= clear_back_pixmap
;
906 else if (sizeof(GLushort
)!=2 || sizeof(GLuint
)!=4) {
907 xmesa
->xm_buffer
->back_clear_func
= clear_nbit_ximage
;
909 else switch (xmesa
->xm_visual
->BitsPerPixel
) {
911 if (xmesa
->xm_visual
->hpcr_clear_flag
) {
912 xmesa
->xm_buffer
->back_clear_func
= clear_HPCR_ximage
;
915 xmesa
->xm_buffer
->back_clear_func
= clear_8bit_ximage
;
919 xmesa
->xm_buffer
->back_clear_func
= clear_16bit_ximage
;
922 xmesa
->xm_buffer
->back_clear_func
= clear_24bit_ximage
;
925 xmesa
->xm_buffer
->back_clear_func
= clear_32bit_ximage
;
928 xmesa
->xm_buffer
->back_clear_func
= clear_nbit_ximage
;
932 xmesa_update_span_funcs(ctx
);
937 /* Setup pointers and other driver state that is constant for the life
940 void xmesa_init_pointers( GLcontext
*ctx
)
944 ctx
->Driver
.GetString
= get_string
;
945 ctx
->Driver
.GetBufferSize
= get_buffer_size
;
946 ctx
->Driver
.Flush
= flush
;
947 ctx
->Driver
.Finish
= finish
;
949 /* Software rasterizer pixel paths:
951 ctx
->Driver
.Accum
= _swrast_Accum
;
952 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
953 ctx
->Driver
.Clear
= clear_buffers
;
954 ctx
->Driver
.ResizeBuffers
= xmesa_resize_buffers
;
955 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
956 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
957 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;
959 /* Software texture functions:
961 ctx
->Driver
.ChooseTextureFormat
= _mesa_choose_tex_format
;
962 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
963 ctx
->Driver
.TexImage2D
= _mesa_store_teximage2d
;
964 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
965 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
966 ctx
->Driver
.TexSubImage2D
= _mesa_store_texsubimage2d
;
967 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
968 ctx
->Driver
.TestProxyTexImage
= _mesa_test_proxy_teximage
;
970 ctx
->Driver
.CopyTexImage1D
= _swrast_copy_teximage1d
;
971 ctx
->Driver
.CopyTexImage2D
= _swrast_copy_teximage2d
;
972 ctx
->Driver
.CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
973 ctx
->Driver
.CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
974 ctx
->Driver
.CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
976 ctx
->Driver
.BaseCompressedTexFormat
= _mesa_base_compressed_texformat
;
977 ctx
->Driver
.CompressedTextureSize
= _mesa_compressed_texture_size
;
978 ctx
->Driver
.GetCompressedTexImage
= _mesa_get_compressed_teximage
;
980 /* Swrast hooks for imaging extensions:
982 ctx
->Driver
.CopyColorTable
= _swrast_CopyColorTable
;
983 ctx
->Driver
.CopyColorSubTable
= _swrast_CopyColorSubTable
;
984 ctx
->Driver
.CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
985 ctx
->Driver
.CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
988 /* Statechange callbacks:
990 ctx
->Driver
.SetDrawBuffer
= set_draw_buffer
;
991 ctx
->Driver
.ClearIndex
= clear_index
;
992 ctx
->Driver
.ClearColor
= clear_color
;
993 ctx
->Driver
.IndexMask
= index_mask
;
994 ctx
->Driver
.ColorMask
= color_mask
;
995 ctx
->Driver
.Enable
= enable
;
998 /* Initialize the TNL driver interface:
1000 tnl
= TNL_CONTEXT(ctx
);
1001 tnl
->Driver
.RunPipeline
= _tnl_run_pipeline
;
1003 /* Install swsetup for tnl->Driver.Render.*:
1005 _swsetup_Wakeup(ctx
);
1007 (void) DitherValues
; /* silenced unused var warning */
1014 #define XMESA_NEW_POINT (_NEW_POINT | \
1016 _SWRAST_NEW_RASTERMASK)
1018 #define XMESA_NEW_LINE (_NEW_LINE | \
1023 _SWRAST_NEW_RASTERMASK)
1025 #define XMESA_NEW_TRIANGLE (_NEW_POLYGON | \
1030 _SWRAST_NEW_RASTERMASK)
1033 /* Extend the software rasterizer with our line/point/triangle
1036 void xmesa_register_swrast_functions( GLcontext
*ctx
)
1038 SWcontext
*swrast
= SWRAST_CONTEXT( ctx
);
1040 swrast
->choose_point
= xmesa_choose_point
;
1041 swrast
->choose_line
= xmesa_choose_line
;
1042 swrast
->choose_triangle
= xmesa_choose_triangle
;
1044 swrast
->invalidate_point
|= XMESA_NEW_POINT
;
1045 swrast
->invalidate_line
|= XMESA_NEW_LINE
;
1046 swrast
->invalidate_triangle
|= XMESA_NEW_TRIANGLE
;