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