1 /* -*- mode: C; tab-width:8; -*-
3 fxsetup.c - 3Dfx VooDoo rendering mode setup functions
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * See the file fxapi.c for more informations about authors
34 static void fxTexValidate(GLcontext
*ctx
, struct gl_texture_object
*tObj
)
36 tfxTexInfo
*ti
=(tfxTexInfo
*)tObj
->DriverData
;
39 if (MESA_VERBOSE
&VERBOSE_DRIVER
)
40 fprintf(stderr
,"fxmesa: fxTexValidate(...) Start\n");
44 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
45 fprintf(stderr
,"fxmesa: fxTexValidate(...) End (validated=GL_TRUE)\n");
50 minl
=ti
->minLevel
=tObj
->BaseLevel
;
51 maxl
=ti
->maxLevel
=MIN2(tObj
->MaxLevel
,tObj
->Image
[0]->MaxLog2
);
54 fxTexGetInfo(tObj
->Image
[minl
]->Width
,tObj
->Image
[minl
]->Height
,
55 &(FX_largeLodLog2(ti
->info
)),&(FX_aspectRatioLog2(ti
->info
)),
56 &(ti
->sScale
),&(ti
->tScale
),
57 &(ti
->int_sScale
),&(ti
->int_tScale
),
60 if((tObj
->MinFilter
!=GL_NEAREST
) && (tObj
->MinFilter
!=GL_LINEAR
))
61 fxTexGetInfo(tObj
->Image
[maxl
]->Width
,tObj
->Image
[maxl
]->Height
,
62 &(FX_smallLodLog2(ti
->info
)),NULL
,
67 FX_smallLodLog2(ti
->info
)=FX_largeLodLog2(ti
->info
);
69 fxTexGetFormat(tObj
->Image
[minl
]->Format
,&(ti
->info
.format
),&(ti
->baseLevelInternalFormat
));
71 ti
->validated
=GL_TRUE
;
75 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
76 fprintf(stderr
,"fxmesa: fxTexValidate(...) End\n");
80 static void fxPrintUnitsMode( const char *msg
, GLuint mode
)
83 "%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",
86 (mode
& FX_UM_E0_REPLACE
) ? "E0_REPLACE, " : "",
87 (mode
& FX_UM_E0_MODULATE
) ? "E0_MODULATE, " : "",
88 (mode
& FX_UM_E0_DECAL
) ? "E0_DECAL, " : "",
89 (mode
& FX_UM_E0_BLEND
) ? "E0_BLEND, " : "",
90 (mode
& FX_UM_E1_REPLACE
) ? "E1_REPLACE, " : "",
91 (mode
& FX_UM_E1_MODULATE
) ? "E1_MODULATE, " : "",
92 (mode
& FX_UM_E1_DECAL
) ? "E1_DECAL, " : "",
93 (mode
& FX_UM_E1_BLEND
) ? "E1_BLEND, " : "",
94 (mode
& FX_UM_E0_ALPHA
) ? "E0_ALPHA, " : "",
95 (mode
& FX_UM_E0_LUMINANCE
) ? "E0_LUMINANCE, " : "",
96 (mode
& FX_UM_E0_LUMINANCE_ALPHA
) ? "E0_LUMINANCE_ALPHA, " : "",
97 (mode
& FX_UM_E0_INTENSITY
) ? "E0_INTENSITY, " : "",
98 (mode
& FX_UM_E0_RGB
) ? "E0_RGB, " : "",
99 (mode
& FX_UM_E0_RGBA
) ? "E0_RGBA, " : "",
100 (mode
& FX_UM_E1_ALPHA
) ? "E1_ALPHA, " : "",
101 (mode
& FX_UM_E1_LUMINANCE
) ? "E1_LUMINANCE, " : "",
102 (mode
& FX_UM_E1_LUMINANCE_ALPHA
) ? "E1_LUMINANCE_ALPHA, " : "",
103 (mode
& FX_UM_E1_INTENSITY
) ? "E1_INTENSITY, " : "",
104 (mode
& FX_UM_E1_RGB
) ? "E1_RGB, " : "",
105 (mode
& FX_UM_E1_RGBA
) ? "E1_RGBA, " : "",
106 (mode
& FX_UM_COLOR_ITERATED
) ? "COLOR_ITERATED, " : "",
107 (mode
& FX_UM_COLOR_CONSTANT
) ? "COLOR_CONSTANT, " : "",
108 (mode
& FX_UM_ALPHA_ITERATED
) ? "ALPHA_ITERATED, " : "",
109 (mode
& FX_UM_ALPHA_CONSTANT
) ? "ALPHA_CONSTANT, " : "");
112 GLuint
fxGetTexSetConfiguration(GLcontext
*ctx
,
113 struct gl_texture_object
*tObj0
,
114 struct gl_texture_object
*tObj1
)
120 if((ctx
->Light
.ShadeModel
==GL_SMOOTH
) ||
121 (ctx
->Point
.SmoothFlag
) ||
122 (ctx
->Line
.SmoothFlag
) ||
123 (ctx
->Polygon
.SmoothFlag
))
124 unitsmode
|=FX_UM_ALPHA_ITERATED
;
126 unitsmode
|=FX_UM_ALPHA_CONSTANT
;
128 if(ctx
->Light
.ShadeModel
==GL_SMOOTH
)
129 unitsmode
|=FX_UM_COLOR_ITERATED
;
131 unitsmode
|=FX_UM_COLOR_CONSTANT
;
134 tfxTexInfo
*ti0
=(tfxTexInfo
*)tObj0
->DriverData
;
136 switch(ti0
->baseLevelInternalFormat
) {
138 ifmt
|=FX_UM_E0_ALPHA
;
141 ifmt
|=FX_UM_E0_LUMINANCE
;
143 case GL_LUMINANCE_ALPHA
:
144 ifmt
|=FX_UM_E0_LUMINANCE_ALPHA
;
147 ifmt
|=FX_UM_E0_INTENSITY
;
157 switch(ctx
->Texture
.Unit
[0].EnvMode
) {
159 envmode
|=FX_UM_E0_DECAL
;
162 envmode
|=FX_UM_E0_MODULATE
;
165 envmode
|=FX_UM_E0_REPLACE
;
168 envmode
|=FX_UM_E0_BLEND
;
171 envmode
|=FX_UM_E0_ADD
;
180 tfxTexInfo
*ti1
=(tfxTexInfo
*)tObj1
->DriverData
;
182 switch(ti1
->baseLevelInternalFormat
) {
184 ifmt
|=FX_UM_E1_ALPHA
;
187 ifmt
|=FX_UM_E1_LUMINANCE
;
189 case GL_LUMINANCE_ALPHA
:
190 ifmt
|=FX_UM_E1_LUMINANCE_ALPHA
;
193 ifmt
|=FX_UM_E1_INTENSITY
;
206 switch(ctx
->Texture
.Unit
[1].EnvMode
) {
208 envmode
|=FX_UM_E1_DECAL
;
211 envmode
|=FX_UM_E1_MODULATE
;
214 envmode
|=FX_UM_E1_REPLACE
;
217 envmode
|=FX_UM_E1_BLEND
;
220 envmode
|=FX_UM_E1_ADD
;
228 unitsmode
|=(ifmt
| envmode
);
230 if (MESA_VERBOSE
& (VERBOSE_DRIVER
|VERBOSE_TEXTURE
))
231 fxPrintUnitsMode("unitsmode", unitsmode
);
236 /************************************************************************/
237 /************************* Rendering Mode SetUp *************************/
238 /************************************************************************/
240 /************************* Single Texture Set ***************************/
242 static void fxSetupSingleTMU(fxMesaContext fxMesa
, struct gl_texture_object
*tObj
)
244 tfxTexInfo
*ti
=(tfxTexInfo
*)tObj
->DriverData
;
246 if(!ti
->tmi
.isInTM
) {
248 fxTMMoveInTM(fxMesa
,tObj
,FX_TMU_SPLIT
);
250 if(fxMesa
->haveTwoTMUs
) {
251 if(fxMesa
->freeTexMem
[FX_TMU0
]>grTexTextureMemRequired(GR_MIPMAPLEVELMASK_BOTH
,&(ti
->info
)))
252 fxTMMoveInTM(fxMesa
,tObj
,FX_TMU0
);
254 fxTMMoveInTM(fxMesa
,tObj
,FX_TMU1
);
256 fxTMMoveInTM(fxMesa
,tObj
,FX_TMU0
);
260 if(ti
->LODblend
&& ti
->tmi
.whichTMU
== FX_TMU_SPLIT
) {
261 if((ti
->info
.format
==GR_TEXFMT_P_8
) && (!fxMesa
->haveGlobalPaletteTexture
)) {
262 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
263 fprintf(stderr
,"fxmesa: uploading texture palette\n");
265 FX_grTexDownloadTable(GR_TMU0
,GR_TEXTABLE_PALETTE
,&(ti
->palette
));
266 FX_grTexDownloadTable(GR_TMU1
,GR_TEXTABLE_PALETTE
,&(ti
->palette
));
269 grTexClampMode(GR_TMU0
,ti
->sClamp
,ti
->tClamp
);
270 grTexClampMode(GR_TMU1
,ti
->sClamp
,ti
->tClamp
);
271 grTexFilterMode(GR_TMU0
,ti
->minFilt
,ti
->maxFilt
);
272 grTexFilterMode(GR_TMU1
,ti
->minFilt
,ti
->maxFilt
);
273 grTexMipMapMode(GR_TMU0
,ti
->mmMode
,ti
->LODblend
);
274 grTexMipMapMode(GR_TMU1
,ti
->mmMode
,ti
->LODblend
);
276 grTexSource(GR_TMU0
,ti
->tmi
.tm
[FX_TMU0
]->startAddress
,
277 GR_MIPMAPLEVELMASK_ODD
,&(ti
->info
));
278 grTexSource(GR_TMU1
,ti
->tmi
.tm
[FX_TMU1
]->startAddress
,
279 GR_MIPMAPLEVELMASK_EVEN
,&(ti
->info
));
281 if((ti
->info
.format
==GR_TEXFMT_P_8
) && (!fxMesa
->haveGlobalPaletteTexture
)) {
282 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
283 fprintf(stderr
,"fxmesa: uploading texture palette\n");
285 FX_grTexDownloadTable(ti
->tmi
.whichTMU
,GR_TEXTABLE_PALETTE
,&(ti
->palette
));
288 /* KW: The alternative is to do the download to the other tmu. If
289 * we get to this point, I think it means we are thrashing the
290 * texture memory, so perhaps it's not a good idea.
292 if (ti
->LODblend
&& (MESA_VERBOSE
&VERBOSE_DRIVER
))
293 fprintf(stderr
, "fxmesa: not blending texture - only on one tmu\n");
296 grTexClampMode(ti
->tmi
.whichTMU
,ti
->sClamp
,ti
->tClamp
);
297 grTexFilterMode(ti
->tmi
.whichTMU
,ti
->minFilt
,ti
->maxFilt
);
298 grTexMipMapMode(ti
->tmi
.whichTMU
,ti
->mmMode
,FXFALSE
);
300 grTexSource(ti
->tmi
.whichTMU
,ti
->tmi
.tm
[ti
->tmi
.whichTMU
]->startAddress
,
301 GR_MIPMAPLEVELMASK_BOTH
,&(ti
->info
));
305 static void fxSelectSingleTMUSrc(fxMesaContext fxMesa
, GLint tmu
, FxBool LODblend
)
307 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
308 fprintf(stderr
,"fxmesa: fxSelectSingleTMUSrc(%d,%d)\n",tmu
,LODblend
);
312 grTexCombine(GR_TMU0
,
313 GR_COMBINE_FUNCTION_BLEND
,
314 GR_COMBINE_FACTOR_ONE_MINUS_LOD_FRACTION
,
315 GR_COMBINE_FUNCTION_BLEND
,
316 GR_COMBINE_FACTOR_ONE_MINUS_LOD_FRACTION
,
319 grTexCombine(GR_TMU1
,
320 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
321 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
324 fxMesa
->tmuSrc
=FX_TMU_SPLIT
;
327 grTexCombine(GR_TMU0
,
328 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
329 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
332 fxMesa
->tmuSrc
=FX_TMU0
;
334 grTexCombine(GR_TMU1
,
335 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
336 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
339 /* GR_COMBINE_FUNCTION_SCALE_OTHER doesn't work ?!? */
341 grTexCombine(GR_TMU0
,
342 GR_COMBINE_FUNCTION_BLEND
,GR_COMBINE_FACTOR_ONE
,
343 GR_COMBINE_FUNCTION_BLEND
,GR_COMBINE_FACTOR_ONE
,
346 fxMesa
->tmuSrc
=FX_TMU1
;
351 void fxSetupTextureSingleTMU(GLcontext
*ctx
, GLuint textureset
)
353 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
354 GrCombineLocal_t localc
,locala
;
358 struct gl_texture_object
*tObj
=ctx
->Texture
.Unit
[textureset
].CurrentD
[2];
360 if (MESA_VERBOSE
&VERBOSE_DRIVER
)
361 fprintf(stderr
,"fxmesa: fxSetupTextureSingleTMU(...) Start\n");
364 ti
=(tfxTexInfo
*)tObj
->DriverData
;
366 fxTexValidate(ctx
,tObj
);
368 fxSetupSingleTMU(fxMesa
,tObj
);
370 if(fxMesa
->tmuSrc
!=ti
->tmi
.whichTMU
)
371 fxSelectSingleTMUSrc(fxMesa
,ti
->tmi
.whichTMU
,ti
->LODblend
);
373 if(textureset
==0 || !fxMesa
->haveTwoTMUs
)
374 unitsmode
=fxGetTexSetConfiguration(ctx
,tObj
,NULL
);
376 unitsmode
=fxGetTexSetConfiguration(ctx
,NULL
,tObj
);
378 if(fxMesa
->lastUnitsMode
==unitsmode
)
381 fxMesa
->lastUnitsMode
=unitsmode
;
383 fxMesa
->stw_hint_state
= 0;
384 FX_grHints(GR_HINT_STWHINT
,0);
386 ifmt
=ti
->baseLevelInternalFormat
;
388 if(unitsmode
& FX_UM_ALPHA_ITERATED
)
389 locala
=GR_COMBINE_LOCAL_ITERATED
;
391 locala
=GR_COMBINE_LOCAL_CONSTANT
;
393 if(unitsmode
& FX_UM_COLOR_ITERATED
)
394 localc
=GR_COMBINE_LOCAL_ITERATED
;
396 localc
=GR_COMBINE_LOCAL_CONSTANT
;
398 if (MESA_VERBOSE
& (VERBOSE_DRIVER
|VERBOSE_TEXTURE
))
399 fprintf(stderr
, "fxMesa: fxSetupTextureSingleTMU, envmode is %s\n",
400 gl_lookup_enum_by_nr(ctx
->Texture
.Unit
[textureset
].EnvMode
));
402 switch(ctx
->Texture
.Unit
[textureset
].EnvMode
) {
404 grAlphaCombine(GR_COMBINE_FUNCTION_LOCAL
,
405 GR_COMBINE_FACTOR_NONE
,
407 GR_COMBINE_OTHER_NONE
,
410 grColorCombine(GR_COMBINE_FUNCTION_BLEND
,
411 GR_COMBINE_FACTOR_TEXTURE_ALPHA
,
413 GR_COMBINE_OTHER_TEXTURE
,
417 grAlphaCombine(GR_COMBINE_FUNCTION_SCALE_OTHER
,
418 GR_COMBINE_FACTOR_LOCAL
,
420 GR_COMBINE_OTHER_TEXTURE
,
424 grColorCombine(GR_COMBINE_FUNCTION_LOCAL
,
425 GR_COMBINE_FACTOR_NONE
,
427 GR_COMBINE_OTHER_NONE
,
430 grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER
,
431 GR_COMBINE_FACTOR_LOCAL
,
433 GR_COMBINE_OTHER_TEXTURE
,
438 fprintf(stderr
,"fx Driver: GL_BLEND not yet supported\n");
440 /* TO DO (I think that the Voodoo Graphics isn't able to support GL_BLEND) */
443 if((ifmt
==GL_RGB
) || (ifmt
==GL_LUMINANCE
))
444 grAlphaCombine(GR_COMBINE_FUNCTION_LOCAL
,
445 GR_COMBINE_FACTOR_NONE
,
447 GR_COMBINE_OTHER_NONE
,
450 grAlphaCombine(GR_COMBINE_FUNCTION_SCALE_OTHER
,
451 GR_COMBINE_FACTOR_ONE
,
453 GR_COMBINE_OTHER_TEXTURE
,
457 grColorCombine(GR_COMBINE_FUNCTION_LOCAL
,
458 GR_COMBINE_FACTOR_NONE
,
460 GR_COMBINE_OTHER_NONE
,
463 grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER
,
464 GR_COMBINE_FACTOR_ONE
,
466 GR_COMBINE_OTHER_TEXTURE
,
471 fprintf(stderr
,"fx Driver: %x Texture.EnvMode not yet supported\n",ctx
->Texture
.Unit
[textureset
].EnvMode
);
476 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
477 fprintf(stderr
,"fxmesa: fxSetupTextureSingleTMU(...) End\n");
481 /************************* Double Texture Set ***************************/
483 void fxSetupDoubleTMU(fxMesaContext fxMesa
, struct gl_texture_object
*tObj0
,
484 struct gl_texture_object
*tObj1
)
486 #define T0_NOT_IN_TMU 0x01
487 #define T1_NOT_IN_TMU 0x02
488 #define T0_IN_TMU0 0x04
489 #define T1_IN_TMU0 0x08
490 #define T0_IN_TMU1 0x10
491 #define T1_IN_TMU1 0x20
493 tfxTexInfo
*ti0
=(tfxTexInfo
*)tObj0
->DriverData
;
494 tfxTexInfo
*ti1
=(tfxTexInfo
*)tObj1
->DriverData
;
497 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
498 fprintf(stderr
,"fxmesa: fxSetupDoubleTMU(...)\n");
501 if(ti0
->tmi
.isInTM
) {
502 if(ti0
->tmi
.whichTMU
==FX_TMU0
)
504 else if(ti0
->tmi
.whichTMU
==FX_TMU1
)
507 fxTMMoveOutTM(fxMesa
,tObj0
);
508 tstate
|=T0_NOT_IN_TMU
;
511 tstate
|=T0_NOT_IN_TMU
;
513 if(ti1
->tmi
.isInTM
) {
514 if(ti1
->tmi
.whichTMU
==FX_TMU0
)
516 else if(ti1
->tmi
.whichTMU
==FX_TMU1
)
519 fxTMMoveOutTM(fxMesa
,tObj1
);
520 tstate
|=T1_NOT_IN_TMU
;
523 tstate
|=T1_NOT_IN_TMU
;
525 ti0
->tmi
.lastTimeUsed
=fxMesa
->texBindNumber
;
526 ti1
->tmi
.lastTimeUsed
=fxMesa
->texBindNumber
;
528 /* Move texture maps in TMUs */
531 case (T0_IN_TMU0
| T1_IN_TMU0
):
532 fxTMMoveOutTM(fxMesa
,tObj1
);
534 fxTMMoveInTM(fxMesa
,tObj1
,FX_TMU1
);
537 case (T0_IN_TMU1
| T1_IN_TMU1
):
538 fxTMMoveOutTM(fxMesa
,tObj0
);
540 fxTMMoveInTM(fxMesa
,tObj0
,FX_TMU0
);
543 case (T0_NOT_IN_TMU
| T1_NOT_IN_TMU
):
544 fxTMMoveInTM(fxMesa
,tObj0
,FX_TMU0
);
545 fxTMMoveInTM(fxMesa
,tObj1
,FX_TMU1
);
550 case (T0_NOT_IN_TMU
| T1_IN_TMU0
):
551 fxTMMoveInTM(fxMesa
,tObj0
,FX_TMU1
);
554 case (T0_NOT_IN_TMU
| T1_IN_TMU1
):
555 fxTMMoveInTM(fxMesa
,tObj0
,FX_TMU0
);
558 case (T0_IN_TMU0
| T1_NOT_IN_TMU
):
559 fxTMMoveInTM(fxMesa
,tObj1
,FX_TMU1
);
562 case (T0_IN_TMU1
| T1_NOT_IN_TMU
):
563 fxTMMoveInTM(fxMesa
,tObj1
,FX_TMU0
);
568 case (T0_IN_TMU1
| T1_IN_TMU0
):
569 case (T0_IN_TMU0
| T1_IN_TMU1
):
573 fprintf(stderr
,"fx Driver: internal error in fxSetupDoubleTMU()\n");
579 if(!fxMesa
->haveGlobalPaletteTexture
) {
580 if(ti0
->info
.format
==GR_TEXFMT_P_8
) {
581 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
582 fprintf(stderr
,"fxmesa: uploading texture palette TMU0\n");
584 FX_grTexDownloadTable(ti0
->tmi
.whichTMU
,GR_TEXTABLE_PALETTE
,&(ti0
->palette
));
587 if(ti1
->info
.format
==GR_TEXFMT_P_8
) {
588 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
589 fprintf(stderr
,"fxmesa: uploading texture palette TMU1\n");
591 FX_grTexDownloadTable(ti1
->tmi
.whichTMU
,GR_TEXTABLE_PALETTE
,&(ti1
->palette
));
595 grTexClampMode(ti0
->tmi
.whichTMU
,ti0
->sClamp
,ti0
->tClamp
);
596 grTexFilterMode(ti0
->tmi
.whichTMU
,ti0
->minFilt
,ti0
->maxFilt
);
597 grTexMipMapMode(ti0
->tmi
.whichTMU
,ti0
->mmMode
,FXFALSE
);
598 grTexSource(ti0
->tmi
.whichTMU
,ti0
->tmi
.tm
[ti0
->tmi
.whichTMU
]->startAddress
,
599 GR_MIPMAPLEVELMASK_BOTH
,&(ti0
->info
));
601 grTexClampMode(ti1
->tmi
.whichTMU
,ti1
->sClamp
,ti1
->tClamp
);
602 grTexFilterMode(ti1
->tmi
.whichTMU
,ti1
->minFilt
,ti1
->maxFilt
);
603 grTexMipMapMode(ti1
->tmi
.whichTMU
,ti1
->mmMode
,FXFALSE
);
604 grTexSource(ti1
->tmi
.whichTMU
,ti1
->tmi
.tm
[ti1
->tmi
.whichTMU
]->startAddress
,
605 GR_MIPMAPLEVELMASK_BOTH
,&(ti1
->info
));
615 static void fxSetupTextureDoubleTMU(GLcontext
*ctx
)
617 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
618 GrCombineLocal_t localc
,locala
;
619 tfxTexInfo
*ti0
,*ti1
;
620 struct gl_texture_object
*tObj0
=ctx
->Texture
.Unit
[0].CurrentD
[2];
621 struct gl_texture_object
*tObj1
=ctx
->Texture
.Unit
[1].CurrentD
[2];
622 GLuint envmode
,ifmt
,unitsmode
;
624 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
625 fprintf(stderr
,"fxmesa: fxSetupTextureDoubleTMU(...) Start\n");
628 ti0
=(tfxTexInfo
*)tObj0
->DriverData
;
629 fxTexValidate(ctx
,tObj0
);
631 ti1
=(tfxTexInfo
*)tObj1
->DriverData
;
632 fxTexValidate(ctx
,tObj1
);
634 fxSetupDoubleTMU(fxMesa
,tObj0
,tObj1
);
636 unitsmode
=fxGetTexSetConfiguration(ctx
,tObj0
,tObj1
);
638 if(fxMesa
->lastUnitsMode
==unitsmode
)
641 fxMesa
->lastUnitsMode
=unitsmode
;
643 fxMesa
->stw_hint_state
|= GR_STWHINT_ST_DIFF_TMU1
;
644 FX_grHints(GR_HINT_STWHINT
, fxMesa
->stw_hint_state
);
646 envmode
=unitsmode
& FX_UM_E_ENVMODE
;
647 ifmt
=unitsmode
& FX_UM_E_IFMT
;
649 if(unitsmode
& FX_UM_ALPHA_ITERATED
)
650 locala
=GR_COMBINE_LOCAL_ITERATED
;
652 locala
=GR_COMBINE_LOCAL_CONSTANT
;
654 if(unitsmode
& FX_UM_COLOR_ITERATED
)
655 localc
=GR_COMBINE_LOCAL_ITERATED
;
657 localc
=GR_COMBINE_LOCAL_CONSTANT
;
660 if (MESA_VERBOSE
& (VERBOSE_DRIVER
|VERBOSE_TEXTURE
))
661 fprintf(stderr
, "fxMesa: fxSetupTextureDoubleTMU, envmode is %s/%s\n",
662 gl_lookup_enum_by_nr(ctx
->Texture
.Unit
[0].EnvMode
),
663 gl_lookup_enum_by_nr(ctx
->Texture
.Unit
[1].EnvMode
));
666 fxMesa
->tmuSrc
=FX_TMU_BOTH
;
668 case (FX_UM_E0_MODULATE
| FX_UM_E1_MODULATE
):
670 GLboolean isalpha
[FX_NUM_TMU
];
672 if(ti0
->baseLevelInternalFormat
==GL_ALPHA
)
673 isalpha
[ti0
->tmi
.whichTMU
]=GL_TRUE
;
675 isalpha
[ti0
->tmi
.whichTMU
]=GL_FALSE
;
677 if(ti1
->baseLevelInternalFormat
==GL_ALPHA
)
678 isalpha
[ti1
->tmi
.whichTMU
]=GL_TRUE
;
680 isalpha
[ti1
->tmi
.whichTMU
]=GL_FALSE
;
683 grTexCombine(GR_TMU1
,
684 GR_COMBINE_FUNCTION_ZERO
,GR_COMBINE_FACTOR_NONE
,
685 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
688 grTexCombine(GR_TMU1
,
689 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
690 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
694 grTexCombine(GR_TMU0
,
695 GR_COMBINE_FUNCTION_BLEND_OTHER
,GR_COMBINE_FACTOR_ONE
,
696 GR_COMBINE_FUNCTION_BLEND_OTHER
,GR_COMBINE_FACTOR_LOCAL
,
699 grTexCombine(GR_TMU0
,
700 GR_COMBINE_FUNCTION_BLEND_OTHER
,GR_COMBINE_FACTOR_LOCAL
,
701 GR_COMBINE_FUNCTION_BLEND_OTHER
,GR_COMBINE_FACTOR_LOCAL
,
704 grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER
,
705 GR_COMBINE_FACTOR_LOCAL
,
707 GR_COMBINE_OTHER_TEXTURE
,
710 grAlphaCombine(GR_COMBINE_FUNCTION_SCALE_OTHER
,
711 GR_COMBINE_FACTOR_LOCAL
,
713 GR_COMBINE_OTHER_TEXTURE
,
717 case (FX_UM_E0_REPLACE
| FX_UM_E1_BLEND
): /* Only for GLQuake */
718 if(ti1
->tmi
.whichTMU
==FX_TMU1
) {
719 grTexCombine(GR_TMU1
,
720 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
721 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
724 grTexCombine(GR_TMU0
,
725 GR_COMBINE_FUNCTION_BLEND_OTHER
,GR_COMBINE_FACTOR_LOCAL
,
726 GR_COMBINE_FUNCTION_BLEND_OTHER
,GR_COMBINE_FACTOR_LOCAL
,
729 grTexCombine(GR_TMU1
,
730 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
731 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
734 grTexCombine(GR_TMU0
,
735 GR_COMBINE_FUNCTION_BLEND_OTHER
,GR_COMBINE_FACTOR_ONE_MINUS_LOCAL
,
736 GR_COMBINE_FUNCTION_BLEND_OTHER
,GR_COMBINE_FACTOR_ONE_MINUS_LOCAL
,
740 grAlphaCombine(GR_COMBINE_FUNCTION_LOCAL
,
741 GR_COMBINE_FACTOR_NONE
,
743 GR_COMBINE_OTHER_NONE
,
746 grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER
,
747 GR_COMBINE_FACTOR_ONE
,
749 GR_COMBINE_OTHER_TEXTURE
,
752 case (FX_UM_E0_REPLACE
| FX_UM_E1_MODULATE
): /* Quake 2 and 3 */
753 if(ti1
->tmi
.whichTMU
==FX_TMU1
) {
754 grTexCombine(GR_TMU1
,
755 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
756 GR_COMBINE_FUNCTION_ZERO
,GR_COMBINE_FACTOR_NONE
,
759 grTexCombine(GR_TMU0
,
760 GR_COMBINE_FUNCTION_BLEND_OTHER
,GR_COMBINE_FACTOR_LOCAL
,
761 GR_COMBINE_FUNCTION_BLEND_OTHER
,GR_COMBINE_FACTOR_LOCAL
,
765 grTexCombine(GR_TMU1
,
766 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
767 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
770 grTexCombine(GR_TMU0
,
771 GR_COMBINE_FUNCTION_BLEND_OTHER
,GR_COMBINE_FACTOR_LOCAL
,
772 GR_COMBINE_FUNCTION_BLEND_OTHER
,GR_COMBINE_FACTOR_ONE
,
776 if(ti0
->baseLevelInternalFormat
==GL_RGB
)
777 grAlphaCombine(GR_COMBINE_FUNCTION_LOCAL
,
778 GR_COMBINE_FACTOR_NONE
,
780 GR_COMBINE_OTHER_NONE
,
783 grAlphaCombine(GR_COMBINE_FUNCTION_SCALE_OTHER
,
784 GR_COMBINE_FACTOR_ONE
,
786 GR_COMBINE_OTHER_NONE
,
790 grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER
,
791 GR_COMBINE_FACTOR_ONE
,
793 GR_COMBINE_OTHER_TEXTURE
,
798 case (FX_UM_E0_MODULATE
| FX_UM_E1_ADD
): /* Quake 3 Sky */
800 GLboolean isalpha
[FX_NUM_TMU
];
802 if(ti0
->baseLevelInternalFormat
==GL_ALPHA
)
803 isalpha
[ti0
->tmi
.whichTMU
]=GL_TRUE
;
805 isalpha
[ti0
->tmi
.whichTMU
]=GL_FALSE
;
807 if(ti1
->baseLevelInternalFormat
==GL_ALPHA
)
808 isalpha
[ti1
->tmi
.whichTMU
]=GL_TRUE
;
810 isalpha
[ti1
->tmi
.whichTMU
]=GL_FALSE
;
813 grTexCombine(GR_TMU1
,
814 GR_COMBINE_FUNCTION_ZERO
,GR_COMBINE_FACTOR_NONE
,
815 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
818 grTexCombine(GR_TMU1
,
819 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
820 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
824 grTexCombine(GR_TMU0
,
825 GR_COMBINE_FUNCTION_SCALE_OTHER
,GR_COMBINE_FACTOR_ONE
,
826 GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL
,GR_COMBINE_FACTOR_ONE
,
829 grTexCombine(GR_TMU0
,
830 GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL
,GR_COMBINE_FACTOR_ONE
,
831 GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL
,GR_COMBINE_FACTOR_ONE
,
834 grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER
,
835 GR_COMBINE_FACTOR_LOCAL
,
837 GR_COMBINE_OTHER_TEXTURE
,
840 grAlphaCombine(GR_COMBINE_FUNCTION_SCALE_OTHER
,
841 GR_COMBINE_FACTOR_LOCAL
,
842 locala
, GR_COMBINE_OTHER_TEXTURE
,
849 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
850 fprintf(stderr
,"fxmesa: fxSetupTextureDoubleTMU(...) End\n");
854 /************************* No Texture ***************************/
856 static void fxSetupTextureNone(GLcontext
*ctx
)
858 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
859 GrCombineLocal_t localc
,locala
;
861 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
862 fprintf(stderr
,"fxmesa: fxSetupTextureNone(...)\n");
865 if((ctx
->Light
.ShadeModel
==GL_SMOOTH
) ||
866 (ctx
->Point
.SmoothFlag
) ||
867 (ctx
->Line
.SmoothFlag
) ||
868 (ctx
->Polygon
.SmoothFlag
))
869 locala
=GR_COMBINE_LOCAL_ITERATED
;
871 locala
=GR_COMBINE_LOCAL_CONSTANT
;
873 if(ctx
->Light
.ShadeModel
==GL_SMOOTH
)
874 localc
=GR_COMBINE_LOCAL_ITERATED
;
876 localc
=GR_COMBINE_LOCAL_CONSTANT
;
878 grAlphaCombine(GR_COMBINE_FUNCTION_LOCAL
,
879 GR_COMBINE_FACTOR_NONE
,
881 GR_COMBINE_OTHER_NONE
,
884 grColorCombine(GR_COMBINE_FUNCTION_LOCAL
,
885 GR_COMBINE_FACTOR_NONE
,
887 GR_COMBINE_OTHER_NONE
,
890 fxMesa
->lastUnitsMode
=FX_UM_NONE
;
895 static GLboolean
fxMultipassTexture( struct vertex_buffer
*, GLuint
);
899 /************************************************************************/
900 /************************** Texture Mode SetUp **************************/
901 /************************************************************************/
903 void fxSetupTexture(GLcontext
*ctx
)
905 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
908 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
909 fprintf(stderr
,"fxmesa: fxSetupTexture(...)\n");
912 /* Disable multipass texturing.
914 ctx
->Driver
.MultipassFunc
= 0;
916 /* Texture Combine, Color Combine and Alpha Combine.
918 tex2Denabled
= (ctx
->Texture
.ReallyEnabled
& TEXTURE0_2D
);
920 if (fxMesa
->emulateTwoTMUs
)
921 tex2Denabled
|= (ctx
->Texture
.ReallyEnabled
& TEXTURE1_2D
);
923 switch(tex2Denabled
) {
925 fxSetupTextureSingleTMU(ctx
,0);
928 fxSetupTextureSingleTMU(ctx
,1);
930 case (TEXTURE0_2D
|TEXTURE1_2D
):
931 if (fxMesa
->haveTwoTMUs
)
932 fxSetupTextureDoubleTMU(ctx
);
934 if (MESA_VERBOSE
&VERBOSE_DRIVER
)
935 fprintf(stderr
, "fxmesa: enabling fake multitexture\n");
937 fxSetupTextureSingleTMU(ctx
,0);
938 ctx
->Driver
.MultipassFunc
= fxMultipassTexture
;
942 fxSetupTextureNone(ctx
);
947 /************************************************************************/
948 /**************************** Blend SetUp *******************************/
949 /************************************************************************/
951 /* XXX consider supporting GL_INGR_blend_func_separate */
952 void fxDDBlendFunc(GLcontext
*ctx
, GLenum sfactor
, GLenum dfactor
)
954 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
955 tfxUnitsState
*us
=&fxMesa
->unitsState
;
956 GrAlphaBlendFnc_t sfact
,dfact
,asfact
,adfact
;
958 /* From the Glide documentation:
959 For alpha source and destination blend function factor
960 parameters, Voodoo Graphics supports only
961 GR_BLEND_ZERO and GR_BLEND_ONE.
966 asfact
=sfact
=GR_BLEND_ZERO
;
969 asfact
=sfact
=GR_BLEND_ONE
;
972 sfact
=GR_BLEND_DST_COLOR
;
975 case GL_ONE_MINUS_DST_COLOR
:
976 sfact
=GR_BLEND_ONE_MINUS_DST_COLOR
;
980 sfact
=GR_BLEND_SRC_ALPHA
;
983 case GL_ONE_MINUS_SRC_ALPHA
:
984 sfact
=GR_BLEND_ONE_MINUS_SRC_ALPHA
;
988 sfact
=GR_BLEND_DST_ALPHA
;
991 case GL_ONE_MINUS_DST_ALPHA
:
992 sfact
=GR_BLEND_ONE_MINUS_DST_ALPHA
;
995 case GL_SRC_ALPHA_SATURATE
:
996 sfact
=GR_BLEND_ALPHA_SATURATE
;
1000 case GL_ONE_MINUS_SRC_COLOR
:
1002 asfact
=sfact
=GR_BLEND_ONE
;
1005 asfact
=sfact
=GR_BLEND_ONE
;
1009 if((sfact
!=us
->blendSrcFuncRGB
) ||
1010 (asfact
!=us
->blendSrcFuncAlpha
)) {
1011 us
->blendSrcFuncRGB
=sfact
;
1012 us
->blendSrcFuncAlpha
=asfact
;
1013 fxMesa
->new_state
|= FX_NEW_BLEND
;
1014 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1019 adfact
=dfact
=GR_BLEND_ZERO
;
1022 adfact
=dfact
=GR_BLEND_ONE
;
1025 dfact
=GR_BLEND_SRC_COLOR
;
1026 adfact
=GR_BLEND_ZERO
;
1028 case GL_ONE_MINUS_SRC_COLOR
:
1029 dfact
=GR_BLEND_ONE_MINUS_SRC_COLOR
;
1030 adfact
=GR_BLEND_ZERO
;
1033 dfact
=GR_BLEND_SRC_ALPHA
;
1034 adfact
=GR_BLEND_ZERO
;
1036 case GL_ONE_MINUS_SRC_ALPHA
:
1037 dfact
=GR_BLEND_ONE_MINUS_SRC_ALPHA
;
1038 adfact
=GR_BLEND_ZERO
;
1041 dfact
=GR_BLEND_DST_ALPHA
;
1042 adfact
=GR_BLEND_ZERO
;
1044 case GL_ONE_MINUS_DST_ALPHA
:
1045 dfact
=GR_BLEND_ONE_MINUS_DST_ALPHA
;
1046 adfact
=GR_BLEND_ZERO
;
1048 case GL_SRC_ALPHA_SATURATE
:
1050 case GL_ONE_MINUS_DST_COLOR
:
1052 adfact
=dfact
=GR_BLEND_ZERO
;
1055 adfact
=dfact
=GR_BLEND_ZERO
;
1059 if((dfact
!=us
->blendDstFuncRGB
) ||
1060 (adfact
!=us
->blendDstFuncAlpha
)) {
1061 us
->blendDstFuncRGB
=dfact
;
1062 us
->blendDstFuncAlpha
=adfact
;
1063 fxMesa
->new_state
|= FX_NEW_BLEND
;
1064 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1068 void fxSetupBlend(GLcontext
*ctx
)
1070 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1071 tfxUnitsState
*us
=&fxMesa
->unitsState
;
1073 if(us
->blendEnabled
)
1074 grAlphaBlendFunction(us
->blendSrcFuncRGB
,us
->blendDstFuncRGB
,
1075 us
->blendSrcFuncAlpha
,us
->blendDstFuncAlpha
);
1077 grAlphaBlendFunction(GR_BLEND_ONE
,GR_BLEND_ZERO
,GR_BLEND_ONE
,GR_BLEND_ZERO
);
1080 /************************************************************************/
1081 /************************** Alpha Test SetUp ****************************/
1082 /************************************************************************/
1084 void fxDDAlphaFunc(GLcontext
*ctx
, GLenum func
, GLclampf ref
)
1086 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1087 tfxUnitsState
*us
=&fxMesa
->unitsState
;
1092 newfunc
=GR_CMP_NEVER
;
1095 newfunc
=GR_CMP_LESS
;
1098 newfunc
=GR_CMP_EQUAL
;
1101 newfunc
=GR_CMP_LEQUAL
;
1104 newfunc
=GR_CMP_GREATER
;
1107 newfunc
=GR_CMP_NOTEQUAL
;
1110 newfunc
=GR_CMP_GEQUAL
;
1113 newfunc
=GR_CMP_ALWAYS
;
1116 fprintf(stderr
,"fx Driver: internal error in fxDDAlphaFunc()\n");
1122 if(newfunc
!=us
->alphaTestFunc
) {
1123 us
->alphaTestFunc
=newfunc
;
1124 fxMesa
->new_state
|= FX_NEW_ALPHA
;
1125 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1128 if(ctx
->Color
.AlphaRef
!=us
->alphaTestRefValue
) {
1129 us
->alphaTestRefValue
=ctx
->Color
.AlphaRef
;
1130 fxMesa
->new_state
|= FX_NEW_ALPHA
;
1131 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1135 static void fxSetupAlphaTest(GLcontext
*ctx
)
1137 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1138 tfxUnitsState
*us
=&fxMesa
->unitsState
;
1140 if(us
->alphaTestEnabled
) {
1141 grAlphaTestFunction(us
->alphaTestFunc
);
1142 grAlphaTestReferenceValue(us
->alphaTestRefValue
);
1144 grAlphaTestFunction(GR_CMP_ALWAYS
);
1147 /************************************************************************/
1148 /************************** Depth Test SetUp ****************************/
1149 /************************************************************************/
1151 void fxDDDepthFunc(GLcontext
*ctx
, GLenum func
)
1153 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1154 tfxUnitsState
*us
=&fxMesa
->unitsState
;
1165 dfunc
=GR_CMP_GEQUAL
;
1168 dfunc
=GR_CMP_LEQUAL
;
1171 dfunc
=GR_CMP_GREATER
;
1174 dfunc
=GR_CMP_NOTEQUAL
;
1180 dfunc
=GR_CMP_ALWAYS
;
1183 fprintf(stderr
,"fx Driver: internal error in fxDDDepthFunc()\n");
1189 if(dfunc
!=us
->depthTestFunc
) {
1190 us
->depthTestFunc
=dfunc
;
1191 fxMesa
->new_state
|= FX_NEW_DEPTH
;
1192 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1197 void fxDDDepthMask(GLcontext
*ctx
, GLboolean flag
)
1199 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1200 tfxUnitsState
*us
=&fxMesa
->unitsState
;
1202 if(flag
!=us
->depthMask
) {
1204 fxMesa
->new_state
|= FX_NEW_DEPTH
;
1205 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1209 void fxSetupDepthTest(GLcontext
*ctx
)
1211 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1212 tfxUnitsState
*us
=&fxMesa
->unitsState
;
1214 if(us
->depthTestEnabled
)
1215 grDepthBufferFunction(us
->depthTestFunc
);
1217 grDepthBufferFunction(GR_CMP_ALWAYS
);
1219 grDepthMask(us
->depthMask
);
1222 /************************************************************************/
1223 /**************************** Color Mask SetUp **************************/
1224 /************************************************************************/
1226 GLboolean
fxDDColorMask(GLcontext
*ctx
,
1227 GLboolean r
, GLboolean g
,
1228 GLboolean b
, GLboolean a
)
1230 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1231 fxMesa
->new_state
|= FX_NEW_COLOR_MASK
;
1232 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1233 (void) r
; (void) g
; (void) b
; (void) a
;
1237 static void fxSetupColorMask(GLcontext
*ctx
)
1239 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1241 grColorMask(ctx
->Color
.ColorMask
[RCOMP
] ||
1242 ctx
->Color
.ColorMask
[GCOMP
] ||
1243 ctx
->Color
.ColorMask
[BCOMP
],
1244 ctx
->Color
.ColorMask
[ACOMP
] && fxMesa
->haveAlphaBuffer
);
1249 /************************************************************************/
1250 /**************************** Fog Mode SetUp ****************************/
1251 /************************************************************************/
1253 void fxFogTableGenerate(GLcontext
*ctx
)
1257 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1259 for(i
=0;i
<FX_grGetInteger(FX_FOG_TABLE_ENTRIES
);i
++) {
1260 eyez
=guFogTableIndexToW(i
);
1262 switch(ctx
->Fog
.Mode
) {
1264 f
=(ctx
->Fog
.End
-eyez
)/(ctx
->Fog
.End
-ctx
->Fog
.Start
);
1267 f
=exp(-ctx
->Fog
.Density
*eyez
);
1270 f
=exp(-ctx
->Fog
.Density
*ctx
->Fog
.Density
*eyez
*eyez
);
1272 default: /* That should never happen */
1277 fxMesa
->fogTable
[i
]=(GrFog_t
)((1.0f
-CLAMP(f
,0.0f
,1.0f
))*255.0f
);
1281 void fxSetupFog(GLcontext
*ctx
, GLboolean forceTableRebuild
)
1283 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1285 if(ctx
->Fog
.Enabled
&& ctx
->FogMode
==FOG_FRAGMENT
) {
1287 grFogMode(GR_FOG_WITH_TABLE
);
1289 col
[0]=(unsigned int)(255*ctx
->Fog
.Color
[0]);
1290 col
[1]=(unsigned int)(255*ctx
->Fog
.Color
[1]);
1291 col
[2]=(unsigned int)(255*ctx
->Fog
.Color
[2]);
1292 col
[3]=(unsigned int)(255*ctx
->Fog
.Color
[3]);
1294 grFogColorValue(FXCOLOR4(col
));
1296 if(forceTableRebuild
||
1297 (fxMesa
->fogTableMode
!=ctx
->Fog
.Mode
) ||
1298 (fxMesa
->fogDensity
!=ctx
->Fog
.Density
)) {
1299 fxFogTableGenerate(ctx
);
1301 fxMesa
->fogTableMode
=ctx
->Fog
.Mode
;
1302 fxMesa
->fogDensity
=ctx
->Fog
.Density
;
1305 grFogTable(fxMesa
->fogTable
);
1307 grFogMode(GR_FOG_DISABLE
);
1310 void fxDDFogfv( GLcontext
*ctx
, GLenum pname
, const GLfloat
*params
)
1312 FX_CONTEXT(ctx
)->new_state
|= FX_NEW_FOG
;
1313 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1316 /************************************************************************/
1317 /************************** Scissor Test SetUp **************************/
1318 /************************************************************************/
1320 static void fxSetupScissor(GLcontext
*ctx
)
1322 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1324 if (ctx
->Scissor
.Enabled
) {
1327 ymin
=ctx
->Scissor
.Y
;
1328 ymax
=ctx
->Scissor
.Y
+ctx
->Scissor
.Height
;
1332 if (ymax
>fxMesa
->height
) ymax
=fxMesa
->height
;
1334 grClipWindow(ctx
->Scissor
.X
,
1336 ctx
->Scissor
.X
+ctx
->Scissor
.Width
,
1339 grClipWindow(0,0,fxMesa
->width
,fxMesa
->height
);
1342 void fxDDScissor( GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
1344 FX_CONTEXT(ctx
)->new_state
|= FX_NEW_SCISSOR
;
1345 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1348 /************************************************************************/
1349 /*************************** Cull mode setup ****************************/
1350 /************************************************************************/
1353 void fxDDCullFace(GLcontext
*ctx
, GLenum mode
)
1356 FX_CONTEXT(ctx
)->new_state
|= FX_NEW_CULL
;
1357 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1360 void fxDDFrontFace(GLcontext
*ctx
, GLenum mode
)
1363 FX_CONTEXT(ctx
)->new_state
|= FX_NEW_CULL
;
1364 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1368 void fxSetupCull(GLcontext
*ctx
)
1370 if(ctx
->Polygon
.CullFlag
) {
1371 switch(ctx
->Polygon
.CullFaceMode
) {
1373 if(ctx
->Polygon
.FrontFace
==GL_CCW
)
1374 grCullMode(GR_CULL_NEGATIVE
);
1376 grCullMode(GR_CULL_POSITIVE
);
1379 if(ctx
->Polygon
.FrontFace
==GL_CCW
)
1380 grCullMode(GR_CULL_POSITIVE
);
1382 grCullMode(GR_CULL_NEGATIVE
);
1384 case GL_FRONT_AND_BACK
:
1385 grCullMode(GR_CULL_DISABLE
);
1391 grCullMode(GR_CULL_DISABLE
);
1395 /************************************************************************/
1396 /****************************** DD Enable ******************************/
1397 /************************************************************************/
1399 void fxDDEnable(GLcontext
*ctx
, GLenum cap
, GLboolean state
)
1401 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1402 tfxUnitsState
*us
=&fxMesa
->unitsState
;
1404 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1405 fprintf(stderr
,"fxmesa: fxDDEnable(...)\n");
1410 if(state
!=us
->alphaTestEnabled
) {
1411 us
->alphaTestEnabled
=state
;
1412 fxMesa
->new_state
|= FX_NEW_ALPHA
;
1413 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1417 if(state
!=us
->blendEnabled
) {
1418 us
->blendEnabled
=state
;
1419 fxMesa
->new_state
|= FX_NEW_BLEND
;
1420 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1424 if(state
!=us
->depthTestEnabled
) {
1425 us
->depthTestEnabled
=state
;
1426 fxMesa
->new_state
|= FX_NEW_DEPTH
;
1427 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1430 case GL_SCISSOR_TEST
:
1431 fxMesa
->new_state
|= FX_NEW_SCISSOR
;
1432 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1435 fxMesa
->new_state
|= FX_NEW_FOG
;
1436 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1439 fxMesa
->new_state
|= FX_NEW_CULL
;
1440 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1442 case GL_LINE_SMOOTH
:
1443 case GL_POINT_SMOOTH
:
1444 case GL_POLYGON_SMOOTH
:
1446 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
1447 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1450 ; /* XXX no-op??? */
1454 /************************************************************************/
1455 /******************** Fake Multitexture Support *************************/
1456 /************************************************************************/
1458 /* Its considered cheeky to try to fake ARB multitexture by doing
1459 * multipass rendering, because it is not possible to emulate the full
1460 * spec in this way. The fact is that the voodoo 2 supports only a
1461 * subset of the possible multitexturing modes, and it is possible to
1462 * support almost the same subset using multipass blending on the
1463 * voodoo 1. In all other cases for both voodoo 1 and 2, we fall back
1464 * to software rendering, satisfying the spec if not the user.
1466 static GLboolean
fxMultipassTexture( struct vertex_buffer
*VB
, GLuint pass
)
1468 GLcontext
*ctx
= VB
->ctx
;
1469 fxVertex
*v
= FX_DRIVER_DATA(VB
)->verts
;
1470 fxVertex
*last
= FX_DRIVER_DATA(VB
)->last_vert
;
1471 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1475 if (MESA_VERBOSE
&(VERBOSE_DRIVER
|VERBOSE_PIPELINE
|VERBOSE_TEXTURE
))
1476 fprintf(stderr
, "fxmesa: Second texture pass\n");
1478 for ( ; v
!= last
; v
++) {
1479 v
->f
[S0COORD
] = v
->f
[S1COORD
];
1480 v
->f
[T0COORD
] = v
->f
[T1COORD
];
1483 fxMesa
->restoreUnitsState
= fxMesa
->unitsState
;
1484 fxMesa
->tmu_source
[0] = 1;
1486 if (ctx
->Depth
.Mask
) {
1487 switch (ctx
->Depth
.Func
) {
1492 fxDDDepthFunc( ctx
, GL_EQUAL
);
1496 fxDDDepthMask( ctx
, GL_FALSE
);
1499 if (ctx
->Texture
.Unit
[1].EnvMode
== GL_MODULATE
) {
1500 fxDDEnable( ctx
, GL_BLEND
, GL_TRUE
);
1501 fxDDBlendFunc( ctx
, GL_DST_COLOR
, GL_ZERO
);
1504 fxSetupTextureSingleTMU( ctx
, 1 );
1505 fxSetupBlend( ctx
);
1506 fxSetupDepthTest( ctx
);
1510 /* Restore original state.
1512 fxMesa
->tmu_source
[0] = 0;
1513 fxMesa
->unitsState
= fxMesa
->restoreUnitsState
;
1514 fxMesa
->setupdone
&= ~SETUP_TMU0
;
1515 fxSetupTextureSingleTMU( ctx
, 0 );
1516 fxSetupBlend( ctx
);
1517 fxSetupDepthTest( ctx
);
1525 /************************************************************************/
1526 /************************** Changes to units state **********************/
1527 /************************************************************************/
1530 /* All units setup is handled under texture setup.
1532 void fxDDShadeModel(GLcontext
*ctx
, GLenum mode
)
1534 FX_CONTEXT(ctx
)->new_state
|= FX_NEW_TEXTURING
;
1535 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1540 /************************************************************************/
1541 /****************************** Units SetUp *****************************/
1542 /************************************************************************/
1543 void gl_print_fx_state_flags( const char *msg
, GLuint flags
)
1546 "%s: (0x%x) %s%s%s%s%s%s%s\n",
1549 (flags
& FX_NEW_TEXTURING
) ? "texture, " : "",
1550 (flags
& FX_NEW_BLEND
) ? "blend, " : "",
1551 (flags
& FX_NEW_ALPHA
) ? "alpha, " : "",
1552 (flags
& FX_NEW_FOG
) ? "fog, " : "",
1553 (flags
& FX_NEW_SCISSOR
) ? "scissor, " : "",
1554 (flags
& FX_NEW_COLOR_MASK
) ? "colormask, " : "",
1555 (flags
& FX_NEW_CULL
) ? "cull, " : "");
1558 void fxSetupFXUnits( GLcontext
*ctx
)
1560 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1561 GLuint newstate
= fxMesa
->new_state
;
1564 if (MESA_VERBOSE
&VERBOSE_DRIVER
)
1565 gl_print_fx_state_flags("fxmesa: fxSetupFXUnits", newstate
);
1569 if (newstate
& FX_NEW_TEXTURING
)
1570 fxSetupTexture(ctx
);
1572 if (newstate
& FX_NEW_BLEND
)
1575 if (newstate
& FX_NEW_ALPHA
)
1576 fxSetupAlphaTest(ctx
);
1578 if (newstate
& FX_NEW_DEPTH
)
1579 fxSetupDepthTest(ctx
);
1581 if (newstate
& FX_NEW_FOG
)
1582 fxSetupFog(ctx
,GL_FALSE
);
1584 if (newstate
& FX_NEW_SCISSOR
)
1585 fxSetupScissor(ctx
);
1587 if (newstate
& FX_NEW_COLOR_MASK
)
1588 fxSetupColorMask(ctx
);
1590 if (newstate
& FX_NEW_CULL
)
1593 fxMesa
->new_state
= 0;
1594 /* ctx->Driver.RenderStart = 0; */
1604 * Need this to provide at least one external definition.
1607 int gl_fx_dummy_function_setup(void)