GL_(UN)PACK_SKIP_IMAGES should only be applied to 3D texture pack/unpacking
[mesa.git] / src / mesa / drivers / x11 / xm_dd.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.3
4 *
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25
26 #include "glxheader.h"
27 #include "bufferobj.h"
28 #include "context.h"
29 #include "colormac.h"
30 #include "depth.h"
31 #include "drawpix.h"
32 #include "extensions.h"
33 #include "macros.h"
34 #include "image.h"
35 #include "imports.h"
36 #include "mtypes.h"
37 #include "state.h"
38 #include "texobj.h"
39 #include "teximage.h"
40 #include "texstore.h"
41 #include "texformat.h"
42 #include "xmesaP.h"
43 #include "array_cache/acache.h"
44 #include "swrast/swrast.h"
45 #include "swrast/s_auxbuffer.h"
46 #include "swrast/s_context.h"
47 #include "swrast/s_alphabuf.h"
48 #include "swrast_setup/swrast_setup.h"
49 #include "tnl/tnl.h"
50 #include "tnl/t_context.h"
51
52 #ifdef XFree86Server
53 #include <GL/glxtokens.h>
54 #endif
55
56
57
58 /*
59 * Dithering kernels and lookup tables.
60 */
61
62 const int xmesa_kernel8[DITH_DY * DITH_DX] = {
63 0 * MAXC, 8 * MAXC, 2 * MAXC, 10 * MAXC,
64 12 * MAXC, 4 * MAXC, 14 * MAXC, 6 * MAXC,
65 3 * MAXC, 11 * MAXC, 1 * MAXC, 9 * MAXC,
66 15 * MAXC, 7 * MAXC, 13 * MAXC, 5 * MAXC,
67 };
68
69 const short xmesa_HPCR_DRGB[3][2][16] = {
70 {
71 { 16, -4, 1,-11, 14, -6, 3, -9, 15, -5, 2,-10, 13, -7, 4, -8},
72 {-15, 5, 0, 12,-13, 7, -2, 10,-14, 6, -1, 11,-12, 8, -3, 9}
73 },
74 {
75 {-11, 15, -7, 3, -8, 14, -4, 2,-10, 16, -6, 4, -9, 13, -5, 1},
76 { 12,-14, 8, -2, 9,-13, 5, -1, 11,-15, 7, -3, 10,-12, 6, 0}
77 },
78 {
79 { 6,-18, 26,-14, 2,-22, 30,-10, 8,-16, 28,-12, 4,-20, 32, -8},
80 { -4, 20,-24, 16, 0, 24,-28, 12, -6, 18,-26, 14, -2, 22,-30, 10}
81 }
82 };
83
84 const int xmesa_kernel1[16] = {
85 0*47, 9*47, 4*47, 12*47, /* 47 = (255*3)/16 */
86 6*47, 2*47, 14*47, 8*47,
87 10*47, 1*47, 5*47, 11*47,
88 7*47, 13*47, 3*47, 15*47
89 };
90
91
92 /*
93 * Return the size (width, height) of the X window for the given GLframebuffer.
94 * Output: width - width of buffer in pixels.
95 * height - height of buffer in pixels.
96 */
97 static void
98 get_buffer_size( GLframebuffer *buffer, GLuint *width, GLuint *height )
99 {
100 /* We can do this cast because the first field in the XMesaBuffer
101 * struct is a GLframebuffer struct. If this weren't true, we'd
102 * need a pointer from the GLframebuffer to the XMesaBuffer.
103 */
104 const XMesaBuffer xmBuffer = (XMesaBuffer) buffer;
105 unsigned int winwidth, winheight;
106 #ifdef XFree86Server
107 /* XFree86 GLX renderer */
108 winwidth = MIN2(xmBuffer->frontbuffer->width, MAX_WIDTH);
109 winheight = MIN2(xmBuffer->frontbuffer->height, MAX_HEIGHT);
110 #else
111 Window root;
112 int winx, winy;
113 unsigned int bw, d;
114
115 _glthread_LOCK_MUTEX(_xmesa_lock);
116 XSync(xmBuffer->xm_visual->display, 0); /* added for Chromium */
117 XGetGeometry( xmBuffer->xm_visual->display, xmBuffer->frontbuffer, &root,
118 &winx, &winy, &winwidth, &winheight, &bw, &d );
119 _glthread_UNLOCK_MUTEX(_xmesa_lock);
120 #endif
121
122 *width = winwidth;
123 *height = winheight;
124 }
125
126
127 static void
128 finish_or_flush( GLcontext *ctx )
129 {
130 #ifdef XFree86Server
131 /* NOT_NEEDED */
132 #else
133 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
134 if (xmesa) {
135 _glthread_LOCK_MUTEX(_xmesa_lock);
136 XSync( xmesa->display, False );
137 _glthread_UNLOCK_MUTEX(_xmesa_lock);
138 }
139 #endif
140 }
141
142
143
144 /*
145 * This chooses the color buffer for reading and writing spans, points,
146 * lines, and triangles.
147 */
148 void
149 xmesa_set_buffer( GLcontext *ctx, GLframebuffer *buffer, GLuint bufferBit )
150 {
151 /* We can make this cast since the XMesaBuffer wraps GLframebuffer.
152 * GLframebuffer is the first member in a XMesaBuffer struct.
153 */
154 XMesaBuffer target = (XMesaBuffer) buffer;
155 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
156
157 /* This assignment tells the span/point/line/triangle functions
158 * which XMesaBuffer to use.
159 */
160 xmesa->xm_buffer = target;
161
162 /*
163 * Now determine front vs back color buffer.
164 */
165 if (bufferBit == DD_FRONT_LEFT_BIT) {
166 target->buffer = target->frontbuffer;
167 xmesa_update_span_funcs(ctx);
168 }
169 else if (bufferBit == DD_BACK_LEFT_BIT) {
170 ASSERT(target->db_state);
171 if (target->backpixmap) {
172 /* back buffer is a pixmap */
173 target->buffer = (XMesaDrawable) target->backpixmap;
174 }
175 else if (target->backimage) {
176 /* back buffer is an XImage */
177 target->buffer = None;
178 }
179 else {
180 /* No back buffer!!!! Must be out of memory, use front buffer */
181 target->buffer = target->frontbuffer;
182 }
183 xmesa_update_span_funcs(ctx);
184 }
185 else if (bufferBit & (DD_AUX0_BIT | DD_AUX1_BIT | DD_AUX2_BIT | DD_AUX3_BIT)) {
186 _swrast_use_aux_buffer(ctx, buffer, bufferBit);
187 }
188 else {
189 _mesa_problem(ctx, "invalid buffer 0x%x in set_buffer() in xm_dd.c");
190 return;
191 }
192 }
193
194
195
196 static void
197 clear_index( GLcontext *ctx, GLuint index )
198 {
199 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
200 xmesa->clearpixel = (unsigned long) index;
201 XMesaSetForeground( xmesa->display, xmesa->xm_draw_buffer->cleargc,
202 (unsigned long) index );
203 }
204
205
206 static void
207 clear_color( GLcontext *ctx, const GLfloat color[4] )
208 {
209 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
210 CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[0], color[0]);
211 CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[1], color[1]);
212 CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[2], color[2]);
213 CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[3], color[3]);
214 xmesa->clearpixel = xmesa_color_to_pixel( xmesa,
215 xmesa->clearcolor[0],
216 xmesa->clearcolor[1],
217 xmesa->clearcolor[2],
218 xmesa->clearcolor[3],
219 xmesa->xm_visual->undithered_pf );
220 _glthread_LOCK_MUTEX(_xmesa_lock);
221 XMesaSetForeground( xmesa->display, xmesa->xm_draw_buffer->cleargc,
222 xmesa->clearpixel );
223 _glthread_UNLOCK_MUTEX(_xmesa_lock);
224 }
225
226
227
228 /* Set index mask ala glIndexMask */
229 static void
230 index_mask( GLcontext *ctx, GLuint mask )
231 {
232 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
233 if (xmesa->xm_draw_buffer->buffer != XIMAGE) {
234 unsigned long m;
235 if (mask==0xffffffff) {
236 m = ((unsigned long)~0L);
237 }
238 else {
239 m = (unsigned long) mask;
240 }
241 XMesaSetPlaneMask( xmesa->display, xmesa->xm_draw_buffer->cleargc, m );
242 XMesaSetPlaneMask( xmesa->display, xmesa->xm_draw_buffer->gc, m );
243 }
244 }
245
246
247 /* Implements glColorMask() */
248 static void
249 color_mask(GLcontext *ctx,
250 GLboolean rmask, GLboolean gmask, GLboolean bmask, GLboolean amask)
251 {
252 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
253 const int xclass = xmesa->xm_visual->mesa_visual.visualType;
254 (void) amask;
255
256 if (xclass == GLX_TRUE_COLOR || xclass == GLX_DIRECT_COLOR) {
257 unsigned long m;
258 if (rmask && gmask && bmask) {
259 m = ((unsigned long)~0L);
260 }
261 else {
262 m = 0;
263 if (rmask) m |= GET_REDMASK(xmesa->xm_visual);
264 if (gmask) m |= GET_GREENMASK(xmesa->xm_visual);
265 if (bmask) m |= GET_BLUEMASK(xmesa->xm_visual);
266 }
267 XMesaSetPlaneMask( xmesa->display, xmesa->xm_draw_buffer->cleargc, m );
268 XMesaSetPlaneMask( xmesa->display, xmesa->xm_draw_buffer->gc, m );
269 }
270 }
271
272
273
274 /**********************************************************************/
275 /*** glClear implementations ***/
276 /**********************************************************************/
277
278
279 static void
280 clear_front_pixmap( GLcontext *ctx, GLboolean all,
281 GLint x, GLint y, GLint width, GLint height )
282 {
283 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
284 if (all) {
285 XMesaFillRectangle( xmesa->display, xmesa->xm_draw_buffer->frontbuffer,
286 xmesa->xm_draw_buffer->cleargc,
287 0, 0,
288 xmesa->xm_draw_buffer->width+1,
289 xmesa->xm_draw_buffer->height+1 );
290 }
291 else {
292 XMesaFillRectangle( xmesa->display, xmesa->xm_draw_buffer->frontbuffer,
293 xmesa->xm_draw_buffer->cleargc,
294 x, xmesa->xm_draw_buffer->height - y - height,
295 width, height );
296 }
297 }
298
299
300 static void
301 clear_back_pixmap( GLcontext *ctx, GLboolean all,
302 GLint x, GLint y, GLint width, GLint height )
303 {
304 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
305 if (all) {
306 XMesaFillRectangle( xmesa->display, xmesa->xm_draw_buffer->backpixmap,
307 xmesa->xm_draw_buffer->cleargc,
308 0, 0,
309 xmesa->xm_draw_buffer->width+1,
310 xmesa->xm_draw_buffer->height+1 );
311 }
312 else {
313 XMesaFillRectangle( xmesa->display, xmesa->xm_draw_buffer->backpixmap,
314 xmesa->xm_draw_buffer->cleargc,
315 x, xmesa->xm_draw_buffer->height - y - height,
316 width, height );
317 }
318 }
319
320
321 static void
322 clear_8bit_ximage( GLcontext *ctx, GLboolean all,
323 GLint x, GLint y, GLint width, GLint height )
324 {
325 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
326 if (all) {
327 size_t n = xmesa->xm_draw_buffer->backimage->bytes_per_line
328 * xmesa->xm_draw_buffer->backimage->height;
329 MEMSET( xmesa->xm_draw_buffer->backimage->data, xmesa->clearpixel, n );
330 }
331 else {
332 GLint i;
333 for (i=0;i<height;i++) {
334 GLubyte *ptr = PIXELADDR1( xmesa->xm_draw_buffer, x, y+i );
335 MEMSET( ptr, xmesa->clearpixel, width );
336 }
337 }
338 }
339
340
341 static void
342 clear_HPCR_ximage( GLcontext *ctx, GLboolean all,
343 GLint x, GLint y, GLint width, GLint height )
344 {
345 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
346 if (all) {
347 GLint i, c16 = (xmesa->xm_draw_buffer->backimage->bytes_per_line>>4)<<4;
348 GLubyte *ptr = (GLubyte *)xmesa->xm_draw_buffer->backimage->data;
349 for (i=0; i<xmesa->xm_draw_buffer->backimage->height; i++) {
350 GLint j;
351 GLubyte *sptr = xmesa->xm_visual->hpcr_clear_ximage_pattern[0];
352 if (i&1) {
353 sptr += 16;
354 }
355 for (j=0; j<c16; j+=16) {
356 ptr[0] = sptr[0];
357 ptr[1] = sptr[1];
358 ptr[2] = sptr[2];
359 ptr[3] = sptr[3];
360 ptr[4] = sptr[4];
361 ptr[5] = sptr[5];
362 ptr[6] = sptr[6];
363 ptr[7] = sptr[7];
364 ptr[8] = sptr[8];
365 ptr[9] = sptr[9];
366 ptr[10] = sptr[10];
367 ptr[11] = sptr[11];
368 ptr[12] = sptr[12];
369 ptr[13] = sptr[13];
370 ptr[14] = sptr[14];
371 ptr[15] = sptr[15];
372 ptr += 16;
373 }
374 for (; j<xmesa->xm_draw_buffer->backimage->bytes_per_line; j++) {
375 *ptr = sptr[j&15];
376 ptr++;
377 }
378 }
379 }
380 else {
381 GLint i;
382 for (i=y; i<y+height; i++) {
383 GLubyte *ptr = PIXELADDR1( xmesa->xm_draw_buffer, x, i );
384 int j;
385 GLubyte *sptr = xmesa->xm_visual->hpcr_clear_ximage_pattern[0];
386 if (i&1) {
387 sptr += 16;
388 }
389 for (j=x; j<x+width; j++) {
390 *ptr = sptr[j&15];
391 ptr++;
392 }
393 }
394 }
395 }
396
397
398 static void
399 clear_16bit_ximage( GLcontext *ctx, GLboolean all,
400 GLint x, GLint y, GLint width, GLint height )
401 {
402 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
403 register GLuint pixel = (GLuint) xmesa->clearpixel;
404 if (xmesa->swapbytes) {
405 pixel = ((pixel >> 8) & 0x00ff) | ((pixel << 8) & 0xff00);
406 }
407 if (all) {
408 register GLuint n;
409 register GLuint *ptr4 = (GLuint *) xmesa->xm_draw_buffer->backimage->data;
410 if ((pixel & 0xff) == ((pixel >> 8) & 0xff)) {
411 /* low and high bytes are equal so use memset() */
412 n = xmesa->xm_draw_buffer->backimage->bytes_per_line
413 * xmesa->xm_draw_buffer->height;
414 MEMSET( ptr4, pixel & 0xff, n );
415 }
416 else {
417 pixel = pixel | (pixel<<16);
418 n = xmesa->xm_draw_buffer->backimage->bytes_per_line
419 * xmesa->xm_draw_buffer->height / 4;
420 do {
421 *ptr4++ = pixel;
422 n--;
423 } while (n!=0);
424
425 if ((xmesa->xm_draw_buffer->backimage->bytes_per_line *
426 xmesa->xm_draw_buffer->height) & 0x2)
427 *(GLushort *)ptr4 = pixel & 0xffff;
428 }
429 }
430 else {
431 register int i, j;
432 for (j=0;j<height;j++) {
433 register GLushort *ptr2 = PIXELADDR2( xmesa->xm_draw_buffer, x, y+j );
434 for (i=0;i<width;i++) {
435 *ptr2++ = pixel;
436 }
437 }
438 }
439 }
440
441
442 /* Optimized code provided by Nozomi Ytow <noz@xfree86.org> */
443 static void
444 clear_24bit_ximage( GLcontext *ctx, GLboolean all,
445 GLint x, GLint y, GLint width, GLint height )
446 {
447 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
448 const GLubyte r = xmesa->clearcolor[0];
449 const GLubyte g = xmesa->clearcolor[1];
450 const GLubyte b = xmesa->clearcolor[2];
451 #if 0 /* See below */
452 register GLuint clearPixel;
453 if (xmesa->swapbytes) {
454 clearPixel = (b << 16) | (g << 8) | r;
455 }
456 else {
457 clearPixel = (r << 16) | (g << 8) | b;
458 }
459 #endif
460
461 if (all) {
462 if (r==g && g==b) {
463 /* same value for all three components (gray) */
464 const GLint w3 = xmesa->xm_draw_buffer->width * 3;
465 const GLint h = xmesa->xm_draw_buffer->height;
466 GLint i;
467 for (i = 0; i < h; i++) {
468 bgr_t *ptr3 = PIXELADDR3(xmesa->xm_draw_buffer, 0, i);
469 MEMSET(ptr3, r, w3);
470 }
471 }
472 else {
473 /* the usual case */
474 const GLint w = xmesa->xm_draw_buffer->width;
475 const GLint h = xmesa->xm_draw_buffer->height;
476 GLint i, j;
477 for (i = 0; i < h; i++) {
478 bgr_t *ptr3 = PIXELADDR3(xmesa->xm_draw_buffer, 0, i);
479 for (j = 0; j < w; j++) {
480 ptr3->r = r;
481 ptr3->g = g;
482 ptr3->b = b;
483 ptr3++;
484 }
485 }
486 #if 0 /* this code doesn't work for all window widths */
487 register GLuint *ptr4 = (GLuint *) ptr3;
488 register GLuint px;
489 GLuint pixel4[3];
490 register GLuint *p = pixel4;
491 pixel4[0] = clearPixel | (clearPixel << 24);
492 pixel4[1] = (clearPixel << 16) | (clearPixel >> 8);
493 pixel4[2] = (clearPixel << 8) | (clearPixel >> 16);
494 switch (3 & (int)(ptr3 - (bgr_t*) ptr4)){
495 case 0:
496 break;
497 case 1:
498 px = *ptr4 & 0x00ffffff;
499 px |= pixel4[0] & 0xff000000;
500 *ptr4++ = px;
501 px = *ptr4 & 0xffff0000;
502 px |= pixel4[2] & 0x0000ffff;
503 *ptr4 = px;
504 if (0 == --n)
505 break;
506 case 2:
507 px = *ptr4 & 0x0000fffff;
508 px |= pixel4[1] & 0xffff0000;
509 *ptr4++ = px;
510 px = *ptr4 & 0xffffff00;
511 px |= pixel4[2] & 0x000000ff;
512 *ptr4 = px;
513 if (0 == --n)
514 break;
515 case 3:
516 px = *ptr4 & 0x000000ff;
517 px |= pixel4[2] & 0xffffff00;
518 *ptr4++ = px;
519 --n;
520 break;
521 }
522 while (n > 3) {
523 p = pixel4;
524 *ptr4++ = *p++;
525 *ptr4++ = *p++;
526 *ptr4++ = *p++;
527 n -= 4;
528 }
529 switch (n) {
530 case 3:
531 p = pixel4;
532 *ptr4++ = *p++;
533 *ptr4++ = *p++;
534 px = *ptr4 & 0xffffff00;
535 px |= clearPixel & 0xff;
536 *ptr4 = px;
537 break;
538 case 2:
539 p = pixel4;
540 *ptr4++ = *p++;
541 px = *ptr4 & 0xffff0000;
542 px |= *p & 0xffff;
543 *ptr4 = px;
544 break;
545 case 1:
546 px = *ptr4 & 0xff000000;
547 px |= *p & 0xffffff;
548 *ptr4 = px;
549 break;
550 case 0:
551 break;
552 }
553 #endif
554 }
555 }
556 else {
557 /* only clear subrect of color buffer */
558 if (r==g && g==b) {
559 /* same value for all three components (gray) */
560 GLint j;
561 for (j=0;j<height;j++) {
562 bgr_t *ptr3 = PIXELADDR3( xmesa->xm_draw_buffer, x, y+j );
563 MEMSET(ptr3, r, 3 * width);
564 }
565 }
566 else {
567 /* non-gray clear color */
568 GLint i, j;
569 for (j = 0; j < height; j++) {
570 bgr_t *ptr3 = PIXELADDR3( xmesa->xm_draw_buffer, x, y+j );
571 for (i = 0; i < width; i++) {
572 ptr3->r = r;
573 ptr3->g = g;
574 ptr3->b = b;
575 ptr3++;
576 }
577 }
578 #if 0 /* this code might not always (seems ptr3 always == ptr4) */
579 GLint j;
580 GLuint pixel4[3];
581 pixel4[0] = clearPixel | (clearPixel << 24);
582 pixel4[1] = (clearPixel << 16) | (clearPixel >> 8);
583 pixel4[2] = (clearPixel << 8) | (clearPixel >> 16);
584 for (j=0;j<height;j++) {
585 bgr_t *ptr3 = PIXELADDR3( xmesa->xm_draw_buffer, x, y+j );
586 register GLuint *ptr4 = (GLuint *)ptr3;
587 register GLuint *p, px;
588 GLuint w = width;
589 switch (3 & (int)(ptr3 - (bgr_t*) ptr4)){
590 case 0:
591 break;
592 case 1:
593 px = *ptr4 & 0x00ffffff;
594 px |= pixel4[0] & 0xff000000;
595 *ptr4++ = px;
596 px = *ptr4 & 0xffff0000;
597 px |= pixel4[2] & 0x0000ffff;
598 *ptr4 = px;
599 if (0 == --w)
600 break;
601 case 2:
602 px = *ptr4 & 0x0000fffff;
603 px |= pixel4[1] & 0xffff0000;
604 *ptr4++ = px;
605 px = *ptr4 & 0xffffff00;
606 px |= pixel4[2] & 0x000000ff;
607 *ptr4 = px;
608 if (0 == --w)
609 break;
610 case 3:
611 px = *ptr4 & 0x000000ff;
612 px |= pixel4[2] & 0xffffff00;
613 *ptr4++ = px;
614 --w;
615 break;
616 }
617 while (w > 3){
618 p = pixel4;
619 *ptr4++ = *p++;
620 *ptr4++ = *p++;
621 *ptr4++ = *p++;
622 w -= 4;
623 }
624 switch (w) {
625 case 3:
626 p = pixel4;
627 *ptr4++ = *p++;
628 *ptr4++ = *p++;
629 px = *ptr4 & 0xffffff00;
630 px |= *p & 0xff;
631 *ptr4 = px;
632 break;
633 case 2:
634 p = pixel4;
635 *ptr4++ = *p++;
636 px = *ptr4 & 0xffff0000;
637 px |= *p & 0xffff;
638 *ptr4 = px;
639 break;
640 case 1:
641 px = *ptr4 & 0xff000000;
642 px |= pixel4[0] & 0xffffff;
643 *ptr4 = px;
644 break;
645 case 0:
646 break;
647 }
648 }
649 #endif
650 }
651 }
652 }
653
654
655 static void
656 clear_32bit_ximage( GLcontext *ctx, GLboolean all,
657 GLint x, GLint y, GLint width, GLint height )
658 {
659 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
660 register GLuint pixel = (GLuint) xmesa->clearpixel;
661 if (xmesa->swapbytes) {
662 pixel = ((pixel >> 24) & 0x000000ff)
663 | ((pixel >> 8) & 0x0000ff00)
664 | ((pixel << 8) & 0x00ff0000)
665 | ((pixel << 24) & 0xff000000);
666 }
667 if (all) {
668 register GLint n = xmesa->xm_draw_buffer->width * xmesa->xm_draw_buffer->height;
669 register GLuint *ptr4 = (GLuint *) xmesa->xm_draw_buffer->backimage->data;
670 if (pixel==0) {
671 MEMSET( ptr4, pixel, 4*n );
672 }
673 else {
674 do {
675 *ptr4++ = pixel;
676 n--;
677 } while (n!=0);
678 }
679 }
680 else {
681 register int i, j;
682 for (j=0;j<height;j++) {
683 register GLuint *ptr4 = PIXELADDR4( xmesa->xm_draw_buffer, x, y+j );
684 for (i=0;i<width;i++) {
685 *ptr4++ = pixel;
686 }
687 }
688 }
689 }
690
691
692 static void
693 clear_nbit_ximage( GLcontext *ctx, GLboolean all,
694 GLint x, GLint y, GLint width, GLint height )
695 {
696 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
697 XMesaImage *img = xmesa->xm_draw_buffer->backimage;
698 if (all) {
699 register int i, j;
700 width = xmesa->xm_draw_buffer->width;
701 height = xmesa->xm_draw_buffer->height;
702 for (j=0;j<height;j++) {
703 for (i=0;i<width;i++) {
704 XMesaPutPixel( img, i, j, xmesa->clearpixel );
705 }
706 }
707 }
708 else {
709 /* TODO: optimize this */
710 register int i, j;
711 y = FLIP(xmesa->xm_draw_buffer, y);
712 for (j=0;j<height;j++) {
713 for (i=0;i<width;i++) {
714 XMesaPutPixel( img, x+i, y-j, xmesa->clearpixel );
715 }
716 }
717 }
718 }
719
720
721
722 static void
723 clear_buffers( GLcontext *ctx, GLbitfield mask,
724 GLboolean all, GLint x, GLint y, GLint width, GLint height )
725 {
726 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
727 const GLuint *colorMask = (GLuint *) &ctx->Color.ColorMask;
728
729 if ((mask & (DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT)) &&
730 xmesa->xm_draw_buffer->mesa_buffer.UseSoftwareAlphaBuffers &&
731 ctx->Color.ColorMask[ACOMP]) {
732 _swrast_clear_alpha_buffers(ctx);
733 }
734
735 /* we can't handle color or index masking */
736 if (*colorMask == 0xffffffff && ctx->Color.IndexMask == 0xffffffff) {
737 if (mask & DD_FRONT_LEFT_BIT) {
738 ASSERT(xmesa->xm_draw_buffer->front_clear_func);
739 (*xmesa->xm_draw_buffer->front_clear_func)( ctx, all, x, y, width, height );
740 mask &= ~DD_FRONT_LEFT_BIT;
741 }
742 if (mask & DD_BACK_LEFT_BIT) {
743 ASSERT(xmesa->xm_draw_buffer->back_clear_func);
744 (*xmesa->xm_draw_buffer->back_clear_func)( ctx, all, x, y, width, height );
745 mask &= ~DD_BACK_LEFT_BIT;
746 }
747 }
748
749 if (mask)
750 _swrast_Clear( ctx, mask, all, x, y, width, height );
751 }
752
753
754 /*
755 * When we detect that the user has resized the window this function will
756 * get called. Here we'll reallocate the back buffer, depth buffer,
757 * stencil buffer etc. to match the new window size.
758 */
759 void
760 xmesa_resize_buffers( GLframebuffer *buffer )
761 {
762 int height = (int) buffer->Height;
763 /* We can do this cast because the first field in the XMesaBuffer
764 * struct is a GLframebuffer struct. If this weren't true, we'd
765 * need a pointer from the GLframebuffer to the XMesaBuffer.
766 */
767 XMesaBuffer xmBuffer = (XMesaBuffer) buffer;
768
769 xmBuffer->width = buffer->Width;
770 xmBuffer->height = buffer->Height;
771 xmesa_alloc_back_buffer( xmBuffer );
772
773 /* Needed by FLIP macro */
774 xmBuffer->bottom = height - 1;
775
776 if (xmBuffer->backimage) {
777 /* Needed by PIXELADDR1 macro */
778 xmBuffer->ximage_width1 = xmBuffer->backimage->bytes_per_line;
779 xmBuffer->ximage_origin1 = (GLubyte *) xmBuffer->backimage->data
780 + xmBuffer->ximage_width1 * (height-1);
781
782 /* Needed by PIXELADDR2 macro */
783 xmBuffer->ximage_width2 = xmBuffer->backimage->bytes_per_line / 2;
784 xmBuffer->ximage_origin2 = (GLushort *) xmBuffer->backimage->data
785 + xmBuffer->ximage_width2 * (height-1);
786
787 /* Needed by PIXELADDR3 macro */
788 xmBuffer->ximage_width3 = xmBuffer->backimage->bytes_per_line;
789 xmBuffer->ximage_origin3 = (GLubyte *) xmBuffer->backimage->data
790 + xmBuffer->ximage_width3 * (height-1);
791
792 /* Needed by PIXELADDR4 macro */
793 xmBuffer->ximage_width4 = xmBuffer->backimage->width;
794 xmBuffer->ximage_origin4 = (GLuint *) xmBuffer->backimage->data
795 + xmBuffer->ximage_width4 * (height-1);
796 }
797
798 _swrast_alloc_buffers( buffer );
799 }
800
801
802 #ifndef XFree86Server
803 /* XXX this was never tested in the Xserver environment */
804
805 /**
806 * This function implements glDrawPixels() with an XPutImage call when
807 * drawing to the front buffer (X Window drawable).
808 * The image format must be GL_BGRA to match the PF_8R8G8B pixel format.
809 */
810 static void
811 xmesa_DrawPixels_8R8G8B( GLcontext *ctx,
812 GLint x, GLint y, GLsizei width, GLsizei height,
813 GLenum format, GLenum type,
814 const struct gl_pixelstore_attrib *unpack,
815 const GLvoid *pixels )
816 {
817 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
818 const SWcontext *swrast = SWRAST_CONTEXT( ctx );
819 XMesaDisplay *dpy = xmesa->xm_visual->display;
820 const XMesaDrawable buffer = xmesa->xm_draw_buffer->buffer;
821 const XMesaGC gc = xmesa->xm_draw_buffer->gc;
822
823 ASSERT(dpy);
824 ASSERT(gc);
825 ASSERT(xmesa->xm_visual->dithered_pf == PF_8R8G8B);
826 ASSERT(xmesa->xm_visual->undithered_pf == PF_8R8G8B);
827
828 if (swrast->NewState)
829 _swrast_validate_derived( ctx );
830
831 if (buffer && /* buffer != 0 means it's a Window or Pixmap */
832 format == GL_BGRA &&
833 type == GL_UNSIGNED_BYTE &&
834 (swrast->_RasterMask & ~CLIP_BIT) == 0 && /* no blend, z-test, etc */
835 ctx->_ImageTransferState == 0 && /* no color tables, scale/bias, etc */
836 ctx->Pixel.ZoomX == 1.0 && /* no zooming */
837 ctx->Pixel.ZoomY == 1.0) {
838 int dstX = x;
839 int dstY = y;
840 int w = width;
841 int h = height;
842 int srcX = unpack->SkipPixels;
843 int srcY = unpack->SkipRows;
844 int rowLength = unpack->RowLength ? unpack->RowLength : width;
845
846 if (unpack->BufferObj->Name) {
847 /* unpack from PBO */
848 GLubyte *buf;
849 if (!_mesa_validate_pbo_access(2, unpack, width, height, 1,
850 format, type, pixels)) {
851 _mesa_error(ctx, GL_INVALID_OPERATION,
852 "glDrawPixels(invalid PBO access)");
853 return;
854 }
855 buf = (GLubyte *) ctx->Driver.MapBuffer(ctx,
856 GL_PIXEL_UNPACK_BUFFER_EXT,
857 GL_READ_ONLY_ARB,
858 unpack->BufferObj);
859 if (!buf) {
860 /* buffer is already mapped - that's an error */
861 _mesa_error(ctx, GL_INVALID_OPERATION,
862 "glDrawPixels(PBO is mapped)");
863 return;
864 }
865 pixels = ADD_POINTERS(buf, pixels);
866 }
867
868 if (_mesa_clip_drawpixels(ctx, &dstX, &dstY, &w, &h, &srcX, &srcY)) {
869 /* This is a little tricky since all coordinates up to now have
870 * been in the OpenGL bottom-to-top orientation. X is top-to-bottom
871 * so we have to carefully compute the Y coordinates/addresses here.
872 */
873 XMesaImage ximage;
874 MEMSET(&ximage, 0, sizeof(XMesaImage));
875 ximage.width = width;
876 ximage.height = height;
877 ximage.format = ZPixmap;
878 ximage.data = (char *) pixels
879 + ((srcY + h - 1) * rowLength + srcX) * 4;
880 ximage.byte_order = LSBFirst;
881 ximage.bitmap_unit = 32;
882 ximage.bitmap_bit_order = LSBFirst;
883 ximage.bitmap_pad = 32;
884 ximage.depth = 24;
885 ximage.bytes_per_line = -rowLength * 4; /* negative to flip image */
886 ximage.bits_per_pixel = 32;
887 /* it seems we don't need to set the ximage.red/green/blue_mask fields */
888 /* flip Y axis for dest position */
889 dstY = FLIP(xmesa->xm_draw_buffer, dstY) - h + 1;
890 XPutImage(dpy, buffer, gc, &ximage, 0, 0, dstX, dstY, w, h);
891 }
892
893 if (unpack->BufferObj->Name) {
894 ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
895 unpack->BufferObj);
896 }
897 }
898 else {
899 /* software fallback */
900 _swrast_DrawPixels(ctx, x, y, width, height,
901 format, type, unpack, pixels);
902 }
903 }
904
905
906
907 /**
908 * This function implements glDrawPixels() with an XPutImage call when
909 * drawing to the front buffer (X Window drawable). The image format
910 * must be GL_RGB and image type must be GL_UNSIGNED_SHORT_5_6_5 to
911 * match the PF_5R6G5B pixel format.
912 */
913 static void
914 xmesa_DrawPixels_5R6G5B( GLcontext *ctx,
915 GLint x, GLint y, GLsizei width, GLsizei height,
916 GLenum format, GLenum type,
917 const struct gl_pixelstore_attrib *unpack,
918 const GLvoid *pixels )
919 {
920 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
921 const SWcontext *swrast = SWRAST_CONTEXT( ctx );
922 XMesaDisplay *dpy = xmesa->xm_visual->display;
923 const XMesaDrawable buffer = xmesa->xm_draw_buffer->buffer;
924 const XMesaGC gc = xmesa->xm_draw_buffer->gc;
925
926 ASSERT(dpy);
927 ASSERT(gc);
928 ASSERT(xmesa->xm_visual->undithered_pf == PF_5R6G5B);
929
930 if (swrast->NewState)
931 _swrast_validate_derived( ctx );
932
933 if (buffer && /* buffer != 0 means it's a Window or Pixmap */
934 format == GL_RGB &&
935 type == GL_UNSIGNED_SHORT_5_6_5 &&
936 !ctx->Color.DitherFlag && /* no dithering */
937 (swrast->_RasterMask & ~CLIP_BIT) == 0 && /* no blend, z-test, etc */
938 ctx->_ImageTransferState == 0 && /* no color tables, scale/bias, etc */
939 ctx->Pixel.ZoomX == 1.0 && /* no zooming */
940 ctx->Pixel.ZoomY == 1.0) {
941 int dstX = x;
942 int dstY = y;
943 int w = width;
944 int h = height;
945 int srcX = unpack->SkipPixels;
946 int srcY = unpack->SkipRows;
947 int rowLength = unpack->RowLength ? unpack->RowLength : width;
948
949 if (unpack->BufferObj->Name) {
950 /* unpack from PBO */
951 GLubyte *buf;
952 if (!_mesa_validate_pbo_access(2, unpack, width, height, 1,
953 format, type, pixels)) {
954 _mesa_error(ctx, GL_INVALID_OPERATION,
955 "glDrawPixels(invalid PBO access)");
956 return;
957 }
958 buf = (GLubyte *) ctx->Driver.MapBuffer(ctx,
959 GL_PIXEL_UNPACK_BUFFER_EXT,
960 GL_READ_ONLY_ARB,
961 unpack->BufferObj);
962 if (!buf) {
963 /* buffer is already mapped - that's an error */
964 _mesa_error(ctx, GL_INVALID_OPERATION,
965 "glDrawPixels(PBO is mapped)");
966 return;
967 }
968 pixels = ADD_POINTERS(buf, pixels);
969 }
970
971 if (_mesa_clip_drawpixels(ctx, &dstX, &dstY, &w, &h, &srcX, &srcY)) {
972 /* This is a little tricky since all coordinates up to now have
973 * been in the OpenGL bottom-to-top orientation. X is top-to-bottom
974 * so we have to carefully compute the Y coordinates/addresses here.
975 */
976 XMesaImage ximage;
977 MEMSET(&ximage, 0, sizeof(XMesaImage));
978 ximage.width = width;
979 ximage.height = height;
980 ximage.format = ZPixmap;
981 ximage.data = (char *) pixels
982 + ((srcY + h - 1) * rowLength + srcX) * 2;
983 ximage.byte_order = LSBFirst;
984 ximage.bitmap_unit = 16;
985 ximage.bitmap_bit_order = LSBFirst;
986 ximage.bitmap_pad = 16;
987 ximage.depth = 16;
988 ximage.bytes_per_line = -rowLength * 2; /* negative to flip image */
989 ximage.bits_per_pixel = 16;
990 /* it seems we don't need to set the ximage.red/green/blue_mask fields */
991 /* flip Y axis for dest position */
992 dstY = FLIP(xmesa->xm_draw_buffer, dstY) - h + 1;
993 XPutImage(dpy, buffer, gc, &ximage, 0, 0, dstX, dstY, w, h);
994 }
995
996 if (unpack->BufferObj->Name) {
997 ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
998 unpack->BufferObj);
999 }
1000 }
1001 else {
1002 /* software fallback */
1003 _swrast_DrawPixels(ctx, x, y, width, height,
1004 format, type, unpack, pixels);
1005 }
1006 }
1007
1008
1009
1010 /**
1011 * Implement glCopyPixels for the front color buffer (or back buffer Pixmap)
1012 * for the color buffer. Don't support zooming, pixel transfer, etc.
1013 * We do support copying from one window to another, ala glXMakeCurrentRead.
1014 */
1015 static void
1016 xmesa_CopyPixels( GLcontext *ctx,
1017 GLint srcx, GLint srcy, GLsizei width, GLsizei height,
1018 GLint destx, GLint desty, GLenum type )
1019 {
1020 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1021 const SWcontext *swrast = SWRAST_CONTEXT( ctx );
1022 XMesaDisplay *dpy = xmesa->xm_visual->display;
1023 const XMesaDrawable drawBuffer = xmesa->xm_draw_buffer->buffer;
1024 const XMesaDrawable readBuffer = xmesa->xm_read_buffer->buffer;
1025 const XMesaGC gc = xmesa->xm_draw_buffer->gc;
1026
1027 ASSERT(dpy);
1028 ASSERT(gc);
1029
1030 if (swrast->NewState)
1031 _swrast_validate_derived( ctx );
1032
1033 if (ctx->Color.DrawBuffer[0] == GL_FRONT &&
1034 ctx->Pixel.ReadBuffer == GL_FRONT &&
1035 drawBuffer && /* buffer != 0 means it's a Window or Pixmap */
1036 readBuffer &&
1037 type == GL_COLOR &&
1038 (swrast->_RasterMask & ~CLIP_BIT) == 0 && /* no blend, z-test, etc */
1039 ctx->_ImageTransferState == 0 && /* no color tables, scale/bias, etc */
1040 ctx->Pixel.ZoomX == 1.0 && /* no zooming */
1041 ctx->Pixel.ZoomY == 1.0) {
1042 /* Note: we don't do any special clipping work here. We could,
1043 * but X will do it for us.
1044 */
1045 srcy = FLIP(xmesa->xm_read_buffer, srcy) - height + 1;
1046 desty = FLIP(xmesa->xm_draw_buffer, desty) - height + 1;
1047 XCopyArea(dpy, readBuffer, drawBuffer, gc,
1048 srcx, srcy, width, height, destx, desty);
1049 }
1050 else {
1051 _swrast_CopyPixels(ctx, srcx, srcy, width, height, destx, desty, type );
1052 }
1053 }
1054 #endif /* XFree86Server */
1055
1056
1057
1058 /*
1059 * Every driver should implement a GetString function in order to
1060 * return a meaningful GL_RENDERER string.
1061 */
1062 static const GLubyte *
1063 get_string( GLcontext *ctx, GLenum name )
1064 {
1065 (void) ctx;
1066 switch (name) {
1067 case GL_RENDERER:
1068 #ifdef XFree86Server
1069 return (const GLubyte *) "Mesa GLX Indirect";
1070 #else
1071 return (const GLubyte *) "Mesa X11";
1072 #endif
1073 case GL_VENDOR:
1074 #ifdef XFree86Server
1075 return (const GLubyte *) "Mesa project: www.mesa3d.org";
1076 #else
1077 return NULL;
1078 #endif
1079 default:
1080 return NULL;
1081 }
1082 }
1083
1084
1085 /*
1086 * We implement the glEnable function only because we care about
1087 * dither enable/disable.
1088 */
1089 static void
1090 enable( GLcontext *ctx, GLenum pname, GLboolean state )
1091 {
1092 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1093
1094 switch (pname) {
1095 case GL_DITHER:
1096 if (state)
1097 xmesa->pixelformat = xmesa->xm_visual->dithered_pf;
1098 else
1099 xmesa->pixelformat = xmesa->xm_visual->undithered_pf;
1100 break;
1101 default:
1102 ; /* silence compiler warning */
1103 }
1104 }
1105
1106
1107 void xmesa_update_state( GLcontext *ctx, GLuint new_state )
1108 {
1109 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1110
1111 /* Propogate statechange information to swrast and swrast_setup
1112 * modules. The X11 driver has no internal GL-dependent state.
1113 */
1114 _swrast_InvalidateState( ctx, new_state );
1115 _ac_InvalidateState( ctx, new_state );
1116 _tnl_InvalidateState( ctx, new_state );
1117 _swsetup_InvalidateState( ctx, new_state );
1118
1119
1120 /* setup pointers to front and back buffer clear functions */
1121 xmesa->xm_draw_buffer->front_clear_func = clear_front_pixmap;
1122 if (xmesa->xm_draw_buffer->backpixmap != XIMAGE) {
1123 xmesa->xm_draw_buffer->back_clear_func = clear_back_pixmap;
1124 }
1125 else if (sizeof(GLushort)!=2 || sizeof(GLuint)!=4) {
1126 xmesa->xm_draw_buffer->back_clear_func = clear_nbit_ximage;
1127 }
1128 else switch (xmesa->xm_visual->BitsPerPixel) {
1129 case 8:
1130 if (xmesa->xm_visual->hpcr_clear_flag) {
1131 xmesa->xm_draw_buffer->back_clear_func = clear_HPCR_ximage;
1132 }
1133 else {
1134 xmesa->xm_draw_buffer->back_clear_func = clear_8bit_ximage;
1135 }
1136 break;
1137 case 16:
1138 xmesa->xm_draw_buffer->back_clear_func = clear_16bit_ximage;
1139 break;
1140 case 24:
1141 xmesa->xm_draw_buffer->back_clear_func = clear_24bit_ximage;
1142 break;
1143 case 32:
1144 xmesa->xm_draw_buffer->back_clear_func = clear_32bit_ximage;
1145 break;
1146 default:
1147 xmesa->xm_draw_buffer->back_clear_func = clear_nbit_ximage;
1148 break;
1149 }
1150
1151 if (ctx->Color._DrawDestMask[0] & (DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT)) {
1152 xmesa_update_span_funcs(ctx);
1153 }
1154 }
1155
1156
1157
1158 /**
1159 * Called via ctx->Driver.TestProxyTeximage(). Normally, we'd just use
1160 * the _mesa_test_proxy_teximage() fallback function, but we're going to
1161 * special-case the 3D texture case to allow textures up to 512x512x32
1162 * texels.
1163 */
1164 static GLboolean
1165 test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level,
1166 GLint internalFormat, GLenum format, GLenum type,
1167 GLint width, GLint height, GLint depth, GLint border)
1168 {
1169 if (target == GL_PROXY_TEXTURE_3D) {
1170 /* special case for 3D textures */
1171 if (width * height * depth > 512 * 512 * 64 ||
1172 width < 2 * border ||
1173 (!ctx->Extensions.ARB_texture_non_power_of_two &&
1174 _mesa_bitcount(width - 2 * border) != 1) ||
1175 height < 2 * border ||
1176 (!ctx->Extensions.ARB_texture_non_power_of_two &&
1177 _mesa_bitcount(height - 2 * border) != 1) ||
1178 depth < 2 * border ||
1179 (!ctx->Extensions.ARB_texture_non_power_of_two &&
1180 _mesa_bitcount(depth - 2 * border) != 1)) {
1181 /* Bad size, or too many texels */
1182 return GL_FALSE;
1183 }
1184 return GL_TRUE;
1185 }
1186 else {
1187 /* use the fallback routine for 1D, 2D, cube and rect targets */
1188 return _mesa_test_proxy_teximage(ctx, target, level, internalFormat,
1189 format, type, width, height, depth,
1190 border);
1191 }
1192 }
1193
1194
1195 /**
1196 * In SW, we don't really compress GL_COMPRESSED_RGB[A] textures!
1197 */
1198 static const struct gl_texture_format *
1199 choose_tex_format( GLcontext *ctx, GLint internalFormat,
1200 GLenum format, GLenum type )
1201 {
1202 switch (internalFormat) {
1203 case GL_COMPRESSED_RGB_ARB:
1204 return &_mesa_texformat_rgb;
1205 case GL_COMPRESSED_RGBA_ARB:
1206 return &_mesa_texformat_rgba;
1207 default:
1208 return _mesa_choose_tex_format(ctx, internalFormat, format, type);
1209 }
1210 }
1211
1212
1213 /**
1214 * Initialize the device driver function table with the functions
1215 * we implement in this driver.
1216 */
1217 void xmesa_init_driver_functions( XMesaVisual xmvisual,
1218 struct dd_function_table *driver )
1219 {
1220 driver->GetString = get_string;
1221 driver->UpdateState = xmesa_update_state;
1222 driver->GetBufferSize = get_buffer_size;
1223 driver->Flush = finish_or_flush;
1224 driver->Finish = finish_or_flush;
1225 driver->ClearIndex = clear_index;
1226 driver->ClearColor = clear_color;
1227 driver->IndexMask = index_mask;
1228 driver->ColorMask = color_mask;
1229 driver->Enable = enable;
1230 driver->Clear = clear_buffers;
1231 driver->ResizeBuffers = xmesa_resize_buffers;
1232 #ifndef XFree86Server
1233 driver->CopyPixels = /*_swrast_CopyPixels;*/xmesa_CopyPixels;
1234 if (xmvisual->undithered_pf == PF_8R8G8B &&
1235 xmvisual->dithered_pf == PF_8R8G8B) {
1236 driver->DrawPixels = xmesa_DrawPixels_8R8G8B;
1237 }
1238 else if (xmvisual->undithered_pf == PF_5R6G5B) {
1239 driver->DrawPixels = xmesa_DrawPixels_5R6G5B;
1240 }
1241 #endif
1242 driver->TestProxyTexImage = test_proxy_teximage;
1243 #if SWTC
1244 driver->ChooseTextureFormat = choose_tex_format;
1245 #endif
1246 }
1247
1248
1249 #define XMESA_NEW_POINT (_NEW_POINT | \
1250 _NEW_RENDERMODE | \
1251 _SWRAST_NEW_RASTERMASK)
1252
1253 #define XMESA_NEW_LINE (_NEW_LINE | \
1254 _NEW_TEXTURE | \
1255 _NEW_LIGHT | \
1256 _NEW_DEPTH | \
1257 _NEW_RENDERMODE | \
1258 _SWRAST_NEW_RASTERMASK)
1259
1260 #define XMESA_NEW_TRIANGLE (_NEW_POLYGON | \
1261 _NEW_TEXTURE | \
1262 _NEW_LIGHT | \
1263 _NEW_DEPTH | \
1264 _NEW_RENDERMODE | \
1265 _SWRAST_NEW_RASTERMASK)
1266
1267
1268 /* Extend the software rasterizer with our line/point/triangle
1269 * functions.
1270 */
1271 void xmesa_register_swrast_functions( GLcontext *ctx )
1272 {
1273 SWcontext *swrast = SWRAST_CONTEXT( ctx );
1274 struct swrast_device_driver *dd = _swrast_GetDeviceDriverReference(ctx);
1275
1276 dd->SetBuffer = xmesa_set_buffer;
1277
1278 swrast->choose_point = xmesa_choose_point;
1279 swrast->choose_line = xmesa_choose_line;
1280 swrast->choose_triangle = xmesa_choose_triangle;
1281
1282 swrast->invalidate_point |= XMESA_NEW_POINT;
1283 swrast->invalidate_line |= XMESA_NEW_LINE;
1284 swrast->invalidate_triangle |= XMESA_NEW_TRIANGLE;
1285 }