applied Daryll's patches
[mesa.git] / src / mesa / drivers / glide / fxddspan.c
1 /* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.1
6 *
7 * Copyright (C) 1999 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 *
27 * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the
28 * terms stated above.
29 *
30 * Thank you for your contribution, David!
31 *
32 * Please make note of the above copyright/license statement. If you
33 * contributed code or bug fixes to this code under the previous (GNU
34 * Library) license and object to the new license, your code will be
35 * removed at your request. Please see the Mesa docs/COPYRIGHT file
36 * for more information.
37 *
38 * Additional Mesa/3Dfx driver developers:
39 * Daryll Strauss <daryll@precisioninsight.com>
40 * Keith Whitwell <keith@precisioninsight.com>
41 *
42 * See fxapi.h for more revision/author details.
43 */
44
45
46 /* fxdd.c - 3Dfx VooDoo Mesa span and pixel functions */
47
48
49 #ifdef HAVE_CONFIG_H
50 #include "conf.h"
51 #endif
52
53 #if defined(FX)
54
55 #include "fxdrv.h"
56
57 #ifdef _MSC_VER
58 #ifdef _WIN32
59 #pragma warning( disable : 4090 4022 )
60 /* 4101 : "different 'const' qualifier"
61 * 4022 : "pointer mistmatch for actual parameter 'n'
62 */
63 #endif
64 #endif
65
66
67 #if !defined(FXMESA_USE_ARGB)
68
69 /* KW: Rearranged the args in the call to grLfbWriteRegion().
70 */
71 #define LFB_WRITE_SPAN_MESA(dst_buffer, \
72 dst_x, \
73 dst_y, \
74 src_width, \
75 src_stride, \
76 src_data) \
77 writeRegionClipped(fxMesa, dst_buffer, \
78 dst_x, \
79 dst_y, \
80 GR_LFB_SRC_FMT_8888, \
81 src_width, \
82 1, \
83 src_stride, \
84 src_data) \
85
86
87 #else /* defined(FXMESA_USE_RGBA) */
88
89 #define MESACOLOR_TO_ARGB(c) ( \
90 ( ((unsigned int)(c[ACOMP]))<<24 ) | \
91 ( ((unsigned int)(c[RCOMP]))<<16 ) | \
92 ( ((unsigned int)(c[GCOMP]))<<8 ) | \
93 ( (unsigned int)(c[BCOMP])) )
94
95 void LFB_WRITE_SPAN_MESA(GrBuffer_t dst_buffer,
96 FxU32 dst_x,
97 FxU32 dst_y,
98 FxU32 src_width,
99 FxI32 src_stride,
100 void *src_data )
101 {
102 /* Covert to ARGB */
103 GLubyte (*rgba)[4] = src_data;
104 GLuint argb[MAX_WIDTH];
105 int i;
106
107 for (i = 0; i < src_width; i++)
108 {
109 argb[i] = MESACOLOR_TO_ARGB(rgba[i]);
110 }
111 writeRegionClipped(fxMesa, dst_buffer,
112 dst_x,
113 dst_y,
114 GR_LFB_SRC_FMT_8888,
115 src_width,
116 1,
117 src_stride,
118 (void*)argb);
119 }
120
121 #endif
122
123 #if defined(FX_GLIDE3) && defined(XF86DRI)
124
125 static FxBool writeRegionClipped(fxMesaContext fxMesa, GrBuffer_t dst_buffer,
126 FxU32 dst_x, FxU32 dst_y, GrLfbSrcFmt_t src_format,
127 FxU32 src_width, FxU32 src_height, FxI32 src_stride,
128 void *src_data);
129
130 FxBool writeRegionClipped(fxMesaContext fxMesa, GrBuffer_t dst_buffer,
131 FxU32 dst_x, FxU32 dst_y, GrLfbSrcFmt_t src_format,
132 FxU32 src_width, FxU32 src_height, FxI32 src_stride,
133 void *src_data)
134 {
135 int i, x, w;
136 void *data;
137
138 if (src_width==1 && src_height==1) { /* Easy case writing a point */
139 for (i=0; i<fxMesa->numClipRects; i++) {
140 if ((dst_x>=fxMesa->pClipRects[i].x1) &&
141 (dst_x<fxMesa->pClipRects[i].x2) &&
142 (dst_y>=fxMesa->pClipRects[i].y1) &&
143 (dst_y<fxMesa->pClipRects[i].y2)) {
144 FX_grLfbWriteRegion(dst_buffer, dst_x, dst_y, src_format,
145 src_width, src_height, src_stride, src_data);
146 return GL_TRUE;
147 }
148 }
149 } else if (src_height==1) { /* Writing a span */
150 for (i=0; i<fxMesa->numClipRects; i++) {
151 if (dst_y>=fxMesa->pClipRects[i].y1 && dst_y<fxMesa->pClipRects[i].y2) {
152 if (dst_x<fxMesa->pClipRects[i].x1) {
153 x=fxMesa->pClipRects[i].x1;
154 data=((char*)src_data)+2*(dst_x-x);
155 w=src_width-(x-dst_x);
156 } else {
157 x=dst_x;
158 data=src_data;
159 w=src_width;
160 }
161 if (x+w>fxMesa->pClipRects[i].x2) {
162 w=fxMesa->pClipRects[i].x2-x;
163 }
164 FX_grLfbWriteRegion(dst_buffer, x, dst_y, src_format, w, src_height,
165 src_stride, data);
166 }
167 }
168 } else { /* Punt on the case of arbitrary rectangles */
169 return GL_FALSE;
170 }
171 return GL_TRUE;
172 }
173
174 #else
175
176 #define writeRegionClipped(fxm,dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data) \
177 FX_grLfbWriteRegion(dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data)
178
179 #endif
180
181 /************************************************************************/
182 /***** Span functions *****/
183 /************************************************************************/
184
185
186 static void fxDDWriteRGBASpan(const GLcontext *ctx,
187 GLuint n, GLint x, GLint y,
188 const GLubyte rgba[][4], const GLubyte mask[])
189 {
190 fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
191 GLuint i;
192 GLint bottom=fxMesa->height+fxMesa->y_offset-1;
193
194 if (MESA_VERBOSE&VERBOSE_DRIVER) {
195 fprintf(stderr,"fxmesa: fxDDWriteRGBASpan(...)\n");
196 }
197
198 x+=fxMesa->x_offset;
199 if (mask) {
200 int span=0;
201
202 for (i=0;i<n;i++) {
203 if (mask[i]) {
204 ++span;
205 } else {
206 if (span > 0) {
207 LFB_WRITE_SPAN_MESA( fxMesa->currentFB, x+i-span, bottom-y,
208 /* GR_LFB_SRC_FMT_8888,*/ span, /*1,*/ 0, (void *) rgba[i-span] );
209 span = 0;
210 }
211 }
212 }
213
214 if (span > 0)
215 LFB_WRITE_SPAN_MESA( fxMesa->currentFB, x+n-span, bottom-y,
216 /* GR_LFB_SRC_FMT_8888, */ span, /*1,*/ 0, (void *) rgba[n-span] );
217 } else
218 LFB_WRITE_SPAN_MESA( fxMesa->currentFB, x, bottom-y,/* GR_LFB_SRC_FMT_8888,*/
219 n,/* 1,*/ 0, (void *) rgba );
220 }
221
222
223 static void fxDDWriteRGBSpan(const GLcontext *ctx,
224 GLuint n, GLint x, GLint y,
225 const GLubyte rgb[][3], const GLubyte mask[])
226 {
227 fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
228 GLuint i;
229 GLint bottom=fxMesa->height+fxMesa->y_offset-1;
230 GLubyte rgba[MAX_WIDTH][4];
231
232 if (MESA_VERBOSE&VERBOSE_DRIVER) {
233 fprintf(stderr,"fxmesa: fxDDWriteRGBSpan()\n");
234 }
235
236 x+=fxMesa->x_offset;
237 if (mask) {
238 int span=0;
239
240 for (i=0;i<n;i++) {
241 if (mask[i]) {
242 rgba[span][RCOMP] = rgb[i][0];
243 rgba[span][GCOMP] = rgb[i][1];
244 rgba[span][BCOMP] = rgb[i][2];
245 rgba[span][ACOMP] = 255;
246 ++span;
247 } else {
248 if (span > 0) {
249 LFB_WRITE_SPAN_MESA( fxMesa->currentFB, x+i-span, bottom-y,
250 /*GR_LFB_SRC_FMT_8888,*/ span,/* 1,*/ 0, (void *) rgba );
251 span = 0;
252 }
253 }
254 }
255
256 if (span > 0)
257 LFB_WRITE_SPAN_MESA( fxMesa->currentFB, x+n-span, bottom-y,
258 /*GR_LFB_SRC_FMT_8888,*/ span,/* 1,*/ 0, (void *) rgba );
259 } else {
260 for (i=0;i<n;i++) {
261 rgba[i][RCOMP]=rgb[i][0];
262 rgba[i][GCOMP]=rgb[i][1];
263 rgba[i][BCOMP]=rgb[i][2];
264 rgba[i][ACOMP]=255;
265 }
266
267 LFB_WRITE_SPAN_MESA( fxMesa->currentFB, x, bottom-y,/* GR_LFB_SRC_FMT_8888,*/
268 n,/* 1,*/ 0, (void *) rgba );
269 }
270 }
271
272
273 static void fxDDWriteMonoRGBASpan(const GLcontext *ctx,
274 GLuint n, GLint x, GLint y,
275 const GLubyte mask[])
276 {
277 fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
278 GLuint i;
279 GLint bottom=fxMesa->height+fxMesa->y_offset-1;
280 GLuint data[MAX_WIDTH];
281
282 if (MESA_VERBOSE&VERBOSE_DRIVER) {
283 fprintf(stderr,"fxmesa: fxDDWriteMonoRGBASpan(...)\n");
284 }
285
286 x+=fxMesa->x_offset;
287 if (mask) {
288 int span=0;
289
290 for (i=0;i<n;i++) {
291 if (mask[i]) {
292 data[span] = (GLuint) fxMesa->color;
293 ++span;
294 } else {
295 if (span > 0) {
296 writeRegionClipped(fxMesa, fxMesa->currentFB, x+i-span, bottom-y,
297 GR_LFB_SRC_FMT_8888, span, 1, 0,
298 (void *) data );
299 span = 0;
300 }
301 }
302 }
303
304 if (span > 0)
305 writeRegionClipped(fxMesa, fxMesa->currentFB, x+n-span, bottom-y,
306 GR_LFB_SRC_FMT_8888, span, 1, 0,
307 (void *) data );
308 } else {
309 for (i=0;i<n;i++) {
310 data[i]=(GLuint) fxMesa->color;
311 }
312
313 writeRegionClipped(fxMesa, fxMesa->currentFB, x, bottom-y, GR_LFB_SRC_FMT_8888,
314 n, 1, 0, (void *) data );
315 }
316 }
317
318
319 static void fxDDReadRGBASpan(const GLcontext *ctx,
320 GLuint n, GLint x, GLint y, GLubyte rgba[][4])
321 {
322 fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
323 GLushort data[MAX_WIDTH];
324 GLuint i;
325 GLint bottom=fxMesa->height+fxMesa->y_offset-1;
326
327 if (MESA_VERBOSE&VERBOSE_DRIVER) {
328 fprintf(stderr,"fxmesa: fxDDReadRGBASpan(...)\n");
329 }
330
331 assert(n < MAX_WIDTH);
332
333 x+=fxMesa->x_offset;
334 FX_grLfbReadRegion( fxMesa->currentFB, x, bottom-y, n, 1, 0, data);
335
336 for (i=0;i<n;i++) {
337 GLushort pixel = data[i];
338 rgba[i][RCOMP] = FX_PixelToR[pixel];
339 rgba[i][GCOMP] = FX_PixelToG[pixel];
340 rgba[i][BCOMP] = FX_PixelToB[pixel];
341 rgba[i][ACOMP] = 255;
342 }
343 }
344
345 /************************************************************************/
346 /***** Pixel functions *****/
347 /************************************************************************/
348
349 static void fxDDWriteRGBAPixels(const GLcontext *ctx,
350 GLuint n, const GLint x[], const GLint y[],
351 CONST GLubyte rgba[][4], const GLubyte mask[])
352 {
353 fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
354 GLuint i;
355 GLint bottom=fxMesa->height+fxMesa->y_offset-1;
356
357 if (MESA_VERBOSE&VERBOSE_DRIVER) {
358 fprintf(stderr,"fxmesa: fxDDWriteRGBAPixels(...)\n");
359 }
360
361 for(i=0;i<n;i++)
362 if(mask[i])
363 LFB_WRITE_SPAN_MESA(fxMesa->currentFB, x[i]+fxMesa->x_offset, bottom-y[i],
364 1, 1, (void *)rgba[i]);
365 }
366
367 static void fxDDWriteMonoRGBAPixels(const GLcontext *ctx,
368 GLuint n, const GLint x[], const GLint y[],
369 const GLubyte mask[])
370 {
371 fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
372 GLuint i;
373 GLint bottom=fxMesa->height+fxMesa->y_offset-1;
374
375 if (MESA_VERBOSE&VERBOSE_DRIVER) {
376 fprintf(stderr,"fxmesa: fxDDWriteMonoRGBAPixels(...)\n");
377 }
378
379 for(i=0;i<n;i++)
380 if(mask[i])
381 writeRegionClipped(fxMesa, fxMesa->currentFB,x[i]+fxMesa->x_offset,bottom-y[i],
382 GR_LFB_SRC_FMT_8888,1,1,0,(void *) &fxMesa->color);
383 }
384
385 static void fxDDReadRGBAPixels(const GLcontext *ctx,
386 GLuint n, const GLint x[], const GLint y[],
387 GLubyte rgba[][4], const GLubyte mask[])
388 {
389 fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
390 GLuint i;
391 GLint bottom=fxMesa->height+fxMesa->y_offset-1;
392
393 if (MESA_VERBOSE&VERBOSE_DRIVER) {
394 fprintf(stderr,"fxmesa: fxDDReadRGBAPixels(...)\n");
395 }
396
397 for(i=0;i<n;i++) {
398 if(mask[i]) {
399 GLushort pixel;
400 FX_grLfbReadRegion(fxMesa->currentFB,x[i],bottom-y[i],1,1,0,&pixel);
401 rgba[i][RCOMP] = FX_PixelToR[pixel];
402 rgba[i][GCOMP] = FX_PixelToG[pixel];
403 rgba[i][BCOMP] = FX_PixelToB[pixel];
404 rgba[i][ACOMP] = 255;
405 }
406 }
407 }
408
409
410 /************************************************************************/
411 /***** Depth functions *****/
412 /************************************************************************/
413
414 void fxDDReadDepthSpanFloat(GLcontext *ctx,
415 GLuint n, GLint x, GLint y, GLfloat depth[])
416 {
417 fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
418 GLuint i;
419 GLint bottom=fxMesa->height+fxMesa->y_offset-1;
420 GLushort data[MAX_WIDTH];
421
422 if (MESA_VERBOSE&VERBOSE_DRIVER) {
423 fprintf(stderr,"fxmesa: fxDDReadDepthSpanFloat(...)\n");
424 }
425
426 x+=fxMesa->x_offset;
427 FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x,bottom-y,n,1,0,data);
428
429 /*
430 convert the read values to float values [0.0 .. 1.0].
431 */
432 for(i=0;i<n;i++)
433 depth[i]=data[i]/65535.0f;
434 }
435
436 void fxDDReadDepthSpanInt(GLcontext *ctx,
437 GLuint n, GLint x, GLint y, GLdepth depth[])
438 {
439 fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
440 GLint bottom=fxMesa->height+fxMesa->y_offset-1;
441
442 if (MESA_VERBOSE&VERBOSE_DRIVER) {
443 fprintf(stderr,"fxmesa: fxDDReadDepthSpanInt(...)\n");
444 }
445
446 x+=fxMesa->x_offset;
447 FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x,bottom-y,n,1,0,depth);
448 }
449
450 GLuint fxDDDepthTestSpanGeneric(GLcontext *ctx,
451 GLuint n, GLint x, GLint y, const GLdepth z[],
452 GLubyte mask[])
453 {
454 fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
455 GLushort depthdata[MAX_WIDTH];
456 GLdepth *zptr=depthdata;
457 GLubyte *m=mask;
458 GLuint i;
459 GLuint passed=0;
460 GLint bottom=fxMesa->height+fxMesa->y_offset-1;
461
462 if (MESA_VERBOSE&VERBOSE_DRIVER) {
463 fprintf(stderr,"fxmesa: fxDDDepthTestSpanGeneric(...)\n");
464 }
465
466 x+=fxMesa->x_offset;
467 FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x,bottom-y,n,1,0,depthdata);
468
469 /* switch cases ordered from most frequent to less frequent */
470 switch (ctx->Depth.Func) {
471 case GL_LESS:
472 if (ctx->Depth.Mask) {
473 /* Update Z buffer */
474 for (i=0; i<n; i++,zptr++,m++) {
475 if (*m) {
476 if (z[i] < *zptr) {
477 /* pass */
478 *zptr = z[i];
479 passed++;
480 } else {
481 /* fail */
482 *m = 0;
483 }
484 }
485 }
486 } else {
487 /* Don't update Z buffer */
488 for (i=0; i<n; i++,zptr++,m++) {
489 if (*m) {
490 if (z[i] < *zptr) {
491 /* pass */
492 passed++;
493 } else {
494 *m = 0;
495 }
496 }
497 }
498 }
499 break;
500 case GL_LEQUAL:
501 if (ctx->Depth.Mask) {
502 /* Update Z buffer */
503 for (i=0;i<n;i++,zptr++,m++) {
504 if (*m) {
505 if (z[i] <= *zptr) {
506 *zptr = z[i];
507 passed++;
508 } else {
509 *m = 0;
510 }
511 }
512 }
513 } else {
514 /* Don't update Z buffer */
515 for (i=0;i<n;i++,zptr++,m++) {
516 if (*m) {
517 if (z[i] <= *zptr) {
518 /* pass */
519 passed++;
520 } else {
521 *m = 0;
522 }
523 }
524 }
525 }
526 break;
527 case GL_GEQUAL:
528 if (ctx->Depth.Mask) {
529 /* Update Z buffer */
530 for (i=0;i<n;i++,zptr++,m++) {
531 if (*m) {
532 if (z[i] >= *zptr) {
533 *zptr = z[i];
534 passed++;
535 } else {
536 *m = 0;
537 }
538 }
539 }
540 } else {
541 /* Don't update Z buffer */
542 for (i=0;i<n;i++,zptr++,m++) {
543 if (*m) {
544 if (z[i] >= *zptr) {
545 /* pass */
546 passed++;
547 } else {
548 *m = 0;
549 }
550 }
551 }
552 }
553 break;
554 case GL_GREATER:
555 if (ctx->Depth.Mask) {
556 /* Update Z buffer */
557 for (i=0;i<n;i++,zptr++,m++) {
558 if (*m) {
559 if (z[i] > *zptr) {
560 *zptr = z[i];
561 passed++;
562 } else {
563 *m = 0;
564 }
565 }
566 }
567 } else {
568 /* Don't update Z buffer */
569 for (i=0;i<n;i++,zptr++,m++) {
570 if (*m) {
571 if (z[i] > *zptr) {
572 /* pass */
573 passed++;
574 } else {
575 *m = 0;
576 }
577 }
578 }
579 }
580 break;
581 case GL_NOTEQUAL:
582 if (ctx->Depth.Mask) {
583 /* Update Z buffer */
584 for (i=0;i<n;i++,zptr++,m++) {
585 if (*m) {
586 if (z[i] != *zptr) {
587 *zptr = z[i];
588 passed++;
589 } else {
590 *m = 0;
591 }
592 }
593 }
594 } else {
595 /* Don't update Z buffer */
596 for (i=0;i<n;i++,zptr++,m++) {
597 if (*m) {
598 if (z[i] != *zptr) {
599 /* pass */
600 passed++;
601 } else {
602 *m = 0;
603 }
604 }
605 }
606 }
607 break;
608 case GL_EQUAL:
609 if (ctx->Depth.Mask) {
610 /* Update Z buffer */
611 for (i=0;i<n;i++,zptr++,m++) {
612 if (*m) {
613 if (z[i] == *zptr) {
614 *zptr = z[i];
615 passed++;
616 } else {
617 *m =0;
618 }
619 }
620 }
621 } else {
622 /* Don't update Z buffer */
623 for (i=0;i<n;i++,zptr++,m++) {
624 if (*m) {
625 if (z[i] == *zptr) {
626 /* pass */
627 passed++;
628 } else {
629 *m =0;
630 }
631 }
632 }
633 }
634 break;
635 case GL_ALWAYS:
636 if (ctx->Depth.Mask) {
637 /* Update Z buffer */
638 for (i=0;i<n;i++,zptr++,m++) {
639 if (*m) {
640 *zptr = z[i];
641 passed++;
642 }
643 }
644 } else {
645 /* Don't update Z buffer or mask */
646 passed = n;
647 }
648 break;
649 case GL_NEVER:
650 for (i=0;i<n;i++) {
651 mask[i] = 0;
652 }
653 break;
654 default:
655 ;
656 } /*switch*/
657
658 if(passed)
659 writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER,x,bottom-y,GR_LFB_SRC_FMT_ZA16,n,1,0,depthdata);
660
661 return passed;
662 }
663
664 void fxDDDepthTestPixelsGeneric(GLcontext* ctx,
665 GLuint n, const GLint x[], const GLint y[],
666 const GLdepth z[], GLubyte mask[])
667 {
668 fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
669 GLdepth zval;
670 GLuint i;
671 GLint bottom=fxMesa->height+fxMesa->y_offset-1;
672
673 if (MESA_VERBOSE&VERBOSE_DRIVER) {
674 fprintf(stderr,"fxmesa: fxDDDepthTestPixelsGeneric(...)\n");
675 }
676
677 /* switch cases ordered from most frequent to less frequent */
678 switch (ctx->Depth.Func) {
679 case GL_LESS:
680 if (ctx->Depth.Mask) {
681 /* Update Z buffer */
682 for (i=0; i<n; i++) {
683 if (mask[i]) {
684 FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],1,1,0,&zval);
685 if (z[i] < zval) {
686 /* pass */
687 writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],GR_LFB_SRC_FMT_ZA16,1,1,0,(void*)&z[i]);
688 } else {
689 /* fail */
690 mask[i] = 0;
691 }
692 }
693 }
694 } else {
695 /* Don't update Z buffer */
696 for (i=0; i<n; i++) {
697 if (mask[i]) {
698 FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],1,1,0,&zval);
699 if (z[i] < zval) {
700 /* pass */
701 }
702 else {
703 /* fail */
704 mask[i] = 0;
705 }
706 }
707 }
708 }
709 break;
710 case GL_LEQUAL:
711 if (ctx->Depth.Mask) {
712 /* Update Z buffer */
713 for (i=0; i<n; i++) {
714 if (mask[i]) {
715 FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],1,1,0,&zval);
716 if (z[i] <= zval) {
717 /* pass */
718 writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],GR_LFB_SRC_FMT_ZA16,1,1,0,(void*)&z[i]);
719 } else {
720 /* fail */
721 mask[i] = 0;
722 }
723 }
724 }
725 } else {
726 /* Don't update Z buffer */
727 for (i=0; i<n; i++) {
728 if (mask[i]) {
729 FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],1,1,0,&zval);
730 if (z[i] <= zval) {
731 /* pass */
732 } else {
733 /* fail */
734 mask[i] = 0;
735 }
736 }
737 }
738 }
739 break;
740 case GL_GEQUAL:
741 if (ctx->Depth.Mask) {
742 /* Update Z buffer */
743 for (i=0; i<n; i++) {
744 if (mask[i]) {
745 FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],1,1,0,&zval);
746 if (z[i] >= zval) {
747 /* pass */
748 writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],GR_LFB_SRC_FMT_ZA16,1,1,0,(void*)&z[i]);
749 } else {
750 /* fail */
751 mask[i] = 0;
752 }
753 }
754 }
755 } else {
756 /* Don't update Z buffer */
757 for (i=0; i<n; i++) {
758 if (mask[i]) {
759 FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],1,1,0,&zval);
760 if (z[i] >= zval) {
761 /* pass */
762 } else {
763 /* fail */
764 mask[i] = 0;
765 }
766 }
767 }
768 }
769 break;
770 case GL_GREATER:
771 if (ctx->Depth.Mask) {
772 /* Update Z buffer */
773 for (i=0; i<n; i++) {
774 if (mask[i]) {
775 FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],1,1,0,&zval);
776 if (z[i] > zval) {
777 /* pass */
778 writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],GR_LFB_SRC_FMT_ZA16,1,1,0,(void*)&z[i]);
779 } else {
780 /* fail */
781 mask[i] = 0;
782 }
783 }
784 }
785 } else {
786 /* Don't update Z buffer */
787 for (i=0; i<n; i++) {
788 if (mask[i]) {
789 FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],1,1,0,&zval);
790 if (z[i] > zval) {
791 /* pass */
792 } else {
793 /* fail */
794 mask[i] = 0;
795 }
796 }
797 }
798 }
799 break;
800 case GL_NOTEQUAL:
801 if (ctx->Depth.Mask) {
802 /* Update Z buffer */
803 for (i=0; i<n; i++) {
804 if (mask[i]) {
805 FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],1,1,0,&zval);
806 if (z[i] != zval) {
807 /* pass */
808 writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],GR_LFB_SRC_FMT_ZA16,1,1,0,(void*)&z[i]);
809 } else {
810 /* fail */
811 mask[i] = 0;
812 }
813 }
814 }
815 } else {
816 /* Don't update Z buffer */
817 for (i=0; i<n; i++) {
818 if (mask[i]) {
819 FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],1,1,0,&zval);
820 if (z[i] != zval) {
821 /* pass */
822 }
823 else {
824 /* fail */
825 mask[i] = 0;
826 }
827 }
828 }
829 }
830 break;
831 case GL_EQUAL:
832 if (ctx->Depth.Mask) {
833 /* Update Z buffer */
834 for (i=0; i<n; i++) {
835 if (mask[i]) {
836 FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],1,1,0,&zval);
837 if (z[i] == zval) {
838 /* pass */
839 writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],GR_LFB_SRC_FMT_ZA16,1,1,0,(void*)&z[i]);
840 } else {
841 /* fail */
842 mask[i] = 0;
843 }
844 }
845 }
846 } else {
847 /* Don't update Z buffer */
848 for (i=0; i<n; i++) {
849 if (mask[i]) {
850 FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],1,1,0,&zval);
851 if (z[i] == zval) {
852 /* pass */
853 } else {
854 /* fail */
855 mask[i] = 0;
856 }
857 }
858 }
859 }
860 break;
861 case GL_ALWAYS:
862 if (ctx->Depth.Mask) {
863 /* Update Z buffer */
864 for (i=0; i<n; i++) {
865 if (mask[i]) {
866 writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],GR_LFB_SRC_FMT_ZA16,1,1,0,(void*)&z[i]);
867 }
868 }
869 } else {
870 /* Don't update Z buffer or mask */
871 }
872 break;
873 case GL_NEVER:
874 /* depth test never passes */
875 for (i=0;i<n;i++) {
876 mask[i] = 0;
877 }
878 break;
879 default:
880 ;
881 } /*switch*/
882 }
883
884 /************************************************************************/
885
886
887 void fxSetupDDSpanPointers(GLcontext *ctx)
888 {
889 ctx->Driver.WriteRGBASpan =fxDDWriteRGBASpan;
890 ctx->Driver.WriteRGBSpan =fxDDWriteRGBSpan;
891 ctx->Driver.WriteMonoRGBASpan =fxDDWriteMonoRGBASpan;
892 ctx->Driver.WriteRGBAPixels =fxDDWriteRGBAPixels;
893 ctx->Driver.WriteMonoRGBAPixels =fxDDWriteMonoRGBAPixels;
894
895 ctx->Driver.WriteCI8Span =NULL;
896 ctx->Driver.WriteCI32Span =NULL;
897 ctx->Driver.WriteMonoCISpan =NULL;
898 ctx->Driver.WriteCI32Pixels =NULL;
899 ctx->Driver.WriteMonoCIPixels =NULL;
900
901 ctx->Driver.ReadRGBASpan =fxDDReadRGBASpan;
902 ctx->Driver.ReadRGBAPixels =fxDDReadRGBAPixels;
903
904 ctx->Driver.ReadCI32Span =NULL;
905 ctx->Driver.ReadCI32Pixels =NULL;
906 }
907
908
909 #else
910
911
912 /*
913 * Need this to provide at least one external definition.
914 */
915
916 int gl_fx_dummy_function_span(void)
917 {
918 return 0;
919 }
920
921 #endif /* FX */