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