2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
34 /* fxdd.c - 3Dfx VooDoo Mesa device driver functions */
47 #include "extensions.h"
51 #include "swrast/swrast.h"
52 #include "swrast/s_context.h"
53 #include "swrast_setup/swrast_setup.h"
55 #include "tnl/t_context.h"
56 #include "tnl/t_pipeline.h"
57 #include "array_cache/acache.h"
61 /* lookup table for scaling 4 bit colors up to 8 bits */
62 GLuint FX_rgb_scale_4
[16] = {
63 0, 17, 34, 51, 68, 85, 102, 119,
64 136, 153, 170, 187, 204, 221, 238, 255
67 /* lookup table for scaling 5 bit colors up to 8 bits */
68 GLuint FX_rgb_scale_5
[32] = {
69 0, 8, 16, 25, 33, 41, 49, 58,
70 66, 74, 82, 90, 99, 107, 115, 123,
71 132, 140, 148, 156, 165, 173, 181, 189,
72 197, 206, 214, 222, 230, 239, 247, 255
75 /* lookup table for scaling 6 bit colors up to 8 bits */
76 GLuint FX_rgb_scale_6
[64] = {
77 0, 4, 8, 12, 16, 20, 24, 28,
78 32, 36, 40, 45, 49, 53, 57, 61,
79 65, 69, 73, 77, 81, 85, 89, 93,
80 97, 101, 105, 109, 113, 117, 121, 125,
81 130, 134, 138, 142, 146, 150, 154, 158,
82 162, 166, 170, 174, 178, 182, 186, 190,
83 194, 198, 202, 206, 210, 215, 219, 223,
84 227, 231, 235, 239, 243, 247, 251, 255
89 * Disable color by masking out R, G, B, A
91 static void fxDisableColor (fxMesaContext fxMesa
)
93 if (fxMesa
->colDepth
== 32) {
95 fxMesa
->Glide
.grColorMaskExt(FXFALSE
, FXFALSE
, FXFALSE
, FXFALSE
);
98 grColorMask(FXFALSE
, FXFALSE
);
103 /**********************************************************************/
104 /***** Miscellaneous functions *****/
105 /**********************************************************************/
107 /* Return buffer size information */
109 fxDDBufferSize(GLframebuffer
*buffer
, GLuint
*width
, GLuint
*height
)
111 GET_CURRENT_CONTEXT(ctx
);
112 if (ctx
&& FX_CONTEXT(ctx
)) {
113 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
115 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
116 fprintf(stderr
, "fxDDBufferSize(...)\n");
119 *width
= fxMesa
->width
;
120 *height
= fxMesa
->height
;
125 /* Implements glClearColor() */
127 fxDDClearColor(GLcontext
* ctx
, const GLfloat color
[4])
129 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
132 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
133 fprintf(stderr
, "fxDDClearColor(%f, %f, %f, %f)\n",
134 color
[0], color
[1], color
[2], color
[3]);
137 CLAMPED_FLOAT_TO_UBYTE(col
[0], color
[0]);
138 CLAMPED_FLOAT_TO_UBYTE(col
[1], color
[1]);
139 CLAMPED_FLOAT_TO_UBYTE(col
[2], color
[2]);
140 CLAMPED_FLOAT_TO_UBYTE(col
[3], color
[3]);
142 fxMesa
->clearC
= FXCOLOR4(col
);
143 fxMesa
->clearA
= col
[3];
147 /* Clear the color and/or depth buffers */
148 static void fxDDClear( GLcontext
*ctx
,
149 GLbitfield mask
, GLboolean all
,
150 GLint x
, GLint y
, GLint width
, GLint height
)
152 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
153 GLbitfield softwareMask
= mask
& (DD_ACCUM_BIT
);
154 const GLuint stencil_size
= fxMesa
->haveHwStencil
? ctx
->Visual
.stencilBits
: 0;
155 const FxU32 clearD
= (FxU32
) (ctx
->DepthMaxF
* ctx
->Depth
.Clear
);
156 const FxU8 clearS
= (FxU8
) (ctx
->Stencil
.Clear
& 0xff);
158 if ( TDFX_DEBUG
& MESA_VERBOSE
) {
159 fprintf( stderr
, "fxDDClear( %d, %d, %d, %d )\n",
160 (int) x
, (int) y
, (int) width
, (int) height
);
163 /* Need this check to respond to glScissor and clipping updates */
164 /* should also take care of FX_NEW_COLOR_MASK, FX_NEW_STENCIL, depth? */
165 if (fxMesa
->new_state
& FX_NEW_SCISSOR
) {
167 fxMesa
->new_state
&= ~FX_NEW_SCISSOR
;
170 /* we can't clear accum buffers */
171 mask
&= ~(DD_ACCUM_BIT
);
174 * As per GL spec, stencil masking should be obeyed when clearing
176 if (mask
& DD_STENCIL_BIT
) {
177 if (!fxMesa
->haveHwStencil
|| fxMesa
->unitsState
.stencilWriteMask
!= 0xff) {
178 /* Napalm seems to have trouble with stencil write masks != 0xff */
179 /* do stencil clear in software */
180 softwareMask
|= DD_STENCIL_BIT
;
181 mask
&= ~(DD_STENCIL_BIT
);
186 * As per GL spec, color masking should be obeyed when clearing
188 if (ctx
->Visual
.greenBits
!= 8) {
189 /* can only do color masking if running in 24/32bpp on Napalm */
190 if (ctx
->Color
.ColorMask
[RCOMP
] != ctx
->Color
.ColorMask
[GCOMP
] ||
191 ctx
->Color
.ColorMask
[GCOMP
] != ctx
->Color
.ColorMask
[BCOMP
]) {
192 softwareMask
|= (mask
& (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
));
193 mask
&= ~(DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
);
197 if (fxMesa
->haveHwStencil
) {
199 * If we want to clear stencil, it must be enabled
200 * in the HW, even if the stencil test is not enabled
204 if (mask
& DD_STENCIL_BIT
) {
205 fxMesa
->Glide
.grStencilMaskExt(0xff /*fxMesa->unitsState.stencilWriteMask*/);
206 /* set stencil ref value = desired clear value */
207 fxMesa
->Glide
.grStencilFuncExt(GR_CMP_ALWAYS
, clearS
, 0xff);
208 fxMesa
->Glide
.grStencilOpExt(GR_STENCILOP_REPLACE
,
209 GR_STENCILOP_REPLACE
, GR_STENCILOP_REPLACE
);
210 grEnable(GR_STENCIL_MODE_EXT
);
213 grDisable(GR_STENCIL_MODE_EXT
);
219 * This may be ugly, but it's needed in order to work around a number
225 * This could probably be done fancier but doing each possible case
226 * explicitly is less error prone.
228 switch (mask
& ~DD_STENCIL_BIT
) {
229 case DD_BACK_LEFT_BIT
| DD_DEPTH_BIT
:
230 /* back buffer & depth */
231 /* FX_grColorMaskv_NoLock(ctx, true4); */ /* work around Voodoo3 bug */
233 grRenderBuffer(GR_BUFFER_BACKBUFFER
);
234 if (stencil_size
> 0) {
235 fxMesa
->Glide
.grBufferClearExt(fxMesa
->clearC
,
240 grBufferClear(fxMesa
->clearC
,
243 if (!fxMesa
->unitsState
.depthTestEnabled
) {
244 grDepthMask(FXFALSE
);
247 case DD_FRONT_LEFT_BIT
| DD_DEPTH_BIT
:
248 /* XXX it appears that the depth buffer isn't cleared when
249 * glRenderBuffer(GR_BUFFER_FRONTBUFFER) is set.
250 * This is a work-around/
254 grRenderBuffer(GR_BUFFER_BACKBUFFER
);
255 fxDisableColor(fxMesa
);
256 if (stencil_size
> 0)
257 fxMesa
->Glide
.grBufferClearExt(fxMesa
->clearC
,
261 grBufferClear(fxMesa
->clearC
,
265 fxSetupColorMask(ctx
);
266 grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
267 if (stencil_size
> 0)
268 fxMesa
->Glide
.grBufferClearExt(fxMesa
->clearC
,
272 grBufferClear(fxMesa
->clearC
,
275 if (!fxMesa
->unitsState
.depthTestEnabled
) {
276 grDepthMask(FXFALSE
);
279 case DD_BACK_LEFT_BIT
:
280 /* back buffer only */
281 grDepthMask(FXFALSE
);
282 grRenderBuffer(GR_BUFFER_BACKBUFFER
);
283 if (stencil_size
> 0)
284 fxMesa
->Glide
.grBufferClearExt(fxMesa
->clearC
,
288 grBufferClear(fxMesa
->clearC
,
291 if (fxMesa
->unitsState
.depthTestEnabled
) {
295 case DD_FRONT_LEFT_BIT
:
296 /* front buffer only */
297 grDepthMask(FXFALSE
);
298 grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
299 if (stencil_size
> 0)
300 fxMesa
->Glide
.grBufferClearExt(fxMesa
->clearC
,
304 grBufferClear(fxMesa
->clearC
,
307 if (fxMesa
->unitsState
.depthTestEnabled
) {
311 case DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
:
313 grDepthMask(FXFALSE
);
314 grRenderBuffer(GR_BUFFER_BACKBUFFER
);
315 if (stencil_size
> 0)
316 fxMesa
->Glide
.grBufferClearExt(fxMesa
->clearC
,
320 grBufferClear(fxMesa
->clearC
,
323 grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
324 if (stencil_size
> 0)
325 fxMesa
->Glide
.grBufferClearExt(fxMesa
->clearC
,
329 grBufferClear(fxMesa
->clearC
,
332 if (fxMesa
->unitsState
.depthTestEnabled
) {
336 case DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
| DD_DEPTH_BIT
:
338 grDepthMask(FXFALSE
);
339 grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
340 if (stencil_size
> 0)
341 fxMesa
->Glide
.grBufferClearExt(fxMesa
->clearC
,
345 grBufferClear(fxMesa
->clearC
,
348 /* clear back and depth */
350 grRenderBuffer(GR_BUFFER_BACKBUFFER
);
351 if (stencil_size
> 0)
352 fxMesa
->Glide
.grBufferClearExt(fxMesa
->clearC
,
356 grBufferClear(fxMesa
->clearC
,
359 if (!fxMesa
->unitsState
.depthTestEnabled
) {
360 grDepthMask(FXFALSE
);
364 /* just the depth buffer */
365 grRenderBuffer(GR_BUFFER_BACKBUFFER
);
366 fxDisableColor(fxMesa
);
368 if (stencil_size
> 0)
369 fxMesa
->Glide
.grBufferClearExt(fxMesa
->clearC
,
373 grBufferClear(fxMesa
->clearC
,
376 fxSetupColorMask(ctx
);
377 if (ctx
->Color
._DrawDestMask
& DD_FRONT_LEFT_BIT
) {
378 grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
380 if (!fxMesa
->unitsState
.depthTestEnabled
) {
381 grDepthMask(FXFALSE
);
385 /* clear no color buffers or depth buffer but might clear stencil */
386 if (stencil_size
> 0 && (mask
& DD_STENCIL_BIT
)) {
387 /* XXX need this RenderBuffer call to work around Glide bug */
388 grRenderBuffer(GR_BUFFER_BACKBUFFER
);
389 grDepthMask(FXFALSE
);
390 fxDisableColor(fxMesa
);
391 fxMesa
->Glide
.grBufferClearExt(fxMesa
->clearC
,
394 if (fxMesa
->unitsState
.depthTestEnabled
) {
397 fxSetupColorMask(ctx
);
398 if (ctx
->Color
._DrawDestMask
& DD_FRONT_LEFT_BIT
) {
399 grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
406 if (fxMesa
->haveHwStencil
&& (mask
& DD_STENCIL_BIT
)) {
407 /* We changed the stencil state above. Signal that we need to
410 fxMesa
->new_state
|= FX_NEW_STENCIL
;
414 _swrast_Clear( ctx
, softwareMask
, all
, x
, y
, width
, height
);
418 /* Set the buffer used for drawing */
419 /* XXX support for separate read/draw buffers hasn't been tested */
421 fxDDSetDrawBuffer(GLcontext
* ctx
, GLenum mode
)
423 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
425 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
426 fprintf(stderr
, "fxDDSetDrawBuffer(%x)\n", (int)mode
);
429 if (mode
== GL_FRONT_LEFT
) {
430 fxMesa
->currentFB
= GR_BUFFER_FRONTBUFFER
;
431 grRenderBuffer(fxMesa
->currentFB
);
433 else if (mode
== GL_BACK_LEFT
) {
434 fxMesa
->currentFB
= GR_BUFFER_BACKBUFFER
;
435 grRenderBuffer(fxMesa
->currentFB
);
437 else if (mode
== GL_NONE
) {
438 fxDisableColor(fxMesa
);
441 /* we'll need a software fallback */
442 /* XXX not implemented */
445 /* update s/w fallback state */
446 _swrast_DrawBuffer(ctx
, mode
);
451 fxDDDrawBitmap2 (GLcontext
*ctx
, GLint px
, GLint py
,
452 GLsizei width
, GLsizei height
,
453 const struct gl_pixelstore_attrib
*unpack
,
454 const GLubyte
*bitmap
)
456 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
457 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
459 GrLfbWriteMode_t mode
;
461 const struct gl_pixelstore_attrib
*finalUnpack
;
462 struct gl_pixelstore_attrib scissoredUnpack
;
464 /* check if there's any raster operations enabled which we can't handle */
465 if (swrast
->_RasterMask
& (ALPHATEST_BIT
|
466 /*BLEND_BIT |*/ /* blending ok, through pixpipe */
467 DEPTH_BIT
| /* could be done with RGB:DEPTH */
468 FOG_BIT
| /* could be done with RGB:DEPTH */
470 /*CLIP_BIT |*/ /* clipping ok, below */
473 ALPHABUF_BIT
| /* nope! see 565 span kludge */
475 OCCLUSION_BIT
| /* nope! at least not yet */
478 _swrast_Bitmap(ctx
, px
, py
, width
, height
, unpack
, bitmap
);
482 /* make sure the pixelpipe is configured correctly */
485 if (ctx
->Scissor
.Enabled
) {
486 /* This is a bit tricky, but by carefully adjusting the px, py,
487 * width, height, skipPixels and skipRows values we can do
488 * scissoring without special code in the rendering loop.
491 /* we'll construct a new pixelstore struct */
492 finalUnpack
= &scissoredUnpack
;
493 scissoredUnpack
= *unpack
;
494 if (scissoredUnpack
.RowLength
== 0)
495 scissoredUnpack
.RowLength
= width
;
498 if (px
< ctx
->Scissor
.X
) {
499 scissoredUnpack
.SkipPixels
+= (ctx
->Scissor
.X
- px
);
500 width
-= (ctx
->Scissor
.X
- px
);
504 if (px
+ width
>= ctx
->Scissor
.X
+ ctx
->Scissor
.Width
) {
505 width
-= (px
+ width
- (ctx
->Scissor
.X
+ ctx
->Scissor
.Width
));
508 if (py
< ctx
->Scissor
.Y
) {
509 scissoredUnpack
.SkipRows
+= (ctx
->Scissor
.Y
- py
);
510 height
-= (ctx
->Scissor
.Y
- py
);
514 if (py
+ height
>= ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
) {
515 height
-= (py
+ height
- (ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
));
518 if (width
<= 0 || height
<= 0)
522 finalUnpack
= unpack
;
525 /* compute pixel value */
527 GLint r
= (GLint
) (ctx
->Current
.RasterColor
[RCOMP
] * 255.0f
);
528 GLint g
= (GLint
) (ctx
->Current
.RasterColor
[GCOMP
] * 255.0f
);
529 GLint b
= (GLint
) (ctx
->Current
.RasterColor
[BCOMP
] * 255.0f
);
530 GLint a
= (GLint
) (ctx
->Current
.RasterColor
[ACOMP
] * 255.0f
);
531 if (fxMesa
->colDepth
== 15) {
532 color
= TDFXPACKCOLOR1555(b
, g
, r
, a
);
533 mode
= GR_LFBWRITEMODE_1555
;
535 color
= fxMesa
->bgrOrder
? TDFXPACKCOLOR565(r
, g
, b
) : TDFXPACKCOLOR565(b
, g
, r
);
536 mode
= GR_LFBWRITEMODE_565
;
540 info
.size
= sizeof(info
);
541 if (!grLfbLock(GR_LFB_WRITE_ONLY
,
544 GR_ORIGIN_LOWER_LEFT
, FXTRUE
, &info
)) {
545 _swrast_Bitmap(ctx
, px
, py
, width
, height
, unpack
, bitmap
);
550 const GLint winX
= 0;
551 const GLint winY
= 0;
552 /* The dest stride depends on the hardware and whether we're drawing
553 * to the front or back buffer. This compile-time test seems to do
556 const GLint dstStride
= info
.strideInBytes
/ 2; /* stride in GLushorts */
559 /* compute dest address of bottom-left pixel in bitmap */
560 GLushort
*dst
= (GLushort
*) info
.lfbPtr
561 + (winY
+ py
) * dstStride
+ (winX
+ px
);
563 for (row
= 0; row
< height
; row
++) {
565 (const GLubyte
*) _mesa_image_address(finalUnpack
,
566 bitmap
, width
, height
,
567 GL_COLOR_INDEX
, GL_BITMAP
,
569 if (finalUnpack
->LsbFirst
) {
570 /* least significan bit first */
571 GLubyte mask
= 1U << (finalUnpack
->SkipPixels
& 0x7);
573 for (col
= 0; col
< width
; col
++) {
589 /* most significan bit first */
590 GLubyte mask
= 128U >> (finalUnpack
->SkipPixels
& 0x7);
592 for (col
= 0; col
< width
; col
++) {
611 grLfbUnlock(GR_LFB_WRITE_ONLY
, fxMesa
->currentFB
);
615 fxDDDrawBitmap4 (GLcontext
*ctx
, GLint px
, GLint py
,
616 GLsizei width
, GLsizei height
,
617 const struct gl_pixelstore_attrib
*unpack
,
618 const GLubyte
*bitmap
)
620 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
621 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
624 const struct gl_pixelstore_attrib
*finalUnpack
;
625 struct gl_pixelstore_attrib scissoredUnpack
;
627 /* check if there's any raster operations enabled which we can't handle */
628 if ((swrast
->_RasterMask
& (/*ALPHATEST_BIT |*/
629 /*BLEND_BIT |*/ /* blending ok, through pixpipe */
630 DEPTH_BIT
| /* could be done with RGB:DEPTH */
631 FOG_BIT
| /* could be done with RGB:DEPTH */
633 /*CLIP_BIT |*/ /* clipping ok, below */
635 /*MASKING_BIT |*/ /* masking ok, we're in 32bpp */
636 /*ALPHABUF_BIT |*//* alpha ok, we're in 32bpp */
638 OCCLUSION_BIT
| /* nope! at least not yet */
642 _swrast_Bitmap(ctx
, px
, py
, width
, height
, unpack
, bitmap
);
646 /* make sure the pixelpipe is configured correctly */
649 if (ctx
->Scissor
.Enabled
) {
650 /* This is a bit tricky, but by carefully adjusting the px, py,
651 * width, height, skipPixels and skipRows values we can do
652 * scissoring without special code in the rendering loop.
655 /* we'll construct a new pixelstore struct */
656 finalUnpack
= &scissoredUnpack
;
657 scissoredUnpack
= *unpack
;
658 if (scissoredUnpack
.RowLength
== 0)
659 scissoredUnpack
.RowLength
= width
;
662 if (px
< ctx
->Scissor
.X
) {
663 scissoredUnpack
.SkipPixels
+= (ctx
->Scissor
.X
- px
);
664 width
-= (ctx
->Scissor
.X
- px
);
668 if (px
+ width
>= ctx
->Scissor
.X
+ ctx
->Scissor
.Width
) {
669 width
-= (px
+ width
- (ctx
->Scissor
.X
+ ctx
->Scissor
.Width
));
672 if (py
< ctx
->Scissor
.Y
) {
673 scissoredUnpack
.SkipRows
+= (ctx
->Scissor
.Y
- py
);
674 height
-= (ctx
->Scissor
.Y
- py
);
678 if (py
+ height
>= ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
) {
679 height
-= (py
+ height
- (ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
));
682 if (width
<= 0 || height
<= 0)
686 finalUnpack
= unpack
;
689 /* compute pixel value */
691 GLint r
= (GLint
) (ctx
->Current
.RasterColor
[RCOMP
] * 255.0f
);
692 GLint g
= (GLint
) (ctx
->Current
.RasterColor
[GCOMP
] * 255.0f
);
693 GLint b
= (GLint
) (ctx
->Current
.RasterColor
[BCOMP
] * 255.0f
);
694 GLint a
= (GLint
) (ctx
->Current
.RasterColor
[ACOMP
] * 255.0f
);
695 color
= TDFXPACKCOLOR8888(b
, g
, r
, a
);
698 info
.size
= sizeof(info
);
699 if (!grLfbLock(GR_LFB_WRITE_ONLY
,
701 GR_LFBWRITEMODE_8888
,
702 GR_ORIGIN_LOWER_LEFT
, FXTRUE
, &info
)) {
703 _swrast_Bitmap(ctx
, px
, py
, width
, height
, unpack
, bitmap
);
708 const GLint winX
= 0;
709 const GLint winY
= 0;
710 /* The dest stride depends on the hardware and whether we're drawing
711 * to the front or back buffer. This compile-time test seems to do
714 const GLint dstStride
= info
.strideInBytes
/ 4; /* stride in GLuints */
717 /* compute dest address of bottom-left pixel in bitmap */
718 GLuint
*dst
= (GLuint
*) info
.lfbPtr
719 + (winY
+ py
) * dstStride
+ (winX
+ px
);
721 for (row
= 0; row
< height
; row
++) {
723 (const GLubyte
*) _mesa_image_address(finalUnpack
,
724 bitmap
, width
, height
,
725 GL_COLOR_INDEX
, GL_BITMAP
,
727 if (finalUnpack
->LsbFirst
) {
728 /* least significan bit first */
729 GLubyte mask
= 1U << (finalUnpack
->SkipPixels
& 0x7);
731 for (col
= 0; col
< width
; col
++) {
747 /* most significan bit first */
748 GLubyte mask
= 128U >> (finalUnpack
->SkipPixels
& 0x7);
750 for (col
= 0; col
< width
; col
++) {
769 grLfbUnlock(GR_LFB_WRITE_ONLY
, fxMesa
->currentFB
);
774 fxDDReadPixels565 (GLcontext
* ctx
,
776 GLsizei width
, GLsizei height
,
777 GLenum format
, GLenum type
,
778 const struct gl_pixelstore_attrib
*packing
,
781 if (ctx
->_ImageTransferState
/* & (IMAGE_SCALE_BIAS_BIT|IMAGE_MAP_COLOR_BIT)*/) {
782 _swrast_ReadPixels(ctx
, x
, y
, width
, height
, format
, type
,
787 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
791 info
.size
= sizeof(info
);
792 if (grLfbLock(GR_LFB_READ_ONLY
,
795 GR_ORIGIN_UPPER_LEFT
, FXFALSE
, &info
)) {
796 const GLint winX
= 0;
797 const GLint winY
= fxMesa
->height
- 1;
798 const GLint srcStride
= info
.strideInBytes
/ 2; /* stride in GLushorts */
799 const GLushort
*src
= (const GLushort
*) info
.lfbPtr
800 + (winY
- y
) * srcStride
+ (winX
+ x
);
801 GLubyte
*dst
= (GLubyte
*) _mesa_image_address(packing
, dstImage
,
802 width
, height
, format
,
805 _mesa_image_row_stride(packing
, width
, format
, type
);
807 if (format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
) {
808 /* convert 5R6G5B into 8R8G8B */
810 const GLint halfWidth
= width
>> 1;
811 const GLint extraPixel
= (width
& 1);
812 for (row
= 0; row
< height
; row
++) {
814 for (col
= 0; col
< halfWidth
; col
++) {
815 const GLuint pixel
= ((const GLuint
*) src
)[col
];
816 *d
++ = FX_rgb_scale_5
[(pixel
>> 11) & 0x1f];
817 *d
++ = FX_rgb_scale_6
[(pixel
>> 5) & 0x3f];
818 *d
++ = FX_rgb_scale_5
[ pixel
& 0x1f];
819 *d
++ = FX_rgb_scale_5
[(pixel
>> 27) & 0x1f];
820 *d
++ = FX_rgb_scale_6
[(pixel
>> 21) & 0x3f];
821 *d
++ = FX_rgb_scale_5
[(pixel
>> 16) & 0x1f];
824 GLushort pixel
= src
[width
- 1];
825 *d
++ = FX_rgb_scale_5
[(pixel
>> 11) & 0x1f];
826 *d
++ = FX_rgb_scale_6
[(pixel
>> 5) & 0x3f];
827 *d
++ = FX_rgb_scale_5
[ pixel
& 0x1f];
833 else if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
) {
834 /* convert 5R6G5B into 8R8G8B8A */
836 const GLint halfWidth
= width
>> 1;
837 const GLint extraPixel
= (width
& 1);
838 for (row
= 0; row
< height
; row
++) {
840 for (col
= 0; col
< halfWidth
; col
++) {
841 const GLuint pixel
= ((const GLuint
*) src
)[col
];
842 *d
++ = FX_rgb_scale_5
[(pixel
>> 11) & 0x1f];
843 *d
++ = FX_rgb_scale_6
[(pixel
>> 5) & 0x3f];
844 *d
++ = FX_rgb_scale_5
[ pixel
& 0x1f];
846 *d
++ = FX_rgb_scale_5
[(pixel
>> 27) & 0x1f];
847 *d
++ = FX_rgb_scale_6
[(pixel
>> 21) & 0x3f];
848 *d
++ = FX_rgb_scale_5
[(pixel
>> 16) & 0x1f];
852 const GLushort pixel
= src
[width
- 1];
853 *d
++ = FX_rgb_scale_5
[(pixel
>> 11) & 0x1f];
854 *d
++ = FX_rgb_scale_6
[(pixel
>> 5) & 0x3f];
855 *d
++ = FX_rgb_scale_5
[ pixel
& 0x1f];
862 else if (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) {
863 /* directly memcpy 5R6G5B pixels into client's buffer */
864 const GLint widthInBytes
= width
* 2;
866 for (row
= 0; row
< height
; row
++) {
867 MEMCPY(dst
, src
, widthInBytes
);
873 grLfbUnlock(GR_LFB_READ_ONLY
, fxMesa
->currentFB
);
875 _swrast_ReadPixels(ctx
, x
, y
, width
, height
, format
, type
,
880 grLfbUnlock(GR_LFB_READ_ONLY
, fxMesa
->currentFB
);
887 fxDDReadPixels555 (GLcontext
* ctx
,
889 GLsizei width
, GLsizei height
,
890 GLenum format
, GLenum type
,
891 const struct gl_pixelstore_attrib
*packing
,
894 if (ctx
->_ImageTransferState
/* & (IMAGE_SCALE_BIAS_BIT|IMAGE_MAP_COLOR_BIT)*/) {
895 _swrast_ReadPixels(ctx
, x
, y
, width
, height
, format
, type
,
900 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
904 info
.size
= sizeof(info
);
905 if (grLfbLock(GR_LFB_READ_ONLY
,
908 GR_ORIGIN_UPPER_LEFT
, FXFALSE
, &info
)) {
909 const GLint winX
= 0;
910 const GLint winY
= fxMesa
->height
- 1;
911 const GLint srcStride
= info
.strideInBytes
/ 2; /* stride in GLushorts */
912 const GLushort
*src
= (const GLushort
*) info
.lfbPtr
913 + (winY
- y
) * srcStride
+ (winX
+ x
);
914 GLubyte
*dst
= (GLubyte
*) _mesa_image_address(packing
, dstImage
,
915 width
, height
, format
,
918 _mesa_image_row_stride(packing
, width
, format
, type
);
920 if (format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
) {
921 /* convert 5R5G5B into 8R8G8B */
923 const GLint halfWidth
= width
>> 1;
924 const GLint extraPixel
= (width
& 1);
925 for (row
= 0; row
< height
; row
++) {
927 for (col
= 0; col
< halfWidth
; col
++) {
928 const GLuint pixel
= ((const GLuint
*) src
)[col
];
929 *d
++ = FX_rgb_scale_5
[(pixel
>> 10) & 0x1f];
930 *d
++ = FX_rgb_scale_5
[(pixel
>> 5) & 0x1f];
931 *d
++ = FX_rgb_scale_5
[ pixel
& 0x1f];
932 *d
++ = FX_rgb_scale_5
[(pixel
>> 26) & 0x1f];
933 *d
++ = FX_rgb_scale_5
[(pixel
>> 21) & 0x1f];
934 *d
++ = FX_rgb_scale_5
[(pixel
>> 16) & 0x1f];
937 GLushort pixel
= src
[width
- 1];
938 *d
++ = FX_rgb_scale_5
[(pixel
>> 10) & 0x1f];
939 *d
++ = FX_rgb_scale_5
[(pixel
>> 5) & 0x1f];
940 *d
++ = FX_rgb_scale_5
[ pixel
& 0x1f];
946 else if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
) {
947 /* convert 5R6G5B into 8R8G8B8A */
949 const GLint halfWidth
= width
>> 1;
950 const GLint extraPixel
= (width
& 1);
951 for (row
= 0; row
< height
; row
++) {
953 for (col
= 0; col
< halfWidth
; col
++) {
954 const GLuint pixel
= ((const GLuint
*) src
)[col
];
955 *d
++ = FX_rgb_scale_5
[(pixel
>> 10) & 0x1f];
956 *d
++ = FX_rgb_scale_5
[(pixel
>> 5) & 0x1f];
957 *d
++ = FX_rgb_scale_5
[ pixel
& 0x1f];
958 *d
++ = (pixel
& 0x8000) ? 255 : 0;
959 *d
++ = FX_rgb_scale_5
[(pixel
>> 26) & 0x1f];
960 *d
++ = FX_rgb_scale_5
[(pixel
>> 21) & 0x1f];
961 *d
++ = FX_rgb_scale_5
[(pixel
>> 16) & 0x1f];
962 *d
++ = (pixel
& 0x80000000) ? 255 : 0;
965 const GLushort pixel
= src
[width
- 1];
966 *d
++ = FX_rgb_scale_5
[(pixel
>> 10) & 0x1f];
967 *d
++ = FX_rgb_scale_5
[(pixel
>> 5) & 0x1f];
968 *d
++ = FX_rgb_scale_5
[ pixel
& 0x1f];
969 *d
++ = (pixel
& 0x8000) ? 255 : 0;
975 else if (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) {
976 /* directly memcpy 5R5G5B pixels into client's buffer */
977 const GLint widthInBytes
= width
* 2;
979 for (row
= 0; row
< height
; row
++) {
980 MEMCPY(dst
, src
, widthInBytes
);
986 grLfbUnlock(GR_LFB_READ_ONLY
, fxMesa
->currentFB
);
988 _swrast_ReadPixels(ctx
, x
, y
, width
, height
, format
, type
,
993 grLfbUnlock(GR_LFB_READ_ONLY
, fxMesa
->currentFB
);
1000 fxDDReadPixels8888 (GLcontext
* ctx
,
1002 GLsizei width
, GLsizei height
,
1003 GLenum format
, GLenum type
,
1004 const struct gl_pixelstore_attrib
*packing
,
1007 if (ctx
->_ImageTransferState
/* & (IMAGE_SCALE_BIAS_BIT|IMAGE_MAP_COLOR_BIT)*/) {
1008 _swrast_ReadPixels(ctx
, x
, y
, width
, height
, format
, type
,
1013 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1017 info
.size
= sizeof(info
);
1018 if (grLfbLock(GR_LFB_READ_ONLY
,
1020 GR_LFBWRITEMODE_ANY
,
1021 GR_ORIGIN_UPPER_LEFT
, FXFALSE
, &info
)) {
1022 const GLint winX
= 0;
1023 const GLint winY
= fxMesa
->height
- 1;
1024 const GLint srcStride
= info
.strideInBytes
/ 4; /* stride in GLuints */
1025 const GLuint
*src
= (const GLuint
*) info
.lfbPtr
1026 + (winY
- y
) * srcStride
+ (winX
+ x
);
1027 GLubyte
*dst
= (GLubyte
*) _mesa_image_address(packing
, dstImage
,
1028 width
, height
, format
,
1031 _mesa_image_row_stride(packing
, width
, format
, type
);
1033 if (format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
) {
1034 /* convert 8A8R8G8B into 8R8G8B */
1036 for (row
= 0; row
< height
; row
++) {
1038 for (col
= 0; col
< width
; col
++) {
1039 const GLuint pixel
= ((const GLuint
*) src
)[col
];
1048 else if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
) {
1049 /* 8A8R8G8B pixels into client's buffer */
1051 for (row
= 0; row
< height
; row
++) {
1053 for (col
= 0; col
< width
; col
++) {
1054 const GLuint pixel
= ((const GLuint
*) src
)[col
];
1064 else if (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) {
1065 /* convert 8A8R8G8B into 5R6G5B */
1067 for (row
= 0; row
< height
; row
++) {
1068 GLushort
*d
= (GLushort
*)dst
;
1069 for (col
= 0; col
< width
; col
++) {
1070 const GLuint pixel
= ((const GLuint
*) src
)[col
];
1071 *d
++ = (((pixel
>> 16) & 0xf8) << 8) |
1072 (((pixel
>> 8) & 0xfc) << 3) |
1073 ((pixel
& 0xf8) >> 3);
1080 grLfbUnlock(GR_LFB_READ_ONLY
, fxMesa
->currentFB
);
1082 _swrast_ReadPixels(ctx
, x
, y
, width
, height
, format
, type
,
1087 grLfbUnlock(GR_LFB_READ_ONLY
, fxMesa
->currentFB
);
1094 /* [dBorca] Hack alert:
1096 * revise fallback tests and fix scissor; implement new formats
1097 * also write its siblings: 565 and 1555
1100 fxDDDrawPixels8888 (GLcontext
* ctx
, GLint x
, GLint y
,
1101 GLsizei width
, GLsizei height
,
1102 GLenum format
, GLenum type
,
1103 const struct gl_pixelstore_attrib
*unpack
,
1104 const GLvoid
* pixels
)
1106 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1109 if (ctx
->Pixel
.ZoomX
!= 1.0F
||
1110 ctx
->Pixel
.ZoomY
!= 1.0F
||
1111 (ctx
->_ImageTransferState
& (IMAGE_SCALE_BIAS_BIT
|
1112 IMAGE_MAP_COLOR_BIT
)) ||
1113 /*ctx->Color.AlphaEnabled ||*/
1116 ctx
->Scissor
.Enabled
||
1117 ctx
->Stencil
.Enabled
||
1118 /*!ctx->Color.ColorMask[0] ||
1119 !ctx->Color.ColorMask[1] ||
1120 !ctx->Color.ColorMask[2] ||
1121 !ctx->Color.ColorMask[3] ||*/
1122 ctx
->Color
.ColorLogicOpEnabled
||
1123 ctx
->Texture
._EnabledUnits
||
1124 ctx
->Depth
.OcclusionTest
||
1127 _swrast_DrawPixels( ctx
, x
, y
, width
, height
, format
, type
,
1132 /* lock early to make sure cliprects are right */
1135 /* make sure the pixelpipe is configured correctly */
1136 fxSetupFXUnits(ctx
);
1138 /* look for clipmasks, giveup if region obscured */
1140 if (ctx
->Color
.DrawBuffer
== GL_FRONT
) {
1141 if (!inClipRects_Region(fxMesa
, scrX
, scrY
, width
, height
)) {
1142 END_BOARD_LOCK(fxMesa
);
1143 _swrast_DrawPixels(ctx
, x
, y
, width
, height
, format
, type
, unpack
, pixels
);
1149 info
.size
= sizeof(info
);
1150 if (!grLfbLock(GR_LFB_WRITE_ONLY
,
1152 GR_LFBWRITEMODE_8888
,
1153 GR_ORIGIN_LOWER_LEFT
, FXTRUE
, &info
)) {
1154 _swrast_DrawPixels(ctx
, x
, y
, width
, height
, format
, type
, unpack
, pixels
);
1159 const GLint winX
= 0;
1160 const GLint winY
= 0;
1162 const GLint dstStride
= info
.strideInBytes
/ 4; /* stride in GLuints */
1163 GLuint
*dst
= (GLuint
*) info
.lfbPtr
+ (winY
+ y
) * dstStride
+ (winX
+ x
);
1164 const GLubyte
*src
= (GLubyte
*)_mesa_image_address(unpack
, pixels
,
1165 width
, height
, format
,
1167 const GLint srcStride
= _mesa_image_row_stride(unpack
, width
, format
, type
);
1169 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
) {
1170 /* directly memcpy 8A8R8G8B pixels to screen */
1171 const GLint widthInBytes
= width
* 4;
1173 for (row
= 0; row
< height
; row
++) {
1174 MEMCPY(dst
, src
, widthInBytes
);
1180 grLfbUnlock(GR_LFB_WRITE_ONLY
, fxMesa
->currentFB
);
1182 _swrast_DrawPixels(ctx
, x
, y
, width
, height
, format
, type
, unpack
, pixels
);
1188 grLfbUnlock(GR_LFB_WRITE_ONLY
, fxMesa
->currentFB
);
1194 fxDDFinish(GLcontext
* ctx
)
1203 /* KW: Put the word Mesa in the render string because quakeworld
1204 * checks for this rather than doing a glGet(GL_MAX_TEXTURE_SIZE).
1207 static const GLubyte
*
1208 fxDDGetString(GLcontext
* ctx
, GLenum name
)
1210 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1214 return (GLubyte
*)fxMesa
->rendererString
;
1215 #if __WIN32__ /* hack to advertise vanilla extension names */
1217 if (ctx
->Extensions
.String
== NULL
) {
1218 GLubyte
*ext
= _mesa_make_extension_string(ctx
);
1220 ctx
->Extensions
.String
= _mesa_malloc(strlen((char *)ext
) + 256);
1221 if (ctx
->Extensions
.String
!= NULL
) {
1222 strcpy((char *)ctx
->Extensions
.String
, (char *)ext
);
1223 /* put any additional extension names here */
1225 strcat((char *)ctx
->Extensions
.String
, " 3DFX_set_global_palette");
1228 strcat((char *)ctx
->Extensions
.String
, " WGL_3DFX_gamma_control");
1229 strcat((char *)ctx
->Extensions
.String
, " WGL_EXT_swap_control");
1230 strcat((char *)ctx
->Extensions
.String
, " WGL_EXT_extensions_string WGL_ARB_extensions_string");
1232 /* put any additional extension names here */
1235 ctx
->Extensions
.String
= ext
;
1239 return ctx
->Extensions
.String
;
1246 static const struct tnl_pipeline_stage
*fx_pipeline
[] = {
1247 &_tnl_vertex_transform_stage
, /* TODO: Add the fastpath here */
1248 &_tnl_normal_transform_stage
,
1249 &_tnl_lighting_stage
,
1250 &_tnl_fog_coordinate_stage
,
1252 &_tnl_texture_transform_stage
,
1253 &_tnl_point_attenuation_stage
,
1254 #if defined(FEATURE_NV_vertex_program) || defined(FEATURE_ARB_vertex_program)
1255 &_tnl_vertex_program_stage
,
1265 fxDDInitFxMesaContext(fxMesaContext fxMesa
)
1268 GLcontext
*ctx
= fxMesa
->glCtx
;
1270 FX_setupGrVertexLayout();
1272 fxMesa
->color
= 0xffffffff;
1276 fxMesa
->stats
.swapBuffer
= 0;
1277 fxMesa
->stats
.reqTexUpload
= 0;
1278 fxMesa
->stats
.texUpload
= 0;
1279 fxMesa
->stats
.memTexUpload
= 0;
1281 fxMesa
->tmuSrc
= FX_TMU_NONE
;
1282 fxMesa
->lastUnitsMode
= FX_UM_NONE
;
1285 /* FX units setup */
1287 fxMesa
->unitsState
.alphaTestEnabled
= GL_FALSE
;
1288 fxMesa
->unitsState
.alphaTestFunc
= GL_ALWAYS
;
1289 fxMesa
->unitsState
.alphaTestRefValue
= 0.0;
1291 fxMesa
->unitsState
.blendEnabled
= GL_FALSE
;
1292 fxMesa
->unitsState
.blendSrcFuncRGB
= GR_BLEND_ONE
;
1293 fxMesa
->unitsState
.blendDstFuncRGB
= GR_BLEND_ZERO
;
1294 fxMesa
->unitsState
.blendSrcFuncAlpha
= GR_BLEND_ONE
;
1295 fxMesa
->unitsState
.blendDstFuncAlpha
= GR_BLEND_ZERO
;
1296 fxMesa
->unitsState
.blendEqRGB
= GR_BLEND_OP_ADD
;
1297 fxMesa
->unitsState
.blendEqAlpha
= GR_BLEND_OP_ADD
;
1299 fxMesa
->unitsState
.depthTestEnabled
= GL_FALSE
;
1300 fxMesa
->unitsState
.depthMask
= GL_TRUE
;
1301 fxMesa
->unitsState
.depthTestFunc
= GL_LESS
;
1302 fxMesa
->unitsState
.depthBias
= 0;
1304 fxMesa
->unitsState
.stencilWriteMask
= 0xff;
1306 if (fxMesa
->colDepth
== 32) {
1308 fxMesa
->Glide
.grColorMaskExt(FXTRUE
, FXTRUE
, FXTRUE
, fxMesa
->haveHwAlpha
);
1310 /* 15/16 bpp mode */
1311 grColorMask(FXTRUE
, fxMesa
->haveHwAlpha
);
1314 fxMesa
->currentFB
= fxMesa
->haveDoubleBuffer
? GR_BUFFER_BACKBUFFER
: GR_BUFFER_FRONTBUFFER
;
1315 grRenderBuffer(fxMesa
->currentFB
);
1317 fxMesa
->state
= MALLOC(FX_grGetInteger(GR_GLIDE_STATE_SIZE
));
1318 fxMesa
->fogTable
= (GrFog_t
*) MALLOC(FX_grGetInteger(GR_FOG_TABLE_ENTRIES
) *
1321 if (!fxMesa
->state
|| !fxMesa
->fogTable
) {
1323 FREE(fxMesa
->state
);
1324 if (fxMesa
->fogTable
)
1325 FREE(fxMesa
->fogTable
);
1329 /* [dBorca] Hack alert:
1330 * Unlike the rest of the Voodoo family, the Rush
1331 * doesn't support ZBUFFER with WBUFFER-like depth functions!
1332 * I guess we could use WBUFFER, which is better, but we can't
1333 * because the depth span functions would need to translate
1334 * depth values to 4.12 floating point...
1336 if (fxMesa
->haveZBuffer
) {
1337 grDepthBufferMode((fxMesa
->type
== GR_SSTTYPE_SST96
)
1338 ? GR_DEPTHBUFFER_WBUFFER
1339 : GR_DEPTHBUFFER_ZBUFFER
);
1342 if (!fxMesa
->bgrOrder
) {
1343 grLfbWriteColorFormat(GR_COLORFORMAT_ABGR
);
1346 if (fxMesa
->Glide
.grSetNumPendingBuffers
!= NULL
) {
1347 fxMesa
->Glide
.grSetNumPendingBuffers(fxMesa
->maxPendingSwapBuffers
);
1350 fxMesa
->textureAlign
= FX_grGetInteger(GR_TEXTURE_ALIGN
);
1354 int textureLevels
= 0;
1355 int textureSize
= FX_grGetInteger(GR_MAX_TEXTURE_SIZE
);
1358 } while ((textureSize
>>= 0x1) & 0x7ff);
1359 ctx
->Const
.MaxTextureLevels
= textureLevels
;
1360 ctx
->Const
.MaxTextureLodBias
= /*textureLevels - 1*/8; /* Glide bug */
1361 #if FX_RESCALE_BIG_TEXURES_HACK
1362 fxMesa
->textureMaxLod
= textureLevels
- 1;
1363 if ((env
= getenv("MESA_FX_MAXLOD")) != NULL
) {
1364 int maxLevels
= atoi(env
) + 1;
1365 if ((maxLevels
<= MAX_TEXTURE_LEVELS
) && (maxLevels
> textureLevels
)) {
1366 ctx
->Const
.MaxTextureLevels
= maxLevels
;
1371 ctx
->Const
.MaxTextureCoordUnits
=
1372 ctx
->Const
.MaxTextureImageUnits
= fxMesa
->haveTwoTMUs
? 2 : 1;
1373 ctx
->Const
.MaxTextureUnits
= MAX2(ctx
->Const
.MaxTextureImageUnits
, ctx
->Const
.MaxTextureCoordUnits
);
1375 fxMesa
->new_state
= _NEW_ALL
;
1376 if (!fxMesa
->haveHwStencil
) {
1377 /* don't touch stencil if there is none */
1378 fxMesa
->new_state
&= ~FX_NEW_STENCIL
;
1381 /* Initialize the software rasterizer and helper modules.
1383 _swrast_CreateContext(ctx
);
1384 _ac_CreateContext(ctx
);
1385 _tnl_CreateContext(ctx
);
1386 _swsetup_CreateContext(ctx
);
1388 /* Install customized pipeline */
1389 _tnl_destroy_pipeline(ctx
);
1390 _tnl_install_pipeline(ctx
, fx_pipeline
);
1394 fxSetupDDPointers(ctx
);
1395 fxDDInitTriFuncs(ctx
);
1397 /* Tell the software rasterizer to use pixel fog always.
1399 _swrast_allow_vertex_fog(ctx
, GL_FALSE
);
1400 _swrast_allow_pixel_fog(ctx
, GL_TRUE
);
1401 _tnl_allow_vertex_fog( ctx
, GL_FALSE
);
1402 _tnl_allow_pixel_fog( ctx
, GL_TRUE
);
1404 /* Tell tnl not to calculate or use vertex fog factors. (Needed to
1405 * tell render stage not to clip fog coords).
1407 /* _tnl_calculate_vertex_fog( ctx, GL_FALSE ); */
1409 fxDDInitExtensions(ctx
);
1412 /* [dBorca] Hack alert:
1413 * do we want dither? It just looks bad...
1415 grEnable(GR_ALLOW_MIPMAP_DITHER
);
1416 grTexNccTable(GR_NCCTABLE_NCC0
); /* set this once... no multipass */
1418 grGlideGetState((GrState
*) fxMesa
->state
);
1426 fxDDDestroyFxMesaContext(fxMesaContext fxMesa
)
1428 _swsetup_DestroyContext(fxMesa
->glCtx
);
1429 _tnl_DestroyContext(fxMesa
->glCtx
);
1430 _ac_DestroyContext(fxMesa
->glCtx
);
1431 _swrast_DestroyContext(fxMesa
->glCtx
);
1434 FREE(fxMesa
->state
);
1435 if (fxMesa
->fogTable
)
1436 FREE(fxMesa
->fogTable
);
1437 fxFreeVB(fxMesa
->glCtx
);
1444 fxDDInitExtensions(GLcontext
* ctx
)
1446 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1448 #if 1 /* multipass ColorSum stage */
1449 _mesa_enable_extension(ctx
, "GL_EXT_secondary_color");
1452 _mesa_enable_extension(ctx
, "GL_ARB_point_sprite");
1453 _mesa_enable_extension(ctx
, "GL_EXT_point_parameters");
1454 _mesa_enable_extension(ctx
, "GL_EXT_paletted_texture");
1455 _mesa_enable_extension(ctx
, "GL_EXT_texture_lod_bias");
1456 _mesa_enable_extension(ctx
, "GL_EXT_shared_texture_palette");
1457 _mesa_enable_extension(ctx
, "GL_EXT_blend_func_separate");
1458 _mesa_enable_extension(ctx
, "GL_EXT_texture_env_add");
1460 if (fxMesa
->haveTwoTMUs
) {
1461 _mesa_enable_extension(ctx
, "GL_ARB_multitexture");
1464 if (fxMesa
->haveHwStencil
) {
1465 _mesa_enable_extension( ctx
, "GL_EXT_stencil_wrap" );
1468 /* [dBorca] Hack alert:
1469 * True texture compression can be done only on Napalm.
1470 * We will advertise, however, generic texture compression
1471 * on all Voodoo cards; the Mesa logic allows us to eventually
1472 * fallback to uncompressed. This will fix those dumb applications
1473 * which refuse to run w/o texture compression! We actually _can_
1474 * do texture compression for pre-Napalm cores, through NCC. But
1475 * NCC poses many issues:
1476 * 1) NCC w/o DITHER_ERR has poor quality and NCC w/ DITHER_ERR is
1478 * 2) NCC compression cannot be used with multitexturing, because
1479 * the decompression tables are not per TMU anymore (bear in mind
1480 * that earlier Voodoos could handle 2 NCC tables for each TMU --
1481 * just look for POINTCAST_PALETTE). As a last resort, we could
1482 * fake NCC multitexturing through multipass rendering, but...
1483 * ohwell, it's not worth the effort...
1484 * This stand true for multitexturing palletized textures.
1485 * 3) since NCC is not an OpenGL standard (as opposed to FXT1/DXTC), we
1486 * can't use precompressed textures!
1488 if (fxMesa
->type
>= GR_SSTTYPE_Voodoo4
) {
1489 _mesa_enable_extension(ctx
, "GL_ARB_texture_compression");
1490 _mesa_enable_extension(ctx
, "GL_3DFX_texture_compression_FXT1");
1491 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
1492 _mesa_enable_extension(ctx
, "GL_S3_s3tc");
1493 _mesa_enable_extension(ctx
, "GL_NV_blend_square");
1495 if (fxMesa
->HaveTexus2
) {
1496 _mesa_enable_extension(ctx
, "GL_ARB_texture_compression");
1501 /* doesn't like texture compression */
1502 _mesa_enable_extension(ctx
, "GL_SGIS_generate_mipmap");
1505 if (fxMesa
->HaveCmbExt
) {
1506 _mesa_enable_extension(ctx
, "GL_EXT_texture_env_combine");
1509 if (fxMesa
->HavePixExt
) {
1510 _mesa_enable_extension(ctx
, "GL_EXT_blend_subtract");
1511 _mesa_enable_extension(ctx
, "GL_EXT_blend_equation_separate");
1514 if (fxMesa
->HaveMirExt
) {
1515 _mesa_enable_extension(ctx
, "GL_ARB_texture_mirrored_repeat");
1518 if (fxMesa
->type
>= GR_SSTTYPE_Voodoo2
) {
1519 _mesa_enable_extension(ctx
, "GL_EXT_fog_coord");
1522 /* core-level extensions */
1523 _mesa_enable_extension(ctx
, "GL_EXT_multi_draw_arrays");
1524 _mesa_enable_extension(ctx
, "GL_IBM_multimode_draw_arrays");
1525 _mesa_enable_extension(ctx
, "GL_ARB_vertex_buffer_object");
1528 _mesa_enable_extension(ctx
, "GL_ARB_vertex_program");
1529 _mesa_enable_extension(ctx
, "GL_NV_vertex_program");
1530 _mesa_enable_extension(ctx
, "GL_NV_vertex_program1_1");
1531 _mesa_enable_extension(ctx
, "GL_MESA_program_debug");
1536 /************************************************************************/
1537 /************************************************************************/
1538 /************************************************************************/
1540 /* Check if the hardware supports the current context
1542 * Performs similar work to fxDDChooseRenderState() - should be merged.
1545 fx_check_IsInHardware(GLcontext
* ctx
)
1547 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1549 if (ctx
->RenderMode
!= GL_RENDER
) {
1550 return FX_FALLBACK_RENDER_MODE
;
1553 if (ctx
->Stencil
.Enabled
&& !fxMesa
->haveHwStencil
) {
1554 return FX_FALLBACK_STENCIL
;
1557 if (ctx
->Color
._DrawDestMask
!= DD_FRONT_LEFT_BIT
&&
1558 ctx
->Color
._DrawDestMask
!= DD_BACK_LEFT_BIT
) {
1559 return FX_FALLBACK_DRAW_BUFFER
;
1562 if (ctx
->Color
.BlendEnabled
) {
1563 if (ctx
->Color
.BlendEquationRGB
!= GL_FUNC_ADD
) {
1564 if (!fxMesa
->HavePixExt
||
1565 ((ctx
->Color
.BlendEquationRGB
!= GL_FUNC_SUBTRACT
) &&
1566 (ctx
->Color
.BlendEquationRGB
!= GL_FUNC_REVERSE_SUBTRACT
))) {
1567 return FX_FALLBACK_BLEND
;
1571 if (ctx
->Color
.BlendEquationA
!= GL_FUNC_ADD
) {
1572 if (!fxMesa
->HavePixExt
||
1573 ((ctx
->Color
.BlendEquationA
!= GL_FUNC_SUBTRACT
) &&
1574 (ctx
->Color
.BlendEquationA
!= GL_FUNC_REVERSE_SUBTRACT
))) {
1575 return FX_FALLBACK_BLEND
;
1581 * We fail the spec here, unless certain blending modes:
1582 * (c1 + c2) * 1 + d * 1 = c1 * 1 + d * 1 + c2 * 1
1583 * (c1 + c2) * 1 + d * 0 = c1 * 1 + d * 0 + c2 * 1
1585 if (NEED_SECONDARY_COLOR(ctx
)) {
1586 if ((ctx
->Color
.BlendEquationRGB
!= GL_FUNC_ADD
) &&
1587 (ctx
->Color
.BlendSrcRGB
!= GL_ONE
)) {
1588 /* Can't use multipass to blend ColorSum stage */
1589 return FX_FALLBACK_SPECULAR
;
1596 * We could avoid this for certain `sfactor/dfactor'
1597 * I do not think that is even worthwhile to check
1598 * because if someone is using blending they use more
1599 * interesting settings and also it would add more
1600 * state tracking to a lot of the code.
1602 if (ctx
->Color
.ColorLogicOpEnabled
&& (ctx
->Color
.LogicOp
!= GL_COPY
)) {
1603 return FX_FALLBACK_LOGICOP
;
1606 if ((fxMesa
->colDepth
!= 32) &&
1607 ((ctx
->Color
.ColorMask
[RCOMP
] != ctx
->Color
.ColorMask
[GCOMP
]) ||
1608 (ctx
->Color
.ColorMask
[GCOMP
] != ctx
->Color
.ColorMask
[BCOMP
]))) {
1609 return FX_FALLBACK_COLORMASK
;
1612 /* Unsupported texture/multitexture cases */
1614 /* we can only do 1D/2D textures */
1615 if (ctx
->Texture
.Unit
[0]._ReallyEnabled
& ~(TEXTURE_1D_BIT
|TEXTURE_2D_BIT
))
1616 return FX_FALLBACK_TEXTURE_MAP
;
1618 if (fxMesa
->haveTwoTMUs
) {
1619 if (ctx
->Texture
.Unit
[1]._ReallyEnabled
& ~(TEXTURE_1D_BIT
|TEXTURE_2D_BIT
))
1620 return FX_FALLBACK_TEXTURE_MAP
;
1622 if (ctx
->Texture
.Unit
[0]._ReallyEnabled
) {
1623 if (fxMesa
->type
< GR_SSTTYPE_Voodoo2
)
1624 if (ctx
->Texture
.Unit
[0].EnvMode
== GL_BLEND
&&
1625 (ctx
->Texture
.Unit
[1]._ReallyEnabled
||
1626 ctx
->Texture
.Unit
[0].EnvColor
[0] != 0 ||
1627 ctx
->Texture
.Unit
[0].EnvColor
[1] != 0 ||
1628 ctx
->Texture
.Unit
[0].EnvColor
[2] != 0 ||
1629 ctx
->Texture
.Unit
[0].EnvColor
[3] != 1)) {
1630 return FX_FALLBACK_TEXTURE_ENV
;
1632 if (ctx
->Texture
.Unit
[0]._Current
->Image
[0][0]->Border
> 0)
1633 return FX_FALLBACK_TEXTURE_BORDER
;
1636 if (ctx
->Texture
.Unit
[1]._ReallyEnabled
) {
1637 if (fxMesa
->type
< GR_SSTTYPE_Voodoo2
)
1638 if (ctx
->Texture
.Unit
[1].EnvMode
== GL_BLEND
)
1639 return FX_FALLBACK_TEXTURE_ENV
;
1640 if (ctx
->Texture
.Unit
[1]._Current
->Image
[0][0]->Border
> 0)
1641 return FX_FALLBACK_TEXTURE_BORDER
;
1644 if (TDFX_DEBUG
& (VERBOSE_DRIVER
| VERBOSE_TEXTURE
))
1645 fprintf(stderr
, "fx_check_IsInHardware: envmode is %s/%s\n",
1646 _mesa_lookup_enum_by_nr(ctx
->Texture
.Unit
[0].EnvMode
),
1647 _mesa_lookup_enum_by_nr(ctx
->Texture
.Unit
[1].EnvMode
));
1649 /* KW: This was wrong (I think) and I changed it... which doesn't mean
1650 * it is now correct...
1651 * BP: The old condition just seemed to test if both texture units
1652 * were enabled. That's easy!
1654 if (ctx
->Texture
._EnabledUnits
== 0x3) {
1655 /* Can't use multipass to blend a multitextured triangle - fall
1657 * [dBorca] we hit this case only when we try to emulate
1658 * multitexture by multipass!
1660 if (!fxMesa
->haveTwoTMUs
&& ctx
->Color
.BlendEnabled
) {
1661 return FX_FALLBACK_TEXTURE_MULTI
;
1664 if ((ctx
->Texture
.Unit
[0].EnvMode
!= ctx
->Texture
.Unit
[1].EnvMode
) &&
1665 (ctx
->Texture
.Unit
[0].EnvMode
!= GL_MODULATE
) &&
1666 (ctx
->Texture
.Unit
[0].EnvMode
!= GL_REPLACE
)) { /* q2, seems ok... */
1667 if (TDFX_DEBUG
& VERBOSE_DRIVER
)
1668 fprintf(stderr
, "fx_check_IsInHardware: unsupported multitex env mode\n");
1669 return FX_FALLBACK_TEXTURE_MULTI
;
1674 /* we have just one texture unit */
1675 if (ctx
->Texture
._EnabledUnits
> 0x1) {
1676 return FX_FALLBACK_TEXTURE_MULTI
;
1679 if (fxMesa
->type
< GR_SSTTYPE_Voodoo2
)
1680 if (ctx
->Texture
.Unit
[0]._ReallyEnabled
&&
1681 (ctx
->Texture
.Unit
[0].EnvMode
== GL_BLEND
)) {
1682 return FX_FALLBACK_TEXTURE_ENV
;
1692 fxDDUpdateDDPointers(GLcontext
* ctx
, GLuint new_state
)
1694 /* TNLcontext *tnl = TNL_CONTEXT(ctx);*/
1695 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1697 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
1698 fprintf(stderr
, "fxDDUpdateDDPointers(%08x)\n", new_state
);
1701 _swrast_InvalidateState(ctx
, new_state
);
1702 _ac_InvalidateState(ctx
, new_state
);
1703 _tnl_InvalidateState(ctx
, new_state
);
1704 _swsetup_InvalidateState(ctx
, new_state
);
1706 fxMesa
->new_gl_state
|= new_state
;
1713 fxSetupDDPointers(GLcontext
* ctx
)
1715 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1716 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1718 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
1719 fprintf(stderr
, "fxSetupDDPointers()\n");
1722 ctx
->Driver
.UpdateState
= fxDDUpdateDDPointers
;
1723 ctx
->Driver
.GetString
= fxDDGetString
;
1724 ctx
->Driver
.ClearIndex
= NULL
;
1725 ctx
->Driver
.ClearColor
= fxDDClearColor
;
1726 ctx
->Driver
.Clear
= fxDDClear
;
1727 ctx
->Driver
.DrawBuffer
= fxDDSetDrawBuffer
;
1728 ctx
->Driver
.GetBufferSize
= fxDDBufferSize
;
1729 switch (fxMesa
->colDepth
) {
1731 ctx
->Driver
.ReadPixels
= fxDDReadPixels555
;
1732 ctx
->Driver
.Bitmap
= fxDDDrawBitmap2
;
1735 ctx
->Driver
.ReadPixels
= fxDDReadPixels565
;
1736 ctx
->Driver
.Bitmap
= fxDDDrawBitmap2
;
1739 ctx
->Driver
.DrawPixels
= fxDDDrawPixels8888
;
1740 ctx
->Driver
.ReadPixels
= fxDDReadPixels8888
;
1741 ctx
->Driver
.Bitmap
= fxDDDrawBitmap4
;
1744 ctx
->Driver
.Finish
= fxDDFinish
;
1745 ctx
->Driver
.Flush
= NULL
;
1746 ctx
->Driver
.ChooseTextureFormat
= fxDDChooseTextureFormat
;
1747 ctx
->Driver
.TexImage1D
= fxDDTexImage1D
;
1748 ctx
->Driver
.TexImage2D
= fxDDTexImage2D
;
1749 ctx
->Driver
.TexSubImage1D
= fxDDTexSubImage1D
;
1750 ctx
->Driver
.TexSubImage2D
= fxDDTexSubImage2D
;
1751 ctx
->Driver
.CompressedTexImage2D
= fxDDCompressedTexImage2D
;
1752 ctx
->Driver
.CompressedTexSubImage2D
= fxDDCompressedTexSubImage2D
;
1753 ctx
->Driver
.TestProxyTexImage
= fxDDTestProxyTexImage
;
1754 ctx
->Driver
.TexEnv
= fxDDTexEnv
;
1755 ctx
->Driver
.TexParameter
= fxDDTexParam
;
1756 ctx
->Driver
.BindTexture
= fxDDTexBind
;
1757 ctx
->Driver
.DeleteTexture
= fxDDTexDel
;
1758 ctx
->Driver
.IsTextureResident
= fxDDIsTextureResident
;
1759 ctx
->Driver
.UpdateTexturePalette
= fxDDTexPalette
;
1760 ctx
->Driver
.AlphaFunc
= fxDDAlphaFunc
;
1761 ctx
->Driver
.BlendFuncSeparate
= fxDDBlendFuncSeparate
;
1762 ctx
->Driver
.BlendEquationSeparate
= fxDDBlendEquationSeparate
;
1763 ctx
->Driver
.DepthFunc
= fxDDDepthFunc
;
1764 ctx
->Driver
.DepthMask
= fxDDDepthMask
;
1765 ctx
->Driver
.ColorMask
= fxDDColorMask
;
1766 ctx
->Driver
.Fogfv
= fxDDFogfv
;
1767 ctx
->Driver
.Scissor
= fxDDScissor
;
1768 ctx
->Driver
.FrontFace
= fxDDFrontFace
;
1769 ctx
->Driver
.CullFace
= fxDDCullFace
;
1770 ctx
->Driver
.ShadeModel
= fxDDShadeModel
;
1771 ctx
->Driver
.Enable
= fxDDEnable
;
1772 if (fxMesa
->haveHwStencil
) {
1773 ctx
->Driver
.StencilFunc
= fxDDStencilFunc
;
1774 ctx
->Driver
.StencilMask
= fxDDStencilMask
;
1775 ctx
->Driver
.StencilOp
= fxDDStencilOp
;
1778 fxSetupDDSpanPointers(ctx
);
1779 fxDDUpdateDDPointers(ctx
, ~0);
1787 * Need this to provide at least one external definition.
1790 extern int gl_fx_dummy_function_dd(void);
1792 gl_fx_dummy_function_dd(void)