1 /* $Id: fxsetup.c,v 1.38 2002/11/04 20:29:04 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 /* fxsetup.c - 3Dfx VooDoo rendering mode setup functions */
45 #include "tnl/t_context.h"
48 fxTexValidate(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
50 tfxTexInfo
*ti
= fxTMGetTexInfo(tObj
);
53 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
54 fprintf(stderr
, "fxmesa: fxTexValidate(...) Start\n");
58 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
60 "fxmesa: fxTexValidate(...) End (validated=GL_TRUE)\n");
66 minl
= ti
->minLevel
= tObj
->BaseLevel
;
67 maxl
= ti
->maxLevel
= MIN2(tObj
->MaxLevel
, tObj
->Image
[0]->MaxLog2
);
69 fxTexGetInfo(tObj
->Image
[minl
]->Width
, tObj
->Image
[minl
]->Height
,
70 &(FX_largeLodLog2(ti
->info
)), &(FX_aspectRatioLog2(ti
->info
)),
71 &(ti
->sScale
), &(ti
->tScale
),
72 &(ti
->int_sScale
), &(ti
->int_tScale
), NULL
, NULL
);
74 if ((tObj
->MinFilter
!= GL_NEAREST
) && (tObj
->MinFilter
!= GL_LINEAR
))
75 fxTexGetInfo(tObj
->Image
[maxl
]->Width
, tObj
->Image
[maxl
]->Height
,
76 &(FX_smallLodLog2(ti
->info
)), NULL
,
77 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
79 FX_smallLodLog2(ti
->info
) = FX_largeLodLog2(ti
->info
);
81 fxTexGetFormat(tObj
->Image
[minl
]->TexFormat
->BaseFormat
, &(ti
->info
.format
),
82 &(ti
->baseLevelInternalFormat
));
84 switch (tObj
->WrapS
) {
85 case GL_CLAMP_TO_EDGE
:
86 /* What's this really mean compared to GL_CLAMP? */
94 ; /* silence compiler warning */
96 switch (tObj
->WrapT
) {
97 case GL_CLAMP_TO_EDGE
:
98 /* What's this really mean compared to GL_CLAMP? */
106 ; /* silence compiler warning */
109 ti
->validated
= GL_TRUE
;
111 ti
->info
.data
= NULL
;
113 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
114 fprintf(stderr
, "fxmesa: fxTexValidate(...) End\n");
119 fxPrintUnitsMode(const char *msg
, GLuint mode
)
122 "%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",
125 (mode
& FX_UM_E0_REPLACE
) ? "E0_REPLACE, " : "",
126 (mode
& FX_UM_E0_MODULATE
) ? "E0_MODULATE, " : "",
127 (mode
& FX_UM_E0_DECAL
) ? "E0_DECAL, " : "",
128 (mode
& FX_UM_E0_BLEND
) ? "E0_BLEND, " : "",
129 (mode
& FX_UM_E1_REPLACE
) ? "E1_REPLACE, " : "",
130 (mode
& FX_UM_E1_MODULATE
) ? "E1_MODULATE, " : "",
131 (mode
& FX_UM_E1_DECAL
) ? "E1_DECAL, " : "",
132 (mode
& FX_UM_E1_BLEND
) ? "E1_BLEND, " : "",
133 (mode
& FX_UM_E0_ALPHA
) ? "E0_ALPHA, " : "",
134 (mode
& FX_UM_E0_LUMINANCE
) ? "E0_LUMINANCE, " : "",
135 (mode
& FX_UM_E0_LUMINANCE_ALPHA
) ? "E0_LUMINANCE_ALPHA, " : "",
136 (mode
& FX_UM_E0_INTENSITY
) ? "E0_INTENSITY, " : "",
137 (mode
& FX_UM_E0_RGB
) ? "E0_RGB, " : "",
138 (mode
& FX_UM_E0_RGBA
) ? "E0_RGBA, " : "",
139 (mode
& FX_UM_E1_ALPHA
) ? "E1_ALPHA, " : "",
140 (mode
& FX_UM_E1_LUMINANCE
) ? "E1_LUMINANCE, " : "",
141 (mode
& FX_UM_E1_LUMINANCE_ALPHA
) ? "E1_LUMINANCE_ALPHA, " : "",
142 (mode
& FX_UM_E1_INTENSITY
) ? "E1_INTENSITY, " : "",
143 (mode
& FX_UM_E1_RGB
) ? "E1_RGB, " : "",
144 (mode
& FX_UM_E1_RGBA
) ? "E1_RGBA, " : "",
145 (mode
& FX_UM_COLOR_ITERATED
) ? "COLOR_ITERATED, " : "",
146 (mode
& FX_UM_COLOR_CONSTANT
) ? "COLOR_CONSTANT, " : "",
147 (mode
& FX_UM_ALPHA_ITERATED
) ? "ALPHA_ITERATED, " : "",
148 (mode
& FX_UM_ALPHA_CONSTANT
) ? "ALPHA_CONSTANT, " : "");
152 fxGetTexSetConfiguration(GLcontext
* ctx
,
153 struct gl_texture_object
*tObj0
,
154 struct gl_texture_object
*tObj1
)
156 GLuint unitsmode
= 0;
160 if ((ctx
->Light
.ShadeModel
== GL_SMOOTH
) || 1 ||
161 (ctx
->Point
.SmoothFlag
) ||
162 (ctx
->Line
.SmoothFlag
) ||
163 (ctx
->Polygon
.SmoothFlag
)) unitsmode
|= FX_UM_ALPHA_ITERATED
;
165 unitsmode
|= FX_UM_ALPHA_CONSTANT
;
167 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
|| 1)
168 unitsmode
|= FX_UM_COLOR_ITERATED
;
170 unitsmode
|= FX_UM_COLOR_CONSTANT
;
175 OpenGL Feeds Texture 0 into Texture 1
176 Glide Feeds Texture 1 into Texture 0
179 tfxTexInfo
*ti0
= fxTMGetTexInfo(tObj0
);
181 switch (ti0
->baseLevelInternalFormat
) {
183 ifmt
|= FX_UM_E0_ALPHA
;
186 ifmt
|= FX_UM_E0_LUMINANCE
;
188 case GL_LUMINANCE_ALPHA
:
189 ifmt
|= FX_UM_E0_LUMINANCE_ALPHA
;
192 ifmt
|= FX_UM_E0_INTENSITY
;
195 ifmt
|= FX_UM_E0_RGB
;
198 ifmt
|= FX_UM_E0_RGBA
;
202 switch (ctx
->Texture
.Unit
[0].EnvMode
) {
204 envmode
|= FX_UM_E0_DECAL
;
207 envmode
|= FX_UM_E0_MODULATE
;
210 envmode
|= FX_UM_E0_REPLACE
;
213 envmode
|= FX_UM_E0_BLEND
;
216 envmode
|= FX_UM_E0_ADD
;
225 tfxTexInfo
*ti1
= fxTMGetTexInfo(tObj1
);
227 switch (ti1
->baseLevelInternalFormat
) {
229 ifmt
|= FX_UM_E1_ALPHA
;
232 ifmt
|= FX_UM_E1_LUMINANCE
;
234 case GL_LUMINANCE_ALPHA
:
235 ifmt
|= FX_UM_E1_LUMINANCE_ALPHA
;
238 ifmt
|= FX_UM_E1_INTENSITY
;
241 ifmt
|= FX_UM_E1_RGB
;
244 ifmt
|= FX_UM_E1_RGBA
;
251 switch (ctx
->Texture
.Unit
[1].EnvMode
) {
253 envmode
|= FX_UM_E1_DECAL
;
256 envmode
|= FX_UM_E1_MODULATE
;
259 envmode
|= FX_UM_E1_REPLACE
;
262 envmode
|= FX_UM_E1_BLEND
;
265 envmode
|= FX_UM_E1_ADD
;
273 unitsmode
|= (ifmt
| envmode
);
275 if (MESA_VERBOSE
& (VERBOSE_DRIVER
| VERBOSE_TEXTURE
))
276 fxPrintUnitsMode("unitsmode", unitsmode
);
281 /************************************************************************/
282 /************************* Rendering Mode SetUp *************************/
283 /************************************************************************/
285 /************************* Single Texture Set ***************************/
288 fxSetupSingleTMU_NoLock(fxMesaContext fxMesa
, struct gl_texture_object
*tObj
)
290 tfxTexInfo
*ti
= fxTMGetTexInfo(tObj
);
293 /* Make sure we're not loaded incorrectly */
296 if (ti
->whichTMU
!= FX_TMU_SPLIT
)
297 fxTMMoveOutTM(fxMesa
, tObj
);
300 if (ti
->whichTMU
== FX_TMU_SPLIT
)
301 fxTMMoveOutTM(fxMesa
, tObj
);
305 /* Make sure we're loaded correctly */
308 fxTMMoveInTM_NoLock(fxMesa
, tObj
, FX_TMU_SPLIT
);
310 if (fxMesa
->haveTwoTMUs
) {
311 if (fxMesa
->freeTexMem
[FX_TMU0
] >
312 FX_grTexTextureMemRequired_NoLock(GR_MIPMAPLEVELMASK_BOTH
,
314 fxTMMoveInTM_NoLock(fxMesa
, tObj
, FX_TMU0
);
317 fxTMMoveInTM_NoLock(fxMesa
, tObj
, FX_TMU1
);
321 fxTMMoveInTM_NoLock(fxMesa
, tObj
, FX_TMU0
);
325 if (ti
->LODblend
&& ti
->whichTMU
== FX_TMU_SPLIT
) {
326 if ((ti
->info
.format
== GR_TEXFMT_P_8
)
327 && (!fxMesa
->haveGlobalPaletteTexture
)) {
328 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
329 fprintf(stderr
, "fxmesa: uploading texture palette\n");
331 FX_grTexDownloadTable_NoLock(GR_TMU0
, GR_TEXTABLE_PALETTE
,
333 FX_grTexDownloadTable_NoLock(GR_TMU1
, GR_TEXTABLE_PALETTE
,
337 FX_grTexClampMode_NoLock(GR_TMU0
, ti
->sClamp
, ti
->tClamp
);
338 FX_grTexClampMode_NoLock(GR_TMU1
, ti
->sClamp
, ti
->tClamp
);
339 FX_grTexFilterMode_NoLock(GR_TMU0
, ti
->minFilt
, ti
->maxFilt
);
340 FX_grTexFilterMode_NoLock(GR_TMU1
, ti
->minFilt
, ti
->maxFilt
);
341 FX_grTexMipMapMode_NoLock(GR_TMU0
, ti
->mmMode
, ti
->LODblend
);
342 FX_grTexMipMapMode_NoLock(GR_TMU1
, ti
->mmMode
, ti
->LODblend
);
344 FX_grTexSource_NoLock(GR_TMU0
, ti
->tm
[FX_TMU0
]->startAddr
,
345 GR_MIPMAPLEVELMASK_ODD
, &(ti
->info
));
346 FX_grTexSource_NoLock(GR_TMU1
, ti
->tm
[FX_TMU1
]->startAddr
,
347 GR_MIPMAPLEVELMASK_EVEN
, &(ti
->info
));
350 if (ti
->whichTMU
== FX_TMU_BOTH
)
355 if ((ti
->info
.format
== GR_TEXFMT_P_8
)
356 && (!fxMesa
->haveGlobalPaletteTexture
)) {
357 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
358 fprintf(stderr
, "fxmesa: uploading texture palette\n");
360 FX_grTexDownloadTable_NoLock(tmu
, GR_TEXTABLE_PALETTE
,
364 /* KW: The alternative is to do the download to the other tmu. If
365 * we get to this point, I think it means we are thrashing the
366 * texture memory, so perhaps it's not a good idea.
368 if (ti
->LODblend
&& (MESA_VERBOSE
& VERBOSE_DRIVER
))
369 fprintf(stderr
, "fxmesa: not blending texture - only on one tmu\n");
371 FX_grTexClampMode_NoLock(tmu
, ti
->sClamp
, ti
->tClamp
);
372 FX_grTexFilterMode_NoLock(tmu
, ti
->minFilt
, ti
->maxFilt
);
373 FX_grTexMipMapMode_NoLock(tmu
, ti
->mmMode
, FXFALSE
);
375 FX_grTexSource_NoLock(tmu
, ti
->tm
[tmu
]->startAddr
,
376 GR_MIPMAPLEVELMASK_BOTH
, &(ti
->info
));
381 fxSelectSingleTMUSrc_NoLock(fxMesaContext fxMesa
, GLint tmu
, FxBool LODblend
)
383 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
384 fprintf(stderr
, "fxmesa: fxSelectSingleTMUSrc(%d,%d)\n", tmu
, LODblend
);
388 FX_grTexCombine_NoLock(GR_TMU0
,
389 GR_COMBINE_FUNCTION_BLEND
,
390 GR_COMBINE_FACTOR_ONE_MINUS_LOD_FRACTION
,
391 GR_COMBINE_FUNCTION_BLEND
,
392 GR_COMBINE_FACTOR_ONE_MINUS_LOD_FRACTION
,
395 if (fxMesa
->haveTwoTMUs
)
396 FX_grTexCombine_NoLock(GR_TMU1
,
397 GR_COMBINE_FUNCTION_LOCAL
,
398 GR_COMBINE_FACTOR_NONE
,
399 GR_COMBINE_FUNCTION_LOCAL
,
400 GR_COMBINE_FACTOR_NONE
, FXFALSE
, FXFALSE
);
401 fxMesa
->tmuSrc
= FX_TMU_SPLIT
;
404 if (tmu
!= FX_TMU1
) {
405 FX_grTexCombine_NoLock(GR_TMU0
,
406 GR_COMBINE_FUNCTION_LOCAL
,
407 GR_COMBINE_FACTOR_NONE
,
408 GR_COMBINE_FUNCTION_LOCAL
,
409 GR_COMBINE_FACTOR_NONE
, FXFALSE
, FXFALSE
);
410 if (fxMesa
->haveTwoTMUs
) {
411 FX_grTexCombine_NoLock(GR_TMU1
,
412 GR_COMBINE_FUNCTION_ZERO
,
413 GR_COMBINE_FACTOR_NONE
,
414 GR_COMBINE_FUNCTION_ZERO
,
415 GR_COMBINE_FACTOR_NONE
, FXFALSE
, FXFALSE
);
417 fxMesa
->tmuSrc
= FX_TMU0
;
420 FX_grTexCombine_NoLock(GR_TMU1
,
421 GR_COMBINE_FUNCTION_LOCAL
,
422 GR_COMBINE_FACTOR_NONE
,
423 GR_COMBINE_FUNCTION_LOCAL
,
424 GR_COMBINE_FACTOR_NONE
, FXFALSE
, FXFALSE
);
426 /* GR_COMBINE_FUNCTION_SCALE_OTHER doesn't work ?!? */
428 FX_grTexCombine_NoLock(GR_TMU0
,
429 GR_COMBINE_FUNCTION_BLEND
,
430 GR_COMBINE_FACTOR_ONE
,
431 GR_COMBINE_FUNCTION_BLEND
,
432 GR_COMBINE_FACTOR_ONE
, FXFALSE
, FXFALSE
);
434 fxMesa
->tmuSrc
= FX_TMU1
;
440 fxSetupTextureSingleTMU_NoLock(GLcontext
* ctx
, GLuint textureset
)
442 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
443 GrCombineLocal_t localc
, locala
;
447 struct gl_texture_object
*tObj
= ctx
->Texture
.Unit
[textureset
].Current2D
;
450 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
451 fprintf(stderr
, "fxmesa: fxSetupTextureSingleTMU(...) Start\n");
454 ti
= fxTMGetTexInfo(tObj
);
456 fxTexValidate(ctx
, tObj
);
458 fxSetupSingleTMU_NoLock(fxMesa
, tObj
);
460 if (ti
->whichTMU
== FX_TMU_BOTH
)
464 if (fxMesa
->tmuSrc
!= tmu
)
465 fxSelectSingleTMUSrc_NoLock(fxMesa
, tmu
, ti
->LODblend
);
467 if (textureset
== 0 || !fxMesa
->haveTwoTMUs
)
468 unitsmode
= fxGetTexSetConfiguration(ctx
, tObj
, NULL
);
470 unitsmode
= fxGetTexSetConfiguration(ctx
, NULL
, tObj
);
472 /* if(fxMesa->lastUnitsMode==unitsmode) */
475 fxMesa
->lastUnitsMode
= unitsmode
;
477 fxMesa
->stw_hint_state
= 0;
478 FX_grHints_NoLock(GR_HINT_STWHINT
, 0);
480 ifmt
= ti
->baseLevelInternalFormat
;
482 if (unitsmode
& FX_UM_ALPHA_ITERATED
)
483 locala
= GR_COMBINE_LOCAL_ITERATED
;
485 locala
= GR_COMBINE_LOCAL_CONSTANT
;
487 if (unitsmode
& FX_UM_COLOR_ITERATED
)
488 localc
= GR_COMBINE_LOCAL_ITERATED
;
490 localc
= GR_COMBINE_LOCAL_CONSTANT
;
492 if (MESA_VERBOSE
& (VERBOSE_DRIVER
| VERBOSE_TEXTURE
))
493 fprintf(stderr
, "fxMesa: fxSetupTextureSingleTMU, envmode is %s\n",
494 _mesa_lookup_enum_by_nr(ctx
->Texture
.Unit
[textureset
].EnvMode
));
496 switch (ctx
->Texture
.Unit
[textureset
].EnvMode
) {
498 FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL
,
499 GR_COMBINE_FACTOR_NONE
,
500 locala
, GR_COMBINE_OTHER_NONE
, FXFALSE
);
502 FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_BLEND
,
503 GR_COMBINE_FACTOR_TEXTURE_ALPHA
,
504 localc
, GR_COMBINE_OTHER_TEXTURE
, FXFALSE
);
507 FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER
,
508 GR_COMBINE_FACTOR_LOCAL
,
509 locala
, GR_COMBINE_OTHER_TEXTURE
, FXFALSE
);
511 if (ifmt
== GL_ALPHA
)
512 FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL
,
513 GR_COMBINE_FACTOR_NONE
,
514 localc
, GR_COMBINE_OTHER_NONE
, FXFALSE
);
516 FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER
,
517 GR_COMBINE_FACTOR_LOCAL
,
518 localc
, GR_COMBINE_OTHER_TEXTURE
, FXFALSE
);
521 if (MESA_VERBOSE
& VERBOSE_DRIVER
)
522 fprintf(stderr
, "fx Driver: GL_BLEND not yet supported\n");
525 if ((ifmt
== GL_RGB
) || (ifmt
== GL_LUMINANCE
))
526 FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL
,
527 GR_COMBINE_FACTOR_NONE
,
528 locala
, GR_COMBINE_OTHER_NONE
, FXFALSE
);
530 FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER
,
531 GR_COMBINE_FACTOR_ONE
,
532 locala
, GR_COMBINE_OTHER_TEXTURE
, FXFALSE
);
534 if (ifmt
== GL_ALPHA
)
535 FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL
,
536 GR_COMBINE_FACTOR_NONE
,
537 localc
, GR_COMBINE_OTHER_NONE
, FXFALSE
);
539 FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER
,
540 GR_COMBINE_FACTOR_ONE
,
541 localc
, GR_COMBINE_OTHER_TEXTURE
, FXFALSE
);
544 if (MESA_VERBOSE
& VERBOSE_DRIVER
)
545 fprintf(stderr
, "fx Driver: %x Texture.EnvMode not yet supported\n",
546 ctx
->Texture
.Unit
[textureset
].EnvMode
);
550 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
551 fprintf(stderr
, "fxmesa: fxSetupTextureSingleTMU(...) End\n");
557 fxSetupTextureSingleTMU(GLcontext
* ctx
, GLuint textureset
)
560 fxSetupTextureSingleTMU_NoLock(ctx
, textureset
);
566 /************************* Double Texture Set ***************************/
569 fxSetupDoubleTMU_NoLock(fxMesaContext fxMesa
,
570 struct gl_texture_object
*tObj0
,
571 struct gl_texture_object
*tObj1
)
573 #define T0_NOT_IN_TMU 0x01
574 #define T1_NOT_IN_TMU 0x02
575 #define T0_IN_TMU0 0x04
576 #define T1_IN_TMU0 0x08
577 #define T0_IN_TMU1 0x10
578 #define T1_IN_TMU1 0x20
580 tfxTexInfo
*ti0
= fxTMGetTexInfo(tObj0
);
581 tfxTexInfo
*ti1
= fxTMGetTexInfo(tObj1
);
583 int tmu0
= 0, tmu1
= 1;
585 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
586 fprintf(stderr
, "fxmesa: fxSetupDoubleTMU(...)\n");
589 /* We shouldn't need to do this. There is something wrong with
590 mutlitexturing when the TMUs are swapped. So, we're forcing
591 them to always be loaded correctly. !!! */
592 if (ti0
->whichTMU
== FX_TMU1
)
593 fxTMMoveOutTM_NoLock(fxMesa
, tObj0
);
594 if (ti1
->whichTMU
== FX_TMU0
)
595 fxTMMoveOutTM_NoLock(fxMesa
, tObj1
);
598 switch (ti0
->whichTMU
) {
600 tstate
|= T0_IN_TMU0
;
603 tstate
|= T0_IN_TMU1
;
606 tstate
|= T0_IN_TMU0
| T0_IN_TMU1
;
609 tstate
|= T0_NOT_IN_TMU
;
614 tstate
|= T0_NOT_IN_TMU
;
617 switch (ti1
->whichTMU
) {
619 tstate
|= T1_IN_TMU0
;
622 tstate
|= T1_IN_TMU1
;
625 tstate
|= T1_IN_TMU0
| T1_IN_TMU1
;
628 tstate
|= T1_NOT_IN_TMU
;
633 tstate
|= T1_NOT_IN_TMU
;
635 ti0
->lastTimeUsed
= fxMesa
->texBindNumber
;
636 ti1
->lastTimeUsed
= fxMesa
->texBindNumber
;
638 /* Move texture maps into TMUs */
640 if (!(((tstate
& T0_IN_TMU0
) && (tstate
& T1_IN_TMU1
)) ||
641 ((tstate
& T0_IN_TMU1
) && (tstate
& T1_IN_TMU0
)))) {
643 fxTMMoveInTM_NoLock(fxMesa
, tObj1
, FX_TMU_BOTH
);
645 /* Find the minimal way to correct the situation */
646 if ((tstate
& T0_IN_TMU0
) || (tstate
& T1_IN_TMU1
)) {
647 /* We have one in the standard order, setup the other */
648 if (tstate
& T0_IN_TMU0
) { /* T0 is in TMU0, put T1 in TMU1 */
649 fxTMMoveInTM_NoLock(fxMesa
, tObj1
, FX_TMU1
);
652 fxTMMoveInTM_NoLock(fxMesa
, tObj0
, FX_TMU0
);
654 /* tmu0 and tmu1 are setup */
656 else if ((tstate
& T0_IN_TMU1
) || (tstate
& T1_IN_TMU0
)) {
657 /* we have one in the reverse order, setup the other */
658 if (tstate
& T1_IN_TMU0
) { /* T1 is in TMU0, put T0 in TMU1 */
659 fxTMMoveInTM_NoLock(fxMesa
, tObj0
, FX_TMU1
);
662 fxTMMoveInTM_NoLock(fxMesa
, tObj1
, FX_TMU0
);
667 else { /* Nothing is loaded */
668 fxTMMoveInTM_NoLock(fxMesa
, tObj0
, FX_TMU0
);
669 fxTMMoveInTM_NoLock(fxMesa
, tObj1
, FX_TMU1
);
670 /* tmu0 and tmu1 are setup */
675 if (!fxMesa
->haveGlobalPaletteTexture
) {
676 if (ti0
->info
.format
== GR_TEXFMT_P_8
) {
677 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
678 fprintf(stderr
, "fxmesa: uploading texture palette TMU0\n");
680 FX_grTexDownloadTable_NoLock(tmu0
, GR_TEXTABLE_PALETTE
,
684 if (ti1
->info
.format
== GR_TEXFMT_P_8
) {
685 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
686 fprintf(stderr
, "fxmesa: uploading texture palette TMU1\n");
688 FX_grTexDownloadTable_NoLock(tmu1
, GR_TEXTABLE_PALETTE
,
693 FX_grTexSource_NoLock(tmu0
, ti0
->tm
[tmu0
]->startAddr
,
694 GR_MIPMAPLEVELMASK_BOTH
, &(ti0
->info
));
695 FX_grTexClampMode_NoLock(tmu0
, ti0
->sClamp
, ti0
->tClamp
);
696 FX_grTexFilterMode_NoLock(tmu0
, ti0
->minFilt
, ti0
->maxFilt
);
697 FX_grTexMipMapMode_NoLock(tmu0
, ti0
->mmMode
, FXFALSE
);
699 FX_grTexSource_NoLock(tmu1
, ti1
->tm
[tmu1
]->startAddr
,
700 GR_MIPMAPLEVELMASK_BOTH
, &(ti1
->info
));
701 FX_grTexClampMode_NoLock(tmu1
, ti1
->sClamp
, ti1
->tClamp
);
702 FX_grTexFilterMode_NoLock(tmu1
, ti1
->minFilt
, ti1
->maxFilt
);
703 FX_grTexMipMapMode_NoLock(tmu1
, ti1
->mmMode
, FXFALSE
);
714 fxSetupTextureDoubleTMU_NoLock(GLcontext
* ctx
)
716 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
717 GrCombineLocal_t localc
, locala
;
718 tfxTexInfo
*ti0
, *ti1
;
719 struct gl_texture_object
*tObj0
= ctx
->Texture
.Unit
[0].Current2D
;
720 struct gl_texture_object
*tObj1
= ctx
->Texture
.Unit
[1].Current2D
;
721 GLuint envmode
, ifmt
, unitsmode
;
722 int tmu0
= 0, tmu1
= 1;
724 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
725 fprintf(stderr
, "fxmesa: fxSetupTextureDoubleTMU(...) Start\n");
728 ti0
= fxTMGetTexInfo(tObj0
);
729 fxTexValidate(ctx
, tObj0
);
731 ti1
= fxTMGetTexInfo(tObj1
);
732 fxTexValidate(ctx
, tObj1
);
734 fxSetupDoubleTMU_NoLock(fxMesa
, tObj0
, tObj1
);
736 unitsmode
= fxGetTexSetConfiguration(ctx
, tObj0
, tObj1
);
738 /* if(fxMesa->lastUnitsMode==unitsmode) */
741 fxMesa
->lastUnitsMode
= unitsmode
;
743 fxMesa
->stw_hint_state
|= GR_STWHINT_ST_DIFF_TMU1
;
744 FX_grHints_NoLock(GR_HINT_STWHINT
, fxMesa
->stw_hint_state
);
746 envmode
= unitsmode
& FX_UM_E_ENVMODE
;
747 ifmt
= unitsmode
& FX_UM_E_IFMT
;
749 if (unitsmode
& FX_UM_ALPHA_ITERATED
)
750 locala
= GR_COMBINE_LOCAL_ITERATED
;
752 locala
= GR_COMBINE_LOCAL_CONSTANT
;
754 if (unitsmode
& FX_UM_COLOR_ITERATED
)
755 localc
= GR_COMBINE_LOCAL_ITERATED
;
757 localc
= GR_COMBINE_LOCAL_CONSTANT
;
760 if (MESA_VERBOSE
& (VERBOSE_DRIVER
| VERBOSE_TEXTURE
))
761 fprintf(stderr
, "fxMesa: fxSetupTextureDoubleTMU, envmode is %s/%s\n",
762 _mesa_lookup_enum_by_nr(ctx
->Texture
.Unit
[0].EnvMode
),
763 _mesa_lookup_enum_by_nr(ctx
->Texture
.Unit
[1].EnvMode
));
766 if ((ti0
->whichTMU
== FX_TMU1
) || (ti1
->whichTMU
== FX_TMU0
)) {
770 fxMesa
->tmuSrc
= FX_TMU_BOTH
;
772 case (FX_UM_E0_MODULATE
| FX_UM_E1_MODULATE
):
774 GLboolean isalpha
[FX_NUM_TMU
];
776 if (ti0
->baseLevelInternalFormat
== GL_ALPHA
)
777 isalpha
[tmu0
] = GL_TRUE
;
779 isalpha
[tmu0
] = GL_FALSE
;
781 if (ti1
->baseLevelInternalFormat
== GL_ALPHA
)
782 isalpha
[tmu1
] = GL_TRUE
;
784 isalpha
[tmu1
] = GL_FALSE
;
786 if (isalpha
[FX_TMU1
])
787 FX_grTexCombine_NoLock(GR_TMU1
,
788 GR_COMBINE_FUNCTION_ZERO
,
789 GR_COMBINE_FACTOR_NONE
,
790 GR_COMBINE_FUNCTION_LOCAL
,
791 GR_COMBINE_FACTOR_NONE
, FXTRUE
, FXFALSE
);
793 FX_grTexCombine_NoLock(GR_TMU1
,
794 GR_COMBINE_FUNCTION_LOCAL
,
795 GR_COMBINE_FACTOR_NONE
,
796 GR_COMBINE_FUNCTION_LOCAL
,
797 GR_COMBINE_FACTOR_NONE
, FXFALSE
, FXFALSE
);
799 if (isalpha
[FX_TMU0
])
800 FX_grTexCombine_NoLock(GR_TMU0
,
801 GR_COMBINE_FUNCTION_BLEND_OTHER
,
802 GR_COMBINE_FACTOR_ONE
,
803 GR_COMBINE_FUNCTION_BLEND_OTHER
,
804 GR_COMBINE_FACTOR_LOCAL
, FXFALSE
, FXFALSE
);
806 FX_grTexCombine_NoLock(GR_TMU0
,
807 GR_COMBINE_FUNCTION_BLEND_OTHER
,
808 GR_COMBINE_FACTOR_LOCAL
,
809 GR_COMBINE_FUNCTION_BLEND_OTHER
,
810 GR_COMBINE_FACTOR_LOCAL
, FXFALSE
, FXFALSE
);
812 FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER
,
813 GR_COMBINE_FACTOR_LOCAL
,
814 localc
, GR_COMBINE_OTHER_TEXTURE
, FXFALSE
);
816 FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER
,
817 GR_COMBINE_FACTOR_LOCAL
,
818 locala
, GR_COMBINE_OTHER_TEXTURE
, FXFALSE
);
821 case (FX_UM_E0_REPLACE
| FX_UM_E1_BLEND
): /* Only for GLQuake */
822 if (tmu1
== FX_TMU1
) {
823 FX_grTexCombine_NoLock(GR_TMU1
,
824 GR_COMBINE_FUNCTION_LOCAL
,
825 GR_COMBINE_FACTOR_NONE
,
826 GR_COMBINE_FUNCTION_LOCAL
,
827 GR_COMBINE_FACTOR_NONE
, FXTRUE
, FXFALSE
);
829 FX_grTexCombine_NoLock(GR_TMU0
,
830 GR_COMBINE_FUNCTION_BLEND_OTHER
,
831 GR_COMBINE_FACTOR_LOCAL
,
832 GR_COMBINE_FUNCTION_BLEND_OTHER
,
833 GR_COMBINE_FACTOR_LOCAL
, FXFALSE
, FXFALSE
);
836 FX_grTexCombine_NoLock(GR_TMU1
,
837 GR_COMBINE_FUNCTION_LOCAL
,
838 GR_COMBINE_FACTOR_NONE
,
839 GR_COMBINE_FUNCTION_LOCAL
,
840 GR_COMBINE_FACTOR_NONE
, FXFALSE
, FXFALSE
);
842 FX_grTexCombine_NoLock(GR_TMU0
,
843 GR_COMBINE_FUNCTION_BLEND_OTHER
,
844 GR_COMBINE_FACTOR_ONE_MINUS_LOCAL
,
845 GR_COMBINE_FUNCTION_BLEND_OTHER
,
846 GR_COMBINE_FACTOR_ONE_MINUS_LOCAL
,
850 FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL
,
851 GR_COMBINE_FACTOR_NONE
,
852 locala
, GR_COMBINE_OTHER_NONE
, FXFALSE
);
854 FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER
,
855 GR_COMBINE_FACTOR_ONE
,
856 localc
, GR_COMBINE_OTHER_TEXTURE
, FXFALSE
);
858 case (FX_UM_E0_REPLACE
| FX_UM_E1_MODULATE
): /* Quake 2 and 3 */
859 if (tmu1
== FX_TMU1
) {
860 FX_grTexCombine_NoLock(GR_TMU1
,
861 GR_COMBINE_FUNCTION_LOCAL
,
862 GR_COMBINE_FACTOR_NONE
,
863 GR_COMBINE_FUNCTION_ZERO
,
864 GR_COMBINE_FACTOR_NONE
, FXFALSE
, FXTRUE
);
866 FX_grTexCombine_NoLock(GR_TMU0
,
867 GR_COMBINE_FUNCTION_BLEND_OTHER
,
868 GR_COMBINE_FACTOR_LOCAL
,
869 GR_COMBINE_FUNCTION_BLEND_OTHER
,
870 GR_COMBINE_FACTOR_LOCAL
, FXFALSE
, FXFALSE
);
874 FX_grTexCombine_NoLock(GR_TMU1
,
875 GR_COMBINE_FUNCTION_LOCAL
,
876 GR_COMBINE_FACTOR_NONE
,
877 GR_COMBINE_FUNCTION_LOCAL
,
878 GR_COMBINE_FACTOR_NONE
, FXFALSE
, FXFALSE
);
880 FX_grTexCombine_NoLock(GR_TMU0
,
881 GR_COMBINE_FUNCTION_BLEND_OTHER
,
882 GR_COMBINE_FACTOR_LOCAL
,
883 GR_COMBINE_FUNCTION_BLEND_OTHER
,
884 GR_COMBINE_FACTOR_ONE
, FXFALSE
, FXFALSE
);
887 if (ti0
->baseLevelInternalFormat
== GL_RGB
)
888 FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL
,
889 GR_COMBINE_FACTOR_NONE
,
890 locala
, GR_COMBINE_OTHER_NONE
, FXFALSE
);
892 FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER
,
893 GR_COMBINE_FACTOR_ONE
,
894 locala
, GR_COMBINE_OTHER_NONE
, FXFALSE
);
897 FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER
,
898 GR_COMBINE_FACTOR_ONE
,
899 localc
, GR_COMBINE_OTHER_TEXTURE
, FXFALSE
);
903 case (FX_UM_E0_MODULATE
| FX_UM_E1_ADD
): /* Quake 3 Sky */
905 GLboolean isalpha
[FX_NUM_TMU
];
907 if (ti0
->baseLevelInternalFormat
== GL_ALPHA
)
908 isalpha
[tmu0
] = GL_TRUE
;
910 isalpha
[tmu0
] = GL_FALSE
;
912 if (ti1
->baseLevelInternalFormat
== GL_ALPHA
)
913 isalpha
[tmu1
] = GL_TRUE
;
915 isalpha
[tmu1
] = GL_FALSE
;
917 if (isalpha
[FX_TMU1
])
918 FX_grTexCombine_NoLock(GR_TMU1
,
919 GR_COMBINE_FUNCTION_ZERO
,
920 GR_COMBINE_FACTOR_NONE
,
921 GR_COMBINE_FUNCTION_LOCAL
,
922 GR_COMBINE_FACTOR_NONE
, FXTRUE
, FXFALSE
);
924 FX_grTexCombine_NoLock(GR_TMU1
,
925 GR_COMBINE_FUNCTION_LOCAL
,
926 GR_COMBINE_FACTOR_NONE
,
927 GR_COMBINE_FUNCTION_LOCAL
,
928 GR_COMBINE_FACTOR_NONE
, FXFALSE
, FXFALSE
);
930 if (isalpha
[FX_TMU0
])
931 FX_grTexCombine_NoLock(GR_TMU0
,
932 GR_COMBINE_FUNCTION_SCALE_OTHER
,
933 GR_COMBINE_FACTOR_ONE
,
934 GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL
,
935 GR_COMBINE_FACTOR_ONE
, FXFALSE
, FXFALSE
);
937 FX_grTexCombine_NoLock(GR_TMU0
,
938 GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL
,
939 GR_COMBINE_FACTOR_ONE
,
940 GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL
,
941 GR_COMBINE_FACTOR_ONE
, FXFALSE
, FXFALSE
);
943 FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER
,
944 GR_COMBINE_FACTOR_LOCAL
,
945 localc
, GR_COMBINE_OTHER_TEXTURE
, FXFALSE
);
947 FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER
,
948 GR_COMBINE_FACTOR_LOCAL
,
949 locala
, GR_COMBINE_OTHER_TEXTURE
, FXFALSE
);
953 fprintf(stderr
, "Unexpected dual texture mode encountered\n");
957 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
958 fprintf(stderr
, "fxmesa: fxSetupTextureDoubleTMU(...) End\n");
962 /************************* No Texture ***************************/
965 fxSetupTextureNone_NoLock(GLcontext
* ctx
)
967 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
968 GrCombineLocal_t localc
, locala
;
970 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
971 fprintf(stderr
, "fxmesa: fxSetupTextureNone(...)\n");
974 if ((ctx
->Light
.ShadeModel
== GL_SMOOTH
) || 1 ||
975 (ctx
->Point
.SmoothFlag
) ||
976 (ctx
->Line
.SmoothFlag
) ||
977 (ctx
->Polygon
.SmoothFlag
)) locala
= GR_COMBINE_LOCAL_ITERATED
;
979 locala
= GR_COMBINE_LOCAL_CONSTANT
;
981 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
|| 1)
982 localc
= GR_COMBINE_LOCAL_ITERATED
;
984 localc
= GR_COMBINE_LOCAL_CONSTANT
;
986 FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL
,
987 GR_COMBINE_FACTOR_NONE
,
988 locala
, GR_COMBINE_OTHER_NONE
, FXFALSE
);
990 FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL
,
991 GR_COMBINE_FACTOR_NONE
,
992 localc
, GR_COMBINE_OTHER_NONE
, FXFALSE
);
994 fxMesa
->lastUnitsMode
= FX_UM_NONE
;
997 /************************************************************************/
998 /************************** Texture Mode SetUp **************************/
999 /************************************************************************/
1002 fxSetupTexture_NoLock(GLcontext
* ctx
)
1004 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
1006 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
1007 fprintf(stderr
, "fxmesa: fxSetupTexture(...)\n");
1010 /* Texture Combine, Color Combine and Alpha Combine. */
1011 if (ctx
->Texture
.Unit
[0]._ReallyEnabled
== TEXTURE_2D_BIT
&&
1012 ctx
->Texture
.Unit
[1]._ReallyEnabled
== TEXTURE_2D_BIT
&&
1013 fxMesa
->haveTwoTMUs
) {
1014 fxSetupTextureDoubleTMU_NoLock(ctx
);
1016 else if (ctx
->Texture
.Unit
[0]._ReallyEnabled
== TEXTURE_2D_BIT
) {
1017 fxSetupTextureSingleTMU_NoLock(ctx
, 0);
1019 else if (ctx
->Texture
.Unit
[1]._ReallyEnabled
== TEXTURE_2D_BIT
) {
1020 fxSetupTextureSingleTMU_NoLock(ctx
, 1);
1023 fxSetupTextureNone_NoLock(ctx
);
1028 fxSetupTexture(GLcontext
* ctx
)
1031 fxSetupTexture_NoLock(ctx
);
1035 /************************************************************************/
1036 /**************************** Blend SetUp *******************************/
1037 /************************************************************************/
1039 /* XXX consider supporting GL_INGR_blend_func_separate */
1041 fxDDBlendFunc(GLcontext
* ctx
, GLenum sfactor
, GLenum dfactor
)
1043 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
1044 tfxUnitsState
*us
= &fxMesa
->unitsState
;
1045 GrAlphaBlendFnc_t sfact
, dfact
, asfact
, adfact
;
1047 /* From the Glide documentation:
1048 For alpha source and destination blend function factor
1049 parameters, Voodoo Graphics supports only
1050 GR_BLEND_ZERO and GR_BLEND_ONE.
1055 asfact
= sfact
= GR_BLEND_ZERO
;
1058 asfact
= sfact
= GR_BLEND_ONE
;
1061 sfact
= GR_BLEND_DST_COLOR
;
1062 asfact
= GR_BLEND_ONE
;
1064 case GL_ONE_MINUS_DST_COLOR
:
1065 sfact
= GR_BLEND_ONE_MINUS_DST_COLOR
;
1066 asfact
= GR_BLEND_ONE
;
1069 sfact
= GR_BLEND_SRC_ALPHA
;
1070 asfact
= GR_BLEND_ONE
;
1072 case GL_ONE_MINUS_SRC_ALPHA
:
1073 sfact
= GR_BLEND_ONE_MINUS_SRC_ALPHA
;
1074 asfact
= GR_BLEND_ONE
;
1077 sfact
= GR_BLEND_DST_ALPHA
;
1078 asfact
= GR_BLEND_ONE
;
1080 case GL_ONE_MINUS_DST_ALPHA
:
1081 sfact
= GR_BLEND_ONE_MINUS_DST_ALPHA
;
1082 asfact
= GR_BLEND_ONE
;
1084 case GL_SRC_ALPHA_SATURATE
:
1085 sfact
= GR_BLEND_ALPHA_SATURATE
;
1086 asfact
= GR_BLEND_ONE
;
1089 case GL_ONE_MINUS_SRC_COLOR
:
1091 asfact
= sfact
= GR_BLEND_ONE
;
1094 asfact
= sfact
= GR_BLEND_ONE
;
1098 if ((sfact
!= us
->blendSrcFuncRGB
) || (asfact
!= us
->blendSrcFuncAlpha
)) {
1099 us
->blendSrcFuncRGB
= sfact
;
1100 us
->blendSrcFuncAlpha
= asfact
;
1101 fxMesa
->new_state
|= FX_NEW_BLEND
;
1106 adfact
= dfact
= GR_BLEND_ZERO
;
1109 adfact
= dfact
= GR_BLEND_ONE
;
1112 dfact
= GR_BLEND_SRC_COLOR
;
1113 adfact
= GR_BLEND_ZERO
;
1115 case GL_ONE_MINUS_SRC_COLOR
:
1116 dfact
= GR_BLEND_ONE_MINUS_SRC_COLOR
;
1117 adfact
= GR_BLEND_ZERO
;
1120 dfact
= GR_BLEND_SRC_ALPHA
;
1121 adfact
= GR_BLEND_ZERO
;
1123 case GL_ONE_MINUS_SRC_ALPHA
:
1124 dfact
= GR_BLEND_ONE_MINUS_SRC_ALPHA
;
1125 adfact
= GR_BLEND_ZERO
;
1128 /* dfact=GR_BLEND_DST_ALPHA; */
1129 /* We can't do DST_ALPHA */
1130 dfact
= GR_BLEND_ONE
;
1131 adfact
= GR_BLEND_ZERO
;
1133 case GL_ONE_MINUS_DST_ALPHA
:
1134 /* dfact=GR_BLEND_ONE_MINUS_DST_ALPHA; */
1135 /* We can't do DST_ALPHA */
1136 dfact
= GR_BLEND_ZERO
;
1137 adfact
= GR_BLEND_ZERO
;
1139 case GL_SRC_ALPHA_SATURATE
:
1141 case GL_ONE_MINUS_DST_COLOR
:
1143 adfact
= dfact
= GR_BLEND_ZERO
;
1146 adfact
= dfact
= GR_BLEND_ZERO
;
1150 if ((dfact
!= us
->blendDstFuncRGB
) || (adfact
!= us
->blendDstFuncAlpha
)) {
1151 us
->blendDstFuncRGB
= dfact
;
1152 us
->blendDstFuncAlpha
= adfact
;
1153 fxMesa
->new_state
|= FX_NEW_BLEND
;
1158 fxSetupBlend(GLcontext
* ctx
)
1160 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
1161 tfxUnitsState
*us
= &fxMesa
->unitsState
;
1163 if (us
->blendEnabled
)
1164 FX_grAlphaBlendFunction(us
->blendSrcFuncRGB
, us
->blendDstFuncRGB
,
1165 us
->blendSrcFuncAlpha
, us
->blendDstFuncAlpha
);
1167 FX_grAlphaBlendFunction(GR_BLEND_ONE
, GR_BLEND_ZERO
, GR_BLEND_ONE
,
1171 /************************************************************************/
1172 /************************** Alpha Test SetUp ****************************/
1173 /************************************************************************/
1176 fxDDAlphaFunc(GLcontext
* ctx
, GLenum func
, GLfloat ref
)
1178 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
1179 tfxUnitsState
*us
= &fxMesa
->unitsState
;
1184 newfunc
= GR_CMP_NEVER
;
1187 newfunc
= GR_CMP_LESS
;
1190 newfunc
= GR_CMP_EQUAL
;
1193 newfunc
= GR_CMP_LEQUAL
;
1196 newfunc
= GR_CMP_GREATER
;
1199 newfunc
= GR_CMP_NOTEQUAL
;
1202 newfunc
= GR_CMP_GEQUAL
;
1205 newfunc
= GR_CMP_ALWAYS
;
1208 fprintf(stderr
, "fx Driver: internal error in fxDDAlphaFunc()\n");
1214 if (newfunc
!= us
->alphaTestFunc
) {
1215 us
->alphaTestFunc
= newfunc
;
1216 fxMesa
->new_state
|= FX_NEW_ALPHA
;
1219 if (ref
!= us
->alphaTestRefValue
) {
1220 us
->alphaTestRefValue
= ref
;
1221 fxMesa
->new_state
|= FX_NEW_ALPHA
;
1226 fxSetupAlphaTest(GLcontext
* ctx
)
1228 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
1229 tfxUnitsState
*us
= &fxMesa
->unitsState
;
1231 if (us
->alphaTestEnabled
) {
1232 GrAlpha_t ref
= (GLint
) (us
->alphaTestRefValue
* 255.0);
1233 FX_grAlphaTestFunction(us
->alphaTestFunc
);
1234 FX_grAlphaTestReferenceValue(ref
);
1237 FX_grAlphaTestFunction(GR_CMP_ALWAYS
);
1240 /************************************************************************/
1241 /************************** Depth Test SetUp ****************************/
1242 /************************************************************************/
1245 fxDDDepthFunc(GLcontext
* ctx
, GLenum func
)
1247 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
1248 tfxUnitsState
*us
= &fxMesa
->unitsState
;
1253 dfunc
= GR_CMP_NEVER
;
1256 dfunc
= GR_CMP_LESS
;
1259 dfunc
= GR_CMP_GEQUAL
;
1262 dfunc
= GR_CMP_LEQUAL
;
1265 dfunc
= GR_CMP_GREATER
;
1268 dfunc
= GR_CMP_NOTEQUAL
;
1271 dfunc
= GR_CMP_EQUAL
;
1274 dfunc
= GR_CMP_ALWAYS
;
1277 fprintf(stderr
, "fx Driver: internal error in fxDDDepthFunc()\n");
1283 if (dfunc
!= us
->depthTestFunc
) {
1284 us
->depthTestFunc
= dfunc
;
1285 fxMesa
->new_state
|= FX_NEW_DEPTH
;
1291 fxDDDepthMask(GLcontext
* ctx
, GLboolean flag
)
1293 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
1294 tfxUnitsState
*us
= &fxMesa
->unitsState
;
1296 if (flag
!= us
->depthMask
) {
1297 us
->depthMask
= flag
;
1298 fxMesa
->new_state
|= FX_NEW_DEPTH
;
1303 fxSetupDepthTest(GLcontext
* ctx
)
1305 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
1306 tfxUnitsState
*us
= &fxMesa
->unitsState
;
1308 if (us
->depthTestEnabled
) {
1309 FX_grDepthBufferFunction(us
->depthTestFunc
);
1310 FX_grDepthMask(us
->depthMask
);
1313 FX_grDepthBufferFunction(GR_CMP_ALWAYS
);
1314 FX_grDepthMask(FXFALSE
);
1318 /************************************************************************/
1319 /**************************** Color Mask SetUp **************************/
1320 /************************************************************************/
1323 fxDDColorMask(GLcontext
* ctx
,
1324 GLboolean r
, GLboolean g
, GLboolean b
, GLboolean a
)
1326 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
1327 fxMesa
->new_state
|= FX_NEW_COLOR_MASK
;
1335 fxSetupColorMask(GLcontext
* ctx
)
1337 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1339 if (ctx
->Color
.DrawBuffer
== GL_NONE
) {
1340 FX_grColorMask(FXFALSE
, FXFALSE
);
1343 FX_grColorMask(ctx
->Color
.ColorMask
[RCOMP
] ||
1344 ctx
->Color
.ColorMask
[GCOMP
] ||
1345 ctx
->Color
.ColorMask
[BCOMP
],
1346 ctx
->Color
.ColorMask
[ACOMP
] && fxMesa
->haveAlphaBuffer
);
1353 /************************************************************************/
1354 /**************************** Fog Mode SetUp ****************************/
1355 /************************************************************************/
1358 * This is called during state update in order to update the Glide fog state.
1361 fxSetupFog(GLcontext
* ctx
)
1363 if (ctx
->Fog
.Enabled
/*&& ctx->FogMode==FOG_FRAGMENT */ ) {
1364 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1366 /* update fog color */
1368 col
[0] = (unsigned int) (255 * ctx
->Fog
.Color
[0]);
1369 col
[1] = (unsigned int) (255 * ctx
->Fog
.Color
[1]);
1370 col
[2] = (unsigned int) (255 * ctx
->Fog
.Color
[2]);
1371 col
[3] = (unsigned int) (255 * ctx
->Fog
.Color
[3]);
1372 FX_grFogColorValue(FXCOLOR4(col
));
1374 if (fxMesa
->fogTableMode
!= ctx
->Fog
.Mode
||
1375 fxMesa
->fogDensity
!= ctx
->Fog
.Density
||
1376 fxMesa
->fogStart
!= ctx
->Fog
.Start
||
1377 fxMesa
->fogEnd
!= ctx
->Fog
.End
) {
1378 /* reload the fog table */
1379 switch (ctx
->Fog
.Mode
) {
1381 guFogGenerateLinear(fxMesa
->fogTable
, ctx
->Fog
.Start
,
1385 guFogGenerateExp(fxMesa
->fogTable
, ctx
->Fog
.Density
);
1388 guFogGenerateExp2(fxMesa
->fogTable
, ctx
->Fog
.Density
);
1393 fxMesa
->fogTableMode
= ctx
->Fog
.Mode
;
1394 fxMesa
->fogDensity
= ctx
->Fog
.Density
;
1395 fxMesa
->fogStart
= ctx
->Fog
.Start
;
1396 fxMesa
->fogEnd
= ctx
->Fog
.End
;
1399 FX_grFogTable(fxMesa
->fogTable
);
1400 FX_grFogMode(GR_FOG_WITH_TABLE
);
1403 FX_grFogMode(GR_FOG_DISABLE
);
1408 fxDDFogfv(GLcontext
* ctx
, GLenum pname
, const GLfloat
* params
)
1410 FX_CONTEXT(ctx
)->new_state
|= FX_NEW_FOG
;
1413 /************************************************************************/
1414 /************************** Scissor Test SetUp **************************/
1415 /************************************************************************/
1417 /* This routine is used in managing the lock state, and therefore can't lock */
1419 fxSetScissorValues(GLcontext
* ctx
)
1421 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
1423 int ymin
, ymax
, check
;
1425 if (ctx
->Scissor
.Enabled
) {
1426 xmin
= ctx
->Scissor
.X
;
1427 xmax
= ctx
->Scissor
.X
+ ctx
->Scissor
.Width
;
1428 ymin
= ctx
->Scissor
.Y
;
1429 ymax
= ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
;
1435 xmax
= fxMesa
->width
;
1436 ymax
= fxMesa
->height
;
1439 if (xmin
< fxMesa
->clipMinX
)
1440 xmin
= fxMesa
->clipMinX
;
1441 if (xmax
> fxMesa
->clipMaxX
)
1442 xmax
= fxMesa
->clipMaxX
;
1443 if (ymin
< fxMesa
->screen_height
- fxMesa
->clipMaxY
)
1444 ymin
= fxMesa
->screen_height
- fxMesa
->clipMaxY
;
1445 if (ymax
> fxMesa
->screen_height
- fxMesa
->clipMinY
)
1446 ymax
= fxMesa
->screen_height
- fxMesa
->clipMinY
;
1447 FX_grClipWindow_NoLock(xmin
, ymin
, xmax
, ymax
);
1451 fxSetupScissor(GLcontext
* ctx
)
1454 fxSetScissorValues(ctx
);
1459 fxDDScissor(GLcontext
* ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
1461 FX_CONTEXT(ctx
)->new_state
|= FX_NEW_SCISSOR
;
1464 /************************************************************************/
1465 /*************************** Cull mode setup ****************************/
1466 /************************************************************************/
1470 fxDDCullFace(GLcontext
* ctx
, GLenum mode
)
1473 FX_CONTEXT(ctx
)->new_state
|= FX_NEW_CULL
;
1477 fxDDFrontFace(GLcontext
* ctx
, GLenum mode
)
1480 FX_CONTEXT(ctx
)->new_state
|= FX_NEW_CULL
;
1485 fxSetupCull(GLcontext
* ctx
)
1487 if (ctx
->Polygon
.CullFlag
) {
1488 switch (ctx
->Polygon
.CullFaceMode
) {
1490 if (ctx
->Polygon
.FrontFace
== GL_CCW
)
1491 FX_CONTEXT(ctx
)->cullMode
= GR_CULL_NEGATIVE
;
1493 FX_CONTEXT(ctx
)->cullMode
= GR_CULL_POSITIVE
;
1496 if (ctx
->Polygon
.FrontFace
== GL_CCW
)
1497 FX_CONTEXT(ctx
)->cullMode
= GR_CULL_POSITIVE
;
1499 FX_CONTEXT(ctx
)->cullMode
= GR_CULL_NEGATIVE
;
1501 case GL_FRONT_AND_BACK
:
1502 FX_CONTEXT(ctx
)->cullMode
= GR_CULL_DISABLE
;
1509 FX_CONTEXT(ctx
)->cullMode
= GR_CULL_DISABLE
;
1511 if (FX_CONTEXT(ctx
)->raster_primitive
== GL_TRIANGLES
)
1512 FX_grCullMode(FX_CONTEXT(ctx
)->cullMode
);
1516 /************************************************************************/
1517 /****************************** DD Enable ******************************/
1518 /************************************************************************/
1521 fxDDEnable(GLcontext
* ctx
, GLenum cap
, GLboolean state
)
1523 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
1524 tfxUnitsState
*us
= &fxMesa
->unitsState
;
1526 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
1527 fprintf(stderr
, "fxmesa: fxDDEnable(...)\n");
1532 if (state
!= us
->alphaTestEnabled
) {
1533 us
->alphaTestEnabled
= state
;
1534 fxMesa
->new_state
|= FX_NEW_ALPHA
;
1538 if (state
!= us
->blendEnabled
) {
1539 us
->blendEnabled
= state
;
1540 fxMesa
->new_state
|= FX_NEW_BLEND
;
1544 if (state
!= us
->depthTestEnabled
) {
1545 us
->depthTestEnabled
= state
;
1546 fxMesa
->new_state
|= FX_NEW_DEPTH
;
1551 FX_grDitherMode(GR_DITHER_4x4
);
1554 FX_grDitherMode(GR_DITHER_DISABLE
);
1557 case GL_SCISSOR_TEST
:
1558 fxMesa
->new_state
|= FX_NEW_SCISSOR
;
1560 case GL_SHARED_TEXTURE_PALETTE_EXT
:
1561 fxDDTexUseGlbPalette(ctx
, state
);
1564 fxMesa
->new_state
|= FX_NEW_FOG
;
1567 fxMesa
->new_state
|= FX_NEW_CULL
;
1569 case GL_LINE_SMOOTH
:
1570 case GL_LINE_STIPPLE
:
1571 case GL_POINT_SMOOTH
:
1572 case GL_POLYGON_SMOOTH
:
1574 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
1584 /************************************************************************/
1585 /************************** Changes to units state **********************/
1586 /************************************************************************/
1589 /* All units setup is handled under texture setup.
1592 fxDDShadeModel(GLcontext
* ctx
, GLenum mode
)
1594 FX_CONTEXT(ctx
)->new_state
|= FX_NEW_TEXTURING
;
1599 /************************************************************************/
1600 /****************************** Units SetUp *****************************/
1601 /************************************************************************/
1603 fx_print_state_flags(const char *msg
, GLuint flags
)
1606 "%s: (0x%x) %s%s%s%s%s%s%s\n",
1609 (flags
& FX_NEW_TEXTURING
) ? "texture, " : "",
1610 (flags
& FX_NEW_BLEND
) ? "blend, " : "",
1611 (flags
& FX_NEW_ALPHA
) ? "alpha, " : "",
1612 (flags
& FX_NEW_FOG
) ? "fog, " : "",
1613 (flags
& FX_NEW_SCISSOR
) ? "scissor, " : "",
1614 (flags
& FX_NEW_COLOR_MASK
) ? "colormask, " : "",
1615 (flags
& FX_NEW_CULL
) ? "cull, " : "");
1619 fxSetupFXUnits(GLcontext
* ctx
)
1621 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
1622 GLuint newstate
= fxMesa
->new_state
;
1624 if (MESA_VERBOSE
& VERBOSE_DRIVER
)
1625 fx_print_state_flags("fxmesa: fxSetupFXUnits", newstate
);
1628 if (newstate
& FX_NEW_TEXTURING
)
1629 fxSetupTexture(ctx
);
1631 if (newstate
& FX_NEW_BLEND
)
1634 if (newstate
& FX_NEW_ALPHA
)
1635 fxSetupAlphaTest(ctx
);
1637 if (newstate
& FX_NEW_DEPTH
)
1638 fxSetupDepthTest(ctx
);
1640 if (newstate
& FX_NEW_FOG
)
1643 if (newstate
& FX_NEW_SCISSOR
)
1644 fxSetupScissor(ctx
);
1646 if (newstate
& FX_NEW_COLOR_MASK
)
1647 fxSetupColorMask(ctx
);
1649 if (newstate
& FX_NEW_CULL
)
1652 fxMesa
->new_state
= 0;
1662 * Need this to provide at least one external definition.
1665 extern int gl_fx_dummy_function_setup(void);
1667 gl_fx_dummy_function_setup(void)