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