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