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