2 * Copyright 2000-2001 VA Linux Systems, Inc.
3 * (c) Copyright IBM Corporation 2002
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * on the rights to use, copy, modify, merge, publish, distribute, sub
10 * license, and/or sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * VA LINUX SYSTEMS, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 * USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Ian Romanick <idr@us.ibm.com>
27 * Keith Whitwell <keithw@tungstengraphics.com>
32 #include "mgacontext.h"
43 #include "simple_list.h"
44 #include "texformat.h"
46 #define MGA_USE_TABLE_FOR_FORMAT
47 #ifdef MGA_USE_TABLE_FOR_FORMAT
48 #define TMC_nr_tformat (MESA_FORMAT_YCBCR_REV + 1)
49 static const unsigned TMC_tformat
[ TMC_nr_tformat
] =
51 [MESA_FORMAT_ARGB8888
] = TMC_tformat_tw32
,
52 [MESA_FORMAT_RGB565
] = TMC_tformat_tw16
,
53 [MESA_FORMAT_ARGB4444
] = TMC_tformat_tw12
,
54 [MESA_FORMAT_ARGB1555
] = TMC_tformat_tw15
,
55 [MESA_FORMAT_AL88
] = TMC_tformat_tw8al
,
56 [MESA_FORMAT_I8
] = TMC_tformat_tw8a
,
57 [MESA_FORMAT_CI8
] = TMC_tformat_tw8
,
58 [MESA_FORMAT_YCBCR
] = TMC_tformat_tw422uyvy
,
59 [MESA_FORMAT_YCBCR_REV
] = TMC_tformat_tw422
,
64 mgaSetTexImages( mgaContextPtr mmesa
,
65 const struct gl_texture_object
* tObj
)
67 mgaTextureObjectPtr t
= (mgaTextureObjectPtr
) tObj
->DriverData
;
68 struct gl_texture_image
*baseImage
= tObj
->Image
[0][ tObj
->BaseLevel
];
73 GLint log2Width
, log2Height
;
77 /* Set the hardware texture format
79 #ifndef MGA_USE_TABLE_FOR_FORMAT
80 switch (baseImage
->TexFormat
->MesaFormat
) {
82 case MESA_FORMAT_ARGB8888
: txformat
= TMC_tformat_tw32
; break;
83 case MESA_FORMAT_RGB565
: txformat
= TMC_tformat_tw16
; break;
84 case MESA_FORMAT_ARGB4444
: txformat
= TMC_tformat_tw12
; break;
85 case MESA_FORMAT_ARGB1555
: txformat
= TMC_tformat_tw15
; break;
86 case MESA_FORMAT_AL88
: txformat
= TMC_tformat_tw8al
; break;
87 case MESA_FORMAT_I8
: txformat
= TMC_tformat_tw8a
; break;
88 case MESA_FORMAT_CI8
: txformat
= TMC_tformat_tw8
; break;
89 case MESA_FORMAT_YCBCR
: txformat
= TMC_tformat_tw422uyvy
; break;
90 case MESA_FORMAT_YCBCR_REV
: txformat
= TMC_tformat_tw422
; break;
93 _mesa_problem(NULL
, "unexpected texture format in %s", __FUNCTION__
);
97 if ( (baseImage
->TexFormat
->MesaFormat
>= TMC_nr_tformat
)
98 || (TMC_tformat
[ baseImage
->TexFormat
->MesaFormat
] == 0) )
100 _mesa_problem(NULL
, "unexpected texture format in %s", __FUNCTION__
);
104 txformat
= TMC_tformat
[ baseImage
->TexFormat
->MesaFormat
];
106 #endif /* MGA_USE_TABLE_FOR_FORMAT */
108 driCalculateTextureFirstLastLevel( (driTextureObject
*) t
);
109 if (tObj
->Target
== GL_TEXTURE_RECTANGLE_NV
) {
113 log2Width
= tObj
->Image
[0][t
->base
.firstLevel
]->WidthLog2
;
114 log2Height
= tObj
->Image
[0][t
->base
.firstLevel
]->HeightLog2
;
117 width
= tObj
->Image
[0][t
->base
.firstLevel
]->Width
;
118 height
= tObj
->Image
[0][t
->base
.firstLevel
]->Height
;
120 numLevels
= MIN2( t
->base
.lastLevel
- t
->base
.firstLevel
+ 1,
121 MGA_IS_G200(mmesa
) ? G200_TEX_MAXLEVELS
: G400_TEX_MAXLEVELS
);
125 for ( i
= 0 ; i
< numLevels
; i
++ ) {
126 const struct gl_texture_image
* const texImage
=
127 tObj
->Image
[0][ i
+ t
->base
.firstLevel
];
130 if (texImage
== NULL
)
133 size
= texImage
->Width
* texImage
->Height
*
134 baseImage
->TexFormat
->TexelBytes
;
136 t
->offsets
[i
] = totalSize
;
137 t
->base
.dirty_images
[0] |= (1<<i
);
139 /* All mipmaps must be 32-byte aligned */
140 totalSize
+= (size
+ 31) & ~31;
142 /* Since G400 calculates the offsets in hardware
143 * it can't handle more than one < 32 byte mipmap.
145 * Further testing has indicated that it can't
146 * handle any < 32 byte mipmaps.
148 if (MGA_IS_G400( mmesa
) && size
<= 32) {
154 /* save these values */
156 t
->base
.lastLevel
= t
->base
.firstLevel
+ numLevels
- 1;
157 t
->base
.totalSize
= totalSize
;
159 /* setup hardware register values */
160 t
->setup
.texctl
&= (TMC_tformat_MASK
& TMC_tpitch_MASK
161 & TMC_tpitchext_MASK
);
162 t
->setup
.texctl
|= txformat
;
165 /* Set the texture width. In order to support non-power of 2 textures and
166 * textures larger than 1024 texels wide, "linear" pitch must be used. For
167 * the linear pitch, if the width is 2048, a value of zero is used.
170 t
->setup
.texctl
|= TMC_tpitchlin_enable
;
171 t
->setup
.texctl
|= MGA_FIELD( TMC_tpitchext
, width
& (2048 - 1) );
174 /* G400 specifies the number of mip levels in a strange way. Since there
175 * are up to 11 levels, it requires 4 bits. Three of the bits are at the
176 * high end of TEXFILTER. The other bit is in the middle. Weird.
179 t
->setup
.texfilter
&= TF_mapnb_MASK
& TF_mapnbhigh_MASK
& TF_reserved_MASK
;
180 t
->setup
.texfilter
|= MGA_FIELD( TF_mapnb
, numLevels
& 0x7 );
181 t
->setup
.texfilter
|= MGA_FIELD( TF_mapnbhigh
, (numLevels
>> 3) & 0x1 );
183 /* warp texture registers */
184 ofs
= MGA_IS_G200(mmesa
) ? 28 : 11;
186 t
->setup
.texwidth
= (MGA_FIELD(TW_twmask
, width
- 1) |
187 MGA_FIELD(TW_rfw
, (10 - log2Width
- 8) & 63 ) |
188 MGA_FIELD(TW_tw
, (log2Width
+ ofs
) | 0x40 ));
190 t
->setup
.texheight
= (MGA_FIELD(TH_thmask
, height
- 1) |
191 MGA_FIELD(TH_rfh
, (10 - log2Height
- 8) & 63 ) |
192 MGA_FIELD(TH_th
, (log2Height
+ ofs
) | 0x40 ));
194 mgaUploadTexImages( mmesa
, t
);
198 /* ================================================================
199 * Texture unit state management
202 static void mgaUpdateTextureEnvG200( GLcontext
*ctx
, GLuint unit
)
204 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
205 struct gl_texture_object
*tObj
= ctx
->Texture
.Unit
[0]._Current
;
206 mgaTextureObjectPtr t
= (mgaTextureObjectPtr
) tObj
->DriverData
;
207 GLenum format
= tObj
->Image
[0][tObj
->BaseLevel
]->_BaseFormat
;
209 if (tObj
!= ctx
->Texture
.Unit
[0].Current2D
&&
210 tObj
!= ctx
->Texture
.Unit
[0].CurrentRect
)
214 t
->setup
.texctl
&= ~TMC_tmodulate_enable
;
215 t
->setup
.texctl2
&= ~(TMC_decalblend_enable
|
217 TMC_decaldis_enable
);
219 switch (ctx
->Texture
.Unit
[0].EnvMode
) {
221 if (format
== GL_ALPHA
)
222 t
->setup
.texctl2
|= TMC_idecal_enable
;
224 if (format
== GL_RGB
|| format
== GL_LUMINANCE
)
225 mmesa
->hw
.alpha_sel
= AC_alphasel_diffused
;
227 mmesa
->hw
.alpha_sel
= AC_alphasel_fromtex
;
231 t
->setup
.texctl
|= TMC_tmodulate_enable
;
233 if (format
== GL_ALPHA
)
234 t
->setup
.texctl2
|= (TMC_idecal_enable
|
235 TMC_decaldis_enable
);
237 if (format
== GL_RGB
|| format
== GL_LUMINANCE
)
238 mmesa
->hw
.alpha_sel
= AC_alphasel_diffused
;
240 mmesa
->hw
.alpha_sel
= AC_alphasel_modulated
;
244 if (format
== GL_RGB
|| format
== GL_RGBA
)
245 t
->setup
.texctl2
|= TMC_decalblend_enable
;
247 t
->setup
.texctl2
|= TMC_idecal_enable
;
249 mmesa
->hw
.alpha_sel
= AC_alphasel_diffused
;
253 if (format
== GL_ALPHA
) {
254 t
->setup
.texctl2
|= TMC_idecal_enable
;
255 mmesa
->hw
.alpha_sel
= AC_alphasel_modulated
;
257 t
->texenv_fallback
= GL_TRUE
;
267 #define MGA_REPLACE 0
268 #define MGA_MODULATE 1
271 #define MGA_MAX_COMBFUNC 4
273 static const GLuint g400_color_combine
[][MGA_MAX_COMBFUNC
] =
282 (TD0_color_sel_arg1
|
283 TD0_alpha_arg2_diffuse
|
290 (TD0_color_arg2_diffuse
|
292 TD0_alpha_arg2_diffuse
|
299 (TD0_color_sel_arg1
|
300 TD0_alpha_arg2_diffuse
|
307 (TD0_color_arg2_diffuse
|
310 TD0_alpha_arg2_diffuse
|
321 (TD0_color_sel_arg1
|
322 TD0_alpha_arg2_prevstage
|
329 (TD0_color_arg2_prevstage
|
331 TD0_alpha_arg2_prevstage
|
338 (TD0_color_sel_arg1
|
339 TD0_alpha_arg2_prevstage
|
346 (TD0_color_arg2_prevstage
|
349 TD0_alpha_arg2_prevstage
|
354 static const GLuint g400_color_alpha_combine
[][MGA_MAX_COMBFUNC
] =
363 (TD0_color_sel_arg1
|
370 (TD0_color_arg2_diffuse
|
372 TD0_alpha_arg2_diffuse
|
376 * tmp = Cf ( 1 - As )
380 (TD0_color_arg2_diffuse
|
381 TD0_color_alpha_currtex
|
382 TD0_color_alpha1inv_enable
|
383 TD0_color_arg1mul_alpha1
|
384 TD0_color_blend_enable
|
385 TD0_color_arg1add_mulout
|
386 TD0_color_arg2add_mulout
|
389 TD0_alpha_arg2_diffuse
|
396 (TD0_color_arg2_diffuse
|
399 TD0_alpha_arg2_diffuse
|
410 (TD0_color_sel_arg1
|
417 (TD0_color_arg2_prevstage
|
419 TD0_alpha_arg2_prevstage
|
423 * tmp = Cp ( 1 - As )
427 (TD0_color_arg2_prevstage
|
428 TD0_color_alpha_currtex
|
429 TD0_color_alpha1inv_enable
|
430 TD0_color_arg1mul_alpha1
|
431 TD0_color_blend_enable
|
432 TD0_color_arg1add_mulout
|
433 TD0_color_arg2add_mulout
|
436 TD0_alpha_arg2_prevstage
|
443 (TD0_color_arg2_prevstage
|
446 TD0_alpha_arg2_prevstage
|
451 static const GLuint g400_alpha_combine
[][MGA_MAX_COMBFUNC
] =
460 (TD0_color_arg2_diffuse
|
468 (TD0_color_arg2_diffuse
|
470 TD0_alpha_arg2_diffuse
|
473 /* GL_DECAL (undefined)
477 (TD0_color_arg2_diffuse
|
479 TD0_alpha_arg2_diffuse
|
486 (TD0_color_arg2_diffuse
|
488 TD0_alpha_arg2_diffuse
|
499 (TD0_color_arg2_prevstage
|
507 (TD0_color_arg2_prevstage
|
509 TD0_alpha_arg2_prevstage
|
512 /* GL_DECAL (undefined)
516 (TD0_color_arg2_prevstage
|
518 TD0_alpha_arg2_prevstage
|
525 (TD0_color_arg2_prevstage
|
527 TD0_alpha_arg2_prevstage
|
532 static GLboolean
mgaUpdateTextureEnvBlend( GLcontext
*ctx
, int unit
)
534 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
535 const int source
= mmesa
->tmu_source
[unit
];
536 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[source
];
537 const struct gl_texture_object
*tObj
= texUnit
->_Current
;
538 GLuint
*reg
= ((GLuint
*)&mmesa
->setup
.tdualstage0
+ unit
);
539 GLenum format
= tObj
->Image
[0][tObj
->BaseLevel
]->_BaseFormat
;
543 if (format
== GL_ALPHA
) {
545 *reg
|= (TD0_color_arg2_diffuse
|
548 *reg
|= (TD0_alpha_arg2_diffuse
|
553 /* C1 = Cf ( 1 - Cs ) */
554 *reg
|= (TD0_color_arg1_inv_enable
|
555 TD0_color_arg2_diffuse
|
558 if (format
== GL_RGB
|| format
== GL_LUMINANCE
) {
560 *reg
|= (TD0_alpha_arg2_diffuse
|
563 if (format
== GL_RGBA
|| format
== GL_LUMINANCE_ALPHA
) {
565 *reg
|= (TD0_alpha_arg2_diffuse
|
568 if (format
== GL_INTENSITY
) {
569 /* A1 = Af ( 1 - As ) */
570 *reg
|= (TD0_alpha_arg1_inv_enable
|
571 TD0_alpha_arg2_diffuse
|
575 if (RGB_ZERO(mmesa
->envcolor
[source
]) &&
576 (format
!= GL_INTENSITY
|| ALPHA_ZERO(mmesa
->envcolor
[source
])))
577 return GL_TRUE
; /* all done */
579 if (ctx
->Texture
._EnabledUnits
== 0x03)
580 return GL_FALSE
; /* need both units */
582 mmesa
->force_dualtex
= GL_TRUE
;
583 reg
= &mmesa
->setup
.tdualstage1
;
586 if (RGB_ZERO(mmesa
->envcolor
[source
])) {
588 *reg
|= (TD0_color_arg2_prevstage
|
591 if (RGB_ONE(mmesa
->envcolor
[source
])) {
593 *reg
|= (TD0_color_arg2_prevstage
|
597 if (RGBA_EQUAL(mmesa
->envcolor
[source
])) {
598 /* Cv = C1 + Cc Cs */
599 *reg
|= (TD0_color_arg2_prevstage
|
600 TD0_color_alpha_fcol
|
601 TD0_color_arg2mul_alpha2
|
602 TD0_color_arg1add_mulout
|
606 mmesa
->setup
.fcol
= mmesa
->envcolor
[source
];
611 if (format
!= GL_INTENSITY
|| ALPHA_ZERO(mmesa
->envcolor
[source
])) {
613 *reg
|= (TD0_alpha_arg2_prevstage
|
616 if (ALPHA_ONE(mmesa
->envcolor
[source
])) {
618 *reg
|= (TD0_alpha_arg2_prevstage
|
619 TD0_alpha_add_enable
|
628 static void mgaUpdateTextureEnvG400( GLcontext
*ctx
, GLuint unit
)
630 mgaContextPtr mmesa
= MGA_CONTEXT( ctx
);
631 const int source
= mmesa
->tmu_source
[unit
];
632 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[source
];
633 const struct gl_texture_object
*tObj
= texUnit
->_Current
;
634 GLuint
*reg
= ((GLuint
*)&mmesa
->setup
.tdualstage0
+ unit
);
635 mgaTextureObjectPtr t
= (mgaTextureObjectPtr
) tObj
->DriverData
;
636 GLenum format
= tObj
->Image
[0][tObj
->BaseLevel
]->_BaseFormat
;
638 if (tObj
!= ctx
->Texture
.Unit
[source
].Current2D
&&
639 tObj
!= ctx
->Texture
.Unit
[source
].CurrentRect
)
642 switch (ctx
->Texture
.Unit
[source
].EnvMode
) {
644 if (format
== GL_ALPHA
) {
645 *reg
= g400_alpha_combine
[unit
][MGA_REPLACE
];
646 } else if (format
== GL_RGB
|| format
== GL_LUMINANCE
) {
647 *reg
= g400_color_combine
[unit
][MGA_REPLACE
];
649 *reg
= g400_color_alpha_combine
[unit
][MGA_REPLACE
];
654 if (format
== GL_ALPHA
) {
655 *reg
= g400_alpha_combine
[unit
][MGA_MODULATE
];
656 } else if (format
== GL_RGB
|| format
== GL_LUMINANCE
) {
657 *reg
= g400_color_combine
[unit
][MGA_MODULATE
];
659 *reg
= g400_color_alpha_combine
[unit
][MGA_MODULATE
];
664 if (format
== GL_RGB
) {
665 *reg
= g400_color_combine
[unit
][MGA_DECAL
];
666 } else if (format
== GL_RGBA
) {
667 *reg
= g400_color_alpha_combine
[unit
][MGA_DECAL
];
668 if (ctx
->Texture
._EnabledUnits
!= 0x03) {
669 /* Linear blending mode needs dual texturing enabled */
670 *(reg
+1) = (TD0_color_arg2_prevstage
|
672 TD0_alpha_arg2_prevstage
|
674 mmesa
->force_dualtex
= GL_TRUE
;
678 *reg
= g400_alpha_combine
[unit
][MGA_DECAL
];
683 if (format
== GL_ALPHA
) {
684 *reg
= g400_alpha_combine
[unit
][MGA_ADD
];
685 } else if (format
== GL_RGB
|| format
== GL_LUMINANCE
) {
686 *reg
= g400_color_combine
[unit
][MGA_ADD
];
687 } else if (format
== GL_RGBA
|| format
== GL_LUMINANCE_ALPHA
) {
688 *reg
= g400_color_alpha_combine
[unit
][MGA_ADD
];
689 } else if (format
== GL_INTENSITY
) {
694 *reg
= (TD0_color_arg2_diffuse
|
697 TD0_alpha_arg2_diffuse
|
698 TD0_alpha_add_enable
|
701 *reg
= (TD0_color_arg2_prevstage
|
704 TD0_alpha_arg2_prevstage
|
705 TD0_alpha_add_enable
|
712 if (!mgaUpdateTextureEnvBlend(ctx
, unit
))
713 t
->texenv_fallback
= GL_TRUE
;
717 if (!mgaUpdateTextureEnvCombine(ctx
, unit
))
718 t
->texenv_fallback
= GL_TRUE
;
725 static void disable_tex( GLcontext
*ctx
, int unit
)
727 mgaContextPtr mmesa
= MGA_CONTEXT( ctx
);
729 /* Texture unit disabled */
731 if ( mmesa
->CurrentTexObj
[unit
] != NULL
) {
732 /* The old texture is no longer bound to this texture unit.
736 mmesa
->CurrentTexObj
[unit
]->base
.bound
&= ~(1UL << unit
);
737 mmesa
->CurrentTexObj
[unit
] = NULL
;
740 if ( unit
!= 0 && !mmesa
->force_dualtex
) {
741 mmesa
->setup
.tdualstage1
= mmesa
->setup
.tdualstage0
;
744 if ( ctx
->Texture
._EnabledUnits
== 0 ) {
745 mmesa
->setup
.dwgctl
&= DC_opcod_MASK
;
746 mmesa
->setup
.dwgctl
|= DC_opcod_trap
;
747 mmesa
->hw
.alpha_sel
= AC_alphasel_diffused
;
750 mmesa
->dirty
|= MGA_UPLOAD_CONTEXT
| (MGA_UPLOAD_TEX0
<< unit
);
753 static GLboolean
enable_tex( GLcontext
*ctx
, int unit
)
755 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
756 const int source
= mmesa
->tmu_source
[unit
];
757 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[source
];
758 const struct gl_texture_object
*tObj
= texUnit
->_Current
;
759 mgaTextureObjectPtr t
= (mgaTextureObjectPtr
) tObj
->DriverData
;
761 /* Upload teximages (not pipelined)
763 if (t
->base
.dirty_images
[0]) {
764 FLUSH_BATCH( mmesa
);
765 mgaSetTexImages( mmesa
, tObj
);
766 if ( t
->base
.memBlock
== NULL
) {
774 static GLboolean
update_tex_common( GLcontext
*ctx
, int unit
)
776 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
777 const int source
= mmesa
->tmu_source
[unit
];
778 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[source
];
779 struct gl_texture_object
*tObj
= texUnit
->_Current
;
780 mgaTextureObjectPtr t
= (mgaTextureObjectPtr
) tObj
->DriverData
;
782 /* Fallback if there's a texture border */
783 if ( tObj
->Image
[0][tObj
->BaseLevel
]->Border
> 0 ) {
788 /* Update state if this is a different texture object to last
791 if ( mmesa
->CurrentTexObj
[unit
] != t
) {
792 if ( mmesa
->CurrentTexObj
[unit
] != NULL
) {
793 /* The old texture is no longer bound to this texture unit.
797 mmesa
->CurrentTexObj
[unit
]->base
.bound
&= ~(1UL << unit
);
800 mmesa
->CurrentTexObj
[unit
] = t
;
801 t
->base
.bound
|= (1UL << unit
);
803 driUpdateTextureLRU( (driTextureObject
*) t
); /* done too often */
808 mmesa
->setup
.tdualstage1
= mmesa
->setup
.tdualstage0
;
811 t
->texenv_fallback
= GL_FALSE
;
813 /* Set this before mgaUpdateTextureEnvG400() since
814 * GL_ARB_texture_env_crossbar may have to disable texturing.
816 mmesa
->setup
.dwgctl
&= DC_opcod_MASK
;
817 mmesa
->setup
.dwgctl
|= DC_opcod_texture_trap
;
819 /* FIXME: The Radeon has some cached state so that it can avoid calling
820 * FIXME: UpdateTextureEnv in some cases. Is that possible here?
822 if (MGA_IS_G400(mmesa
)) {
823 /* G400: Regardless of texture env mode, we use the alpha from the
824 * texture unit (AC_alphasel_fromtex) since it will have already
825 * been modulated by the incoming fragment color, if needed.
826 * We don't want (AC_alphasel_modulate) since that'll effectively
827 * do the modulation twice.
829 mmesa
->hw
.alpha_sel
= AC_alphasel_fromtex
;
831 mgaUpdateTextureEnvG400( ctx
, unit
);
833 mgaUpdateTextureEnvG200( ctx
, unit
);
836 t
->setup
.texctl2
&= TMC_dualtex_MASK
;
837 if (ctx
->Texture
._EnabledUnits
== 0x03 || mmesa
->force_dualtex
) {
838 t
->setup
.texctl2
|= TMC_dualtex_enable
;
841 mmesa
->dirty
|= MGA_UPLOAD_CONTEXT
| (MGA_UPLOAD_TEX0
<< unit
);
843 FALLBACK( ctx
, MGA_FALLBACK_BORDER_MODE
, t
->border_fallback
);
844 return !t
->border_fallback
&& !t
->texenv_fallback
;
848 static GLboolean
updateTextureUnit( GLcontext
*ctx
, int unit
)
850 mgaContextPtr mmesa
= MGA_CONTEXT( ctx
);
851 const int source
= mmesa
->tmu_source
[unit
];
852 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[source
];
855 if ( texUnit
->_ReallyEnabled
== TEXTURE_2D_BIT
||
856 texUnit
->_ReallyEnabled
== TEXTURE_RECT_BIT
) {
857 return(enable_tex( ctx
, unit
) &&
858 update_tex_common( ctx
, unit
));
860 else if ( texUnit
->_ReallyEnabled
) {
864 disable_tex( ctx
, unit
);
869 /* The G400 is now programmed quite differently wrt texture environment.
871 void mgaUpdateTextureState( GLcontext
*ctx
)
873 mgaContextPtr mmesa
= MGA_CONTEXT( ctx
);
877 mmesa
->force_dualtex
= GL_FALSE
;
878 mmesa
->fcol_used
= GL_FALSE
;
880 /* This works around a quirk with the MGA hardware. If only OpenGL
881 * TEXTURE1 is enabled, then the hardware TEXTURE0 must be used. The
882 * hardware TEXTURE1 can ONLY be used when hardware TEXTURE0 is also used.
885 mmesa
->tmu_source
[0] = 0;
886 mmesa
->tmu_source
[1] = 1;
888 if ((ctx
->Texture
._EnabledUnits
& 0x03) == 0x02) {
889 /* only texture 1 enabled */
890 mmesa
->tmu_source
[0] = 1;
891 mmesa
->tmu_source
[1] = 0;
894 for ( i
= 0, ok
= GL_TRUE
895 ; (i
< ctx
->Const
.MaxTextureUnits
) && ok
897 ok
= updateTextureUnit( ctx
, i
);
900 FALLBACK( ctx
, MGA_FALLBACK_TEXTURE
, !ok
);