1 /* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
27 * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the
30 * Thank you for your contribution, David!
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.
38 * Additional Mesa/3Dfx driver developers:
39 * Daryll Strauss <daryll@precisioninsight.com>
40 * Keith Whitwell <keith@precisioninsight.com>
42 * See fxapi.h for more revision/author details.
46 /* fxdd.c - 3Dfx VooDoo Mesa span and pixel functions */
59 #pragma warning( disable : 4090 4022 )
60 /* 4101 : "different 'const' qualifier"
61 * 4022 : "pointer mistmatch for actual parameter 'n'
67 #if !defined(FXMESA_USE_ARGB)
70 #if defined(FX_GLIDE3) && defined(XF86DRI)
72 static FxBool
writeRegionClipped(fxMesaContext fxMesa
, GrBuffer_t dst_buffer
,
73 FxU32 dst_x
, FxU32 dst_y
, GrLfbSrcFmt_t src_format
,
74 FxU32 src_width
, FxU32 src_height
, FxI32 src_stride
,
80 if (src_width
==1 && src_height
==1) { /* Easy case writing a point */
81 for (i
=0; i
<fxMesa
->numClipRects
; i
++) {
82 if ((dst_x
>=fxMesa
->pClipRects
[i
].x1
) &&
83 (dst_x
<fxMesa
->pClipRects
[i
].x2
) &&
84 (dst_y
>=fxMesa
->pClipRects
[i
].y1
) &&
85 (dst_y
<fxMesa
->pClipRects
[i
].y2
)) {
86 FX_grLfbWriteRegion(dst_buffer
, dst_x
, dst_y
, src_format
,
87 1, 1, src_stride
, src_data
);
91 } else if (src_height
==1) { /* Writing a span */
92 if (src_format
==GR_LFB_SRC_FMT_8888
) srcElt
=4;
93 else if (src_format
==GR_LFB_SRC_FMT_ZA16
) srcElt
=2;
95 fprintf(stderr
, "Unknown src_format passed to writeRegionClipped\n");
98 for (i
=0; i
<fxMesa
->numClipRects
; i
++) {
99 if (dst_y
>=fxMesa
->pClipRects
[i
].y1
&& dst_y
<fxMesa
->pClipRects
[i
].y2
) {
100 if (dst_x
<fxMesa
->pClipRects
[i
].x1
) {
101 x
=fxMesa
->pClipRects
[i
].x1
;
102 data
=((char*)src_data
)+srcElt
*(dst_x
-x
);
103 w
=src_width
-(x
-dst_x
);
109 if (x
+w
>fxMesa
->pClipRects
[i
].x2
) {
110 w
=fxMesa
->pClipRects
[i
].x2
-x
;
112 FX_grLfbWriteRegion(dst_buffer
, x
, dst_y
, src_format
, w
, 1,
116 } else { /* Punt on the case of arbitrary rectangles */
124 #define writeRegionClipped(fxm,dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data) \
125 FX_grLfbWriteRegion(dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data)
130 /* KW: Rearranged the args in the call to grLfbWriteRegion().
132 #define LFB_WRITE_SPAN_MESA(dst_buffer, \
138 writeRegionClipped(fxMesa, dst_buffer, \
141 GR_LFB_SRC_FMT_8888, \
148 #else /* !defined(FXMESA_USE_RGBA) */
150 #define writeRegionClipped(fxm,dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data) \
151 FX_grLfbWriteRegion(dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data)
154 #define MESACOLOR_TO_ARGB(c) ( \
155 ( ((unsigned int)(c[ACOMP]))<<24 ) | \
156 ( ((unsigned int)(c[RCOMP]))<<16 ) | \
157 ( ((unsigned int)(c[GCOMP]))<<8 ) | \
158 ( (unsigned int)(c[BCOMP])) )
160 inline void LFB_WRITE_SPAN_MESA(GrBuffer_t dst_buffer
,
168 GLubyte (*rgba
)[4] = src_data
;
169 GLuint argb
[MAX_WIDTH
];
172 for (i
= 0; i
< src_width
; i
++)
174 argb
[i
] = MESACOLOR_TO_ARGB(rgba
[i
]);
176 writeRegionClipped( /*fxMesa,*/ NULL
, dst_buffer
,
186 #endif /* !defined(FXMESA_USE_RGBA) */
189 /************************************************************************/
190 /***** Span functions *****/
191 /************************************************************************/
194 static void fxDDWriteRGBASpan(const GLcontext
*ctx
,
195 GLuint n
, GLint x
, GLint y
,
196 const GLubyte rgba
[][4], const GLubyte mask
[])
198 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
200 GLint bottom
=fxMesa
->height
+fxMesa
->y_offset
-1;
202 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
203 fprintf(stderr
,"fxmesa: fxDDWriteRGBASpan(...)\n");
215 LFB_WRITE_SPAN_MESA( fxMesa
->currentFB
, x
+i
-span
, bottom
-y
,
216 /* GR_LFB_SRC_FMT_8888,*/ span
, /*1,*/ 0, (void *) rgba
[i
-span
] );
223 LFB_WRITE_SPAN_MESA( fxMesa
->currentFB
, x
+n
-span
, bottom
-y
,
224 /* GR_LFB_SRC_FMT_8888, */ span
, /*1,*/ 0, (void *) rgba
[n
-span
] );
226 LFB_WRITE_SPAN_MESA( fxMesa
->currentFB
, x
, bottom
-y
,/* GR_LFB_SRC_FMT_8888,*/
227 n
,/* 1,*/ 0, (void *) rgba
);
231 static void fxDDWriteRGBSpan(const GLcontext
*ctx
,
232 GLuint n
, GLint x
, GLint y
,
233 const GLubyte rgb
[][3], const GLubyte mask
[])
235 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
237 GLint bottom
=fxMesa
->height
+fxMesa
->y_offset
-1;
238 GLubyte rgba
[MAX_WIDTH
][4];
240 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
241 fprintf(stderr
,"fxmesa: fxDDWriteRGBSpan()\n");
250 rgba
[span
][RCOMP
] = rgb
[i
][0];
251 rgba
[span
][GCOMP
] = rgb
[i
][1];
252 rgba
[span
][BCOMP
] = rgb
[i
][2];
253 rgba
[span
][ACOMP
] = 255;
257 LFB_WRITE_SPAN_MESA( fxMesa
->currentFB
, x
+i
-span
, bottom
-y
,
258 /*GR_LFB_SRC_FMT_8888,*/ span
,/* 1,*/ 0, (void *) rgba
);
265 LFB_WRITE_SPAN_MESA( fxMesa
->currentFB
, x
+n
-span
, bottom
-y
,
266 /*GR_LFB_SRC_FMT_8888,*/ span
,/* 1,*/ 0, (void *) rgba
);
269 rgba
[i
][RCOMP
]=rgb
[i
][0];
270 rgba
[i
][GCOMP
]=rgb
[i
][1];
271 rgba
[i
][BCOMP
]=rgb
[i
][2];
275 LFB_WRITE_SPAN_MESA( fxMesa
->currentFB
, x
, bottom
-y
,/* GR_LFB_SRC_FMT_8888,*/
276 n
,/* 1,*/ 0, (void *) rgba
);
281 static void fxDDWriteMonoRGBASpan(const GLcontext
*ctx
,
282 GLuint n
, GLint x
, GLint y
,
283 const GLubyte mask
[])
285 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
287 GLint bottom
=fxMesa
->height
+fxMesa
->y_offset
-1;
288 GLuint data
[MAX_WIDTH
];
290 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
291 fprintf(stderr
,"fxmesa: fxDDWriteMonoRGBASpan(...)\n");
300 data
[span
] = (GLuint
) fxMesa
->color
;
304 writeRegionClipped(fxMesa
, fxMesa
->currentFB
, x
+i
-span
, bottom
-y
,
305 GR_LFB_SRC_FMT_8888
, span
, 1, 0,
313 writeRegionClipped(fxMesa
, fxMesa
->currentFB
, x
+n
-span
, bottom
-y
,
314 GR_LFB_SRC_FMT_8888
, span
, 1, 0,
318 data
[i
]=(GLuint
) fxMesa
->color
;
321 writeRegionClipped(fxMesa
, fxMesa
->currentFB
, x
, bottom
-y
, GR_LFB_SRC_FMT_8888
,
322 n
, 1, 0, (void *) data
);
327 static void fxDDReadRGBASpan(const GLcontext
*ctx
,
328 GLuint n
, GLint x
, GLint y
, GLubyte rgba
[][4])
330 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
331 GLushort data
[MAX_WIDTH
];
333 GLint bottom
=fxMesa
->height
+fxMesa
->y_offset
-1;
335 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
336 fprintf(stderr
,"fxmesa: fxDDReadRGBASpan(...)\n");
339 assert(n
< MAX_WIDTH
);
342 FX_grLfbReadRegion( fxMesa
->currentFB
, x
, bottom
-y
, n
, 1, 0, data
);
345 GLushort pixel
= data
[i
];
346 rgba
[i
][RCOMP
] = FX_PixelToR
[pixel
];
347 rgba
[i
][GCOMP
] = FX_PixelToG
[pixel
];
348 rgba
[i
][BCOMP
] = FX_PixelToB
[pixel
];
349 rgba
[i
][ACOMP
] = 255;
353 /************************************************************************/
354 /***** Pixel functions *****/
355 /************************************************************************/
357 static void fxDDWriteRGBAPixels(const GLcontext
*ctx
,
358 GLuint n
, const GLint x
[], const GLint y
[],
359 CONST GLubyte rgba
[][4], const GLubyte mask
[])
361 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
363 GLint bottom
=fxMesa
->height
+fxMesa
->y_offset
-1;
365 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
366 fprintf(stderr
,"fxmesa: fxDDWriteRGBAPixels(...)\n");
371 LFB_WRITE_SPAN_MESA(fxMesa
->currentFB
, x
[i
]+fxMesa
->x_offset
, bottom
-y
[i
],
372 1, 1, (void *)rgba
[i
]);
375 static void fxDDWriteMonoRGBAPixels(const GLcontext
*ctx
,
376 GLuint n
, const GLint x
[], const GLint y
[],
377 const GLubyte mask
[])
379 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
381 GLint bottom
=fxMesa
->height
+fxMesa
->y_offset
-1;
383 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
384 fprintf(stderr
,"fxmesa: fxDDWriteMonoRGBAPixels(...)\n");
389 writeRegionClipped(fxMesa
, fxMesa
->currentFB
,x
[i
]+fxMesa
->x_offset
,bottom
-y
[i
],
390 GR_LFB_SRC_FMT_8888
,1,1,0,(void *) &fxMesa
->color
);
393 static void fxDDReadRGBAPixels(const GLcontext
*ctx
,
394 GLuint n
, const GLint x
[], const GLint y
[],
395 GLubyte rgba
[][4], const GLubyte mask
[])
397 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
399 GLint bottom
=fxMesa
->y_delta
-1;
401 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
402 fprintf(stderr
,"fxmesa: fxDDReadRGBAPixels(...)\n");
408 FX_grLfbReadRegion(fxMesa
->currentFB
,x
[i
],bottom
-y
[i
],1,1,0,&pixel
);
409 rgba
[i
][RCOMP
] = FX_PixelToR
[pixel
];
410 rgba
[i
][GCOMP
] = FX_PixelToG
[pixel
];
411 rgba
[i
][BCOMP
] = FX_PixelToB
[pixel
];
412 rgba
[i
][ACOMP
] = 255;
418 /************************************************************************/
419 /***** Depth functions *****/
420 /************************************************************************/
422 void fxDDWriteDepthSpan(GLcontext
*ctx
,
423 GLuint n
, GLint x
, GLint y
, const GLdepth depth
[],
424 const GLubyte mask
[])
426 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
427 GLint bottom
=fxMesa
->height
+fxMesa
->y_offset
-1;
429 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
430 fprintf(stderr
,"fxmesa: fxDDReadDepthSpanInt(...)\n");
433 x
+= fxMesa
->x_offset
;
437 for (i
= 0; i
< n
; i
++) {
439 writeRegionClipped(fxMesa
, GR_BUFFER_AUXBUFFER
, x
+ i
, bottom
-y
,
440 GR_LFB_SRC_FMT_ZA16
, 1, 1, 0, (void *) &depth
[i
]);
445 writeRegionClipped(fxMesa
, GR_BUFFER_AUXBUFFER
, x
, bottom
-y
,
446 GR_LFB_SRC_FMT_ZA16
, n
, 1, 0, (void *) depth
);
451 void fxDDReadDepthSpan(GLcontext
*ctx
,
452 GLuint n
, GLint x
, GLint y
, GLdepth depth
[])
454 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
455 GLint bottom
=fxMesa
->height
+fxMesa
->y_offset
-1;
457 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
458 fprintf(stderr
,"fxmesa: fxDDReadDepthSpanInt(...)\n");
462 FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER
,x
,bottom
-y
,n
,1,0,depth
);
467 void fxDDWriteDepthPixels(GLcontext
*ctx
,
468 GLuint n
, const GLint x
[], const GLint y
[],
469 const GLdepth depth
[], const GLubyte mask
[])
471 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
472 GLint bottom
=fxMesa
->height
+fxMesa
->y_offset
-1;
475 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
476 fprintf(stderr
,"fxmesa: fxDDReadDepthSpanInt(...)\n");
479 for (i
= 0; i
< n
; i
++) {
481 int xpos
= x
[i
] + fxMesa
->x_offset
;
482 int ypos
= bottom
- y
[i
];
483 writeRegionClipped(fxMesa
, GR_BUFFER_AUXBUFFER
, xpos
, ypos
,
484 GR_LFB_SRC_FMT_ZA16
, 1, 1, 0, (void *) &depth
[i
]);
490 void fxDDReadDepthPixels(GLcontext
*ctx
, GLuint n
,
491 const GLint x
[], const GLint y
[], GLdepth depth
[])
493 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
494 GLint bottom
=fxMesa
->height
+fxMesa
->y_offset
-1;
497 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
498 fprintf(stderr
,"fxmesa: fxDDReadDepthSpanInt(...)\n");
502 for (i
= 0; i
< n
; i
++) {
503 int xpos
= x
[i
] + fxMesa
->x_offset
;
504 int ypos
= bottom
- y
[i
];
505 FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER
,xpos
,ypos
,1,1,0,&depth
[i
]);
512 /************************************************************************/
515 void fxSetupDDSpanPointers(GLcontext
*ctx
)
517 ctx
->Driver
.WriteRGBASpan
=fxDDWriteRGBASpan
;
518 ctx
->Driver
.WriteRGBSpan
=fxDDWriteRGBSpan
;
519 ctx
->Driver
.WriteMonoRGBASpan
=fxDDWriteMonoRGBASpan
;
520 ctx
->Driver
.WriteRGBAPixels
=fxDDWriteRGBAPixels
;
521 ctx
->Driver
.WriteMonoRGBAPixels
=fxDDWriteMonoRGBAPixels
;
523 ctx
->Driver
.WriteCI8Span
=NULL
;
524 ctx
->Driver
.WriteCI32Span
=NULL
;
525 ctx
->Driver
.WriteMonoCISpan
=NULL
;
526 ctx
->Driver
.WriteCI32Pixels
=NULL
;
527 ctx
->Driver
.WriteMonoCIPixels
=NULL
;
529 ctx
->Driver
.ReadRGBASpan
=fxDDReadRGBASpan
;
530 ctx
->Driver
.ReadRGBAPixels
=fxDDReadRGBAPixels
;
532 ctx
->Driver
.ReadCI32Span
=NULL
;
533 ctx
->Driver
.ReadCI32Pixels
=NULL
;
541 * Need this to provide at least one external definition.
544 int gl_fx_dummy_function_span(void)