2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2001 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 /* fxsetup.c - 3Dfx VooDoo rendering mode setup functions */
46 #include "tnl/t_context.h"
52 fxTexValidate(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
54 tfxTexInfo
*ti
= fxTMGetTexInfo(tObj
);
58 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
59 fprintf(stderr
, "fxTexValidate(NOP)\n");
64 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
65 fprintf(stderr
, "fxTexValidate(%p (%d))\n", (void *)tObj
, tObj
->Name
);
69 minl
= ti
->minLevel
= tObj
->BaseLevel
;
70 maxl
= ti
->maxLevel
= MIN2(tObj
->MaxLevel
, tObj
->Image
[0][0]->MaxLog2
);
72 #if FX_RESCALE_BIG_TEXURES_HACK
74 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
76 * Fake textures larger than HW supports:
77 * 1) we have mipmaps. Then we just push up to the first supported
78 * LOD. A possible drawback is that Mesa will ignore the skipped
79 * LODs on further texture handling.
80 * Will this interfere with GL_TEXTURE_[MIN|BASE]_LEVEL? How?
81 * 2) we don't have mipmaps. We need to rescale the big LOD in place.
82 * The above approach is somehow dumb! we might have rescaled
83 * once in TexImage2D to accomodate aspect ratio, and now we
84 * are rescaling again. The thing is, in TexImage2D we don't
85 * know whether we'll hit 1) or 2) by the time of validation.
87 if ((tObj
->MinFilter
== GL_NEAREST
) || (tObj
->MinFilter
== GL_LINEAR
)) {
89 struct gl_texture_image
*texImage
= tObj
->Image
[0][minl
];
90 tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
91 GLint _w
, _h
, maxSize
= 1 << fxMesa
->textureMaxLod
;
92 if ((mml
->width
> maxSize
) || (mml
->height
> maxSize
)) {
94 GLint texelBytes
= texImage
->TexFormat
->TexelBytes
;
95 GLvoid
*texImage_Data
= texImage
->Data
;
96 _w
= MIN2(texImage
->Width
, maxSize
);
97 _h
= MIN2(texImage
->Height
, maxSize
);
98 if (TDFX_DEBUG
& VERBOSE_TEXTURE
) {
99 fprintf(stderr
, "fxTexValidate: rescaling %d x %d -> %d x %d\n",
100 texImage
->Width
, texImage
->Height
, _w
, _h
);
102 /* we should leave these as is and... (!) */
103 texImage
->Width
= _w
;
104 texImage
->Height
= _h
;
105 fxTexGetInfo(_w
, _h
, NULL
, NULL
, NULL
, NULL
,
106 &(mml
->wScale
), &(mml
->hScale
));
109 texImage
->Data
= _mesa_malloc(_w
* _h
* texelBytes
);
110 _mesa_rescale_teximage2d(texelBytes
,
112 _w
* texelBytes
, /* dst stride */
113 mml
->width
, mml
->height
, /* src */
115 texImage_Data
/*src*/, texImage
->Data
/*dst*/ );
116 _mesa_free(texImage_Data
);
119 /* (!) ... and set mml->wScale = _w / texImage->Width */
123 if (maxl
- minl
> fxMesa
->textureMaxLod
) {
124 /* skip a certain number of LODs */
125 minl
+= maxl
- fxMesa
->textureMaxLod
;
126 if (TDFX_DEBUG
& VERBOSE_TEXTURE
) {
127 fprintf(stderr
, "fxTexValidate: skipping %d LODs\n", minl
- ti
->minLevel
);
129 ti
->minLevel
= tObj
->BaseLevel
= minl
;
135 fxTexGetInfo(tObj
->Image
[0][minl
]->Width
, tObj
->Image
[0][minl
]->Height
,
136 &(FX_largeLodLog2(ti
->info
)), &(FX_aspectRatioLog2(ti
->info
)),
137 &(ti
->sScale
), &(ti
->tScale
),
140 if ((tObj
->MinFilter
!= GL_NEAREST
) && (tObj
->MinFilter
!= GL_LINEAR
))
141 fxTexGetInfo(tObj
->Image
[0][maxl
]->Width
, tObj
->Image
[0][maxl
]->Height
,
142 &(FX_smallLodLog2(ti
->info
)), NULL
,
143 NULL
, NULL
, NULL
, NULL
);
145 FX_smallLodLog2(ti
->info
) = FX_largeLodLog2(ti
->info
);
147 /* [dBorca] this is necessary because of fxDDCompressedTexImage2D */
149 struct gl_texture_image
*texImage
= tObj
->Image
[0][minl
];
150 tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
151 if (mml
->wScale
!= 1 || mml
->hScale
!= 1) {
152 ti
->sScale
/= mml
->wScale
;
153 ti
->tScale
/= mml
->hScale
;
157 ti
->baseLevelInternalFormat
= tObj
->Image
[0][minl
]->Format
;
159 ti
->validated
= GL_TRUE
;
161 ti
->info
.data
= NULL
;
165 fxPrintUnitsMode(const char *msg
, GLuint mode
)
168 "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
171 (mode
& FX_UM_E0_REPLACE
) ? "E0_REPLACE, " : "",
172 (mode
& FX_UM_E0_MODULATE
) ? "E0_MODULATE, " : "",
173 (mode
& FX_UM_E0_DECAL
) ? "E0_DECAL, " : "",
174 (mode
& FX_UM_E0_BLEND
) ? "E0_BLEND, " : "",
175 (mode
& FX_UM_E1_REPLACE
) ? "E1_REPLACE, " : "",
176 (mode
& FX_UM_E1_MODULATE
) ? "E1_MODULATE, " : "",
177 (mode
& FX_UM_E1_DECAL
) ? "E1_DECAL, " : "",
178 (mode
& FX_UM_E1_BLEND
) ? "E1_BLEND, " : "",
179 (mode
& FX_UM_E0_ALPHA
) ? "E0_ALPHA, " : "",
180 (mode
& FX_UM_E0_LUMINANCE
) ? "E0_LUMINANCE, " : "",
181 (mode
& FX_UM_E0_LUMINANCE_ALPHA
) ? "E0_LUMINANCE_ALPHA, " : "",
182 (mode
& FX_UM_E0_INTENSITY
) ? "E0_INTENSITY, " : "",
183 (mode
& FX_UM_E0_RGB
) ? "E0_RGB, " : "",
184 (mode
& FX_UM_E0_RGBA
) ? "E0_RGBA, " : "",
185 (mode
& FX_UM_E1_ALPHA
) ? "E1_ALPHA, " : "",
186 (mode
& FX_UM_E1_LUMINANCE
) ? "E1_LUMINANCE, " : "",
187 (mode
& FX_UM_E1_LUMINANCE_ALPHA
) ? "E1_LUMINANCE_ALPHA, " : "",
188 (mode
& FX_UM_E1_INTENSITY
) ? "E1_INTENSITY, " : "",
189 (mode
& FX_UM_E1_RGB
) ? "E1_RGB, " : "",
190 (mode
& FX_UM_E1_RGBA
) ? "E1_RGBA, " : "",
191 (mode
& FX_UM_COLOR_ITERATED
) ? "COLOR_ITERATED, " : "",
192 (mode
& FX_UM_COLOR_CONSTANT
) ? "COLOR_CONSTANT, " : "",
193 (mode
& FX_UM_ALPHA_ITERATED
) ? "ALPHA_ITERATED, " : "",
194 (mode
& FX_UM_ALPHA_CONSTANT
) ? "ALPHA_CONSTANT, " : "");
198 fxGetTexSetConfiguration(GLcontext
* ctx
,
199 struct gl_texture_object
*tObj0
,
200 struct gl_texture_object
*tObj1
)
202 GLuint unitsmode
= 0;
206 if ((ctx
->Light
.ShadeModel
== GL_SMOOTH
) || 1 ||
207 (ctx
->Point
.SmoothFlag
) ||
208 (ctx
->Line
.SmoothFlag
) ||
209 (ctx
->Polygon
.SmoothFlag
)) unitsmode
|= FX_UM_ALPHA_ITERATED
;
211 unitsmode
|= FX_UM_ALPHA_CONSTANT
;
213 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
|| 1)
214 unitsmode
|= FX_UM_COLOR_ITERATED
;
216 unitsmode
|= FX_UM_COLOR_CONSTANT
;
221 OpenGL Feeds Texture 0 into Texture 1
222 Glide Feeds Texture 1 into Texture 0
225 tfxTexInfo
*ti0
= fxTMGetTexInfo(tObj0
);
227 switch (ti0
->baseLevelInternalFormat
) {
229 ifmt
|= FX_UM_E0_ALPHA
;
232 ifmt
|= FX_UM_E0_LUMINANCE
;
234 case GL_LUMINANCE_ALPHA
:
235 ifmt
|= FX_UM_E0_LUMINANCE_ALPHA
;
238 ifmt
|= FX_UM_E0_INTENSITY
;
241 ifmt
|= FX_UM_E0_RGB
;
244 ifmt
|= FX_UM_E0_RGBA
;
248 switch (ctx
->Texture
.Unit
[0].EnvMode
) {
250 envmode
|= FX_UM_E0_DECAL
;
253 envmode
|= FX_UM_E0_MODULATE
;
256 envmode
|= FX_UM_E0_REPLACE
;
259 envmode
|= FX_UM_E0_BLEND
;
262 envmode
|= FX_UM_E0_ADD
;
271 tfxTexInfo
*ti1
= fxTMGetTexInfo(tObj1
);
273 switch (ti1
->baseLevelInternalFormat
) {
275 ifmt
|= FX_UM_E1_ALPHA
;
278 ifmt
|= FX_UM_E1_LUMINANCE
;
280 case GL_LUMINANCE_ALPHA
:
281 ifmt
|= FX_UM_E1_LUMINANCE_ALPHA
;
284 ifmt
|= FX_UM_E1_INTENSITY
;
287 ifmt
|= FX_UM_E1_RGB
;
290 ifmt
|= FX_UM_E1_RGBA
;
297 switch (ctx
->Texture
.Unit
[1].EnvMode
) {
299 envmode
|= FX_UM_E1_DECAL
;
302 envmode
|= FX_UM_E1_MODULATE
;
305 envmode
|= FX_UM_E1_REPLACE
;
308 envmode
|= FX_UM_E1_BLEND
;
311 envmode
|= FX_UM_E1_ADD
;
319 unitsmode
|= (ifmt
| envmode
);
321 if (TDFX_DEBUG
& (VERBOSE_DRIVER
| VERBOSE_TEXTURE
))
322 fxPrintUnitsMode("fxGetTexSetConfiguration", unitsmode
);
327 /************************************************************************/
328 /************************* Rendering Mode SetUp *************************/
329 /************************************************************************/
331 /************************* Single Texture Set ***************************/
334 fxSetupSingleTMU_NoLock(fxMesaContext fxMesa
, struct gl_texture_object
*tObj
)
336 tfxTexInfo
*ti
= fxTMGetTexInfo(tObj
);
339 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
340 fprintf(stderr
, "fxSetupSingleTMU_NoLock(%p (%d))\n", (void *)tObj
, tObj
->Name
);
343 ti
->lastTimeUsed
= fxMesa
->texBindNumber
;
345 /* Make sure we're not loaded incorrectly */
348 if (ti
->whichTMU
!= FX_TMU_SPLIT
)
349 fxTMMoveOutTM(fxMesa
, tObj
);
352 if (ti
->whichTMU
== FX_TMU_SPLIT
)
353 fxTMMoveOutTM(fxMesa
, tObj
);
357 /* Make sure we're loaded correctly */
360 fxTMMoveInTM_NoLock(fxMesa
, tObj
, FX_TMU_SPLIT
);
362 if (fxMesa
->haveTwoTMUs
) {
363 if (fxTMCheckStartAddr(fxMesa
, FX_TMU0
, ti
)) {
364 fxTMMoveInTM_NoLock(fxMesa
, tObj
, FX_TMU0
);
367 fxTMMoveInTM_NoLock(fxMesa
, tObj
, FX_TMU1
);
371 fxTMMoveInTM_NoLock(fxMesa
, tObj
, FX_TMU0
);
375 if (ti
->LODblend
&& ti
->whichTMU
== FX_TMU_SPLIT
) {
377 if ((ti
->info
.format
== GR_TEXFMT_P_8
)
378 && (!fxMesa
->haveGlobalPaletteTexture
)) {
379 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
380 fprintf(stderr
, "fxSetupSingleTMU_NoLock: uploading texture palette\n");
382 grTexDownloadTable(ti
->paltype
, &(ti
->palette
));
385 grTexClampMode(GR_TMU0
, ti
->sClamp
, ti
->tClamp
);
386 grTexClampMode(GR_TMU1
, ti
->sClamp
, ti
->tClamp
);
387 grTexFilterMode(GR_TMU0
, ti
->minFilt
, ti
->maxFilt
);
388 grTexFilterMode(GR_TMU1
, ti
->minFilt
, ti
->maxFilt
);
389 grTexMipMapMode(GR_TMU0
, ti
->mmMode
, ti
->LODblend
);
390 grTexMipMapMode(GR_TMU1
, ti
->mmMode
, ti
->LODblend
);
392 grTexSource(GR_TMU0
, ti
->tm
[FX_TMU0
]->startAddr
,
393 GR_MIPMAPLEVELMASK_ODD
, &(ti
->info
));
394 grTexSource(GR_TMU1
, ti
->tm
[FX_TMU1
]->startAddr
,
395 GR_MIPMAPLEVELMASK_EVEN
, &(ti
->info
));
398 if (ti
->whichTMU
== FX_TMU_BOTH
)
404 if ((ti
->info
.format
== GR_TEXFMT_P_8
)
405 && (!fxMesa
->haveGlobalPaletteTexture
)) {
406 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
407 fprintf(stderr
, "fxSetupSingleTMU_NoLock: uploading texture palette\n");
409 fxMesa
->Glide
.grTexDownloadTableExt(tmu
, ti
->paltype
, &(ti
->palette
));
412 /* KW: The alternative is to do the download to the other tmu. If
413 * we get to this point, I think it means we are thrashing the
414 * texture memory, so perhaps it's not a good idea.
416 if (ti
->LODblend
&& (TDFX_DEBUG
& VERBOSE_DRIVER
)) {
417 fprintf(stderr
, "fxSetupSingleTMU_NoLock: not blending texture - only one tmu\n");
420 grTexClampMode(tmu
, ti
->sClamp
, ti
->tClamp
);
421 grTexFilterMode(tmu
, ti
->minFilt
, ti
->maxFilt
);
422 grTexMipMapMode(tmu
, ti
->mmMode
, FXFALSE
);
424 grTexSource(tmu
, ti
->tm
[tmu
]->startAddr
, GR_MIPMAPLEVELMASK_BOTH
, &(ti
->info
));
429 fxSelectSingleTMUSrc_NoLock(fxMesaContext fxMesa
, GLint tmu
, FxBool LODblend
)
431 struct tdfx_texcombine tex0
, tex1
;
433 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
434 fprintf(stderr
, "fxSelectSingleTMUSrc_NoLock(%d, %d)\n", tmu
, LODblend
);
437 tex0
.InvertRGB
= FXFALSE
;
438 tex0
.InvertAlpha
= FXFALSE
;
439 tex1
.InvertRGB
= FXFALSE
;
440 tex1
.InvertAlpha
= FXFALSE
;
443 tex0
.FunctionRGB
= GR_COMBINE_FUNCTION_BLEND
;
444 tex0
.FactorRGB
= GR_COMBINE_FACTOR_ONE_MINUS_LOD_FRACTION
;
445 tex0
.FunctionAlpha
= GR_COMBINE_FUNCTION_BLEND
;
446 tex0
.FactorAlpha
= GR_COMBINE_FACTOR_ONE_MINUS_LOD_FRACTION
;
448 tex1
.FunctionRGB
= GR_COMBINE_FUNCTION_LOCAL
;
449 tex1
.FactorRGB
= GR_COMBINE_FACTOR_NONE
;
450 tex1
.FunctionAlpha
= GR_COMBINE_FUNCTION_LOCAL
;
451 tex1
.FactorAlpha
= GR_COMBINE_FACTOR_NONE
;
453 fxMesa
->tmuSrc
= FX_TMU_SPLIT
;
456 if (tmu
!= FX_TMU1
) {
457 tex0
.FunctionRGB
= GR_COMBINE_FUNCTION_LOCAL
;
458 tex0
.FactorRGB
= GR_COMBINE_FACTOR_NONE
;
459 tex0
.FunctionAlpha
= GR_COMBINE_FUNCTION_LOCAL
;
460 tex0
.FactorAlpha
= GR_COMBINE_FACTOR_NONE
;
462 tex1
.FunctionRGB
= GR_COMBINE_FUNCTION_ZERO
;
463 tex1
.FactorRGB
= GR_COMBINE_FACTOR_NONE
;
464 tex1
.FunctionAlpha
= GR_COMBINE_FUNCTION_ZERO
;
465 tex1
.FactorAlpha
= GR_COMBINE_FACTOR_NONE
;
467 fxMesa
->tmuSrc
= FX_TMU0
;
470 tex1
.FunctionRGB
= GR_COMBINE_FUNCTION_LOCAL
;
471 tex1
.FactorRGB
= GR_COMBINE_FACTOR_NONE
;
472 tex1
.FunctionAlpha
= GR_COMBINE_FUNCTION_LOCAL
;
473 tex1
.FactorAlpha
= GR_COMBINE_FACTOR_NONE
;
475 /* correct values to set TMU0 in passthrough mode */
476 tex0
.FunctionRGB
= GR_COMBINE_FUNCTION_BLEND
;
477 tex0
.FactorRGB
= GR_COMBINE_FACTOR_ONE
;
478 tex0
.FunctionAlpha
= GR_COMBINE_FUNCTION_BLEND
;
479 tex0
.FactorAlpha
= GR_COMBINE_FACTOR_ONE
;
481 fxMesa
->tmuSrc
= FX_TMU1
;
485 grTexCombine(GR_TMU0
,
492 if (fxMesa
->haveTwoTMUs
) {
493 grTexCombine(GR_TMU1
,
504 fxSetupTextureSingleTMU_NoLock(GLcontext
* ctx
, GLuint textureset
)
506 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
507 struct tdfx_combine alphaComb
, colorComb
;
508 GrCombineLocal_t localc
, locala
;
512 struct gl_texture_object
*tObj
= ctx
->Texture
.Unit
[textureset
]._Current
;
515 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
516 fprintf(stderr
, "fxSetupTextureSingleTMU_NoLock(%d)\n", textureset
);
519 ti
= fxTMGetTexInfo(tObj
);
521 fxTexValidate(ctx
, tObj
);
523 fxSetupSingleTMU_NoLock(fxMesa
, tObj
);
525 if (ti
->whichTMU
== FX_TMU_BOTH
)
529 if (fxMesa
->tmuSrc
!= tmu
)
530 fxSelectSingleTMUSrc_NoLock(fxMesa
, tmu
, ti
->LODblend
);
532 if (textureset
== 0 || !fxMesa
->haveTwoTMUs
)
533 unitsmode
= fxGetTexSetConfiguration(ctx
, tObj
, NULL
);
535 unitsmode
= fxGetTexSetConfiguration(ctx
, NULL
, tObj
);
537 /* if(fxMesa->lastUnitsMode==unitsmode) */
540 fxMesa
->lastUnitsMode
= unitsmode
;
542 fxMesa
->stw_hint_state
= 0;
543 FX_grHints_NoLock(GR_HINT_STWHINT
, 0);
545 ifmt
= ti
->baseLevelInternalFormat
;
547 if (unitsmode
& FX_UM_ALPHA_ITERATED
)
548 locala
= GR_COMBINE_LOCAL_ITERATED
;
550 locala
= GR_COMBINE_LOCAL_CONSTANT
;
552 if (unitsmode
& FX_UM_COLOR_ITERATED
)
553 localc
= GR_COMBINE_LOCAL_ITERATED
;
555 localc
= GR_COMBINE_LOCAL_CONSTANT
;
557 if (TDFX_DEBUG
& (VERBOSE_DRIVER
| VERBOSE_TEXTURE
))
558 fprintf(stderr
, "fxSetupTextureSingleTMU_NoLock: envmode is %s\n",
559 _mesa_lookup_enum_by_nr(ctx
->Texture
.Unit
[textureset
].EnvMode
));
561 alphaComb
.Local
= locala
;
562 alphaComb
.Invert
= FXFALSE
;
563 colorComb
.Local
= localc
;
564 colorComb
.Invert
= FXFALSE
;
566 switch (ctx
->Texture
.Unit
[textureset
].EnvMode
) {
568 alphaComb
.Function
= GR_COMBINE_FUNCTION_LOCAL
;
569 alphaComb
.Factor
= GR_COMBINE_FACTOR_NONE
;
570 alphaComb
.Other
= GR_COMBINE_OTHER_NONE
;
572 colorComb
.Function
= GR_COMBINE_FUNCTION_BLEND
;
573 colorComb
.Factor
= GR_COMBINE_FACTOR_TEXTURE_ALPHA
;
574 colorComb
.Other
= GR_COMBINE_OTHER_TEXTURE
;
577 alphaComb
.Function
= GR_COMBINE_FUNCTION_SCALE_OTHER
;
578 alphaComb
.Factor
= GR_COMBINE_FACTOR_LOCAL
;
579 alphaComb
.Other
= GR_COMBINE_OTHER_TEXTURE
;
581 if (ifmt
== GL_ALPHA
) {
582 colorComb
.Function
= GR_COMBINE_FUNCTION_LOCAL
;
583 colorComb
.Factor
= GR_COMBINE_FACTOR_NONE
;
584 colorComb
.Other
= GR_COMBINE_OTHER_NONE
;
586 colorComb
.Function
= GR_COMBINE_FUNCTION_SCALE_OTHER
;
587 colorComb
.Factor
= GR_COMBINE_FACTOR_LOCAL
;
588 colorComb
.Other
= GR_COMBINE_OTHER_TEXTURE
;
592 if (ifmt
== GL_LUMINANCE
|| ifmt
== GL_RGB
) {
594 alphaComb
.Function
= GR_COMBINE_FUNCTION_LOCAL
;
595 alphaComb
.Factor
= GR_COMBINE_FACTOR_NONE
;
596 alphaComb
.Other
= GR_COMBINE_OTHER_NONE
;
598 else if (ifmt
== GL_INTENSITY
) {
599 /* Av = Af * (1 - It) + Ac * It */
600 alphaComb
.Function
= GR_COMBINE_FUNCTION_BLEND
;
601 alphaComb
.Factor
= GR_COMBINE_FACTOR_TEXTURE_ALPHA
;
602 alphaComb
.Other
= GR_COMBINE_OTHER_CONSTANT
;
606 alphaComb
.Function
= GR_COMBINE_FUNCTION_SCALE_OTHER
;
607 alphaComb
.Factor
= GR_COMBINE_FACTOR_LOCAL
;
608 alphaComb
.Other
= GR_COMBINE_OTHER_TEXTURE
;
611 if (ifmt
== GL_ALPHA
) {
612 colorComb
.Function
= GR_COMBINE_FUNCTION_LOCAL
;
613 colorComb
.Factor
= GR_COMBINE_FACTOR_NONE
;
614 colorComb
.Other
= GR_COMBINE_OTHER_NONE
;
616 if (fxMesa
->type
>= GR_SSTTYPE_Voodoo2
) {
617 colorComb
.Function
= GR_COMBINE_FUNCTION_BLEND
;
618 colorComb
.Factor
= GR_COMBINE_FACTOR_TEXTURE_RGB
;
619 colorComb
.Other
= GR_COMBINE_OTHER_CONSTANT
;
620 } else if (ifmt
== GL_INTENSITY
) {
621 /* just a hack: RGB == ALPHA */
622 colorComb
.Function
= GR_COMBINE_FUNCTION_BLEND
;
623 colorComb
.Factor
= GR_COMBINE_FACTOR_TEXTURE_ALPHA
;
624 colorComb
.Other
= GR_COMBINE_OTHER_CONSTANT
;
626 /* Only Voodoo^2 can GL_BLEND (GR_COMBINE_FACTOR_TEXTURE_RGB)
627 * These settings assume that the TexEnv color is black and
628 * incoming fragment color is white.
630 colorComb
.Function
= GR_COMBINE_FUNCTION_SCALE_OTHER
;
631 colorComb
.Factor
= GR_COMBINE_FACTOR_ONE
;
632 colorComb
.Other
= GR_COMBINE_OTHER_TEXTURE
;
633 colorComb
.Invert
= FXTRUE
;
634 _mesa_problem(NULL
, "can't GL_BLEND with SST1");
638 grConstantColorValue(
639 (((GLuint
)(ctx
->Texture
.Unit
[textureset
].EnvColor
[0] * 255.0f
)) ) |
640 (((GLuint
)(ctx
->Texture
.Unit
[textureset
].EnvColor
[1] * 255.0f
)) << 8) |
641 (((GLuint
)(ctx
->Texture
.Unit
[textureset
].EnvColor
[2] * 255.0f
)) << 16) |
642 (((GLuint
)(ctx
->Texture
.Unit
[textureset
].EnvColor
[3] * 255.0f
)) << 24));
645 if ((ifmt
== GL_RGB
) || (ifmt
== GL_LUMINANCE
)) {
646 alphaComb
.Function
= GR_COMBINE_FUNCTION_LOCAL
;
647 alphaComb
.Factor
= GR_COMBINE_FACTOR_NONE
;
648 alphaComb
.Other
= GR_COMBINE_OTHER_NONE
;
650 alphaComb
.Function
= GR_COMBINE_FUNCTION_SCALE_OTHER
;
651 alphaComb
.Factor
= GR_COMBINE_FACTOR_ONE
;
652 alphaComb
.Other
= GR_COMBINE_OTHER_TEXTURE
;
655 if (ifmt
== GL_ALPHA
) {
656 colorComb
.Function
= GR_COMBINE_FUNCTION_LOCAL
;
657 colorComb
.Factor
= GR_COMBINE_FACTOR_NONE
;
658 colorComb
.Other
= GR_COMBINE_OTHER_NONE
;
660 colorComb
.Function
= GR_COMBINE_FUNCTION_SCALE_OTHER
;
661 colorComb
.Factor
= GR_COMBINE_FACTOR_ONE
;
662 colorComb
.Other
= GR_COMBINE_OTHER_TEXTURE
;
666 if (ifmt
== GL_ALPHA
||
667 ifmt
== GL_LUMINANCE_ALPHA
||
669 /* product of texel and fragment alpha */
670 alphaComb
.Function
= GR_COMBINE_FUNCTION_SCALE_OTHER
;
671 alphaComb
.Factor
= GR_COMBINE_FACTOR_LOCAL
;
672 alphaComb
.Other
= GR_COMBINE_OTHER_TEXTURE
;
674 else if (ifmt
== GL_LUMINANCE
|| ifmt
== GL_RGB
) {
675 /* fragment alpha is unchanged */
676 alphaComb
.Function
= GR_COMBINE_FUNCTION_LOCAL
;
677 alphaComb
.Factor
= GR_COMBINE_FACTOR_NONE
;
678 alphaComb
.Other
= GR_COMBINE_OTHER_NONE
;
681 /* sum of texel and fragment alpha */
682 alphaComb
.Function
= GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL
;
683 alphaComb
.Factor
= GR_COMBINE_FACTOR_ONE
;
684 alphaComb
.Other
= GR_COMBINE_OTHER_TEXTURE
;
687 if (ifmt
== GL_ALPHA
) {
689 colorComb
.Function
= GR_COMBINE_FUNCTION_LOCAL
;
690 colorComb
.Factor
= GR_COMBINE_FACTOR_NONE
;
691 colorComb
.Other
= GR_COMBINE_OTHER_NONE
;
694 /* sum of texel and fragment rgb */
695 colorComb
.Function
= GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL
;
696 colorComb
.Factor
= GR_COMBINE_FACTOR_ONE
;
697 colorComb
.Other
= GR_COMBINE_OTHER_TEXTURE
;
701 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
702 fprintf(stderr
, "fxSetupTextureSingleTMU_NoLock: %x Texture.EnvMode not yet supported\n",
703 ctx
->Texture
.Unit
[textureset
].EnvMode
);
708 grAlphaCombine(alphaComb
.Function
,
713 grColorCombine(colorComb
.Function
,
722 fxSetupTextureSingleTMU(GLcontext
* ctx
, GLuint textureset
)
725 fxSetupTextureSingleTMU_NoLock(ctx
, textureset
);
731 /************************* Double Texture Set ***************************/
734 fxSetupDoubleTMU_NoLock(fxMesaContext fxMesa
,
735 struct gl_texture_object
*tObj0
,
736 struct gl_texture_object
*tObj1
)
738 #define T0_NOT_IN_TMU 0x01
739 #define T1_NOT_IN_TMU 0x02
740 #define T0_IN_TMU0 0x04
741 #define T1_IN_TMU0 0x08
742 #define T0_IN_TMU1 0x10
743 #define T1_IN_TMU1 0x20
745 tfxTexInfo
*ti0
= fxTMGetTexInfo(tObj0
);
746 tfxTexInfo
*ti1
= fxTMGetTexInfo(tObj1
);
748 int tmu0
= 0, tmu1
= 1;
750 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
751 fprintf(stderr
, "fxSetupDoubleTMU_NoLock(...)\n");
754 /* We shouldn't need to do this. There is something wrong with
755 mutlitexturing when the TMUs are swapped. So, we're forcing
756 them to always be loaded correctly. !!! */
757 if (ti0
->whichTMU
== FX_TMU1
)
758 fxTMMoveOutTM_NoLock(fxMesa
, tObj0
);
759 if (ti1
->whichTMU
== FX_TMU0
)
760 fxTMMoveOutTM_NoLock(fxMesa
, tObj1
);
763 switch (ti0
->whichTMU
) {
765 tstate
|= T0_IN_TMU0
;
768 tstate
|= T0_IN_TMU1
;
771 tstate
|= T0_IN_TMU0
| T0_IN_TMU1
;
774 tstate
|= T0_NOT_IN_TMU
;
779 tstate
|= T0_NOT_IN_TMU
;
782 switch (ti1
->whichTMU
) {
784 tstate
|= T1_IN_TMU0
;
787 tstate
|= T1_IN_TMU1
;
790 tstate
|= T1_IN_TMU0
| T1_IN_TMU1
;
793 tstate
|= T1_NOT_IN_TMU
;
798 tstate
|= T1_NOT_IN_TMU
;
800 ti0
->lastTimeUsed
= fxMesa
->texBindNumber
;
801 ti1
->lastTimeUsed
= fxMesa
->texBindNumber
;
803 /* Move texture maps into TMUs */
805 if (!(((tstate
& T0_IN_TMU0
) && (tstate
& T1_IN_TMU1
)) ||
806 ((tstate
& T0_IN_TMU1
) && (tstate
& T1_IN_TMU0
)))) {
808 fxTMMoveInTM_NoLock(fxMesa
, tObj1
, FX_TMU_BOTH
);
810 /* Find the minimal way to correct the situation */
811 if ((tstate
& T0_IN_TMU0
) || (tstate
& T1_IN_TMU1
)) {
812 /* We have one in the standard order, setup the other */
813 if (tstate
& T0_IN_TMU0
) { /* T0 is in TMU0, put T1 in TMU1 */
814 fxTMMoveInTM_NoLock(fxMesa
, tObj1
, FX_TMU1
);
817 fxTMMoveInTM_NoLock(fxMesa
, tObj0
, FX_TMU0
);
819 /* tmu0 and tmu1 are setup */
821 else if ((tstate
& T0_IN_TMU1
) || (tstate
& T1_IN_TMU0
)) {
822 /* we have one in the reverse order, setup the other */
823 if (tstate
& T1_IN_TMU0
) { /* T1 is in TMU0, put T0 in TMU1 */
824 fxTMMoveInTM_NoLock(fxMesa
, tObj0
, FX_TMU1
);
827 fxTMMoveInTM_NoLock(fxMesa
, tObj1
, FX_TMU0
);
832 else { /* Nothing is loaded */
833 fxTMMoveInTM_NoLock(fxMesa
, tObj0
, FX_TMU0
);
834 fxTMMoveInTM_NoLock(fxMesa
, tObj1
, FX_TMU1
);
835 /* tmu0 and tmu1 are setup */
840 /* [dBorca] Hack alert:
841 * we put these in reverse order, so that if we can't
842 * do _REAL_ pointcast, the TMU0 table gets broadcasted
844 if (!fxMesa
->haveGlobalPaletteTexture
) {
846 if (ti1
->info
.format
== GR_TEXFMT_P_8
) {
847 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
848 fprintf(stderr
, "fxSetupDoubleTMU_NoLock: uploading texture palette for TMU1\n");
850 fxMesa
->Glide
.grTexDownloadTableExt(ti1
->whichTMU
, ti1
->paltype
, &(ti1
->palette
));
852 if (ti0
->info
.format
== GR_TEXFMT_P_8
) {
853 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
854 fprintf(stderr
, "fxSetupDoubleTMU_NoLock: uploading texture palette for TMU0\n");
856 fxMesa
->Glide
.grTexDownloadTableExt(ti0
->whichTMU
, ti0
->paltype
, &(ti0
->palette
));
860 grTexSource(tmu0
, ti0
->tm
[tmu0
]->startAddr
,
861 GR_MIPMAPLEVELMASK_BOTH
, &(ti0
->info
));
862 grTexClampMode(tmu0
, ti0
->sClamp
, ti0
->tClamp
);
863 grTexFilterMode(tmu0
, ti0
->minFilt
, ti0
->maxFilt
);
864 grTexMipMapMode(tmu0
, ti0
->mmMode
, FXFALSE
);
866 grTexSource(tmu1
, ti1
->tm
[tmu1
]->startAddr
,
867 GR_MIPMAPLEVELMASK_BOTH
, &(ti1
->info
));
868 grTexClampMode(tmu1
, ti1
->sClamp
, ti1
->tClamp
);
869 grTexFilterMode(tmu1
, ti1
->minFilt
, ti1
->maxFilt
);
870 grTexMipMapMode(tmu1
, ti1
->mmMode
, FXFALSE
);
881 fxSetupTextureDoubleTMU_NoLock(GLcontext
* ctx
)
883 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
884 struct tdfx_combine alphaComb
, colorComb
;
885 struct tdfx_texcombine tex0
, tex1
;
886 GrCombineLocal_t localc
, locala
;
887 tfxTexInfo
*ti0
, *ti1
;
888 struct gl_texture_object
*tObj0
= ctx
->Texture
.Unit
[1]._Current
;
889 struct gl_texture_object
*tObj1
= ctx
->Texture
.Unit
[0]._Current
;
890 GLuint envmode
, ifmt
, unitsmode
;
891 int tmu0
= 0, tmu1
= 1;
893 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
894 fprintf(stderr
, "fxSetupTextureDoubleTMU_NoLock(...)\n");
897 ti0
= fxTMGetTexInfo(tObj0
);
898 fxTexValidate(ctx
, tObj0
);
900 ti1
= fxTMGetTexInfo(tObj1
);
901 fxTexValidate(ctx
, tObj1
);
903 fxSetupDoubleTMU_NoLock(fxMesa
, tObj0
, tObj1
);
905 unitsmode
= fxGetTexSetConfiguration(ctx
, tObj0
, tObj1
);
907 /* if(fxMesa->lastUnitsMode==unitsmode) */
910 fxMesa
->lastUnitsMode
= unitsmode
;
912 fxMesa
->stw_hint_state
|= GR_STWHINT_ST_DIFF_TMU1
;
913 FX_grHints_NoLock(GR_HINT_STWHINT
, fxMesa
->stw_hint_state
);
915 envmode
= unitsmode
& FX_UM_E_ENVMODE
;
916 ifmt
= unitsmode
& FX_UM_E_IFMT
;
918 if (unitsmode
& FX_UM_ALPHA_ITERATED
)
919 locala
= GR_COMBINE_LOCAL_ITERATED
;
921 locala
= GR_COMBINE_LOCAL_CONSTANT
;
923 if (unitsmode
& FX_UM_COLOR_ITERATED
)
924 localc
= GR_COMBINE_LOCAL_ITERATED
;
926 localc
= GR_COMBINE_LOCAL_CONSTANT
;
929 if (TDFX_DEBUG
& (VERBOSE_DRIVER
| VERBOSE_TEXTURE
))
930 fprintf(stderr
, "fxSetupTextureDoubleTMU_NoLock: envmode is %s/%s\n",
931 _mesa_lookup_enum_by_nr(ctx
->Texture
.Unit
[0].EnvMode
),
932 _mesa_lookup_enum_by_nr(ctx
->Texture
.Unit
[1].EnvMode
));
935 if ((ti0
->whichTMU
== FX_TMU1
) || (ti1
->whichTMU
== FX_TMU0
)) {
939 fxMesa
->tmuSrc
= FX_TMU_BOTH
;
941 tex0
.InvertRGB
= FXFALSE
;
942 tex0
.InvertAlpha
= FXFALSE
;
943 tex1
.InvertRGB
= FXFALSE
;
944 tex1
.InvertAlpha
= FXFALSE
;
945 alphaComb
.Local
= locala
;
946 alphaComb
.Invert
= FXFALSE
;
947 colorComb
.Local
= localc
;
948 colorComb
.Invert
= FXFALSE
;
951 case (FX_UM_E0_MODULATE
| FX_UM_E1_MODULATE
):
953 GLboolean isalpha
[FX_NUM_TMU
];
955 isalpha
[tmu0
] = (ti0
->baseLevelInternalFormat
== GL_ALPHA
);
956 isalpha
[tmu1
] = (ti1
->baseLevelInternalFormat
== GL_ALPHA
);
958 if (isalpha
[FX_TMU1
]) {
959 tex1
.FunctionRGB
= GR_COMBINE_FUNCTION_ZERO
;
960 tex1
.FactorRGB
= GR_COMBINE_FACTOR_NONE
;
961 tex1
.FunctionAlpha
= GR_COMBINE_FUNCTION_LOCAL
;
962 tex1
.FactorAlpha
= GR_COMBINE_FACTOR_NONE
;
963 tex1
.InvertRGB
= FXTRUE
;
965 tex1
.FunctionRGB
= GR_COMBINE_FUNCTION_LOCAL
;
966 tex1
.FactorRGB
= GR_COMBINE_FACTOR_NONE
;
967 tex1
.FunctionAlpha
= GR_COMBINE_FUNCTION_LOCAL
;
968 tex1
.FactorAlpha
= GR_COMBINE_FACTOR_NONE
;
971 if (isalpha
[FX_TMU0
]) {
972 tex0
.FunctionRGB
= GR_COMBINE_FUNCTION_BLEND_OTHER
;
973 tex0
.FactorRGB
= GR_COMBINE_FACTOR_ONE
;
974 tex0
.FunctionAlpha
= GR_COMBINE_FUNCTION_BLEND_OTHER
;
975 tex0
.FactorAlpha
= GR_COMBINE_FACTOR_LOCAL
;
977 tex0
.FunctionRGB
= GR_COMBINE_FUNCTION_BLEND_OTHER
;
978 tex0
.FactorRGB
= GR_COMBINE_FACTOR_LOCAL
;
979 tex0
.FunctionAlpha
= GR_COMBINE_FUNCTION_BLEND_OTHER
;
980 tex0
.FactorAlpha
= GR_COMBINE_FACTOR_LOCAL
;
983 colorComb
.Function
= GR_COMBINE_FUNCTION_SCALE_OTHER
;
984 colorComb
.Factor
= GR_COMBINE_FACTOR_LOCAL
;
985 colorComb
.Other
= GR_COMBINE_OTHER_TEXTURE
;
987 alphaComb
.Function
= GR_COMBINE_FUNCTION_SCALE_OTHER
;
988 alphaComb
.Factor
= GR_COMBINE_FACTOR_LOCAL
;
989 alphaComb
.Other
= GR_COMBINE_OTHER_TEXTURE
;
992 case (FX_UM_E0_REPLACE
| FX_UM_E1_BLEND
): /* Only for GLQuake */
993 if (tmu0
== FX_TMU1
) {
994 tex1
.FunctionRGB
= GR_COMBINE_FUNCTION_LOCAL
;
995 tex1
.FactorRGB
= GR_COMBINE_FACTOR_NONE
;
996 tex1
.FunctionAlpha
= GR_COMBINE_FUNCTION_LOCAL
;
997 tex1
.FactorAlpha
= GR_COMBINE_FACTOR_NONE
;
998 tex1
.InvertRGB
= FXTRUE
;
1000 tex0
.FunctionRGB
= GR_COMBINE_FUNCTION_BLEND_OTHER
;
1001 tex0
.FactorRGB
= GR_COMBINE_FACTOR_LOCAL
;
1002 tex0
.FunctionAlpha
= GR_COMBINE_FUNCTION_BLEND_OTHER
;
1003 tex0
.FactorAlpha
= GR_COMBINE_FACTOR_LOCAL
;
1006 tex1
.FunctionRGB
= GR_COMBINE_FUNCTION_LOCAL
;
1007 tex1
.FactorRGB
= GR_COMBINE_FACTOR_NONE
;
1008 tex1
.FunctionAlpha
= GR_COMBINE_FUNCTION_LOCAL
;
1009 tex1
.FactorAlpha
= GR_COMBINE_FACTOR_NONE
;
1011 tex0
.FunctionRGB
= GR_COMBINE_FUNCTION_BLEND_OTHER
;
1012 tex0
.FactorRGB
= GR_COMBINE_FACTOR_ONE_MINUS_LOCAL
;
1013 tex0
.FunctionAlpha
= GR_COMBINE_FUNCTION_BLEND_OTHER
;
1014 tex0
.FactorAlpha
= GR_COMBINE_FACTOR_ONE_MINUS_LOCAL
;
1017 alphaComb
.Function
= GR_COMBINE_FUNCTION_LOCAL
;
1018 alphaComb
.Factor
= GR_COMBINE_FACTOR_NONE
;
1019 alphaComb
.Other
= GR_COMBINE_OTHER_NONE
;
1021 colorComb
.Function
= GR_COMBINE_FUNCTION_SCALE_OTHER
;
1022 colorComb
.Factor
= GR_COMBINE_FACTOR_ONE
;
1023 colorComb
.Other
= GR_COMBINE_OTHER_TEXTURE
;
1025 case (FX_UM_E0_REPLACE
| FX_UM_E1_MODULATE
): /* Quake 2 and 3 */
1026 if (tmu1
== FX_TMU1
) {
1027 tex1
.FunctionRGB
= GR_COMBINE_FUNCTION_LOCAL
;
1028 tex1
.FactorRGB
= GR_COMBINE_FACTOR_NONE
;
1029 tex1
.FunctionAlpha
= GR_COMBINE_FUNCTION_ZERO
;
1030 tex1
.FactorAlpha
= GR_COMBINE_FACTOR_NONE
;
1031 tex1
.InvertAlpha
= FXTRUE
;
1033 tex0
.FunctionRGB
= GR_COMBINE_FUNCTION_BLEND_OTHER
;
1034 tex0
.FactorRGB
= GR_COMBINE_FACTOR_LOCAL
;
1035 tex0
.FunctionAlpha
= GR_COMBINE_FUNCTION_BLEND_OTHER
;
1036 tex0
.FactorAlpha
= GR_COMBINE_FACTOR_LOCAL
;
1039 tex1
.FunctionRGB
= GR_COMBINE_FUNCTION_LOCAL
;
1040 tex1
.FactorRGB
= GR_COMBINE_FACTOR_NONE
;
1041 tex1
.FunctionAlpha
= GR_COMBINE_FUNCTION_LOCAL
;
1042 tex1
.FactorAlpha
= GR_COMBINE_FACTOR_NONE
;
1044 tex0
.FunctionRGB
= GR_COMBINE_FUNCTION_BLEND_OTHER
;
1045 tex0
.FactorRGB
= GR_COMBINE_FACTOR_LOCAL
;
1046 tex0
.FunctionAlpha
= GR_COMBINE_FUNCTION_BLEND_OTHER
;
1047 tex0
.FactorAlpha
= GR_COMBINE_FACTOR_ONE
;
1050 if (ti0
->baseLevelInternalFormat
== GL_RGB
) {
1051 alphaComb
.Function
= GR_COMBINE_FUNCTION_LOCAL
;
1052 alphaComb
.Factor
= GR_COMBINE_FACTOR_NONE
;
1053 alphaComb
.Other
= GR_COMBINE_OTHER_NONE
;
1055 alphaComb
.Function
= GR_COMBINE_FUNCTION_SCALE_OTHER
;
1056 alphaComb
.Factor
= GR_COMBINE_FACTOR_ONE
;
1057 alphaComb
.Other
= GR_COMBINE_OTHER_NONE
;
1060 colorComb
.Function
= GR_COMBINE_FUNCTION_SCALE_OTHER
;
1061 colorComb
.Factor
= GR_COMBINE_FACTOR_ONE
;
1062 colorComb
.Other
= GR_COMBINE_OTHER_TEXTURE
;
1066 case (FX_UM_E0_MODULATE
| FX_UM_E1_ADD
): /* Quake 3 Sky */
1068 GLboolean isalpha
[FX_NUM_TMU
];
1070 isalpha
[tmu0
] = (ti0
->baseLevelInternalFormat
== GL_ALPHA
);
1071 isalpha
[tmu1
] = (ti1
->baseLevelInternalFormat
== GL_ALPHA
);
1073 if (isalpha
[FX_TMU1
]) {
1074 tex1
.FunctionRGB
= GR_COMBINE_FUNCTION_ZERO
;
1075 tex1
.FactorRGB
= GR_COMBINE_FACTOR_NONE
;
1076 tex1
.FunctionAlpha
= GR_COMBINE_FUNCTION_LOCAL
;
1077 tex1
.FactorAlpha
= GR_COMBINE_FACTOR_NONE
;
1078 tex1
.InvertRGB
= FXTRUE
;
1080 tex1
.FunctionRGB
= GR_COMBINE_FUNCTION_LOCAL
;
1081 tex1
.FactorRGB
= GR_COMBINE_FACTOR_NONE
;
1082 tex1
.FunctionAlpha
= GR_COMBINE_FUNCTION_LOCAL
;
1083 tex1
.FactorAlpha
= GR_COMBINE_FACTOR_NONE
;
1086 if (isalpha
[FX_TMU0
]) {
1087 tex0
.FunctionRGB
= GR_COMBINE_FUNCTION_SCALE_OTHER
;
1088 tex0
.FactorRGB
= GR_COMBINE_FACTOR_ONE
;
1089 tex0
.FunctionAlpha
= GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL
;
1090 tex0
.FactorAlpha
= GR_COMBINE_FACTOR_ONE
;
1092 tex0
.FunctionRGB
= GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL
;
1093 tex0
.FactorRGB
= GR_COMBINE_FACTOR_ONE
;
1094 tex0
.FunctionAlpha
= GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL
;
1095 tex0
.FactorAlpha
= GR_COMBINE_FACTOR_ONE
;
1098 colorComb
.Function
= GR_COMBINE_FUNCTION_SCALE_OTHER
;
1099 colorComb
.Factor
= GR_COMBINE_FACTOR_LOCAL
;
1100 colorComb
.Other
= GR_COMBINE_OTHER_TEXTURE
;
1102 alphaComb
.Function
= GR_COMBINE_FUNCTION_SCALE_OTHER
;
1103 alphaComb
.Factor
= GR_COMBINE_FACTOR_LOCAL
;
1104 alphaComb
.Other
= GR_COMBINE_OTHER_TEXTURE
;
1108 case (FX_UM_E0_REPLACE
| FX_UM_E1_ADD
): /* Vulpine Sky */
1110 GLboolean isalpha
[FX_NUM_TMU
];
1112 isalpha
[tmu0
] = (ti0
->baseLevelInternalFormat
== GL_ALPHA
);
1113 isalpha
[tmu1
] = (ti1
->baseLevelInternalFormat
== GL_ALPHA
);
1115 if (isalpha
[FX_TMU1
]) {
1116 tex1
.FunctionRGB
= GR_COMBINE_FUNCTION_ZERO
;
1117 tex1
.FactorRGB
= GR_COMBINE_FACTOR_NONE
;
1118 tex1
.FunctionAlpha
= GR_COMBINE_FUNCTION_LOCAL
;
1119 tex1
.FactorAlpha
= GR_COMBINE_FACTOR_NONE
;
1120 tex1
.InvertRGB
= FXTRUE
;
1122 tex1
.FunctionRGB
= GR_COMBINE_FUNCTION_LOCAL
;
1123 tex1
.FactorRGB
= GR_COMBINE_FACTOR_NONE
;
1124 tex1
.FunctionAlpha
= GR_COMBINE_FUNCTION_LOCAL
;
1125 tex1
.FactorAlpha
= GR_COMBINE_FACTOR_NONE
;
1128 if (isalpha
[FX_TMU0
]) {
1129 tex0
.FunctionRGB
= GR_COMBINE_FUNCTION_SCALE_OTHER
;
1130 tex0
.FactorRGB
= GR_COMBINE_FACTOR_ONE
;
1131 tex0
.FunctionAlpha
= GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL
;
1132 tex0
.FactorAlpha
= GR_COMBINE_FACTOR_ONE
;
1134 tex0
.FunctionRGB
= GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL
;
1135 tex0
.FactorRGB
= GR_COMBINE_FACTOR_ONE
;
1136 tex0
.FunctionAlpha
= GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL
;
1137 tex0
.FactorAlpha
= GR_COMBINE_FACTOR_ONE
;
1140 colorComb
.Function
= GR_COMBINE_FUNCTION_SCALE_OTHER
;
1141 colorComb
.Factor
= GR_COMBINE_FACTOR_ONE
;
1142 colorComb
.Other
= GR_COMBINE_OTHER_TEXTURE
;
1144 alphaComb
.Function
= GR_COMBINE_FUNCTION_SCALE_OTHER
;
1145 alphaComb
.Factor
= GR_COMBINE_FACTOR_ONE
;
1146 alphaComb
.Other
= GR_COMBINE_OTHER_TEXTURE
;
1150 case (FX_UM_E0_MODULATE
| FX_UM_E1_REPLACE
): /* Homeworld2 */
1152 tex1
.FunctionRGB
= GR_COMBINE_FUNCTION_ZERO
;
1153 tex1
.FactorRGB
= GR_COMBINE_FACTOR_NONE
;
1154 tex1
.FunctionAlpha
= GR_COMBINE_FUNCTION_ZERO
;
1155 tex1
.FactorAlpha
= GR_COMBINE_FACTOR_NONE
;
1157 tex0
.FunctionRGB
= GR_COMBINE_FUNCTION_LOCAL
;
1158 tex0
.FactorRGB
= GR_COMBINE_FACTOR_NONE
;
1159 tex0
.FunctionAlpha
= GR_COMBINE_FUNCTION_LOCAL
;
1160 tex0
.FactorAlpha
= GR_COMBINE_FACTOR_NONE
;
1162 if (ifmt
& (FX_UM_E0_RGB
| FX_UM_E0_LUMINANCE
)) {
1163 alphaComb
.Function
= GR_COMBINE_FUNCTION_LOCAL
;
1164 alphaComb
.Factor
= GR_COMBINE_FACTOR_NONE
;
1165 alphaComb
.Other
= GR_COMBINE_OTHER_NONE
;
1167 alphaComb
.Function
= GR_COMBINE_FUNCTION_SCALE_OTHER
;
1168 alphaComb
.Factor
= GR_COMBINE_FACTOR_ONE
;
1169 alphaComb
.Other
= GR_COMBINE_OTHER_TEXTURE
;
1172 if (ifmt
& FX_UM_E0_ALPHA
) {
1173 colorComb
.Function
= GR_COMBINE_FUNCTION_LOCAL
;
1174 colorComb
.Factor
= GR_COMBINE_FACTOR_NONE
;
1175 colorComb
.Other
= GR_COMBINE_OTHER_NONE
;
1177 colorComb
.Function
= GR_COMBINE_FUNCTION_SCALE_OTHER
;
1178 colorComb
.Factor
= GR_COMBINE_FACTOR_ONE
;
1179 colorComb
.Other
= GR_COMBINE_OTHER_TEXTURE
;
1184 fprintf(stderr
, "fxSetupTextureDoubleTMU_NoLock: Unexpected dual texture mode encountered\n");
1188 grAlphaCombine(alphaComb
.Function
,
1193 grColorCombine(colorComb
.Function
,
1198 grTexCombine(GR_TMU0
,
1205 grTexCombine(GR_TMU1
,
1214 /************************* No Texture ***************************/
1217 fxSetupTextureNone_NoLock(GLcontext
* ctx
)
1219 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1220 GrCombineLocal_t localc
, locala
;
1222 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
1223 fprintf(stderr
, "fxSetupTextureNone_NoLock(...)\n");
1226 if ((ctx
->Light
.ShadeModel
== GL_SMOOTH
) || 1 ||
1227 (ctx
->Point
.SmoothFlag
) ||
1228 (ctx
->Line
.SmoothFlag
) ||
1229 (ctx
->Polygon
.SmoothFlag
)) locala
= GR_COMBINE_LOCAL_ITERATED
;
1231 locala
= GR_COMBINE_LOCAL_CONSTANT
;
1233 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
|| 1)
1234 localc
= GR_COMBINE_LOCAL_ITERATED
;
1236 localc
= GR_COMBINE_LOCAL_CONSTANT
;
1238 grAlphaCombine(GR_COMBINE_FUNCTION_LOCAL
,
1239 GR_COMBINE_FACTOR_NONE
,
1241 GR_COMBINE_OTHER_NONE
,
1244 grColorCombine(GR_COMBINE_FUNCTION_LOCAL
,
1245 GR_COMBINE_FACTOR_NONE
,
1247 GR_COMBINE_OTHER_NONE
,
1250 fxMesa
->lastUnitsMode
= FX_UM_NONE
;
1253 #include "fxsetup.h"
1255 /************************************************************************/
1256 /************************** Texture Mode SetUp **************************/
1257 /************************************************************************/
1260 fxSetupTexture_NoLock(GLcontext
* ctx
)
1262 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1264 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
1265 fprintf(stderr
, "fxSetupTexture_NoLock(...)\n");
1268 if (fxMesa
->HaveCmbExt
) {
1269 /* Texture Combine, Color Combine and Alpha Combine. */
1270 if ((ctx
->Texture
.Unit
[0]._ReallyEnabled
& (TEXTURE_1D_BIT
|TEXTURE_2D_BIT
)) &&
1271 (ctx
->Texture
.Unit
[1]._ReallyEnabled
& (TEXTURE_1D_BIT
|TEXTURE_2D_BIT
)) &&
1272 fxMesa
->haveTwoTMUs
) {
1273 fxSetupTextureDoubleTMUNapalm_NoLock(ctx
);
1275 else if (ctx
->Texture
.Unit
[0]._ReallyEnabled
& (TEXTURE_1D_BIT
|TEXTURE_2D_BIT
)) {
1276 fxSetupTextureSingleTMUNapalm_NoLock(ctx
, 0);
1278 else if (ctx
->Texture
.Unit
[1]._ReallyEnabled
& (TEXTURE_1D_BIT
|TEXTURE_2D_BIT
)) {
1279 fxSetupTextureSingleTMUNapalm_NoLock(ctx
, 1);
1282 fxSetupTextureNoneNapalm_NoLock(ctx
);
1285 /* Texture Combine, Color Combine and Alpha Combine. */
1286 if ((ctx
->Texture
.Unit
[0]._ReallyEnabled
& (TEXTURE_1D_BIT
|TEXTURE_2D_BIT
)) &&
1287 (ctx
->Texture
.Unit
[1]._ReallyEnabled
& (TEXTURE_1D_BIT
|TEXTURE_2D_BIT
)) &&
1288 fxMesa
->haveTwoTMUs
) {
1289 fxSetupTextureDoubleTMU_NoLock(ctx
);
1291 else if (ctx
->Texture
.Unit
[0]._ReallyEnabled
& (TEXTURE_1D_BIT
|TEXTURE_2D_BIT
)) {
1292 fxSetupTextureSingleTMU_NoLock(ctx
, 0);
1294 else if (ctx
->Texture
.Unit
[1]._ReallyEnabled
& (TEXTURE_1D_BIT
|TEXTURE_2D_BIT
)) {
1295 fxSetupTextureSingleTMU_NoLock(ctx
, 1);
1298 fxSetupTextureNone_NoLock(ctx
);
1304 fxSetupTexture(GLcontext
* ctx
)
1307 fxSetupTexture_NoLock(ctx
);
1311 /************************************************************************/
1312 /**************************** Blend SetUp *******************************/
1313 /************************************************************************/
1316 fxDDBlendFuncSeparate(GLcontext
* ctx
, GLenum sfactor
, GLenum dfactor
, GLenum asfactor
, GLenum adfactor
)
1318 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1319 tfxUnitsState
*us
= &fxMesa
->unitsState
;
1320 GLboolean isNapalm
= (fxMesa
->type
>= GR_SSTTYPE_Voodoo4
);
1321 GLboolean have32bpp
= (fxMesa
->colDepth
== 32);
1322 GLboolean haveAlpha
= fxMesa
->haveHwAlpha
;
1323 GrAlphaBlendFnc_t sfact
, dfact
, asfact
, adfact
;
1326 * 15/16 BPP alpha channel alpha blending modes
1330 * 32 BPP alpha channel alpha blending modes
1332 * 0x1 ASRC_ALPHA Source alpha
1333 * 0x3 ADST_ALPHA Destination alpha
1335 * 0x5 AOMSRC_ALPHA 1 - Source alpha
1336 * 0x7 AOMDST_ALPHA 1 - Destination alpha
1338 * If we don't have HW alpha buffer:
1340 * ONE_MINUS_DST_ALPHA == 0
1341 * Unsupported modes are:
1342 * 1 if used as src blending factor
1343 * 0 if used as dst blending factor
1348 sfact
= GR_BLEND_ZERO
;
1351 sfact
= GR_BLEND_ONE
;
1354 sfact
= GR_BLEND_DST_COLOR
;
1356 case GL_ONE_MINUS_DST_COLOR
:
1357 sfact
= GR_BLEND_ONE_MINUS_DST_COLOR
;
1360 sfact
= GR_BLEND_SRC_ALPHA
;
1362 case GL_ONE_MINUS_SRC_ALPHA
:
1363 sfact
= GR_BLEND_ONE_MINUS_SRC_ALPHA
;
1366 sfact
= haveAlpha
? GR_BLEND_DST_ALPHA
: GR_BLEND_ONE
/*bad*/;
1368 case GL_ONE_MINUS_DST_ALPHA
:
1369 sfact
= haveAlpha
? GR_BLEND_ONE_MINUS_DST_ALPHA
: GR_BLEND_ZERO
/*bad*/;
1371 case GL_SRC_ALPHA_SATURATE
:
1372 sfact
= GR_BLEND_ALPHA_SATURATE
;
1376 sfact
= GR_BLEND_SAME_COLOR_EXT
;
1379 case GL_ONE_MINUS_SRC_COLOR
:
1381 sfact
= GR_BLEND_ONE_MINUS_SAME_COLOR_EXT
;
1385 sfact
= GR_BLEND_ONE
;
1391 asfact
= GR_BLEND_ZERO
;
1394 asfact
= GR_BLEND_ONE
;
1398 asfact
= have32bpp
? GR_BLEND_SRC_ALPHA
: GR_BLEND_ONE
/*bad*/;
1400 case GL_ONE_MINUS_SRC_COLOR
:
1401 case GL_ONE_MINUS_SRC_ALPHA
:
1402 asfact
= have32bpp
? GR_BLEND_ONE_MINUS_SRC_ALPHA
: GR_BLEND_ONE
/*bad*/;
1406 asfact
= (have32bpp
&& haveAlpha
) ? GR_BLEND_DST_ALPHA
: GR_BLEND_ONE
/*bad*/;
1408 case GL_ONE_MINUS_DST_COLOR
:
1409 case GL_ONE_MINUS_DST_ALPHA
:
1410 asfact
= (have32bpp
&& haveAlpha
) ? GR_BLEND_ONE_MINUS_DST_ALPHA
: GR_BLEND_ZERO
/*bad*/;
1412 case GL_SRC_ALPHA_SATURATE
:
1413 asfact
= GR_BLEND_ONE
;
1416 asfact
= GR_BLEND_ONE
;
1422 dfact
= GR_BLEND_ZERO
;
1425 dfact
= GR_BLEND_ONE
;
1428 dfact
= GR_BLEND_SRC_COLOR
;
1430 case GL_ONE_MINUS_SRC_COLOR
:
1431 dfact
= GR_BLEND_ONE_MINUS_SRC_COLOR
;
1434 dfact
= GR_BLEND_SRC_ALPHA
;
1436 case GL_ONE_MINUS_SRC_ALPHA
:
1437 dfact
= GR_BLEND_ONE_MINUS_SRC_ALPHA
;
1440 dfact
= haveAlpha
? GR_BLEND_DST_ALPHA
: GR_BLEND_ONE
/*bad*/;
1442 case GL_ONE_MINUS_DST_ALPHA
:
1443 dfact
= haveAlpha
? GR_BLEND_ONE_MINUS_DST_ALPHA
: GR_BLEND_ZERO
/*bad*/;
1447 dfact
= GR_BLEND_SAME_COLOR_EXT
;
1450 case GL_ONE_MINUS_DST_COLOR
:
1452 dfact
= GR_BLEND_ONE_MINUS_SAME_COLOR_EXT
;
1456 dfact
= GR_BLEND_ZERO
;
1462 adfact
= GR_BLEND_ZERO
;
1465 adfact
= GR_BLEND_ONE
;
1469 adfact
= have32bpp
? GR_BLEND_SRC_ALPHA
: GR_BLEND_ZERO
/*bad*/;
1471 case GL_ONE_MINUS_SRC_COLOR
:
1472 case GL_ONE_MINUS_SRC_ALPHA
:
1473 adfact
= have32bpp
? GR_BLEND_ONE_MINUS_SRC_ALPHA
: GR_BLEND_ZERO
/*bad*/;
1477 adfact
= (have32bpp
&& haveAlpha
) ? GR_BLEND_DST_ALPHA
: GR_BLEND_ONE
/*bad*/;
1479 case GL_ONE_MINUS_DST_COLOR
:
1480 case GL_ONE_MINUS_DST_ALPHA
:
1481 adfact
= (have32bpp
&& haveAlpha
) ? GR_BLEND_ONE_MINUS_DST_ALPHA
: GR_BLEND_ZERO
/*bad*/;
1484 adfact
= GR_BLEND_ZERO
;
1488 if ((sfact
!= us
->blendSrcFuncRGB
) || (asfact
!= us
->blendSrcFuncAlpha
)) {
1489 us
->blendSrcFuncRGB
= sfact
;
1490 us
->blendSrcFuncAlpha
= asfact
;
1491 fxMesa
->new_state
|= FX_NEW_BLEND
;
1494 if ((dfact
!= us
->blendDstFuncRGB
) || (adfact
!= us
->blendDstFuncAlpha
)) {
1495 us
->blendDstFuncRGB
= dfact
;
1496 us
->blendDstFuncAlpha
= adfact
;
1497 fxMesa
->new_state
|= FX_NEW_BLEND
;
1502 fxDDBlendEquationSeparate(GLcontext
* ctx
, GLenum modeRGB
, GLenum modeA
)
1504 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1505 tfxUnitsState
*us
= &fxMesa
->unitsState
;
1510 q
= GR_BLEND_OP_ADD
;
1512 case GL_FUNC_SUBTRACT
:
1513 q
= GR_BLEND_OP_SUB
;
1515 case GL_FUNC_REVERSE_SUBTRACT
:
1516 q
= GR_BLEND_OP_REVSUB
;
1521 if (q
!= us
->blendEqRGB
) {
1523 fxMesa
->new_state
|= FX_NEW_BLEND
;
1528 q
= GR_BLEND_OP_ADD
;
1530 case GL_FUNC_SUBTRACT
:
1531 q
= GR_BLEND_OP_SUB
;
1533 case GL_FUNC_REVERSE_SUBTRACT
:
1534 q
= GR_BLEND_OP_REVSUB
;
1537 q
= us
->blendEqAlpha
;
1539 if (q
!= us
->blendEqAlpha
) {
1540 us
->blendEqAlpha
= q
;
1541 fxMesa
->new_state
|= FX_NEW_BLEND
;
1546 fxSetupBlend(GLcontext
* ctx
)
1548 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1549 tfxUnitsState
*us
= &fxMesa
->unitsState
;
1551 if (fxMesa
->HavePixExt
) {
1552 if (us
->blendEnabled
) {
1553 fxMesa
->Glide
.grAlphaBlendFunctionExt(us
->blendSrcFuncRGB
, us
->blendDstFuncRGB
,
1555 us
->blendSrcFuncAlpha
, us
->blendDstFuncAlpha
,
1558 fxMesa
->Glide
.grAlphaBlendFunctionExt(GR_BLEND_ONE
, GR_BLEND_ZERO
,
1560 GR_BLEND_ONE
, GR_BLEND_ZERO
,
1564 if (us
->blendEnabled
) {
1565 grAlphaBlendFunction(us
->blendSrcFuncRGB
, us
->blendDstFuncRGB
,
1566 us
->blendSrcFuncAlpha
, us
->blendDstFuncAlpha
);
1568 grAlphaBlendFunction(GR_BLEND_ONE
, GR_BLEND_ZERO
,
1569 GR_BLEND_ONE
, GR_BLEND_ZERO
);
1574 /************************************************************************/
1575 /************************** Alpha Test SetUp ****************************/
1576 /************************************************************************/
1579 fxDDAlphaFunc(GLcontext
* ctx
, GLenum func
, GLfloat ref
)
1581 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1582 tfxUnitsState
*us
= &fxMesa
->unitsState
;
1585 (us
->alphaTestFunc
!= func
)
1587 (us
->alphaTestRefValue
!= ref
)
1589 us
->alphaTestFunc
= func
;
1590 us
->alphaTestRefValue
= ref
;
1591 fxMesa
->new_state
|= FX_NEW_ALPHA
;
1596 fxSetupAlphaTest(GLcontext
* ctx
)
1598 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1599 tfxUnitsState
*us
= &fxMesa
->unitsState
;
1601 if (us
->alphaTestEnabled
) {
1602 GrAlpha_t ref
= (GLint
) (us
->alphaTestRefValue
* 255.0);
1603 grAlphaTestFunction(us
->alphaTestFunc
- GL_NEVER
+ GR_CMP_NEVER
);
1604 grAlphaTestReferenceValue(ref
);
1607 grAlphaTestFunction(GR_CMP_ALWAYS
);
1610 /************************************************************************/
1611 /************************** Depth Test SetUp ****************************/
1612 /************************************************************************/
1615 fxDDDepthFunc(GLcontext
* ctx
, GLenum func
)
1617 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1618 tfxUnitsState
*us
= &fxMesa
->unitsState
;
1620 if (us
->depthTestFunc
!= func
) {
1621 us
->depthTestFunc
= func
;
1622 fxMesa
->new_state
|= FX_NEW_DEPTH
;
1627 fxDDDepthMask(GLcontext
* ctx
, GLboolean flag
)
1629 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1630 tfxUnitsState
*us
= &fxMesa
->unitsState
;
1632 if (flag
!= us
->depthMask
) {
1633 us
->depthMask
= flag
;
1634 fxMesa
->new_state
|= FX_NEW_DEPTH
;
1639 fxSetupDepthTest(GLcontext
* ctx
)
1641 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1642 tfxUnitsState
*us
= &fxMesa
->unitsState
;
1644 if (us
->depthTestEnabled
) {
1645 grDepthBufferFunction(us
->depthTestFunc
- GL_NEVER
+ GR_CMP_NEVER
);
1646 grDepthMask(us
->depthMask
);
1649 grDepthBufferFunction(GR_CMP_ALWAYS
);
1650 grDepthMask(FXFALSE
);
1654 /************************************************************************/
1655 /************************** Stencil SetUp *******************************/
1656 /************************************************************************/
1658 static GrStencil_t
convertGLStencilOp( GLenum op
)
1662 return GR_STENCILOP_KEEP
;
1664 return GR_STENCILOP_ZERO
;
1666 return GR_STENCILOP_REPLACE
;
1668 return GR_STENCILOP_INCR_CLAMP
;
1670 return GR_STENCILOP_DECR_CLAMP
;
1672 return GR_STENCILOP_INVERT
;
1673 case GL_INCR_WRAP_EXT
:
1674 return GR_STENCILOP_INCR_WRAP
;
1675 case GL_DECR_WRAP_EXT
:
1676 return GR_STENCILOP_DECR_WRAP
;
1678 _mesa_problem( NULL
, "bad stencil op in convertGLStencilOp" );
1680 return GR_STENCILOP_KEEP
; /* never get, silence compiler warning */
1684 fxDDStencilFuncSeparate (GLcontext
*ctx
, GLenum face
, GLenum func
,
1685 GLint ref
, GLuint mask
)
1687 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1688 tfxUnitsState
*us
= &fxMesa
->unitsState
;
1690 if (ctx
->Stencil
.ActiveFace
) {
1695 (us
->stencilFunction
!= func
)
1697 (us
->stencilRefValue
!= ref
)
1699 (us
->stencilValueMask
!= mask
)
1701 us
->stencilFunction
= func
;
1702 us
->stencilRefValue
= ref
;
1703 us
->stencilValueMask
= mask
;
1704 fxMesa
->new_state
|= FX_NEW_STENCIL
;
1709 fxDDStencilMaskSeparate (GLcontext
*ctx
, GLenum face
, GLuint mask
)
1711 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1712 tfxUnitsState
*us
= &fxMesa
->unitsState
;
1714 if (ctx
->Stencil
.ActiveFace
) {
1718 if (us
->stencilWriteMask
!= mask
) {
1719 us
->stencilWriteMask
= mask
;
1720 fxMesa
->new_state
|= FX_NEW_STENCIL
;
1725 fxDDStencilOpSeparate (GLcontext
*ctx
, GLenum face
, GLenum sfail
,
1726 GLenum zfail
, GLenum zpass
)
1728 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1729 tfxUnitsState
*us
= &fxMesa
->unitsState
;
1731 if (ctx
->Stencil
.ActiveFace
) {
1736 (us
->stencilFailFunc
!= sfail
)
1738 (us
->stencilZFailFunc
!= zfail
)
1740 (us
->stencilZPassFunc
!= zpass
)
1742 us
->stencilFailFunc
= sfail
;
1743 us
->stencilZFailFunc
= zfail
;
1744 us
->stencilZPassFunc
= zpass
;
1745 fxMesa
->new_state
|= FX_NEW_STENCIL
;
1750 fxSetupStencil (GLcontext
* ctx
)
1752 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1753 tfxUnitsState
*us
= &fxMesa
->unitsState
;
1755 if (us
->stencilEnabled
) {
1756 GrCmpFnc_t stencilFailFunc
= GR_STENCILOP_KEEP
;
1757 GrCmpFnc_t stencilZFailFunc
= GR_STENCILOP_KEEP
;
1758 GrCmpFnc_t stencilZPassFunc
= GR_STENCILOP_KEEP
;
1759 if (!fxMesa
->multipass
) {
1760 stencilFailFunc
= convertGLStencilOp(us
->stencilFailFunc
);
1761 stencilZFailFunc
= convertGLStencilOp(us
->stencilZFailFunc
);
1762 stencilZPassFunc
= convertGLStencilOp(us
->stencilZPassFunc
);
1764 grEnable(GR_STENCIL_MODE_EXT
);
1765 fxMesa
->Glide
.grStencilOpExt(stencilFailFunc
,
1768 fxMesa
->Glide
.grStencilFuncExt(us
->stencilFunction
- GL_NEVER
+ GR_CMP_NEVER
,
1769 us
->stencilRefValue
,
1770 us
->stencilValueMask
);
1771 fxMesa
->Glide
.grStencilMaskExt(us
->stencilWriteMask
);
1773 grDisable(GR_STENCIL_MODE_EXT
);
1778 fxSetupStencilFace (GLcontext
* ctx
, GLint face
)
1780 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1781 tfxUnitsState
*us
= &fxMesa
->unitsState
;
1783 if (us
->stencilEnabled
) {
1784 GrCmpFnc_t stencilFailFunc
= GR_STENCILOP_KEEP
;
1785 GrCmpFnc_t stencilZFailFunc
= GR_STENCILOP_KEEP
;
1786 GrCmpFnc_t stencilZPassFunc
= GR_STENCILOP_KEEP
;
1787 if (!fxMesa
->multipass
) {
1788 stencilFailFunc
= convertGLStencilOp(ctx
->Stencil
.FailFunc
[face
]);
1789 stencilZFailFunc
= convertGLStencilOp(ctx
->Stencil
.ZFailFunc
[face
]);
1790 stencilZPassFunc
= convertGLStencilOp(ctx
->Stencil
.ZPassFunc
[face
]);
1792 grEnable(GR_STENCIL_MODE_EXT
);
1793 fxMesa
->Glide
.grStencilOpExt(stencilFailFunc
,
1796 fxMesa
->Glide
.grStencilFuncExt(ctx
->Stencil
.Function
[face
] - GL_NEVER
+ GR_CMP_NEVER
,
1797 ctx
->Stencil
.Ref
[face
],
1798 ctx
->Stencil
.ValueMask
[face
]);
1799 fxMesa
->Glide
.grStencilMaskExt(ctx
->Stencil
.WriteMask
[face
]);
1801 grDisable(GR_STENCIL_MODE_EXT
);
1805 /************************************************************************/
1806 /**************************** Color Mask SetUp **************************/
1807 /************************************************************************/
1810 fxDDColorMask(GLcontext
* ctx
,
1811 GLboolean r
, GLboolean g
, GLboolean b
, GLboolean a
)
1813 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1814 fxMesa
->new_state
|= FX_NEW_COLOR_MASK
;
1822 fxSetupColorMask(GLcontext
* ctx
)
1824 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1826 if (fxMesa
->colDepth
== 32) {
1828 fxMesa
->Glide
.grColorMaskExt(ctx
->Color
.ColorMask
[RCOMP
],
1829 ctx
->Color
.ColorMask
[GCOMP
],
1830 ctx
->Color
.ColorMask
[BCOMP
],
1831 ctx
->Color
.ColorMask
[ACOMP
] && fxMesa
->haveHwAlpha
);
1834 /* 15/16 bpp mode */
1835 grColorMask(ctx
->Color
.ColorMask
[RCOMP
] |
1836 ctx
->Color
.ColorMask
[GCOMP
] |
1837 ctx
->Color
.ColorMask
[BCOMP
],
1838 ctx
->Color
.ColorMask
[ACOMP
] && fxMesa
->haveHwAlpha
);
1845 /************************************************************************/
1846 /**************************** Fog Mode SetUp ****************************/
1847 /************************************************************************/
1850 * This is called during state update in order to update the Glide fog state.
1853 fxSetupFog(GLcontext
* ctx
)
1855 if (ctx
->Fog
.Enabled
/*&& ctx->FogMode==FOG_FRAGMENT */ ) {
1856 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1858 /* update fog color */
1860 col
[0] = (unsigned int) (255 * ctx
->Fog
.Color
[0]);
1861 col
[1] = (unsigned int) (255 * ctx
->Fog
.Color
[1]);
1862 col
[2] = (unsigned int) (255 * ctx
->Fog
.Color
[2]);
1863 col
[3] = (unsigned int) (255 * ctx
->Fog
.Color
[3]);
1864 grFogColorValue(FXCOLOR4(col
));
1866 if (fxMesa
->fogTableMode
!= ctx
->Fog
.Mode
||
1867 fxMesa
->fogDensity
!= ctx
->Fog
.Density
||
1868 fxMesa
->fogStart
!= ctx
->Fog
.Start
||
1869 fxMesa
->fogEnd
!= ctx
->Fog
.End
) {
1870 /* reload the fog table */
1871 switch (ctx
->Fog
.Mode
) {
1873 guFogGenerateLinear(fxMesa
->fogTable
, ctx
->Fog
.Start
,
1875 if (fxMesa
->fogTable
[0] > 63) {
1876 /* [dBorca] Hack alert:
1877 * As per Glide3 Programming Guide:
1878 * The difference between consecutive fog values
1879 * must be less than 64.
1881 fxMesa
->fogTable
[0] = 63;
1885 guFogGenerateExp(fxMesa
->fogTable
, ctx
->Fog
.Density
);
1888 guFogGenerateExp2(fxMesa
->fogTable
, ctx
->Fog
.Density
);
1893 fxMesa
->fogTableMode
= ctx
->Fog
.Mode
;
1894 fxMesa
->fogDensity
= ctx
->Fog
.Density
;
1895 fxMesa
->fogStart
= ctx
->Fog
.Start
;
1896 fxMesa
->fogEnd
= ctx
->Fog
.End
;
1899 grFogTable(fxMesa
->fogTable
);
1900 if (ctx
->Fog
.FogCoordinateSource
== GL_FOG_COORDINATE_EXT
) {
1901 grVertexLayout(GR_PARAM_FOG_EXT
, GR_VERTEX_FOG_OFFSET
<< 2,
1903 grFogMode(GR_FOG_WITH_TABLE_ON_FOGCOORD_EXT
);
1905 grVertexLayout(GR_PARAM_FOG_EXT
, GR_VERTEX_FOG_OFFSET
<< 2,
1907 grFogMode(GR_FOG_WITH_TABLE_ON_Q
);
1911 grFogMode(GR_FOG_DISABLE
);
1916 fxDDFogfv(GLcontext
* ctx
, GLenum pname
, const GLfloat
* params
)
1918 FX_CONTEXT(ctx
)->new_state
|= FX_NEW_FOG
;
1920 case GL_FOG_COORDINATE_SOURCE_EXT
: {
1921 GLenum p
= (GLenum
)*params
;
1922 if (p
== GL_FOG_COORDINATE_EXT
) {
1923 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
1924 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
1925 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
1926 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
1928 _swrast_allow_vertex_fog(ctx
, GL_FALSE
);
1929 _swrast_allow_pixel_fog(ctx
, GL_TRUE
);
1930 _tnl_allow_vertex_fog( ctx
, GL_FALSE
);
1931 _tnl_allow_pixel_fog( ctx
, GL_TRUE
);
1940 /************************************************************************/
1941 /************************** Scissor Test SetUp **************************/
1942 /************************************************************************/
1944 /* This routine is used in managing the lock state, and therefore can't lock */
1946 fxSetScissorValues(GLcontext
* ctx
)
1948 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1952 if (ctx
->Scissor
.Enabled
) {
1953 xmin
= ctx
->Scissor
.X
;
1954 xmax
= ctx
->Scissor
.X
+ ctx
->Scissor
.Width
;
1955 ymin
= ctx
->Scissor
.Y
;
1956 ymax
= ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
;
1960 if (xmax
> fxMesa
->width
)
1961 xmax
= fxMesa
->width
;
1962 if (ymin
< fxMesa
->screen_height
- fxMesa
->height
)
1963 ymin
= fxMesa
->screen_height
- fxMesa
->height
;
1964 if (ymax
> fxMesa
->screen_height
- 0)
1965 ymax
= fxMesa
->screen_height
- 0;
1970 xmax
= fxMesa
->width
;
1971 ymax
= fxMesa
->height
;
1974 fxMesa
->clipMinX
= xmin
;
1975 fxMesa
->clipMinY
= ymin
;
1976 fxMesa
->clipMaxX
= xmax
;
1977 fxMesa
->clipMaxY
= ymax
;
1978 grClipWindow(xmin
, ymin
, xmax
, ymax
);
1982 fxSetupScissor(GLcontext
* ctx
)
1985 fxSetScissorValues(ctx
);
1990 fxDDScissor(GLcontext
* ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
1992 FX_CONTEXT(ctx
)->new_state
|= FX_NEW_SCISSOR
;
1995 /************************************************************************/
1996 /*************************** Cull mode setup ****************************/
1997 /************************************************************************/
2001 fxDDCullFace(GLcontext
* ctx
, GLenum mode
)
2004 FX_CONTEXT(ctx
)->new_state
|= FX_NEW_CULL
;
2008 fxDDFrontFace(GLcontext
* ctx
, GLenum mode
)
2011 FX_CONTEXT(ctx
)->new_state
|= FX_NEW_CULL
;
2016 fxSetupCull(GLcontext
* ctx
)
2018 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
2019 GrCullMode_t mode
= GR_CULL_DISABLE
;
2021 if (ctx
->Polygon
.CullFlag
&& (fxMesa
->raster_primitive
== GL_TRIANGLES
)) {
2022 switch (ctx
->Polygon
.CullFaceMode
) {
2024 if (ctx
->Polygon
.FrontFace
== GL_CCW
)
2025 mode
= GR_CULL_NEGATIVE
;
2027 mode
= GR_CULL_POSITIVE
;
2030 if (ctx
->Polygon
.FrontFace
== GL_CCW
)
2031 mode
= GR_CULL_POSITIVE
;
2033 mode
= GR_CULL_NEGATIVE
;
2035 case GL_FRONT_AND_BACK
:
2036 /* Handled as a fallback on triangles in tdfx_tris.c */
2044 if (fxMesa
->cullMode
!= mode
) {
2045 fxMesa
->cullMode
= mode
;
2051 /************************************************************************/
2052 /****************************** DD Enable ******************************/
2053 /************************************************************************/
2056 fxDDEnable(GLcontext
* ctx
, GLenum cap
, GLboolean state
)
2058 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
2059 tfxUnitsState
*us
= &fxMesa
->unitsState
;
2061 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
2062 fprintf(stderr
, "%s(%s)\n", state
? "fxDDEnable" : "fxDDDisable",
2063 _mesa_lookup_enum_by_nr(cap
));
2068 if (state
!= us
->alphaTestEnabled
) {
2069 us
->alphaTestEnabled
= state
;
2070 fxMesa
->new_state
|= FX_NEW_ALPHA
;
2074 if (state
!= us
->blendEnabled
) {
2075 us
->blendEnabled
= state
;
2076 fxMesa
->new_state
|= FX_NEW_BLEND
;
2080 if (state
!= us
->depthTestEnabled
) {
2081 us
->depthTestEnabled
= state
;
2082 fxMesa
->new_state
|= FX_NEW_DEPTH
;
2085 case GL_STENCIL_TEST
:
2086 if (fxMesa
->haveHwStencil
&& state
!= us
->stencilEnabled
) {
2087 us
->stencilEnabled
= state
;
2088 fxMesa
->new_state
|= FX_NEW_STENCIL
;
2093 grDitherMode(GR_DITHER_4x4
);
2096 grDitherMode(GR_DITHER_DISABLE
);
2099 case GL_SCISSOR_TEST
:
2100 fxMesa
->new_state
|= FX_NEW_SCISSOR
;
2102 case GL_SHARED_TEXTURE_PALETTE_EXT
:
2103 fxDDTexUseGlbPalette(ctx
, state
);
2106 fxMesa
->new_state
|= FX_NEW_FOG
;
2109 fxMesa
->new_state
|= FX_NEW_CULL
;
2111 case GL_LINE_SMOOTH
:
2112 case GL_LINE_STIPPLE
:
2113 case GL_POINT_SMOOTH
:
2114 case GL_POLYGON_SMOOTH
:
2117 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
2127 /************************************************************************/
2128 /************************** Changes to units state **********************/
2129 /************************************************************************/
2132 /* All units setup is handled under texture setup.
2135 fxDDShadeModel(GLcontext
* ctx
, GLenum mode
)
2137 FX_CONTEXT(ctx
)->new_state
|= FX_NEW_TEXTURING
;
2142 /************************************************************************/
2143 /****************************** Units SetUp *****************************/
2144 /************************************************************************/
2146 fx_print_state_flags(const char *msg
, GLuint flags
)
2149 "%s: (0x%x) %s%s%s%s%s%s%s%s\n",
2152 (flags
& FX_NEW_TEXTURING
) ? "texture, " : "",
2153 (flags
& FX_NEW_BLEND
) ? "blend, " : "",
2154 (flags
& FX_NEW_ALPHA
) ? "alpha, " : "",
2155 (flags
& FX_NEW_FOG
) ? "fog, " : "",
2156 (flags
& FX_NEW_SCISSOR
) ? "scissor, " : "",
2157 (flags
& FX_NEW_COLOR_MASK
) ? "colormask, " : "",
2158 (flags
& FX_NEW_CULL
) ? "cull, " : "",
2159 (flags
& FX_NEW_STENCIL
) ? "stencil, " : "");
2163 fxSetupFXUnits(GLcontext
* ctx
)
2165 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
2166 GLuint newstate
= fxMesa
->new_state
;
2168 if (TDFX_DEBUG
& VERBOSE_DRIVER
)
2169 fx_print_state_flags("fxSetupFXUnits", newstate
);
2172 if (newstate
& FX_NEW_TEXTURING
)
2173 fxSetupTexture(ctx
);
2175 if (newstate
& FX_NEW_BLEND
)
2178 if (newstate
& FX_NEW_ALPHA
)
2179 fxSetupAlphaTest(ctx
);
2181 if (newstate
& FX_NEW_DEPTH
)
2182 fxSetupDepthTest(ctx
);
2184 if (newstate
& FX_NEW_STENCIL
)
2185 fxSetupStencil(ctx
);
2187 if (newstate
& FX_NEW_FOG
)
2190 if (newstate
& FX_NEW_SCISSOR
)
2191 fxSetupScissor(ctx
);
2193 if (newstate
& FX_NEW_COLOR_MASK
)
2194 fxSetupColorMask(ctx
);
2196 if (newstate
& FX_NEW_CULL
)
2199 fxMesa
->new_state
= 0;
2209 * Need this to provide at least one external definition.
2212 extern int gl_fx_dummy_function_setup(void);
2214 gl_fx_dummy_function_setup(void)