e106ce291e2ac3b68c1f3d45e9113aaf717c1c8e
[mesa.git] / src / mesa / drivers / glide / fxddspan.c
1 /* Hack alert:
2 * Depth32 functions won't compile with Glide2
3 * Optimize and check endianess for `read_R8G8B8_pixels'
4 */
5
6 /* $Id: fxddspan.c,v 1.23 2003/07/17 14:50:12 brianp Exp $ */
7
8 /*
9 * Mesa 3-D graphics library
10 * Version: 4.0
11 *
12 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
13 *
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the "Software"),
16 * to deal in the Software without restriction, including without limitation
17 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 * and/or sell copies of the Software, and to permit persons to whom the
19 * Software is furnished to do so, subject to the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be included
22 * in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
28 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 */
31
32 /* Authors:
33 * David Bucciarelli
34 * Brian Paul
35 * Daryll Strauss
36 * Keith Whitwell
37 */
38
39
40 /* fxdd.c - 3Dfx VooDoo Mesa span and pixel functions */
41
42
43 #ifdef HAVE_CONFIG_H
44 #include "conf.h"
45 #endif
46
47 #if defined(FX)
48
49 #include "fxdrv.h"
50 #include "fxglidew.h"
51 #include "swrast/swrast.h"
52
53 #ifdef _MSC_VER
54 #ifdef _WIN32
55 #pragma warning( disable : 4090 4022 )
56 /* 4101 : "different 'const' qualifier"
57 * 4022 : "pointer mistmatch for actual parameter 'n'
58 */
59 #endif
60 #endif
61
62
63 #if !defined(FXMESA_USE_ARGB)
64
65
66
67 #define writeRegionClipped(fxm,dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data) \
68 FX_grLfbWriteRegion(dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data)
69
70
71
72 /* KW: Rearranged the args in the call to grLfbWriteRegion().
73 */
74 #define LFB_WRITE_SPAN_MESA(dst_buffer, \
75 dst_x, \
76 dst_y, \
77 src_width, \
78 src_stride, \
79 src_data) \
80 writeRegionClipped(fxMesa, dst_buffer, \
81 dst_x, \
82 dst_y, \
83 GR_LFB_SRC_FMT_8888, \
84 src_width, \
85 1, \
86 src_stride, \
87 src_data) \
88
89
90 #else /* !defined(FXMESA_USE_RGBA) */
91
92 #define writeRegionClipped(fxm,dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data) \
93 FX_grLfbWriteRegion(dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data)
94
95
96 #define MESACOLOR_TO_ARGB(c) ( \
97 ( ((unsigned int)(c[ACOMP]))<<24 ) | \
98 ( ((unsigned int)(c[RCOMP]))<<16 ) | \
99 ( ((unsigned int)(c[GCOMP]))<<8 ) | \
100 ( (unsigned int)(c[BCOMP])) )
101
102 inline void
103 LFB_WRITE_SPAN_MESA(GrBuffer_t dst_buffer,
104 FxU32 dst_x,
105 FxU32 dst_y,
106 FxU32 src_width, FxI32 src_stride, void *src_data)
107 {
108 /* Covert to ARGB */
109 GLubyte(*rgba)[4] = src_data;
110 GLuint argb[MAX_WIDTH];
111 int i;
112
113 for (i = 0; i < src_width; i++) {
114 argb[i] = MESACOLOR_TO_ARGB(rgba[i]);
115 }
116 writeRegionClipped( /*fxMesa, */ NULL, dst_buffer,
117 dst_x,
118 dst_y,
119 GR_LFB_SRC_FMT_8888,
120 src_width, 1, src_stride, (void *) argb);
121 }
122
123 #endif /* !defined(FXMESA_USE_RGBA) */
124
125
126 /************************************************************************/
127 /***** Span functions *****/
128 /************************************************************************/
129
130
131 static void
132 fxDDWriteRGBASpan(const GLcontext * ctx,
133 GLuint n, GLint x, GLint y,
134 const GLubyte rgba[][4], const GLubyte mask[])
135 {
136 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
137 GLuint i;
138 GLint bottom = fxMesa->height - 1;
139
140 if (MESA_VERBOSE & VERBOSE_DRIVER) {
141 fprintf(stderr, "fxmesa: fxDDWriteRGBASpan(...)\n");
142 }
143
144 if (mask) {
145 int span = 0;
146
147 for (i = 0; i < n; i++) {
148 if (mask[i]) {
149 ++span;
150 }
151 else {
152 if (span > 0) {
153 LFB_WRITE_SPAN_MESA(fxMesa->currentFB, x + i - span,
154 bottom - y,
155 /* GR_LFB_SRC_FMT_8888, */ span, /*1, */ 0,
156 (void *) rgba[i - span]);
157 span = 0;
158 }
159 }
160 }
161
162 if (span > 0)
163 LFB_WRITE_SPAN_MESA(fxMesa->currentFB, x + n - span, bottom - y,
164 /* GR_LFB_SRC_FMT_8888, */ span, /*1, */ 0,
165 (void *) rgba[n - span]);
166 }
167 else
168 LFB_WRITE_SPAN_MESA(fxMesa->currentFB, x, bottom - y, /* GR_LFB_SRC_FMT_8888, */
169 n, /* 1, */ 0, (void *) rgba);
170 }
171
172
173 static void
174 fxDDWriteRGBSpan(const GLcontext * ctx,
175 GLuint n, GLint x, GLint y,
176 const GLubyte rgb[][3], const GLubyte mask[])
177 {
178 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
179 GLuint i;
180 GLint bottom = fxMesa->height - 1;
181 GLubyte rgba[MAX_WIDTH][4];
182
183 if (MESA_VERBOSE & VERBOSE_DRIVER) {
184 fprintf(stderr, "fxmesa: fxDDWriteRGBSpan()\n");
185 }
186
187 if (mask) {
188 int span = 0;
189
190 for (i = 0; i < n; i++) {
191 if (mask[i]) {
192 rgba[span][RCOMP] = rgb[i][0];
193 rgba[span][GCOMP] = rgb[i][1];
194 rgba[span][BCOMP] = rgb[i][2];
195 rgba[span][ACOMP] = 255;
196 ++span;
197 }
198 else {
199 if (span > 0) {
200 LFB_WRITE_SPAN_MESA(fxMesa->currentFB, x + i - span,
201 bottom - y,
202 /*GR_LFB_SRC_FMT_8888, */ span, /* 1, */ 0,
203 (void *) rgba);
204 span = 0;
205 }
206 }
207 }
208
209 if (span > 0)
210 LFB_WRITE_SPAN_MESA(fxMesa->currentFB, x + n - span, bottom - y,
211 /*GR_LFB_SRC_FMT_8888, */ span, /* 1, */ 0,
212 (void *) rgba);
213 }
214 else {
215 for (i = 0; i < n; i++) {
216 rgba[i][RCOMP] = rgb[i][0];
217 rgba[i][GCOMP] = rgb[i][1];
218 rgba[i][BCOMP] = rgb[i][2];
219 rgba[i][ACOMP] = 255;
220 }
221
222 LFB_WRITE_SPAN_MESA(fxMesa->currentFB, x, bottom - y, /* GR_LFB_SRC_FMT_8888, */
223 n, /* 1, */ 0, (void *) rgba);
224 }
225 }
226
227
228 static void
229 fxDDWriteMonoRGBASpan(const GLcontext * ctx,
230 GLuint n, GLint x, GLint y,
231 const GLchan color[4], const GLubyte mask[])
232 {
233 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
234 GLuint i;
235 GLint bottom = fxMesa->height - 1;
236 GLuint data[MAX_WIDTH];
237 GrColor_t gColor = FXCOLOR4(color);
238
239 if (MESA_VERBOSE & VERBOSE_DRIVER) {
240 fprintf(stderr, "fxmesa: fxDDWriteMonoRGBASpan(...)\n");
241 }
242
243 if (mask) {
244 int span = 0;
245
246 for (i = 0; i < n; i++) {
247 if (mask[i]) {
248 data[span] = (GLuint) gColor;
249 ++span;
250 }
251 else {
252 if (span > 0) {
253 writeRegionClipped(fxMesa, fxMesa->currentFB, x + i - span,
254 bottom - y, GR_LFB_SRC_FMT_8888, span, 1, 0,
255 (void *) data);
256 span = 0;
257 }
258 }
259 }
260
261 if (span > 0)
262 writeRegionClipped(fxMesa, fxMesa->currentFB, x + n - span,
263 bottom - y, GR_LFB_SRC_FMT_8888, span, 1, 0,
264 (void *) data);
265 }
266 else {
267 for (i = 0; i < n; i++) {
268 data[i] = (GLuint) gColor;
269 }
270
271 writeRegionClipped(fxMesa, fxMesa->currentFB, x, bottom - y,
272 GR_LFB_SRC_FMT_8888, n, 1, 0, (void *) data);
273 }
274 }
275
276
277 #if 0
278 static void
279 fxDDReadRGBASpan(const GLcontext * ctx,
280 GLuint n, GLint x, GLint y, GLubyte rgba[][4])
281 {
282 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
283 GLushort data[MAX_WIDTH];
284 GLuint i;
285 GLint bottom = fxMesa->height - 1;
286
287 printf("read span %d, %d, %d\n", x, y, n);
288 if (MESA_VERBOSE & VERBOSE_DRIVER) {
289 fprintf(stderr, "fxmesa: fxDDReadRGBASpan(...)\n");
290 }
291
292 assert(n < MAX_WIDTH);
293
294 FX_grLfbReadRegion(fxMesa->currentFB, x, bottom - y, n, 1, 0, data);
295
296 for (i = 0; i < n; i++) {
297 GLushort pixel = data[i];
298 rgba[i][RCOMP] = FX_PixelToR[pixel];
299 rgba[i][GCOMP] = FX_PixelToG[pixel];
300 rgba[i][BCOMP] = FX_PixelToB[pixel];
301 rgba[i][ACOMP] = 255;
302 }
303 }
304 #endif
305
306
307 /*
308 * Read a span of 16-bit RGB pixels. Note, we don't worry about cliprects
309 * since OpenGL says obscured pixels have undefined values.
310 */
311 static void
312 read_R5G6B5_span(const GLcontext * ctx,
313 GLuint n, GLint x, GLint y, GLubyte rgba[][4])
314 {
315 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
316 GrLfbInfo_t info;
317 BEGIN_BOARD_LOCK();
318 if (grLfbLock(GR_LFB_READ_ONLY,
319 fxMesa->currentFB,
320 GR_LFBWRITEMODE_ANY, GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) {
321 const GLint winX = 0;
322 const GLint winY = fxMesa->height - 1;
323 const GLint srcStride = info.strideInBytes / 2; /* stride in GLushorts */
324 const GLushort *data16 = (const GLushort *) info.lfbPtr
325 + (winY - y) * srcStride + (winX + x);
326 const GLuint *data32 = (const GLuint *) data16;
327 GLuint i, j;
328 GLuint extraPixel = (n & 1);
329 n -= extraPixel;
330 for (i = j = 0; i < n; i += 2, j++) {
331 GLuint pixel = data32[j];
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 }
343 if (extraPixel) {
344 GLushort pixel = data16[n];
345 rgba[n][RCOMP] = FX_PixelToR[pixel];
346 rgba[n][GCOMP] = FX_PixelToG[pixel];
347 rgba[n][BCOMP] = FX_PixelToB[pixel];
348 rgba[n][ACOMP] = 255;
349 }
350
351 grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB);
352 }
353 END_BOARD_LOCK();
354 }
355
356 /*
357 * Read a span of 15-bit RGB pixels. Note, we don't worry about cliprects
358 * since OpenGL says obscured pixels have undefined values.
359 */
360 static void read_R5G5B5_span (const GLcontext * ctx,
361 GLuint n,
362 GLint x, GLint y,
363 GLubyte rgba[][4])
364 {
365 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
366 GrLfbInfo_t info;
367 BEGIN_BOARD_LOCK();
368 if (grLfbLock(GR_LFB_READ_ONLY,
369 fxMesa->currentFB,
370 GR_LFBWRITEMODE_ANY, GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) {
371 const GLint winX = 0;
372 const GLint winY = fxMesa->height - 1;
373 const GLint srcStride = info.strideInBytes / 2; /* stride in GLushorts */
374 const GLushort *data16 = (const GLushort *) info.lfbPtr
375 + (winY - y) * srcStride + (winX + x);
376 const GLuint *data32 = (const GLuint *) data16;
377 GLuint i, j;
378 GLuint extraPixel = (n & 1);
379 n -= extraPixel;
380 for (i = j = 0; i < n; i += 2, j++) {
381 GLuint pixel = data32[j];
382 rgba[i][RCOMP] = FX_rgb_scale_5[ pixel & 0x1f];
383 rgba[i][GCOMP] = FX_rgb_scale_5[(pixel >> 5) & 0x1f];
384 rgba[i][BCOMP] = FX_rgb_scale_5[(pixel >> 10) & 0x1f];
385 rgba[i][ACOMP] = (pixel & 0x8000) ? 255 : 0;
386 rgba[i + 1][RCOMP] = FX_rgb_scale_5[(pixel >> 16) & 0x1f];
387 rgba[i + 1][GCOMP] = FX_rgb_scale_5[(pixel >> 21) & 0x1f];
388 rgba[i + 1][BCOMP] = FX_rgb_scale_5[(pixel >> 26) & 0x1f];
389 rgba[i + 1][ACOMP] = (pixel & 0x80000000) ? 255 : 0;
390 }
391 if (extraPixel) {
392 GLushort pixel = data16[n];
393 rgba[n][RCOMP] = FX_rgb_scale_5[ pixel & 0x1f];
394 rgba[n][GCOMP] = FX_rgb_scale_5[(pixel >> 5) & 0x1f];
395 rgba[n][BCOMP] = FX_rgb_scale_5[(pixel >> 10) & 0x1f];
396 rgba[n][ACOMP] = (pixel & 0x8000) ? 255 : 0;
397 }
398
399 grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB);
400 }
401 END_BOARD_LOCK();
402 }
403
404 /*
405 * Read a span of 32-bit RGB pixels. Note, we don't worry about cliprects
406 * since OpenGL says obscured pixels have undefined values.
407 */
408 static void read_R8G8B8_span (const GLcontext * ctx,
409 GLuint n,
410 GLint x, GLint y,
411 GLubyte rgba[][4])
412 {
413 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
414 BEGIN_BOARD_LOCK();
415 FX_grLfbReadRegion(fxMesa->currentFB, x, fxMesa->height - 1 - y, n, 1, n * 4, rgba);
416 END_BOARD_LOCK();
417 }
418
419
420 /************************************************************************/
421 /***** Pixel functions *****/
422 /************************************************************************/
423
424 static void
425 fxDDWriteRGBAPixels(const GLcontext * ctx,
426 GLuint n, const GLint x[], const GLint y[],
427 CONST GLubyte rgba[][4], const GLubyte mask[])
428 {
429 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
430 GLuint i;
431 GLint bottom = fxMesa->height - 1;
432
433 if (MESA_VERBOSE & VERBOSE_DRIVER) {
434 fprintf(stderr, "fxmesa: fxDDWriteRGBAPixels(...)\n");
435 }
436
437 for (i = 0; i < n; i++)
438 if (mask[i])
439 LFB_WRITE_SPAN_MESA(fxMesa->currentFB, x[i], bottom - y[i],
440 1, 1, (void *) rgba[i]);
441 }
442
443 static void
444 fxDDWriteMonoRGBAPixels(const GLcontext * ctx,
445 GLuint n, const GLint x[], const GLint y[],
446 const GLchan color[4], const GLubyte mask[])
447 {
448 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
449 GLuint i;
450 GLint bottom = fxMesa->height - 1;
451 GrColor_t gColor = FXCOLOR4(color);
452
453 if (MESA_VERBOSE & VERBOSE_DRIVER) {
454 fprintf(stderr, "fxmesa: fxDDWriteMonoRGBAPixels(...)\n");
455 }
456
457 for (i = 0; i < n; i++)
458 if (mask[i])
459 writeRegionClipped(fxMesa, fxMesa->currentFB, x[i], bottom - y[i],
460 GR_LFB_SRC_FMT_8888, 1, 1, 0, (void *) &gColor);
461 }
462
463
464 static void
465 read_R5G6B5_pixels(const GLcontext * ctx,
466 GLuint n, const GLint x[], const GLint y[],
467 GLubyte rgba[][4], const GLubyte mask[])
468 {
469 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
470 GrLfbInfo_t info;
471 BEGIN_BOARD_LOCK();
472 if (grLfbLock(GR_LFB_READ_ONLY,
473 fxMesa->currentFB,
474 GR_LFBWRITEMODE_ANY, GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) {
475 const GLint srcStride = info.strideInBytes / 2; /* stride in GLushorts */
476 const GLint winX = 0;
477 const GLint winY = fxMesa->height - 1;
478 GLuint i;
479 for (i = 0; i < n; i++) {
480 if (mask[i]) {
481 const GLushort *data16 = (const GLushort *) info.lfbPtr
482 + (winY - y[i]) * srcStride + (winX + x[i]);
483 const GLushort pixel = *data16;
484 rgba[i][RCOMP] = FX_PixelToR[pixel];
485 rgba[i][GCOMP] = FX_PixelToG[pixel];
486 rgba[i][BCOMP] = FX_PixelToB[pixel];
487 rgba[i][ACOMP] = 255;
488 }
489 }
490 grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB);
491 }
492 END_BOARD_LOCK();
493 }
494
495
496 static void read_R5G5B5_pixels (const GLcontext * ctx,
497 GLuint n,
498 const GLint x[], const GLint y[],
499 GLubyte rgba[][4],
500 const GLubyte mask[])
501 {
502 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
503 GrLfbInfo_t info;
504 BEGIN_BOARD_LOCK();
505 if (grLfbLock(GR_LFB_READ_ONLY,
506 fxMesa->currentFB,
507 GR_LFBWRITEMODE_ANY, GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) {
508 const GLint srcStride = info.strideInBytes / 2; /* stride in GLushorts */
509 const GLint winX = 0;
510 const GLint winY = fxMesa->height - 1;
511 GLuint i;
512 for (i = 0; i < n; i++) {
513 if (mask[i]) {
514 const GLushort *data16 = (const GLushort *) info.lfbPtr
515 + (winY - y[i]) * srcStride + (winX + x[i]);
516 const GLushort pixel = *data16;
517 rgba[i][RCOMP] = FX_rgb_scale_5[ pixel & 0x1f];
518 rgba[i][GCOMP] = FX_rgb_scale_5[(pixel >> 5) & 0x1f];
519 rgba[i][BCOMP] = FX_rgb_scale_5[(pixel >> 10) & 0x1f];
520 rgba[i][ACOMP] = (pixel & 0x8000) ? 255 : 0;
521 }
522 }
523 grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB);
524 }
525 END_BOARD_LOCK();
526 }
527
528
529 static void
530 read_R8G8B8_pixels(const GLcontext * ctx,
531 GLuint n, const GLint x[], const GLint y[],
532 GLubyte rgba[][4], const GLubyte mask[])
533 {
534 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
535 GrLfbInfo_t info;
536 BEGIN_BOARD_LOCK();
537 if (grLfbLock(GR_LFB_READ_ONLY,
538 fxMesa->currentFB,
539 GR_LFBWRITEMODE_ANY, GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) {
540 const GLint srcStride = info.strideInBytes / 4; /* stride in GLuints */
541 const GLint winX = 0;
542 const GLint winY = fxMesa->height - 1;
543 GLuint i;
544 for (i = 0; i < n; i++) {
545 if (mask[i]) {
546 const GLuint *data32 = (const GLuint *) info.lfbPtr
547 + (winY - y[i]) * srcStride + (winX + x[i]);
548 const GLuint pixel = *data32;
549 *(GLuint *)&rgba[i][0] = pixel;
550 }
551 }
552 grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB);
553 }
554 END_BOARD_LOCK();
555 }
556
557
558
559 /************************************************************************/
560 /***** Depth functions *****/
561 /************************************************************************/
562
563 void
564 fxDDWriteDepthSpan(GLcontext * ctx,
565 GLuint n, GLint x, GLint y, const GLdepth depth[],
566 const GLubyte mask[])
567 {
568 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
569 GLint bottom = fxMesa->height - 1;
570
571 if (MESA_VERBOSE & VERBOSE_DRIVER) {
572 fprintf(stderr, "fxmesa: fxDDWriteDepthSpan(...)\n");
573 }
574
575
576 if (mask) {
577 GLint i;
578 for (i = 0; i < n; i++) {
579 if (mask[i]) {
580 GLshort d = depth[i];
581 writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, x + i, bottom - y,
582 GR_LFB_SRC_FMT_ZA16, 1, 1, 0, (void *) &d);
583 }
584 }
585 }
586 else {
587 GLushort depth16[MAX_WIDTH];
588 GLint i;
589 for (i = 0; i < n; i++) {
590 depth16[i] = depth[i];
591 }
592 writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, x, bottom - y,
593 GR_LFB_SRC_FMT_ZA16, n, 1, 0, (void *) depth16);
594 }
595 }
596
597
598 void
599 fxDDWriteDepth32Span(GLcontext * ctx,
600 GLuint n, GLint x, GLint y, const GLdepth depth[],
601 const GLubyte mask[])
602 {
603 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
604 GLint bottom = fxMesa->height - 1;
605
606 if (MESA_VERBOSE & VERBOSE_DRIVER) {
607 fprintf(stderr, "fxmesa: fxDDWriteDepth32Span(...)\n");
608 }
609
610
611 if (mask) {
612 GLint i;
613 for (i = 0; i < n; i++) {
614 if (mask[i]) {
615 writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, x + i, bottom - y,
616 GR_LFBWRITEMODE_Z32, 1, 1, 0, (void *) &depth[i]);
617 }
618 }
619 }
620 else {
621 writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, x, bottom - y,
622 GR_LFBWRITEMODE_Z32, n, 1, 0, (void *) depth);
623 }
624 }
625
626
627 void
628 fxDDReadDepthSpan(GLcontext * ctx,
629 GLuint n, GLint x, GLint y, GLdepth depth[])
630 {
631 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
632 GLint bottom = fxMesa->height - 1;
633 GLushort depth16[MAX_WIDTH];
634 GLuint i;
635
636 if (MESA_VERBOSE & VERBOSE_DRIVER) {
637 fprintf(stderr, "fxmesa: fxDDReadDepthSpan(...)\n");
638 }
639
640 FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER, x, bottom - y, n, 1, 0, depth16);
641 for (i = 0; i < n; i++) {
642 depth[i] = depth16[i];
643 }
644 }
645
646
647 void
648 fxDDReadDepth32Span(GLcontext * ctx,
649 GLuint n, GLint x, GLint y, GLdepth depth[])
650 {
651 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
652 GLint bottom = fxMesa->height - 1;
653
654 if (MESA_VERBOSE & VERBOSE_DRIVER) {
655 fprintf(stderr, "fxmesa: fxDDReadDepth32Span(...)\n");
656 }
657
658 FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER, x, bottom - y, n, 1, 0, depth);
659 }
660
661
662
663 void
664 fxDDWriteDepthPixels(GLcontext * ctx,
665 GLuint n, const GLint x[], const GLint y[],
666 const GLdepth depth[], const GLubyte mask[])
667 {
668 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
669 GLint bottom = fxMesa->height - 1;
670 GLuint i;
671
672 if (MESA_VERBOSE & VERBOSE_DRIVER) {
673 fprintf(stderr, "fxmesa: fxDDWriteDepthPixels(...)\n");
674 }
675
676 for (i = 0; i < n; i++) {
677 if (mask[i]) {
678 int xpos = x[i];
679 int ypos = bottom - y[i];
680 GLushort d = depth[i];
681 writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, xpos, ypos,
682 GR_LFB_SRC_FMT_ZA16, 1, 1, 0, (void *) &d);
683 }
684 }
685 }
686
687
688 void
689 fxDDWriteDepth32Pixels(GLcontext * ctx,
690 GLuint n, const GLint x[], const GLint y[],
691 const GLdepth depth[], const GLubyte mask[])
692 {
693 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
694 GLint bottom = fxMesa->height - 1;
695 GLuint i;
696
697 if (MESA_VERBOSE & VERBOSE_DRIVER) {
698 fprintf(stderr, "fxmesa: fxDDWriteDepth32Pixels(...)\n");
699 }
700
701 for (i = 0; i < n; i++) {
702 if (mask[i]) {
703 int xpos = x[i];
704 int ypos = bottom - y[i];
705 writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, xpos, ypos,
706 GR_LFBWRITEMODE_Z32, 1, 1, 0, (void *) &depth[i]);
707 }
708 }
709 }
710
711
712 void
713 fxDDReadDepthPixels(GLcontext * ctx, GLuint n,
714 const GLint x[], const GLint y[], GLdepth depth[])
715 {
716 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
717 GLint bottom = fxMesa->height - 1;
718 GLuint i;
719
720 if (MESA_VERBOSE & VERBOSE_DRIVER) {
721 fprintf(stderr, "fxmesa: fxDDReadDepthPixels(...)\n");
722 }
723
724 for (i = 0; i < n; i++) {
725 int xpos = x[i];
726 int ypos = bottom - y[i];
727 GLushort d;
728 FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER, xpos, ypos, 1, 1, 0, &d);
729 depth[i] = d;
730 }
731 }
732
733
734 void
735 fxDDReadDepth32Pixels(GLcontext * ctx, GLuint n,
736 const GLint x[], const GLint y[], GLdepth depth[])
737 {
738 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
739 GLint bottom = fxMesa->height - 1;
740 GLuint i;
741
742 if (MESA_VERBOSE & VERBOSE_DRIVER) {
743 fprintf(stderr, "fxmesa: fxDDReadDepth32Pixels(...)\n");
744 }
745
746 for (i = 0; i < n; i++) {
747 int xpos = x[i];
748 int ypos = bottom - y[i];
749 FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER, xpos, ypos, 1, 1, 0, &depth[i]);
750 }
751 }
752
753
754
755 /* Set the buffer used for reading */
756 /* XXX support for separate read/draw buffers hasn't been tested */
757 static void
758 fxDDSetBuffer(GLcontext * ctx, GLframebuffer * buffer, GLuint bufferBit)
759 {
760 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
761 (void) buffer;
762
763 if (MESA_VERBOSE & VERBOSE_DRIVER) {
764 fprintf(stderr, "fxmesa: fxDDSetBuffer(%x)\n", (int) bufferBit);
765 }
766
767 if (bufferBit == FRONT_LEFT_BIT) {
768 fxMesa->currentFB = GR_BUFFER_FRONTBUFFER;
769 FX_grRenderBuffer(fxMesa->currentFB);
770 }
771 else if (bufferBit == BACK_LEFT_BIT) {
772 fxMesa->currentFB = GR_BUFFER_BACKBUFFER;
773 FX_grRenderBuffer(fxMesa->currentFB);
774 }
775 }
776
777
778 /************************************************************************/
779
780
781
782 void
783 fxSetupDDSpanPointers(GLcontext * ctx)
784 {
785 struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference( ctx );
786
787 swdd->SetBuffer = fxDDSetBuffer;
788
789 swdd->WriteRGBASpan = fxDDWriteRGBASpan;
790 swdd->WriteRGBSpan = fxDDWriteRGBSpan;
791 swdd->WriteMonoRGBASpan = fxDDWriteMonoRGBASpan;
792 swdd->WriteRGBAPixels = fxDDWriteRGBAPixels;
793 swdd->WriteMonoRGBAPixels = fxDDWriteMonoRGBAPixels;
794
795 /* swdd->ReadRGBASpan =fxDDReadRGBASpan; */
796 {
797 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
798 switch (fxMesa->colDepth) {
799 case 15:
800 swdd->ReadRGBASpan = read_R5G5B5_span;
801 swdd->ReadRGBAPixels = read_R5G5B5_pixels;
802 swdd->WriteDepthSpan = fxDDWriteDepthSpan;
803 swdd->WriteDepthPixels = fxDDWriteDepthPixels;
804 swdd->ReadDepthSpan = fxDDReadDepthSpan;
805 swdd->ReadDepthPixels = fxDDReadDepthPixels;
806 break;
807 case 16:
808 swdd->ReadRGBASpan = read_R5G6B5_span;
809 swdd->ReadRGBAPixels = read_R5G6B5_pixels;
810 swdd->WriteDepthSpan = fxDDWriteDepthSpan;
811 swdd->WriteDepthPixels = fxDDWriteDepthPixels;
812 swdd->ReadDepthSpan = fxDDReadDepthSpan;
813 swdd->ReadDepthPixels = fxDDReadDepthPixels;
814 break;
815 case 32:
816 swdd->ReadRGBASpan = read_R8G8B8_span;
817 swdd->ReadRGBAPixels = read_R8G8B8_pixels;
818 swdd->WriteDepthSpan = fxDDWriteDepth32Span;
819 swdd->WriteDepthPixels = fxDDWriteDepth32Pixels;
820 swdd->ReadDepthSpan = fxDDReadDepth32Span;
821 swdd->ReadDepthPixels = fxDDReadDepth32Pixels;
822 break;
823 }
824 }
825 }
826
827
828 #else
829
830
831 /*
832 * Need this to provide at least one external definition.
833 */
834
835 extern int gl_fx_dummy_function_span(void);
836 int
837 gl_fx_dummy_function_span(void)
838 {
839 return 0;
840 }
841
842 #endif /* FX */