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