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