Reorganized combiners. Added optimized span functions.
[mesa.git] / src / mesa / drivers / glide / fxddspan.c
1 /* $Id: fxddspan.c,v 1.26 2003/10/09 15:12:21 dborca Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 4.0
6 *
7 * Copyright (C) 1999-2001 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 /* Authors:
28 * David Bucciarelli
29 * Brian Paul
30 * Daryll Strauss
31 * Keith Whitwell
32 * Daniel Borca
33 * Hiroshi Morii
34 */
35
36
37 /* fxdd.c - 3Dfx VooDoo Mesa span and pixel functions */
38
39
40 #ifdef HAVE_CONFIG_H
41 #include "conf.h"
42 #endif
43
44 #if defined(FX)
45
46 #include "fxdrv.h"
47 #include "fxglidew.h"
48 #include "swrast/swrast.h"
49
50
51 #define writeRegionClipped(fxm,dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data) \
52 FX_grLfbWriteRegion(dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data)
53
54
55
56 /* KW: Rearranged the args in the call to grLfbWriteRegion().
57 */
58 #define LFB_WRITE_SPAN_MESA(dst_buffer, \
59 dst_x, \
60 dst_y, \
61 src_width, \
62 src_stride, \
63 src_data) \
64 writeRegionClipped(fxMesa, dst_buffer, \
65 dst_x, \
66 dst_y, \
67 GR_LFB_SRC_FMT_8888, \
68 src_width, \
69 1, \
70 src_stride, \
71 src_data) \
72
73
74 /************************************************************************/
75 /***** Span functions *****/
76 /************************************************************************/
77 #define TDFXPACKCOLOR1555( r, g, b, a ) \
78 ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \
79 ((a) ? 0x8000 : 0))
80 #define TDFXPACKCOLOR565( r, g, b ) \
81 ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))
82 #define TDFXPACKCOLOR8888( r, g, b, a ) \
83 (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
84 /************************************************************************/
85
86
87 #define DBG 0
88
89
90 #define LOCAL_VARS \
91 GLuint pitch = info.strideInBytes; \
92 GLuint height = fxMesa->height; \
93 char *buf = (char *)((char *)info.lfbPtr + 0 /* x, y offset */); \
94 GLuint p; \
95 (void) buf; (void) p;
96
97 #define CLIPPIXEL( _x, _y ) ( _x >= minx && _x < maxx && \
98 _y >= miny && _y < maxy )
99
100 #define CLIPSPAN( _x, _y, _n, _x1, _n1, _i ) \
101 if ( _y < miny || _y >= maxy ) { \
102 _n1 = 0, _x1 = x; \
103 } else { \
104 _n1 = _n; \
105 _x1 = _x; \
106 if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx;\
107 if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx); \
108 }
109
110 #define Y_FLIP(_y) (height - _y - 1)
111
112 #define HW_WRITE_LOCK() \
113 fxMesaContext fxMesa = FX_CONTEXT(ctx); \
114 GrLfbInfo_t info; \
115 info.size = sizeof(GrLfbInfo_t); \
116 if ( grLfbLock( GR_LFB_WRITE_ONLY, \
117 fxMesa->currentFB, LFB_MODE, \
118 GR_ORIGIN_UPPER_LEFT, FXFALSE, &info ) ) {
119
120 #define HW_WRITE_UNLOCK() \
121 grLfbUnlock( GR_LFB_WRITE_ONLY, fxMesa->currentFB ); \
122 }
123
124 #define HW_READ_LOCK() \
125 fxMesaContext fxMesa = FX_CONTEXT(ctx); \
126 GrLfbInfo_t info; \
127 info.size = sizeof(GrLfbInfo_t); \
128 if ( grLfbLock( GR_LFB_READ_ONLY, fxMesa->currentFB, \
129 LFB_MODE, GR_ORIGIN_UPPER_LEFT, FXFALSE, &info ) ) {
130
131 #define HW_READ_UNLOCK() \
132 grLfbUnlock( GR_LFB_READ_ONLY, fxMesa->currentFB ); \
133 }
134
135 #define HW_WRITE_CLIPLOOP() \
136 do { \
137 int _nc = 1; /* numcliprects */ \
138 while (_nc--) { \
139 const int minx = fxMesa->clipMinX; \
140 const int miny = fxMesa->clipMinY; \
141 const int maxx = fxMesa->clipMaxX; \
142 const int maxy = fxMesa->clipMaxY;
143
144 #define HW_READ_CLIPLOOP() \
145 do { \
146 int _nc = 1; /* numcliprects */ \
147 while (_nc--) { \
148 const int minx = fxMesa->clipMinX; \
149 const int miny = fxMesa->clipMinY; \
150 const int maxx = fxMesa->clipMaxX; \
151 const int maxy = fxMesa->clipMaxY;
152
153 #define HW_ENDCLIPLOOP() \
154 } \
155 } while (0)
156
157
158 /* 16 bit, ARGB1555 color spanline and pixel functions */
159
160 #undef LFB_MODE
161 #define LFB_MODE GR_LFBWRITEMODE_1555
162
163 #undef BYTESPERPIXEL
164 #define BYTESPERPIXEL 2
165
166 #undef INIT_MONO_PIXEL
167 #define INIT_MONO_PIXEL(p, color) \
168 p = TDFXPACKCOLOR1555( color[RCOMP], color[GCOMP], color[BCOMP], color[ACOMP] )
169
170 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
171 *(GLushort *)(buf + _x*BYTESPERPIXEL + _y*pitch) = \
172 TDFXPACKCOLOR1555( r, g, b, a )
173
174 #define WRITE_PIXEL( _x, _y, p ) \
175 *(GLushort *)(buf + _x*BYTESPERPIXEL + _y*pitch) = p
176
177 #define READ_RGBA( rgba, _x, _y ) \
178 do { \
179 GLushort p = *(GLushort *)(buf + _x*BYTESPERPIXEL + _y*pitch); \
180 rgba[0] = FX_rgb_scale_5[(p >> 10) & 0x1F]; \
181 rgba[1] = FX_rgb_scale_5[(p >> 5) & 0x1F]; \
182 rgba[2] = FX_rgb_scale_5[ p & 0x1F]; \
183 rgba[3] = (p & 0x8000) ? 255 : 0; \
184 } while (0)
185
186 #define TAG(x) tdfx##x##_ARGB1555
187 #include "../dri/common/spantmp.h"
188
189
190 /* 16 bit, RGB565 color spanline and pixel functions */
191
192 #undef LFB_MODE
193 #define LFB_MODE GR_LFBWRITEMODE_565
194
195 #undef BYTESPERPIXEL
196 #define BYTESPERPIXEL 2
197
198 #undef INIT_MONO_PIXEL
199 #define INIT_MONO_PIXEL(p, color) \
200 p = TDFXPACKCOLOR565( color[RCOMP], color[GCOMP], color[BCOMP] )
201
202 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
203 *(GLushort *)(buf + _x*BYTESPERPIXEL + _y*pitch) = \
204 TDFXPACKCOLOR565( r, g, b )
205
206 #define WRITE_PIXEL( _x, _y, p ) \
207 *(GLushort *)(buf + _x*BYTESPERPIXEL + _y*pitch) = p
208
209 #define READ_RGBA( rgba, _x, _y ) \
210 do { \
211 GLushort p = *(GLushort *)(buf + _x*BYTESPERPIXEL + _y*pitch); \
212 rgba[0] = FX_rgb_scale_5[(p >> 11) & 0x1F]; \
213 rgba[1] = FX_rgb_scale_6[(p >> 5) & 0x3F]; \
214 rgba[2] = FX_rgb_scale_5[ p & 0x1F]; \
215 rgba[3] = 0xff; \
216 } while (0)
217
218 #define TAG(x) tdfx##x##_RGB565
219 #include "../dri/common/spantmp.h"
220
221
222 /* 32 bit, ARGB8888 color spanline and pixel functions */
223
224 #undef LFB_MODE
225 #define LFB_MODE GR_LFBWRITEMODE_8888
226
227 #undef BYTESPERPIXEL
228 #define BYTESPERPIXEL 4
229
230 #undef INIT_MONO_PIXEL
231 #define INIT_MONO_PIXEL(p, color) \
232 p = TDFXPACKCOLOR8888( color[RCOMP], color[GCOMP], color[BCOMP], color[ACOMP] )
233
234 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
235 *(GLuint *)(buf + _x*BYTESPERPIXEL + _y*pitch) = \
236 TDFXPACKCOLOR8888( r, g, b, a )
237
238 #define WRITE_PIXEL( _x, _y, p ) \
239 *(GLuint *)(buf + _x*BYTESPERPIXEL + _y*pitch) = p
240
241 #define READ_RGBA( rgba, _x, _y ) \
242 do { \
243 GLuint p = *(GLuint *)(buf + _x*BYTESPERPIXEL + _y*pitch); \
244 rgba[0] = (p >> 16) & 0xff; \
245 rgba[1] = (p >> 8) & 0xff; \
246 rgba[2] = (p >> 0) & 0xff; \
247 rgba[3] = (p >> 24) & 0xff; \
248 } while (0)
249
250 #define TAG(x) tdfx##x##_ARGB8888
251 #include "../dri/common/spantmp.h"
252
253
254 /************************************************************************/
255 /***** Span functions (optimized) *****/
256 /************************************************************************/
257
258 /*
259 * Read a span of 15-bit RGB pixels. Note, we don't worry about cliprects
260 * since OpenGL says obscured pixels have undefined values.
261 */
262 static void fxReadRGBASpan_ARGB1555 (const GLcontext * ctx,
263 GLuint n,
264 GLint x, GLint y,
265 GLubyte rgba[][4])
266 {
267 fxMesaContext fxMesa = FX_CONTEXT(ctx);
268 GrLfbInfo_t info;
269 info.size = sizeof(GrLfbInfo_t);
270 if (grLfbLock(GR_LFB_READ_ONLY, fxMesa->currentFB,
271 GR_LFBWRITEMODE_ANY, GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) {
272 const GLint winX = 0;
273 const GLint winY = fxMesa->height - 1;
274 const GLushort *data16 = (const GLushort *)((const GLubyte *)info.lfbPtr +
275 (winY - y) * info.strideInBytes +
276 (winX + x) * 2);
277 const GLuint *data32 = (const GLuint *) data16;
278 GLuint i, j;
279 GLuint extraPixel = (n & 1);
280 n -= extraPixel;
281
282 for (i = j = 0; i < n; i += 2, j++) {
283 GLuint pixel = data32[j];
284 rgba[i][0] = FX_rgb_scale_5[(pixel >> 10) & 0x1F];
285 rgba[i][1] = FX_rgb_scale_5[(pixel >> 5) & 0x1F];
286 rgba[i][2] = FX_rgb_scale_5[ pixel & 0x1F];
287 rgba[i][3] = (pixel & 0x8000) ? 255 : 0;
288 rgba[i+1][0] = FX_rgb_scale_5[(pixel >> 26) & 0x1F];
289 rgba[i+1][1] = FX_rgb_scale_5[(pixel >> 21) & 0x1F];
290 rgba[i+1][2] = FX_rgb_scale_5[(pixel >> 16) & 0x1F];
291 rgba[i+1][3] = (pixel & 0x80000000) ? 255 : 0;
292 }
293 if (extraPixel) {
294 GLushort pixel = data16[n];
295 rgba[n][0] = FX_rgb_scale_5[(pixel >> 10) & 0x1F];
296 rgba[n][1] = FX_rgb_scale_5[(pixel >> 5) & 0x1F];
297 rgba[n][2] = FX_rgb_scale_5[ pixel & 0x1F];
298 rgba[n][3] = (pixel & 0x8000) ? 255 : 0;
299 }
300
301 grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB);
302 }
303 }
304
305 /*
306 * Read a span of 16-bit RGB pixels. Note, we don't worry about cliprects
307 * since OpenGL says obscured pixels have undefined values.
308 */
309 static void fxReadRGBASpan_RGB565 (const GLcontext * ctx,
310 GLuint n,
311 GLint x, GLint y,
312 GLubyte rgba[][4])
313 {
314 fxMesaContext fxMesa = FX_CONTEXT(ctx);
315 GrLfbInfo_t info;
316 info.size = sizeof(GrLfbInfo_t);
317 if (grLfbLock(GR_LFB_READ_ONLY, fxMesa->currentFB,
318 GR_LFBWRITEMODE_ANY, GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) {
319 const GLint winX = 0;
320 const GLint winY = fxMesa->height - 1;
321 const GLushort *data16 = (const GLushort *)((const GLubyte *)info.lfbPtr +
322 (winY - y) * info.strideInBytes +
323 (winX + x) * 2);
324 const GLuint *data32 = (const GLuint *) data16;
325 GLuint i, j;
326 GLuint extraPixel = (n & 1);
327 n -= extraPixel;
328
329 for (i = j = 0; i < n; i += 2, j++) {
330 GLuint pixel = data32[j];
331 #if 0
332 GLuint pixel0 = pixel & 0xffff;
333 GLuint pixel1 = pixel >> 16;
334 rgba[i][RCOMP] = FX_PixelToR[pixel0];
335 rgba[i][GCOMP] = FX_PixelToG[pixel0];
336 rgba[i][BCOMP] = FX_PixelToB[pixel0];
337 rgba[i][ACOMP] = 255;
338 rgba[i + 1][RCOMP] = FX_PixelToR[pixel1];
339 rgba[i + 1][GCOMP] = FX_PixelToG[pixel1];
340 rgba[i + 1][BCOMP] = FX_PixelToB[pixel1];
341 rgba[i + 1][ACOMP] = 255;
342 #else
343 rgba[i][0] = FX_rgb_scale_5[(pixel >> 11) & 0x1F];
344 rgba[i][1] = FX_rgb_scale_6[(pixel >> 5) & 0x3F];
345 rgba[i][2] = FX_rgb_scale_5[ pixel & 0x1F];
346 rgba[i][3] = 255;
347 rgba[i+1][0] = FX_rgb_scale_5[(pixel >> 27) & 0x1F];
348 rgba[i+1][1] = FX_rgb_scale_6[(pixel >> 21) & 0x3F];
349 rgba[i+1][2] = FX_rgb_scale_5[(pixel >> 16) & 0x1F];
350 rgba[i+1][3] = 255;
351 #endif
352 }
353 if (extraPixel) {
354 GLushort pixel = data16[n];
355 #if 0
356 rgba[n][RCOMP] = FX_PixelToR[pixel];
357 rgba[n][GCOMP] = FX_PixelToG[pixel];
358 rgba[n][BCOMP] = FX_PixelToB[pixel];
359 rgba[n][ACOMP] = 255;
360 #else
361 rgba[n][0] = FX_rgb_scale_5[(pixel >> 11) & 0x1F];
362 rgba[n][1] = FX_rgb_scale_6[(pixel >> 5) & 0x3F];
363 rgba[n][2] = FX_rgb_scale_5[ pixel & 0x1F];
364 rgba[n][3] = 255;
365 #endif
366 }
367
368 grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB);
369 }
370 }
371
372 /*
373 * Read a span of 32-bit RGB pixels. Note, we don't worry about cliprects
374 * since OpenGL says obscured pixels have undefined values.
375 */
376 static void fxReadRGBASpan_ARGB8888 (const GLcontext * ctx,
377 GLuint n,
378 GLint x, GLint y,
379 GLubyte rgba[][4])
380 {
381 /* Hack alert: WRONG! */
382 fxMesaContext fxMesa = FX_CONTEXT(ctx);
383 grLfbReadRegion(fxMesa->currentFB, x, fxMesa->height - 1 - y, n, 1, n * 4, rgba);
384 }
385
386
387 /************************************************************************/
388 /***** Depth functions *****/
389 /************************************************************************/
390
391 void
392 fxDDWriteDepthSpan(GLcontext * ctx,
393 GLuint n, GLint x, GLint y, const GLdepth depth[],
394 const GLubyte mask[])
395 {
396 fxMesaContext fxMesa = FX_CONTEXT(ctx);
397 GLint bottom = fxMesa->height - 1;
398
399 if (TDFX_DEBUG & VERBOSE_DRIVER) {
400 fprintf(stderr, "%s(...)\n", __FUNCTION__);
401 }
402
403
404 if (mask) {
405 GLint i;
406 for (i = 0; i < n; i++) {
407 if (mask[i]) {
408 GLshort d = depth[i];
409 writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, x + i, bottom - y,
410 GR_LFB_SRC_FMT_ZA16, 1, 1, 0, (void *) &d);
411 }
412 }
413 }
414 else {
415 GLushort depth16[MAX_WIDTH];
416 GLint i;
417 for (i = 0; i < n; i++) {
418 depth16[i] = depth[i];
419 }
420 writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, x, bottom - y,
421 GR_LFB_SRC_FMT_ZA16, n, 1, 0, (void *) depth16);
422 }
423 }
424
425
426 void
427 fxDDWriteDepth32Span(GLcontext * ctx,
428 GLuint n, GLint x, GLint y, const GLdepth depth[],
429 const GLubyte mask[])
430 {
431 fxMesaContext fxMesa = FX_CONTEXT(ctx);
432 GLint bottom = fxMesa->height - 1;
433 GLint i;
434
435 if (TDFX_DEBUG & VERBOSE_DRIVER) {
436 fprintf(stderr, "%s(...)\n", __FUNCTION__);
437 }
438
439
440 if (mask) {
441 for (i = 0; i < n; i++) {
442 if (mask[i]) {
443 GLuint d = depth[i] << 8;
444 writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, x + i, bottom - y,
445 GR_LFBWRITEMODE_Z32, 1, 1, 0, (void *) &d);
446 }
447 }
448 }
449 else {
450 GLuint depth32[MAX_WIDTH];
451 for (i = 0; i < n; i++) {
452 depth32[i] = depth[i] << 8;
453 }
454 writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, x, bottom - y,
455 GR_LFBWRITEMODE_Z32, n, 1, 0, (void *) depth32);
456 }
457 }
458
459
460 void
461 fxDDReadDepthSpan(GLcontext * ctx,
462 GLuint n, GLint x, GLint y, GLdepth depth[])
463 {
464 fxMesaContext fxMesa = FX_CONTEXT(ctx);
465 GLint bottom = fxMesa->height - 1;
466 GLushort depth16[MAX_WIDTH];
467 GLuint i;
468
469 if (TDFX_DEBUG & VERBOSE_DRIVER) {
470 fprintf(stderr, "%s(...)\n", __FUNCTION__);
471 }
472
473 grLfbReadRegion(GR_BUFFER_AUXBUFFER, x, bottom - y, n, 1, 0, depth16);
474 for (i = 0; i < n; i++) {
475 depth[i] = depth16[i];
476 }
477 }
478
479
480 void
481 fxDDReadDepth32Span(GLcontext * ctx,
482 GLuint n, GLint x, GLint y, GLdepth depth[])
483 {
484 fxMesaContext fxMesa = FX_CONTEXT(ctx);
485 GLint bottom = fxMesa->height - 1;
486
487 if (TDFX_DEBUG & VERBOSE_DRIVER) {
488 fprintf(stderr, "%s(...)\n", __FUNCTION__);
489 }
490
491 grLfbReadRegion(GR_BUFFER_AUXBUFFER, x, bottom - y, n, 1, 0, depth);
492 }
493
494
495
496 void
497 fxDDWriteDepthPixels(GLcontext * ctx,
498 GLuint n, const GLint x[], const GLint y[],
499 const GLdepth depth[], const GLubyte mask[])
500 {
501 fxMesaContext fxMesa = FX_CONTEXT(ctx);
502 GLint bottom = fxMesa->height - 1;
503 GLuint i;
504
505 if (TDFX_DEBUG & VERBOSE_DRIVER) {
506 fprintf(stderr, "%s(...)\n", __FUNCTION__);
507 }
508
509 for (i = 0; i < n; i++) {
510 if (mask[i]) {
511 int xpos = x[i];
512 int ypos = bottom - y[i];
513 GLushort d = depth[i];
514 writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, xpos, ypos,
515 GR_LFB_SRC_FMT_ZA16, 1, 1, 0, (void *) &d);
516 }
517 }
518 }
519
520
521 void
522 fxDDWriteDepth32Pixels(GLcontext * ctx,
523 GLuint n, const GLint x[], const GLint y[],
524 const GLdepth depth[], const GLubyte mask[])
525 {
526 fxMesaContext fxMesa = FX_CONTEXT(ctx);
527 GLint bottom = fxMesa->height - 1;
528 GLuint i;
529
530 if (TDFX_DEBUG & VERBOSE_DRIVER) {
531 fprintf(stderr, "%s(...)\n", __FUNCTION__);
532 }
533
534 for (i = 0; i < n; i++) {
535 if (mask[i]) {
536 int xpos = x[i];
537 int ypos = bottom - y[i];
538 GLuint d = depth[i] << 8;
539 writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, xpos, ypos,
540 GR_LFBWRITEMODE_Z32, 1, 1, 0, (void *) &d);
541 }
542 }
543 }
544
545
546 void
547 fxDDReadDepthPixels(GLcontext * ctx, GLuint n,
548 const GLint x[], const GLint y[], GLdepth depth[])
549 {
550 fxMesaContext fxMesa = FX_CONTEXT(ctx);
551 GLint bottom = fxMesa->height - 1;
552 GLuint i;
553
554 if (TDFX_DEBUG & VERBOSE_DRIVER) {
555 fprintf(stderr, "%s(...)\n", __FUNCTION__);
556 }
557
558 for (i = 0; i < n; i++) {
559 int xpos = x[i];
560 int ypos = bottom - y[i];
561 GLushort d;
562 grLfbReadRegion(GR_BUFFER_AUXBUFFER, xpos, ypos, 1, 1, 0, &d);
563 depth[i] = d;
564 }
565 }
566
567
568 void
569 fxDDReadDepth32Pixels(GLcontext * ctx, GLuint n,
570 const GLint x[], const GLint y[], GLdepth depth[])
571 {
572 fxMesaContext fxMesa = FX_CONTEXT(ctx);
573 GLint bottom = fxMesa->height - 1;
574 GLuint i;
575
576 if (TDFX_DEBUG & VERBOSE_DRIVER) {
577 fprintf(stderr, "%s(...)\n", __FUNCTION__);
578 }
579
580 for (i = 0; i < n; i++) {
581 int xpos = x[i];
582 int ypos = bottom - y[i];
583 grLfbReadRegion(GR_BUFFER_AUXBUFFER, xpos, ypos, 1, 1, 0, &depth[i]);
584 }
585 }
586
587
588
589 /* Set the buffer used for reading */
590 /* XXX support for separate read/draw buffers hasn't been tested */
591 static void
592 fxDDSetBuffer(GLcontext * ctx, GLframebuffer * buffer, GLuint bufferBit)
593 {
594 fxMesaContext fxMesa = FX_CONTEXT(ctx);
595 (void) buffer;
596
597 if (TDFX_DEBUG & VERBOSE_DRIVER) {
598 fprintf(stderr, "%s(%x)\n", __FUNCTION__, (int)bufferBit);
599 }
600
601 if (bufferBit == FRONT_LEFT_BIT) {
602 fxMesa->currentFB = GR_BUFFER_FRONTBUFFER;
603 grRenderBuffer(fxMesa->currentFB);
604 }
605 else if (bufferBit == BACK_LEFT_BIT) {
606 fxMesa->currentFB = GR_BUFFER_BACKBUFFER;
607 grRenderBuffer(fxMesa->currentFB);
608 }
609 }
610
611
612 /************************************************************************/
613
614
615
616 void
617 fxSetupDDSpanPointers(GLcontext * ctx)
618 {
619 struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference( ctx );
620 fxMesaContext fxMesa = FX_CONTEXT(ctx);
621
622 swdd->SetBuffer = fxDDSetBuffer;
623
624 switch (fxMesa->colDepth) {
625 case 15:
626 swdd->WriteRGBASpan = tdfxWriteRGBASpan_ARGB1555;
627 swdd->WriteRGBSpan = tdfxWriteRGBSpan_ARGB1555;
628 swdd->WriteRGBAPixels = tdfxWriteRGBAPixels_ARGB1555;
629 swdd->WriteMonoRGBASpan = tdfxWriteMonoRGBASpan_ARGB1555;
630 swdd->WriteMonoRGBAPixels = tdfxWriteMonoRGBAPixels_ARGB1555;
631 swdd->ReadRGBASpan = /*td*/fxReadRGBASpan_ARGB1555;
632 swdd->ReadRGBAPixels = tdfxReadRGBAPixels_ARGB1555;
633
634 swdd->WriteDepthSpan = fxDDWriteDepthSpan;
635 swdd->WriteDepthPixels = fxDDWriteDepthPixels;
636 swdd->ReadDepthSpan = fxDDReadDepthSpan;
637 swdd->ReadDepthPixels = fxDDReadDepthPixels;
638 break;
639 case 16:
640 swdd->WriteRGBASpan = tdfxWriteRGBASpan_RGB565;
641 swdd->WriteRGBSpan = tdfxWriteRGBSpan_RGB565;
642 swdd->WriteRGBAPixels = tdfxWriteRGBAPixels_RGB565;
643 swdd->WriteMonoRGBASpan = tdfxWriteMonoRGBASpan_RGB565;
644 swdd->WriteMonoRGBAPixels = tdfxWriteMonoRGBAPixels_RGB565;
645 swdd->ReadRGBASpan = /*td*/fxReadRGBASpan_RGB565;
646 swdd->ReadRGBAPixels = tdfxReadRGBAPixels_RGB565;
647
648 swdd->WriteDepthSpan = fxDDWriteDepthSpan;
649 swdd->WriteDepthPixels = fxDDWriteDepthPixels;
650 swdd->ReadDepthSpan = fxDDReadDepthSpan;
651 swdd->ReadDepthPixels = fxDDReadDepthPixels;
652 break;
653 case 32:
654 swdd->WriteRGBASpan = tdfxWriteRGBASpan_ARGB8888;
655 swdd->WriteRGBSpan = tdfxWriteRGBSpan_ARGB8888;
656 swdd->WriteRGBAPixels = tdfxWriteRGBAPixels_ARGB8888;
657 swdd->WriteMonoRGBASpan = tdfxWriteMonoRGBASpan_ARGB8888;
658 swdd->WriteMonoRGBAPixels = tdfxWriteMonoRGBAPixels_ARGB8888;
659 swdd->ReadRGBASpan = tdfxReadRGBASpan_ARGB8888;
660 swdd->ReadRGBAPixels = tdfxReadRGBAPixels_ARGB8888;
661
662 swdd->WriteDepthSpan = fxDDWriteDepth32Span;
663 swdd->WriteDepthPixels = fxDDWriteDepth32Pixels;
664 swdd->ReadDepthSpan = fxDDReadDepth32Span;
665 swdd->ReadDepthPixels = fxDDReadDepth32Pixels;
666 break;
667 }
668
669 #if 0
670 if ( fxMesa->haveHwStencil ) {
671 swdd->WriteStencilSpan = write_stencil_span;
672 swdd->ReadStencilSpan = read_stencil_span;
673 swdd->WriteStencilPixels = write_stencil_pixels;
674 swdd->ReadStencilPixels = read_stencil_pixels;
675 }
676
677 swdd->WriteDepthSpan = tdfxDDWriteDepthSpan;
678 swdd->WriteDepthPixels = tdfxDDWriteDepthPixels;
679 swdd->ReadDepthSpan = tdfxDDReadDepthSpan;
680 swdd->ReadDepthPixels = tdfxDDReadDepthPixels;
681
682 swdd->WriteCI8Span = NULL;
683 swdd->WriteCI32Span = NULL;
684 swdd->WriteMonoCISpan = NULL;
685 swdd->WriteCI32Pixels = NULL;
686 swdd->WriteMonoCIPixels = NULL;
687 swdd->ReadCI32Span = NULL;
688 swdd->ReadCI32Pixels = NULL;
689
690 swdd->SpanRenderStart = tdfxSpanRenderStart; /* BEGIN_BOARD_LOCK */
691 swdd->SpanRenderFinish = tdfxSpanRenderFinish; /* END_BOARD_LOCK */
692 #endif
693 }
694
695
696 #else
697
698
699 /*
700 * Need this to provide at least one external definition.
701 */
702
703 extern int gl_fx_dummy_function_span(void);
704 int
705 gl_fx_dummy_function_span(void)
706 {
707 return 0;
708 }
709
710 #endif /* FX */