3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the
29 * Thank you for your contribution, David!
31 * Please make note of the above copyright/license statement. If you
32 * contributed code or bug fixes to this code under the previous (GNU
33 * Library) license and object to the new license, your code will be
34 * removed at your request. Please see the Mesa docs/COPYRIGHT file
35 * for more information.
37 * Additional Mesa/3Dfx driver developers:
38 * Daryll Strauss <daryll@precisioninsight.com>
39 * Keith Whitwell <keith@precisioninsight.com>
41 * See fxapi.h for more revision/author details.
45 /* fxsetup.c - 3Dfx VooDoo rendering mode setup functions */
57 static GLuint
fxGetTexSetConfiguration(GLcontext
*ctx
,
58 struct gl_texture_object
*tObj0
,
59 struct gl_texture_object
*tObj1
);
60 static void fxSetupTextureSingleTMU_NoLock(GLcontext
*ctx
, GLuint textureset
);
61 static void fxSetupDoubleTMU_NoLock(fxMesaContext fxMesa
,
62 struct gl_texture_object
*tObj0
,
63 struct gl_texture_object
*tObj1
);
64 static void fxSetupTexture_NoLock(GLcontext
*ctx
);
65 static void fxSetupTexture(GLcontext
*ctx
);
66 static void fxSetupBlend(GLcontext
*ctx
);
67 static void fxSetupDepthTest(GLcontext
*ctx
);
68 static void fxSetupScissor(GLcontext
*ctx
);
69 static void fxSetupCull(GLcontext
*ctx
);
70 static void gl_print_fx_state_flags( const char *msg
, GLuint flags
);
71 /*static GLboolean fxMultipassBlend(struct vertex_buffer *, GLuint);*/
72 static GLboolean
fxMultipassTexture( struct vertex_buffer
*, GLuint
);
74 static void fxTexValidate(GLcontext
*ctx
, struct gl_texture_object
*tObj
)
76 tfxTexInfo
*ti
=fxTMGetTexInfo(tObj
);
79 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
80 fprintf(stderr
,"fxmesa: fxTexValidate(...) Start\n");
84 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
85 fprintf(stderr
,"fxmesa: fxTexValidate(...) End (validated=GL_TRUE)\n");
91 minl
=ti
->minLevel
=tObj
->BaseLevel
;
92 maxl
=ti
->maxLevel
=MIN2(tObj
->MaxLevel
,tObj
->Image
[0]->MaxLog2
);
94 fxTexGetInfo(tObj
->Image
[minl
]->Width
, tObj
->Image
[minl
]->Height
,
95 &(FX_largeLodLog2(ti
->info
)), &(FX_aspectRatioLog2(ti
->info
)),
96 &(ti
->sScale
), &(ti
->tScale
),
97 &(ti
->int_sScale
), &(ti
->int_tScale
),
100 if((tObj
->MinFilter
!=GL_NEAREST
) && (tObj
->MinFilter
!=GL_LINEAR
))
101 fxTexGetInfo(tObj
->Image
[maxl
]->Width
,tObj
->Image
[maxl
]->Height
,
102 &(FX_smallLodLog2(ti
->info
)),NULL
,
107 FX_smallLodLog2(ti
->info
)=FX_largeLodLog2(ti
->info
);
109 fxTexGetFormat(tObj
->Image
[minl
]->IntFormat
,&(ti
->info
.format
),&(ti
->baseLevelInternalFormat
));
111 switch (tObj
->WrapS
) {
112 case GL_CLAMP_TO_EDGE
:
113 /* What's this really mean compared to GL_CLAMP? */
121 ; /* silence compiler warning */
123 switch (tObj
->WrapT
) {
124 case GL_CLAMP_TO_EDGE
:
125 /* What's this really mean compared to GL_CLAMP? */
133 ; /* silence compiler warning */
136 ti
->validated
=GL_TRUE
;
140 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
141 fprintf(stderr
,"fxmesa: fxTexValidate(...) End\n");
145 static void fxPrintUnitsMode( const char *msg
, GLuint mode
)
148 "%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",
151 (mode
& FX_UM_E0_REPLACE
) ? "E0_REPLACE, " : "",
152 (mode
& FX_UM_E0_MODULATE
) ? "E0_MODULATE, " : "",
153 (mode
& FX_UM_E0_DECAL
) ? "E0_DECAL, " : "",
154 (mode
& FX_UM_E0_BLEND
) ? "E0_BLEND, " : "",
155 (mode
& FX_UM_E1_REPLACE
) ? "E1_REPLACE, " : "",
156 (mode
& FX_UM_E1_MODULATE
) ? "E1_MODULATE, " : "",
157 (mode
& FX_UM_E1_DECAL
) ? "E1_DECAL, " : "",
158 (mode
& FX_UM_E1_BLEND
) ? "E1_BLEND, " : "",
159 (mode
& FX_UM_E0_ALPHA
) ? "E0_ALPHA, " : "",
160 (mode
& FX_UM_E0_LUMINANCE
) ? "E0_LUMINANCE, " : "",
161 (mode
& FX_UM_E0_LUMINANCE_ALPHA
) ? "E0_LUMINANCE_ALPHA, " : "",
162 (mode
& FX_UM_E0_INTENSITY
) ? "E0_INTENSITY, " : "",
163 (mode
& FX_UM_E0_RGB
) ? "E0_RGB, " : "",
164 (mode
& FX_UM_E0_RGBA
) ? "E0_RGBA, " : "",
165 (mode
& FX_UM_E1_ALPHA
) ? "E1_ALPHA, " : "",
166 (mode
& FX_UM_E1_LUMINANCE
) ? "E1_LUMINANCE, " : "",
167 (mode
& FX_UM_E1_LUMINANCE_ALPHA
) ? "E1_LUMINANCE_ALPHA, " : "",
168 (mode
& FX_UM_E1_INTENSITY
) ? "E1_INTENSITY, " : "",
169 (mode
& FX_UM_E1_RGB
) ? "E1_RGB, " : "",
170 (mode
& FX_UM_E1_RGBA
) ? "E1_RGBA, " : "",
171 (mode
& FX_UM_COLOR_ITERATED
) ? "COLOR_ITERATED, " : "",
172 (mode
& FX_UM_COLOR_CONSTANT
) ? "COLOR_CONSTANT, " : "",
173 (mode
& FX_UM_ALPHA_ITERATED
) ? "ALPHA_ITERATED, " : "",
174 (mode
& FX_UM_ALPHA_CONSTANT
) ? "ALPHA_CONSTANT, " : "");
177 static GLuint
fxGetTexSetConfiguration(GLcontext
*ctx
,
178 struct gl_texture_object
*tObj0
,
179 struct gl_texture_object
*tObj1
)
185 if((ctx
->Light
.ShadeModel
==GL_SMOOTH
) || 1 ||
186 (ctx
->Point
.SmoothFlag
) ||
187 (ctx
->Line
.SmoothFlag
) ||
188 (ctx
->Polygon
.SmoothFlag
))
189 unitsmode
|=FX_UM_ALPHA_ITERATED
;
191 unitsmode
|=FX_UM_ALPHA_CONSTANT
;
193 if(ctx
->Light
.ShadeModel
==GL_SMOOTH
|| 1)
194 unitsmode
|=FX_UM_COLOR_ITERATED
;
196 unitsmode
|=FX_UM_COLOR_CONSTANT
;
201 OpenGL Feeds Texture 0 into Texture 1
202 Glide Feeds Texture 1 into Texture 0
205 tfxTexInfo
*ti0
=fxTMGetTexInfo(tObj0
);
207 switch(ti0
->baseLevelInternalFormat
) {
209 ifmt
|=FX_UM_E0_ALPHA
;
212 ifmt
|=FX_UM_E0_LUMINANCE
;
214 case GL_LUMINANCE_ALPHA
:
215 ifmt
|=FX_UM_E0_LUMINANCE_ALPHA
;
218 ifmt
|=FX_UM_E0_INTENSITY
;
228 switch(ctx
->Texture
.Unit
[0].EnvMode
) {
230 envmode
|=FX_UM_E0_DECAL
;
233 envmode
|=FX_UM_E0_MODULATE
;
236 envmode
|=FX_UM_E0_REPLACE
;
239 envmode
|=FX_UM_E0_BLEND
;
242 envmode
|=FX_UM_E0_ADD
;
251 tfxTexInfo
*ti1
=fxTMGetTexInfo(tObj1
);
253 switch(ti1
->baseLevelInternalFormat
) {
255 ifmt
|=FX_UM_E1_ALPHA
;
258 ifmt
|=FX_UM_E1_LUMINANCE
;
260 case GL_LUMINANCE_ALPHA
:
261 ifmt
|=FX_UM_E1_LUMINANCE_ALPHA
;
264 ifmt
|=FX_UM_E1_INTENSITY
;
277 switch(ctx
->Texture
.Unit
[1].EnvMode
) {
279 envmode
|=FX_UM_E1_DECAL
;
282 envmode
|=FX_UM_E1_MODULATE
;
285 envmode
|=FX_UM_E1_REPLACE
;
288 envmode
|=FX_UM_E1_BLEND
;
291 envmode
|=FX_UM_E1_ADD
;
299 unitsmode
|=(ifmt
| envmode
);
301 if (MESA_VERBOSE
& (VERBOSE_DRIVER
|VERBOSE_TEXTURE
))
302 fxPrintUnitsMode("unitsmode", unitsmode
);
307 /************************************************************************/
308 /************************* Rendering Mode SetUp *************************/
309 /************************************************************************/
311 /************************* Single Texture Set ***************************/
313 static void fxSetupSingleTMU_NoLock(fxMesaContext fxMesa
, struct gl_texture_object
*tObj
)
315 tfxTexInfo
*ti
=fxTMGetTexInfo(tObj
);
318 /* Make sure we're not loaded incorrectly */
321 if (ti
->whichTMU
!=FX_TMU_SPLIT
)
322 fxTMMoveOutTM(fxMesa
, tObj
);
324 if (ti
->whichTMU
==FX_TMU_SPLIT
)
325 fxTMMoveOutTM(fxMesa
, tObj
);
329 /* Make sure we're loaded correctly */
332 fxTMMoveInTM_NoLock(fxMesa
,tObj
,FX_TMU_SPLIT
);
334 if (fxMesa
->haveTwoTMUs
) {
335 if (fxMesa
->freeTexMem
[FX_TMU0
] >
336 FX_grTexTextureMemRequired_NoLock(GR_MIPMAPLEVELMASK_BOTH
,
338 fxTMMoveInTM_NoLock(fxMesa
,tObj
, FX_TMU0
);
340 fxTMMoveInTM_NoLock(fxMesa
,tObj
, FX_TMU1
);
343 fxTMMoveInTM_NoLock(fxMesa
,tObj
,FX_TMU0
);
347 if (ti
->LODblend
&& ti
->whichTMU
== FX_TMU_SPLIT
) {
348 if ((ti
->info
.format
==GR_TEXFMT_P_8
) && (!fxMesa
->haveGlobalPaletteTexture
)) {
349 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
350 fprintf(stderr
,"fxmesa: uploading texture palette\n");
352 FX_grTexDownloadTable_NoLock(GR_TMU0
,GR_TEXTABLE_PALETTE
,&(ti
->palette
));
353 FX_grTexDownloadTable_NoLock(GR_TMU1
,GR_TEXTABLE_PALETTE
,&(ti
->palette
));
356 FX_grTexClampMode_NoLock(GR_TMU0
,ti
->sClamp
,ti
->tClamp
);
357 FX_grTexClampMode_NoLock(GR_TMU1
,ti
->sClamp
,ti
->tClamp
);
358 FX_grTexFilterMode_NoLock(GR_TMU0
,ti
->minFilt
,ti
->maxFilt
);
359 FX_grTexFilterMode_NoLock(GR_TMU1
,ti
->minFilt
,ti
->maxFilt
);
360 FX_grTexMipMapMode_NoLock(GR_TMU0
,ti
->mmMode
,ti
->LODblend
);
361 FX_grTexMipMapMode_NoLock(GR_TMU1
,ti
->mmMode
,ti
->LODblend
);
363 FX_grTexSource_NoLock(GR_TMU0
,ti
->tm
[FX_TMU0
]->startAddr
,
364 GR_MIPMAPLEVELMASK_ODD
,&(ti
->info
));
365 FX_grTexSource_NoLock(GR_TMU1
,ti
->tm
[FX_TMU1
]->startAddr
,
366 GR_MIPMAPLEVELMASK_EVEN
,&(ti
->info
));
368 if (ti
->whichTMU
==FX_TMU_BOTH
) tmu
=FX_TMU0
;
369 else tmu
=ti
->whichTMU
;
371 if((ti
->info
.format
==GR_TEXFMT_P_8
) && (!fxMesa
->haveGlobalPaletteTexture
)) {
372 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
373 fprintf(stderr
,"fxmesa: uploading texture palette\n");
375 FX_grTexDownloadTable_NoLock(tmu
, GR_TEXTABLE_PALETTE
, &(ti
->palette
));
378 /* KW: The alternative is to do the download to the other tmu. If
379 * we get to this point, I think it means we are thrashing the
380 * texture memory, so perhaps it's not a good idea.
382 if (ti
->LODblend
&& (MESA_VERBOSE
&VERBOSE_DRIVER
))
383 fprintf(stderr
, "fxmesa: not blending texture - only on one tmu\n");
385 FX_grTexClampMode_NoLock(tmu
, ti
->sClamp
, ti
->tClamp
);
386 FX_grTexFilterMode_NoLock(tmu
, ti
->minFilt
, ti
->maxFilt
);
387 FX_grTexMipMapMode_NoLock(tmu
, ti
->mmMode
, FXFALSE
);
389 FX_grTexSource_NoLock(tmu
, ti
->tm
[tmu
]->startAddr
,
390 GR_MIPMAPLEVELMASK_BOTH
, &(ti
->info
));
394 static void fxSelectSingleTMUSrc_NoLock(fxMesaContext fxMesa
, GLint tmu
,
397 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
398 fprintf(stderr
,"fxmesa: fxSelectSingleTMUSrc(%d,%d)\n",tmu
,LODblend
);
402 FX_grTexCombine_NoLock(GR_TMU0
,
403 GR_COMBINE_FUNCTION_BLEND
,
404 GR_COMBINE_FACTOR_ONE_MINUS_LOD_FRACTION
,
405 GR_COMBINE_FUNCTION_BLEND
,
406 GR_COMBINE_FACTOR_ONE_MINUS_LOD_FRACTION
,
409 if (fxMesa
->haveTwoTMUs
)
410 FX_grTexCombine_NoLock(GR_TMU1
,
411 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
412 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
414 fxMesa
->tmuSrc
=FX_TMU_SPLIT
;
418 FX_grTexCombine_NoLock(GR_TMU0
,
419 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
420 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
422 if (fxMesa
->haveTwoTMUs
) {
423 FX_grTexCombine_NoLock(GR_TMU1
,
424 GR_COMBINE_FUNCTION_ZERO
, GR_COMBINE_FACTOR_NONE
,
425 GR_COMBINE_FUNCTION_ZERO
, GR_COMBINE_FACTOR_NONE
,
428 fxMesa
->tmuSrc
=FX_TMU0
;
431 FX_grTexCombine_NoLock(GR_TMU1
,
432 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
433 GR_COMBINE_FUNCTION_LOCAL
,GR_COMBINE_FACTOR_NONE
,
436 /* GR_COMBINE_FUNCTION_SCALE_OTHER doesn't work ?!? */
438 FX_grTexCombine_NoLock(GR_TMU0
,
439 GR_COMBINE_FUNCTION_BLEND
,
440 GR_COMBINE_FACTOR_ONE
,
441 GR_COMBINE_FUNCTION_BLEND
,
442 GR_COMBINE_FACTOR_ONE
,
445 fxMesa
->tmuSrc
=FX_TMU1
;
450 static void fxSetupTextureSingleTMU_NoLock(GLcontext
*ctx
, GLuint textureset
)
452 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
453 GrCombineLocal_t localc
,locala
;
457 struct gl_texture_object
*tObj
=ctx
->Texture
.Unit
[textureset
].CurrentD
[2];
460 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
461 fprintf(stderr
,"fxmesa: fxSetupTextureSingleTMU(...) Start\n");
464 ti
=fxTMGetTexInfo(tObj
);
466 fxTexValidate(ctx
,tObj
);
468 fxSetupSingleTMU_NoLock(fxMesa
,tObj
);
470 if (ti
->whichTMU
==FX_TMU_BOTH
) tmu
=FX_TMU0
;
471 else tmu
=ti
->whichTMU
;
472 if (fxMesa
->tmuSrc
!=tmu
)
473 fxSelectSingleTMUSrc_NoLock(fxMesa
, tmu
, ti
->LODblend
);
475 if(textureset
==0 || !fxMesa
->haveTwoTMUs
)
476 unitsmode
=fxGetTexSetConfiguration(ctx
,tObj
,NULL
);
478 unitsmode
=fxGetTexSetConfiguration(ctx
,NULL
,tObj
);
480 /* if(fxMesa->lastUnitsMode==unitsmode) */
483 fxMesa
->lastUnitsMode
=unitsmode
;
485 fxMesa
->stw_hint_state
= 0;
486 FX_grHints_NoLock(GR_HINT_STWHINT
,0);
488 ifmt
=ti
->baseLevelInternalFormat
;
490 if(unitsmode
& FX_UM_ALPHA_ITERATED
)
491 locala
=GR_COMBINE_LOCAL_ITERATED
;
493 locala
=GR_COMBINE_LOCAL_CONSTANT
;
495 if(unitsmode
& FX_UM_COLOR_ITERATED
)
496 localc
=GR_COMBINE_LOCAL_ITERATED
;
498 localc
=GR_COMBINE_LOCAL_CONSTANT
;
500 if (MESA_VERBOSE
& (VERBOSE_DRIVER
|VERBOSE_TEXTURE
))
501 fprintf(stderr
, "fxMesa: fxSetupTextureSingleTMU, envmode is %s\n",
502 gl_lookup_enum_by_nr(ctx
->Texture
.Unit
[textureset
].EnvMode
));
504 switch(ctx
->Texture
.Unit
[textureset
].EnvMode
) {
506 FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL
,
507 GR_COMBINE_FACTOR_NONE
,
509 GR_COMBINE_OTHER_NONE
,
512 FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_BLEND
,
513 GR_COMBINE_FACTOR_TEXTURE_ALPHA
,
515 GR_COMBINE_OTHER_TEXTURE
,
519 FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER
,
520 GR_COMBINE_FACTOR_LOCAL
,
522 GR_COMBINE_OTHER_TEXTURE
,
526 FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL
,
527 GR_COMBINE_FACTOR_NONE
,
529 GR_COMBINE_OTHER_NONE
,
532 FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER
,
533 GR_COMBINE_FACTOR_LOCAL
,
535 GR_COMBINE_OTHER_TEXTURE
,
540 FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER
,
541 GR_COMBINE_FACTOR_LOCAL
,
543 GR_COMBINE_OTHER_TEXTURE
,
546 FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL
,
547 GR_COMBINE_FACTOR_NONE
,
549 GR_COMBINE_OTHER_NONE
,
552 FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL
,
553 GR_COMBINE_FACTOR_LOCAL
,
555 GR_COMBINE_OTHER_TEXTURE
,
557 ctx
->Driver
.MultipassFunc
= fxMultipassBlend
;
559 if (MESA_VERBOSE
&VERBOSE_DRIVER
)
560 fprintf(stderr
,"fx Driver: GL_BLEND not yet supported\n");
564 if((ifmt
==GL_RGB
) || (ifmt
==GL_LUMINANCE
))
565 FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL
,
566 GR_COMBINE_FACTOR_NONE
,
568 GR_COMBINE_OTHER_NONE
,
571 FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER
,
572 GR_COMBINE_FACTOR_ONE
,
574 GR_COMBINE_OTHER_TEXTURE
,
578 FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL
,
579 GR_COMBINE_FACTOR_NONE
,
581 GR_COMBINE_OTHER_NONE
,
584 FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER
,
585 GR_COMBINE_FACTOR_ONE
,
587 GR_COMBINE_OTHER_TEXTURE
,
591 if (MESA_VERBOSE
&VERBOSE_DRIVER
)
592 fprintf(stderr
, "fx Driver: %x Texture.EnvMode not yet supported\n",
593 ctx
->Texture
.Unit
[textureset
].EnvMode
);
597 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
598 fprintf(stderr
,"fxmesa: fxSetupTextureSingleTMU(...) End\n");
602 static void fxSetupTextureSingleTMU(GLcontext
*ctx
, GLuint textureset
) {
604 fxSetupTextureSingleTMU_NoLock(ctx
, textureset
);
608 /************************* Double Texture Set ***************************/
610 static void fxSetupDoubleTMU_NoLock(fxMesaContext fxMesa
,
611 struct gl_texture_object
*tObj0
,
612 struct gl_texture_object
*tObj1
)
614 #define T0_NOT_IN_TMU 0x01
615 #define T1_NOT_IN_TMU 0x02
616 #define T0_IN_TMU0 0x04
617 #define T1_IN_TMU0 0x08
618 #define T0_IN_TMU1 0x10
619 #define T1_IN_TMU1 0x20
621 tfxTexInfo
*ti0
=fxTMGetTexInfo(tObj0
);
622 tfxTexInfo
*ti1
=fxTMGetTexInfo(tObj1
);
626 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
627 fprintf(stderr
,"fxmesa: fxSetupDoubleTMU(...)\n");
630 /* We shouldn't need to do this. There is something wrong with
631 mutlitexturing when the TMUs are swapped. So, we're forcing
632 them to always be loaded correctly. !!! */
633 if (ti0
->whichTMU
==FX_TMU1
)
634 fxTMMoveOutTM_NoLock(fxMesa
, tObj0
);
635 if (ti1
->whichTMU
==FX_TMU0
)
636 fxTMMoveOutTM_NoLock(fxMesa
, tObj1
);
639 switch (ti0
->whichTMU
) {
647 tstate
|=T0_IN_TMU0
|T0_IN_TMU1
;
650 tstate
|=T0_NOT_IN_TMU
;
653 } else tstate
|=T0_NOT_IN_TMU
;
656 switch (ti1
->whichTMU
) {
664 tstate
|=T1_IN_TMU0
|T1_IN_TMU1
;
667 tstate
|=T1_NOT_IN_TMU
;
670 } else tstate
|=T1_NOT_IN_TMU
;
672 ti0
->lastTimeUsed
=fxMesa
->texBindNumber
;
673 ti1
->lastTimeUsed
=fxMesa
->texBindNumber
;
675 /* Move texture maps into TMUs */
677 if (!(((tstate
&T0_IN_TMU0
) && (tstate
&T1_IN_TMU1
)) ||
678 ((tstate
&T0_IN_TMU1
) && (tstate
&T1_IN_TMU0
)))) {
679 if (tObj0
==tObj1
) fxTMMoveInTM_NoLock(fxMesa
, tObj1
, FX_TMU_BOTH
);
681 /* Find the minimal way to correct the situation */
682 if ((tstate
&T0_IN_TMU0
) || (tstate
&T1_IN_TMU1
)) {
683 /* We have one in the standard order, setup the other */
684 if (tstate
&T0_IN_TMU0
) { /* T0 is in TMU0, put T1 in TMU1 */
685 fxTMMoveInTM_NoLock(fxMesa
, tObj1
, FX_TMU1
);
687 fxTMMoveInTM_NoLock(fxMesa
, tObj0
, FX_TMU0
);
689 /* tmu0 and tmu1 are setup */
690 } else if ((tstate
&T0_IN_TMU1
) || (tstate
&T1_IN_TMU0
)) {
691 /* we have one in the reverse order, setup the other */
692 if (tstate
&T1_IN_TMU0
) { /* T1 is in TMU0, put T0 in TMU1 */
693 fxTMMoveInTM_NoLock(fxMesa
, tObj0
, FX_TMU1
);
695 fxTMMoveInTM_NoLock(fxMesa
, tObj1
, FX_TMU0
);
699 } else { /* Nothing is loaded */
700 fxTMMoveInTM_NoLock(fxMesa
, tObj0
, FX_TMU0
);
701 fxTMMoveInTM_NoLock(fxMesa
, tObj1
, FX_TMU1
);
702 /* tmu0 and tmu1 are setup */
707 if (!fxMesa
->haveGlobalPaletteTexture
) {
708 if (ti0
->info
.format
==GR_TEXFMT_P_8
) {
709 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
710 fprintf(stderr
,"fxmesa: uploading texture palette TMU0\n");
712 FX_grTexDownloadTable_NoLock(tmu0
, GR_TEXTABLE_PALETTE
, &(ti0
->palette
));
715 if (ti1
->info
.format
==GR_TEXFMT_P_8
) {
716 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
717 fprintf(stderr
,"fxmesa: uploading texture palette TMU1\n");
719 FX_grTexDownloadTable_NoLock(tmu1
, GR_TEXTABLE_PALETTE
, &(ti1
->palette
));
723 FX_grTexSource_NoLock(tmu0
, ti0
->tm
[tmu0
]->startAddr
,
724 GR_MIPMAPLEVELMASK_BOTH
, &(ti0
->info
));
725 FX_grTexClampMode_NoLock(tmu0
, ti0
->sClamp
, ti0
->tClamp
);
726 FX_grTexFilterMode_NoLock(tmu0
, ti0
->minFilt
, ti0
->maxFilt
);
727 FX_grTexMipMapMode_NoLock(tmu0
, ti0
->mmMode
, FXFALSE
);
729 FX_grTexSource_NoLock(tmu1
, ti1
->tm
[tmu1
]->startAddr
,
730 GR_MIPMAPLEVELMASK_BOTH
, &(ti1
->info
));
731 FX_grTexClampMode_NoLock(tmu1
, ti1
->sClamp
, ti1
->tClamp
);
732 FX_grTexFilterMode_NoLock(tmu1
, ti1
->minFilt
, ti1
->maxFilt
);
733 FX_grTexMipMapMode_NoLock(tmu1
, ti1
->mmMode
, FXFALSE
);
743 static void fxSetupTextureDoubleTMU_NoLock(GLcontext
*ctx
)
745 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
746 GrCombineLocal_t localc
,locala
;
747 tfxTexInfo
*ti0
,*ti1
;
748 struct gl_texture_object
*tObj0
=ctx
->Texture
.Unit
[0].CurrentD
[2];
749 struct gl_texture_object
*tObj1
=ctx
->Texture
.Unit
[1].CurrentD
[2];
750 GLuint envmode
,ifmt
,unitsmode
;
753 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
754 fprintf(stderr
,"fxmesa: fxSetupTextureDoubleTMU(...) Start\n");
757 ti0
=fxTMGetTexInfo(tObj0
);
758 fxTexValidate(ctx
,tObj0
);
760 ti1
=fxTMGetTexInfo(tObj1
);
761 fxTexValidate(ctx
,tObj1
);
763 fxSetupDoubleTMU_NoLock(fxMesa
,tObj0
,tObj1
);
765 unitsmode
=fxGetTexSetConfiguration(ctx
,tObj0
,tObj1
);
767 /* if(fxMesa->lastUnitsMode==unitsmode) */
770 fxMesa
->lastUnitsMode
=unitsmode
;
772 fxMesa
->stw_hint_state
|= GR_STWHINT_ST_DIFF_TMU1
;
773 FX_grHints_NoLock(GR_HINT_STWHINT
, fxMesa
->stw_hint_state
);
775 envmode
=unitsmode
& FX_UM_E_ENVMODE
;
776 ifmt
=unitsmode
& FX_UM_E_IFMT
;
778 if(unitsmode
& FX_UM_ALPHA_ITERATED
)
779 locala
=GR_COMBINE_LOCAL_ITERATED
;
781 locala
=GR_COMBINE_LOCAL_CONSTANT
;
783 if(unitsmode
& FX_UM_COLOR_ITERATED
)
784 localc
=GR_COMBINE_LOCAL_ITERATED
;
786 localc
=GR_COMBINE_LOCAL_CONSTANT
;
789 if (MESA_VERBOSE
& (VERBOSE_DRIVER
|VERBOSE_TEXTURE
))
790 fprintf(stderr
, "fxMesa: fxSetupTextureDoubleTMU, envmode is %s/%s\n",
791 gl_lookup_enum_by_nr(ctx
->Texture
.Unit
[0].EnvMode
),
792 gl_lookup_enum_by_nr(ctx
->Texture
.Unit
[1].EnvMode
));
795 if ((ti0
->whichTMU
==FX_TMU1
) || (ti1
->whichTMU
==FX_TMU0
)) {
799 fxMesa
->tmuSrc
=FX_TMU_BOTH
;
801 case (FX_UM_E0_MODULATE
| FX_UM_E1_MODULATE
):
803 GLboolean isalpha
[FX_NUM_TMU
];
805 if(ti0
->baseLevelInternalFormat
==GL_ALPHA
)
806 isalpha
[tmu0
]=GL_TRUE
;
808 isalpha
[tmu0
]=GL_FALSE
;
810 if(ti1
->baseLevelInternalFormat
==GL_ALPHA
)
811 isalpha
[tmu1
]=GL_TRUE
;
813 isalpha
[tmu1
]=GL_FALSE
;
816 FX_grTexCombine_NoLock(GR_TMU1
,
817 GR_COMBINE_FUNCTION_ZERO
,
818 GR_COMBINE_FACTOR_NONE
,
819 GR_COMBINE_FUNCTION_LOCAL
,
820 GR_COMBINE_FACTOR_NONE
,
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
,
831 FX_grTexCombine_NoLock(GR_TMU0
,
832 GR_COMBINE_FUNCTION_BLEND_OTHER
,
833 GR_COMBINE_FACTOR_ONE
,
834 GR_COMBINE_FUNCTION_BLEND_OTHER
,
835 GR_COMBINE_FACTOR_LOCAL
,
838 FX_grTexCombine_NoLock(GR_TMU0
,
839 GR_COMBINE_FUNCTION_BLEND_OTHER
,
840 GR_COMBINE_FACTOR_LOCAL
,
841 GR_COMBINE_FUNCTION_BLEND_OTHER
,
842 GR_COMBINE_FACTOR_LOCAL
,
845 FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER
,
846 GR_COMBINE_FACTOR_LOCAL
,
848 GR_COMBINE_OTHER_TEXTURE
,
851 FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER
,
852 GR_COMBINE_FACTOR_LOCAL
,
854 GR_COMBINE_OTHER_TEXTURE
,
858 case (FX_UM_E0_REPLACE
| FX_UM_E1_BLEND
): /* Only for GLQuake */
860 FX_grTexCombine_NoLock(GR_TMU1
,
861 GR_COMBINE_FUNCTION_LOCAL
,
862 GR_COMBINE_FACTOR_NONE
,
863 GR_COMBINE_FUNCTION_LOCAL
,
864 GR_COMBINE_FACTOR_NONE
,
867 FX_grTexCombine_NoLock(GR_TMU0
,
868 GR_COMBINE_FUNCTION_BLEND_OTHER
,
869 GR_COMBINE_FACTOR_LOCAL
,
870 GR_COMBINE_FUNCTION_BLEND_OTHER
,
871 GR_COMBINE_FACTOR_LOCAL
,
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
,
881 FX_grTexCombine_NoLock(GR_TMU0
,
882 GR_COMBINE_FUNCTION_BLEND_OTHER
,
883 GR_COMBINE_FACTOR_ONE_MINUS_LOCAL
,
884 GR_COMBINE_FUNCTION_BLEND_OTHER
,
885 GR_COMBINE_FACTOR_ONE_MINUS_LOCAL
,
889 FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL
,
890 GR_COMBINE_FACTOR_NONE
,
892 GR_COMBINE_OTHER_NONE
,
895 FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER
,
896 GR_COMBINE_FACTOR_ONE
,
898 GR_COMBINE_OTHER_TEXTURE
,
901 case (FX_UM_E0_REPLACE
| FX_UM_E1_MODULATE
): /* Quake 2 and 3 */
903 FX_grTexCombine_NoLock(GR_TMU1
,
904 GR_COMBINE_FUNCTION_LOCAL
,
905 GR_COMBINE_FACTOR_NONE
,
906 GR_COMBINE_FUNCTION_ZERO
,
907 GR_COMBINE_FACTOR_NONE
,
910 FX_grTexCombine_NoLock(GR_TMU0
,
911 GR_COMBINE_FUNCTION_BLEND_OTHER
,
912 GR_COMBINE_FACTOR_LOCAL
,
913 GR_COMBINE_FUNCTION_BLEND_OTHER
,
914 GR_COMBINE_FACTOR_LOCAL
,
918 FX_grTexCombine_NoLock(GR_TMU1
,
919 GR_COMBINE_FUNCTION_LOCAL
,
920 GR_COMBINE_FACTOR_NONE
,
921 GR_COMBINE_FUNCTION_LOCAL
,
922 GR_COMBINE_FACTOR_NONE
,
925 FX_grTexCombine_NoLock(GR_TMU0
,
926 GR_COMBINE_FUNCTION_BLEND_OTHER
,
927 GR_COMBINE_FACTOR_LOCAL
,
928 GR_COMBINE_FUNCTION_BLEND_OTHER
,
929 GR_COMBINE_FACTOR_ONE
,
933 if(ti0
->baseLevelInternalFormat
==GL_RGB
)
934 FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL
,
935 GR_COMBINE_FACTOR_NONE
,
937 GR_COMBINE_OTHER_NONE
,
940 FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER
,
941 GR_COMBINE_FACTOR_ONE
,
943 GR_COMBINE_OTHER_NONE
,
947 FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER
,
948 GR_COMBINE_FACTOR_ONE
,
950 GR_COMBINE_OTHER_TEXTURE
,
955 case (FX_UM_E0_MODULATE
| FX_UM_E1_ADD
): /* Quake 3 Sky */
957 GLboolean isalpha
[FX_NUM_TMU
];
959 if(ti0
->baseLevelInternalFormat
==GL_ALPHA
)
960 isalpha
[tmu0
]=GL_TRUE
;
962 isalpha
[tmu0
]=GL_FALSE
;
964 if(ti1
->baseLevelInternalFormat
==GL_ALPHA
)
965 isalpha
[tmu1
]=GL_TRUE
;
967 isalpha
[tmu1
]=GL_FALSE
;
970 FX_grTexCombine_NoLock(GR_TMU1
,
971 GR_COMBINE_FUNCTION_ZERO
,
972 GR_COMBINE_FACTOR_NONE
,
973 GR_COMBINE_FUNCTION_LOCAL
,
974 GR_COMBINE_FACTOR_NONE
,
977 FX_grTexCombine_NoLock(GR_TMU1
,
978 GR_COMBINE_FUNCTION_LOCAL
,
979 GR_COMBINE_FACTOR_NONE
,
980 GR_COMBINE_FUNCTION_LOCAL
,
981 GR_COMBINE_FACTOR_NONE
,
985 FX_grTexCombine_NoLock(GR_TMU0
,
986 GR_COMBINE_FUNCTION_SCALE_OTHER
,
987 GR_COMBINE_FACTOR_ONE
,
988 GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL
,
989 GR_COMBINE_FACTOR_ONE
,
992 FX_grTexCombine_NoLock(GR_TMU0
,
993 GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL
,
994 GR_COMBINE_FACTOR_ONE
,
995 GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL
,
996 GR_COMBINE_FACTOR_ONE
,
999 FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER
,
1000 GR_COMBINE_FACTOR_LOCAL
,
1002 GR_COMBINE_OTHER_TEXTURE
,
1005 FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER
,
1006 GR_COMBINE_FACTOR_LOCAL
,
1008 GR_COMBINE_OTHER_TEXTURE
,
1013 fprintf(stderr
, "Unexpected dual texture mode encountered\n");
1017 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1018 fprintf(stderr
,"fxmesa: fxSetupTextureDoubleTMU(...) End\n");
1022 /************************* No Texture ***************************/
1024 static void fxSetupTextureNone_NoLock(GLcontext
*ctx
)
1026 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1027 GrCombineLocal_t localc
,locala
;
1029 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1030 fprintf(stderr
,"fxmesa: fxSetupTextureNone(...)\n");
1033 if((ctx
->Light
.ShadeModel
==GL_SMOOTH
) || 1 ||
1034 (ctx
->Point
.SmoothFlag
) ||
1035 (ctx
->Line
.SmoothFlag
) ||
1036 (ctx
->Polygon
.SmoothFlag
))
1037 locala
=GR_COMBINE_LOCAL_ITERATED
;
1039 locala
=GR_COMBINE_LOCAL_CONSTANT
;
1041 if(ctx
->Light
.ShadeModel
==GL_SMOOTH
|| 1)
1042 localc
=GR_COMBINE_LOCAL_ITERATED
;
1044 localc
=GR_COMBINE_LOCAL_CONSTANT
;
1046 FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL
,
1047 GR_COMBINE_FACTOR_NONE
,
1049 GR_COMBINE_OTHER_NONE
,
1052 FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL
,
1053 GR_COMBINE_FACTOR_NONE
,
1055 GR_COMBINE_OTHER_NONE
,
1058 fxMesa
->lastUnitsMode
=FX_UM_NONE
;
1061 /************************************************************************/
1062 /************************** Texture Mode SetUp **************************/
1063 /************************************************************************/
1065 static void fxSetupTexture_NoLock(GLcontext
*ctx
)
1067 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1068 GLuint tex2Denabled
;
1070 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1071 fprintf(stderr
,"fxmesa: fxSetupTexture(...)\n");
1074 /* Disable multipass texturing.
1076 ctx
->Driver
.MultipassFunc
= 0;
1078 /* Texture Combine, Color Combine and Alpha Combine.
1080 tex2Denabled
= (ctx
->Texture
._ReallyEnabled
& TEXTURE0_2D
);
1082 if (fxMesa
->emulateTwoTMUs
)
1083 tex2Denabled
|= (ctx
->Texture
._ReallyEnabled
& TEXTURE1_2D
);
1085 switch(tex2Denabled
) {
1087 fxSetupTextureSingleTMU_NoLock(ctx
,0);
1090 fxSetupTextureSingleTMU_NoLock(ctx
,1);
1092 case (TEXTURE0_2D
|TEXTURE1_2D
):
1093 if (fxMesa
->haveTwoTMUs
)
1094 fxSetupTextureDoubleTMU_NoLock(ctx
);
1096 if (MESA_VERBOSE
&VERBOSE_DRIVER
)
1097 fprintf(stderr
, "fxmesa: enabling fake multitexture\n");
1099 fxSetupTextureSingleTMU_NoLock(ctx
,0);
1100 ctx
->Driver
.MultipassFunc
= fxMultipassTexture
;
1104 fxSetupTextureNone_NoLock(ctx
);
1109 static void fxSetupTexture(GLcontext
*ctx
) {
1111 fxSetupTexture_NoLock(ctx
);
1115 /************************************************************************/
1116 /**************************** Blend SetUp *******************************/
1117 /************************************************************************/
1119 /* XXX consider supporting GL_INGR_blend_func_separate */
1120 void fxDDBlendFunc(GLcontext
*ctx
, GLenum sfactor
, GLenum dfactor
)
1122 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1123 tfxUnitsState
*us
=&fxMesa
->unitsState
;
1124 GrAlphaBlendFnc_t sfact
,dfact
,asfact
,adfact
;
1126 /* From the Glide documentation:
1127 For alpha source and destination blend function factor
1128 parameters, Voodoo Graphics supports only
1129 GR_BLEND_ZERO and GR_BLEND_ONE.
1134 asfact
=sfact
=GR_BLEND_ZERO
;
1137 asfact
=sfact
=GR_BLEND_ONE
;
1140 sfact
=GR_BLEND_DST_COLOR
;
1141 asfact
=GR_BLEND_ONE
;
1143 case GL_ONE_MINUS_DST_COLOR
:
1144 sfact
=GR_BLEND_ONE_MINUS_DST_COLOR
;
1145 asfact
=GR_BLEND_ONE
;
1148 sfact
=GR_BLEND_SRC_ALPHA
;
1149 asfact
=GR_BLEND_ONE
;
1151 case GL_ONE_MINUS_SRC_ALPHA
:
1152 sfact
=GR_BLEND_ONE_MINUS_SRC_ALPHA
;
1153 asfact
=GR_BLEND_ONE
;
1156 sfact
=GR_BLEND_DST_ALPHA
;
1157 asfact
=GR_BLEND_ONE
;
1159 case GL_ONE_MINUS_DST_ALPHA
:
1160 sfact
=GR_BLEND_ONE_MINUS_DST_ALPHA
;
1161 asfact
=GR_BLEND_ONE
;
1163 case GL_SRC_ALPHA_SATURATE
:
1164 sfact
=GR_BLEND_ALPHA_SATURATE
;
1165 asfact
=GR_BLEND_ONE
;
1168 case GL_ONE_MINUS_SRC_COLOR
:
1170 asfact
=sfact
=GR_BLEND_ONE
;
1173 asfact
=sfact
=GR_BLEND_ONE
;
1177 if((sfact
!=us
->blendSrcFuncRGB
) ||
1178 (asfact
!=us
->blendSrcFuncAlpha
)) {
1179 us
->blendSrcFuncRGB
=sfact
;
1180 us
->blendSrcFuncAlpha
=asfact
;
1181 fxMesa
->new_state
|= FX_NEW_BLEND
;
1182 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1187 adfact
=dfact
=GR_BLEND_ZERO
;
1190 adfact
=dfact
=GR_BLEND_ONE
;
1193 dfact
=GR_BLEND_SRC_COLOR
;
1194 adfact
=GR_BLEND_ZERO
;
1196 case GL_ONE_MINUS_SRC_COLOR
:
1197 dfact
=GR_BLEND_ONE_MINUS_SRC_COLOR
;
1198 adfact
=GR_BLEND_ZERO
;
1201 dfact
=GR_BLEND_SRC_ALPHA
;
1202 adfact
=GR_BLEND_ZERO
;
1204 case GL_ONE_MINUS_SRC_ALPHA
:
1205 dfact
=GR_BLEND_ONE_MINUS_SRC_ALPHA
;
1206 adfact
=GR_BLEND_ZERO
;
1209 /* dfact=GR_BLEND_DST_ALPHA; */
1210 /* We can't do DST_ALPHA */
1212 adfact
=GR_BLEND_ZERO
;
1214 case GL_ONE_MINUS_DST_ALPHA
:
1215 /* dfact=GR_BLEND_ONE_MINUS_DST_ALPHA; */
1216 /* We can't do DST_ALPHA */
1217 dfact
=GR_BLEND_ZERO
;
1218 adfact
=GR_BLEND_ZERO
;
1220 case GL_SRC_ALPHA_SATURATE
:
1222 case GL_ONE_MINUS_DST_COLOR
:
1224 adfact
=dfact
=GR_BLEND_ZERO
;
1227 adfact
=dfact
=GR_BLEND_ZERO
;
1231 if((dfact
!=us
->blendDstFuncRGB
) ||
1232 (adfact
!=us
->blendDstFuncAlpha
)) {
1233 us
->blendDstFuncRGB
=dfact
;
1234 us
->blendDstFuncAlpha
=adfact
;
1235 fxMesa
->new_state
|= FX_NEW_BLEND
;
1236 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1240 static void fxSetupBlend(GLcontext
*ctx
)
1242 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1243 tfxUnitsState
*us
=&fxMesa
->unitsState
;
1245 if(us
->blendEnabled
)
1246 FX_grAlphaBlendFunction(us
->blendSrcFuncRGB
,us
->blendDstFuncRGB
,
1247 us
->blendSrcFuncAlpha
,us
->blendDstFuncAlpha
);
1249 FX_grAlphaBlendFunction(GR_BLEND_ONE
,GR_BLEND_ZERO
,GR_BLEND_ONE
,GR_BLEND_ZERO
);
1252 /************************************************************************/
1253 /************************** Alpha Test SetUp ****************************/
1254 /************************************************************************/
1256 void fxDDAlphaFunc(GLcontext
*ctx
, GLenum func
, GLclampf ref
)
1258 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1259 tfxUnitsState
*us
=&fxMesa
->unitsState
;
1264 newfunc
=GR_CMP_NEVER
;
1267 newfunc
=GR_CMP_LESS
;
1270 newfunc
=GR_CMP_EQUAL
;
1273 newfunc
=GR_CMP_LEQUAL
;
1276 newfunc
=GR_CMP_GREATER
;
1279 newfunc
=GR_CMP_NOTEQUAL
;
1282 newfunc
=GR_CMP_GEQUAL
;
1285 newfunc
=GR_CMP_ALWAYS
;
1288 fprintf(stderr
,"fx Driver: internal error in fxDDAlphaFunc()\n");
1294 if(newfunc
!=us
->alphaTestFunc
) {
1295 us
->alphaTestFunc
=newfunc
;
1296 fxMesa
->new_state
|= FX_NEW_ALPHA
;
1297 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1300 if(ctx
->Color
.AlphaRef
!=us
->alphaTestRefValue
) {
1301 us
->alphaTestRefValue
=ctx
->Color
.AlphaRef
;
1302 fxMesa
->new_state
|= FX_NEW_ALPHA
;
1303 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1307 static void fxSetupAlphaTest(GLcontext
*ctx
)
1309 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1310 tfxUnitsState
*us
=&fxMesa
->unitsState
;
1312 if(us
->alphaTestEnabled
) {
1313 FX_grAlphaTestFunction(us
->alphaTestFunc
);
1314 FX_grAlphaTestReferenceValue(us
->alphaTestRefValue
);
1316 FX_grAlphaTestFunction(GR_CMP_ALWAYS
);
1319 /************************************************************************/
1320 /************************** Depth Test SetUp ****************************/
1321 /************************************************************************/
1323 void fxDDDepthFunc(GLcontext
*ctx
, GLenum func
)
1325 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1326 tfxUnitsState
*us
=&fxMesa
->unitsState
;
1337 dfunc
=GR_CMP_GEQUAL
;
1340 dfunc
=GR_CMP_LEQUAL
;
1343 dfunc
=GR_CMP_GREATER
;
1346 dfunc
=GR_CMP_NOTEQUAL
;
1352 dfunc
=GR_CMP_ALWAYS
;
1355 fprintf(stderr
,"fx Driver: internal error in fxDDDepthFunc()\n");
1361 if(dfunc
!=us
->depthTestFunc
) {
1362 us
->depthTestFunc
=dfunc
;
1363 fxMesa
->new_state
|= FX_NEW_DEPTH
;
1364 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1369 void fxDDDepthMask(GLcontext
*ctx
, GLboolean flag
)
1371 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1372 tfxUnitsState
*us
=&fxMesa
->unitsState
;
1374 if(flag
!=us
->depthMask
) {
1376 fxMesa
->new_state
|= FX_NEW_DEPTH
;
1377 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1381 static void fxSetupDepthTest(GLcontext
*ctx
)
1383 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1384 tfxUnitsState
*us
=&fxMesa
->unitsState
;
1386 if (us
->depthTestEnabled
) {
1387 FX_grDepthBufferFunction(us
->depthTestFunc
);
1388 FX_grDepthMask(us
->depthMask
);
1391 FX_grDepthBufferFunction(GR_CMP_ALWAYS
);
1392 FX_grDepthMask(FXFALSE
);
1396 /************************************************************************/
1397 /**************************** Color Mask SetUp **************************/
1398 /************************************************************************/
1400 void fxDDColorMask(GLcontext
*ctx
,
1401 GLboolean r
, GLboolean g
,
1402 GLboolean b
, GLboolean a
)
1404 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1405 fxMesa
->new_state
|= FX_NEW_COLOR_MASK
;
1406 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1407 (void) r
; (void) g
; (void) b
; (void) a
;
1410 static void fxSetupColorMask(GLcontext
*ctx
)
1412 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1414 if (ctx
->Color
.DrawBuffer
== GL_NONE
) {
1415 FX_grColorMask(FXFALSE
, FXFALSE
);
1418 FX_grColorMask(ctx
->Color
.ColorMask
[RCOMP
] ||
1419 ctx
->Color
.ColorMask
[GCOMP
] ||
1420 ctx
->Color
.ColorMask
[BCOMP
],
1421 ctx
->Color
.ColorMask
[ACOMP
] && fxMesa
->haveAlphaBuffer
);
1428 /************************************************************************/
1429 /**************************** Fog Mode SetUp ****************************/
1430 /************************************************************************/
1433 * This is called during state update in order to update the Glide fog state.
1435 static void fxSetupFog(GLcontext
*ctx
)
1437 if (ctx
->Fog
.Enabled
/*&& ctx->FogMode==FOG_FRAGMENT*/) {
1438 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1440 /* update fog color */
1442 col
[0]=(unsigned int)(255*ctx
->Fog
.Color
[0]);
1443 col
[1]=(unsigned int)(255*ctx
->Fog
.Color
[1]);
1444 col
[2]=(unsigned int)(255*ctx
->Fog
.Color
[2]);
1445 col
[3]=(unsigned int)(255*ctx
->Fog
.Color
[3]);
1446 FX_grFogColorValue(FXCOLOR4(col
));
1448 if(fxMesa
->fogTableMode
!= ctx
->Fog
.Mode
||
1449 fxMesa
->fogDensity
!= ctx
->Fog
.Density
||
1450 fxMesa
->fogStart
!= ctx
->Fog
.Start
||
1451 fxMesa
->fogEnd
!= ctx
->Fog
.End
) {
1452 /* reload the fog table */
1453 switch (ctx
->Fog
.Mode
) {
1455 guFogGenerateLinear(fxMesa
->fogTable
, ctx
->Fog
.Start
, ctx
->Fog
.End
);
1458 guFogGenerateExp(fxMesa
->fogTable
, ctx
->Fog
.Density
);
1461 guFogGenerateExp2(fxMesa
->fogTable
, ctx
->Fog
.Density
);
1466 fxMesa
->fogTableMode
= ctx
->Fog
.Mode
;
1467 fxMesa
->fogDensity
= ctx
->Fog
.Density
;
1468 fxMesa
->fogStart
= ctx
->Fog
.Start
;
1469 fxMesa
->fogEnd
= ctx
->Fog
.End
;
1472 FX_grFogTable(fxMesa
->fogTable
);
1473 FX_grFogMode(GR_FOG_WITH_TABLE
);
1476 FX_grFogMode(GR_FOG_DISABLE
);
1480 void fxDDFogfv( GLcontext
*ctx
, GLenum pname
, const GLfloat
*params
)
1482 FX_CONTEXT(ctx
)->new_state
|= FX_NEW_FOG
;
1483 ctx
->Driver
.RenderStart
= fxSetupFXUnits
; /* XXX why is this here? */
1486 /************************************************************************/
1487 /************************** Scissor Test SetUp **************************/
1488 /************************************************************************/
1490 /* This routine is used in managing the lock state, and therefore can't lock */
1491 void fxSetScissorValues(GLcontext
*ctx
)
1493 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1495 int ymin
, ymax
, check
;
1497 if (ctx
->Scissor
.Enabled
) {
1498 xmin
=ctx
->Scissor
.X
;
1499 xmax
=ctx
->Scissor
.X
+ctx
->Scissor
.Width
;
1500 ymin
=ctx
->Scissor
.Y
;
1501 ymax
=ctx
->Scissor
.Y
+ctx
->Scissor
.Height
;
1507 ymax
=fxMesa
->height
;
1510 if (xmin
<fxMesa
->clipMinX
) xmin
=fxMesa
->clipMinX
;
1511 if (xmax
>fxMesa
->clipMaxX
) xmax
=fxMesa
->clipMaxX
;
1512 if (ymin
<fxMesa
->screen_height
-fxMesa
->clipMaxY
)
1513 ymin
=fxMesa
->screen_height
-fxMesa
->clipMaxY
;
1514 if (ymax
>fxMesa
->screen_height
-fxMesa
->clipMinY
)
1515 ymax
=fxMesa
->screen_height
-fxMesa
->clipMinY
;
1516 FX_grClipWindow_NoLock(xmin
, ymin
, xmax
, ymax
);
1519 static void fxSetupScissor(GLcontext
*ctx
)
1521 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1523 fxSetScissorValues(ctx
);
1527 void fxDDScissor( GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
1529 FX_CONTEXT(ctx
)->new_state
|= FX_NEW_SCISSOR
;
1530 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1533 /************************************************************************/
1534 /*************************** Cull mode setup ****************************/
1535 /************************************************************************/
1538 void fxDDCullFace(GLcontext
*ctx
, GLenum mode
)
1541 FX_CONTEXT(ctx
)->new_state
|= FX_NEW_CULL
;
1542 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1545 void fxDDFrontFace(GLcontext
*ctx
, GLenum mode
)
1548 FX_CONTEXT(ctx
)->new_state
|= FX_NEW_CULL
;
1549 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1553 static void fxSetupCull(GLcontext
*ctx
)
1555 if (ctx
->Polygon
.CullFlag
) {
1556 switch (ctx
->Polygon
.CullFaceMode
) {
1558 if (ctx
->Polygon
.FrontFace
==GL_CCW
)
1559 FX_CONTEXT(ctx
)->cullMode
=GR_CULL_NEGATIVE
;
1561 FX_CONTEXT(ctx
)->cullMode
=GR_CULL_POSITIVE
;
1564 if(ctx
->Polygon
.FrontFace
==GL_CCW
)
1565 FX_CONTEXT(ctx
)->cullMode
=GR_CULL_POSITIVE
;
1567 FX_CONTEXT(ctx
)->cullMode
=GR_CULL_NEGATIVE
;
1569 case GL_FRONT_AND_BACK
:
1570 FX_CONTEXT(ctx
)->cullMode
=GR_CULL_DISABLE
;
1575 } else FX_CONTEXT(ctx
)->cullMode
=GR_CULL_DISABLE
;
1577 FX_grCullMode(FX_CONTEXT(ctx
)->cullMode
);
1581 /************************************************************************/
1582 /****************************** DD Enable ******************************/
1583 /************************************************************************/
1585 void fxDDEnable(GLcontext
*ctx
, GLenum cap
, GLboolean state
)
1587 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1588 tfxUnitsState
*us
=&fxMesa
->unitsState
;
1590 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1591 fprintf(stderr
,"fxmesa: fxDDEnable(...)\n");
1596 if(state
!=us
->alphaTestEnabled
) {
1597 us
->alphaTestEnabled
=state
;
1598 fxMesa
->new_state
|= FX_NEW_ALPHA
;
1599 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1603 if(state
!=us
->blendEnabled
) {
1604 us
->blendEnabled
=state
;
1605 fxMesa
->new_state
|= FX_NEW_BLEND
;
1606 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1610 if(state
!=us
->depthTestEnabled
) {
1611 us
->depthTestEnabled
=state
;
1612 fxMesa
->new_state
|= FX_NEW_DEPTH
;
1613 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1618 FX_grDitherMode(GR_DITHER_4x4
);
1620 FX_grDitherMode(GR_DITHER_DISABLE
);
1623 case GL_SCISSOR_TEST
:
1624 fxMesa
->new_state
|= FX_NEW_SCISSOR
;
1625 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1627 case GL_SHARED_TEXTURE_PALETTE_EXT
:
1628 fxDDTexUseGlbPalette(ctx
, state
);
1631 fxMesa
->new_state
|= FX_NEW_FOG
;
1632 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1635 fxMesa
->new_state
|= FX_NEW_CULL
;
1636 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1638 case GL_LINE_SMOOTH
:
1639 case GL_LINE_STIPPLE
:
1640 case GL_POINT_SMOOTH
:
1641 case GL_POLYGON_SMOOTH
:
1643 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
1644 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1653 Multipass to do GL_BLEND texture functions
1654 Cf*(1-Ct) has already been written to the buffer during the first pass
1655 Cc*Ct gets written during the second pass (in this function)
1656 Everything gets reset in the third call (in this function)
1658 static GLboolean
fxMultipassBlend(struct vertex_buffer
*VB
, GLuint pass
)
1660 GLcontext
*ctx
= VB
->ctx
;
1661 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1666 fxMesa
->restoreUnitsState
=fxMesa
->unitsState
;
1667 if (ctx
->Depth
.Mask
) {
1668 /* We don't want to check or change the depth buffers */
1669 switch (ctx
->Depth
.Func
) {
1674 fxDDDepthFunc(ctx
, GL_EQUAL
);
1677 fxDDDepthMask(ctx
, FALSE
);
1679 /* Enable Cc*Ct mode */
1680 /* XXX Set the Constant Color ? */
1681 fxDDEnable(ctx
, GL_BLEND
, GL_TRUE
);
1682 fxDDBlendFunc(ctx
, XXX
, XXX
);
1683 fxSetupTextureSingleTMU(ctx
, XXX
);
1685 fxSetupDepthTest(ctx
);
1689 /* Reset everything back to normal */
1690 fxMesa
->unitsState
= fxMesa
->restoreUnitsState
;
1691 fxMesa
->setupdone
&= XXX
;
1692 fxSetupTextureSingleTMU(ctx
, XXX
);
1694 fxSetupDepthTest(ctx
);
1702 /************************************************************************/
1703 /******************** Fake Multitexture Support *************************/
1704 /************************************************************************/
1706 /* Its considered cheeky to try to fake ARB multitexture by doing
1707 * multipass rendering, because it is not possible to emulate the full
1708 * spec in this way. The fact is that the voodoo 2 supports only a
1709 * subset of the possible multitexturing modes, and it is possible to
1710 * support almost the same subset using multipass blending on the
1711 * voodoo 1. In all other cases for both voodoo 1 and 2, we fall back
1712 * to software rendering, satisfying the spec if not the user.
1714 static GLboolean
fxMultipassTexture( struct vertex_buffer
*VB
, GLuint pass
)
1716 GLcontext
*ctx
= VB
->ctx
;
1717 fxVertex
*v
= FX_DRIVER_DATA(VB
)->verts
;
1718 fxVertex
*last
= FX_DRIVER_DATA(VB
)->last_vert
;
1719 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1723 if (MESA_VERBOSE
&(VERBOSE_DRIVER
|VERBOSE_PIPELINE
|VERBOSE_TEXTURE
))
1724 fprintf(stderr
, "fxmesa: Second texture pass\n");
1726 for ( ; v
!= last
; v
++) {
1727 v
->f
[S0COORD
] = v
->f
[S1COORD
];
1728 v
->f
[T0COORD
] = v
->f
[T1COORD
];
1731 fxMesa
->restoreUnitsState
= fxMesa
->unitsState
;
1732 fxMesa
->tmu_source
[0] = 1;
1734 if (ctx
->Depth
.Mask
) {
1735 switch (ctx
->Depth
.Func
) {
1740 fxDDDepthFunc( ctx
, GL_EQUAL
);
1744 fxDDDepthMask( ctx
, GL_FALSE
);
1747 if (ctx
->Texture
.Unit
[1].EnvMode
== GL_MODULATE
) {
1748 fxDDEnable( ctx
, GL_BLEND
, GL_TRUE
);
1749 fxDDBlendFunc( ctx
, GL_DST_COLOR
, GL_ZERO
);
1752 fxSetupTextureSingleTMU( ctx
, 1 );
1753 fxSetupBlend( ctx
);
1754 fxSetupDepthTest( ctx
);
1758 /* Restore original state.
1760 fxMesa
->tmu_source
[0] = 0;
1761 fxMesa
->unitsState
= fxMesa
->restoreUnitsState
;
1762 fxMesa
->setupdone
&= ~SETUP_TMU0
;
1763 fxSetupTextureSingleTMU( ctx
, 0 );
1764 fxSetupBlend( ctx
);
1765 fxSetupDepthTest( ctx
);
1773 /************************************************************************/
1774 /************************** Changes to units state **********************/
1775 /************************************************************************/
1778 /* All units setup is handled under texture setup.
1780 void fxDDShadeModel(GLcontext
*ctx
, GLenum mode
)
1782 FX_CONTEXT(ctx
)->new_state
|= FX_NEW_TEXTURING
;
1783 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
1788 /************************************************************************/
1789 /****************************** Units SetUp *****************************/
1790 /************************************************************************/
1791 static void gl_print_fx_state_flags( const char *msg
, GLuint flags
)
1794 "%s: (0x%x) %s%s%s%s%s%s%s\n",
1797 (flags
& FX_NEW_TEXTURING
) ? "texture, " : "",
1798 (flags
& FX_NEW_BLEND
) ? "blend, " : "",
1799 (flags
& FX_NEW_ALPHA
) ? "alpha, " : "",
1800 (flags
& FX_NEW_FOG
) ? "fog, " : "",
1801 (flags
& FX_NEW_SCISSOR
) ? "scissor, " : "",
1802 (flags
& FX_NEW_COLOR_MASK
) ? "colormask, " : "",
1803 (flags
& FX_NEW_CULL
) ? "cull, " : "");
1806 void fxSetupFXUnits( GLcontext
*ctx
)
1808 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1809 GLuint newstate
= fxMesa
->new_state
;
1811 if (MESA_VERBOSE
&VERBOSE_DRIVER
)
1812 gl_print_fx_state_flags("fxmesa: fxSetupFXUnits", newstate
);
1815 if (newstate
& FX_NEW_TEXTURING
)
1816 fxSetupTexture(ctx
);
1818 if (newstate
& FX_NEW_BLEND
)
1821 if (newstate
& FX_NEW_ALPHA
)
1822 fxSetupAlphaTest(ctx
);
1824 if (newstate
& FX_NEW_DEPTH
)
1825 fxSetupDepthTest(ctx
);
1827 if (newstate
& FX_NEW_FOG
)
1830 if (newstate
& FX_NEW_SCISSOR
)
1831 fxSetupScissor(ctx
);
1833 if (newstate
& FX_NEW_COLOR_MASK
)
1834 fxSetupColorMask(ctx
);
1836 if (newstate
& FX_NEW_CULL
) {
1841 fxMesa
->draw_point
= fxMesa
->initial_point
;
1842 fxMesa
->draw_line
= fxMesa
->initial_line
;
1843 fxMesa
->draw_tri
= fxMesa
->initial_tri
;
1844 fxMesa
->new_state
= 0;
1854 * Need this to provide at least one external definition.
1857 int gl_fx_dummy_function_setup(void)