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>
33 #include "mgacontext.h"
44 #include "simple_list.h"
45 #include "texformat.h"
47 #define MGA_USE_TABLE_FOR_FORMAT
48 #ifdef MGA_USE_TABLE_FOR_FORMAT
49 #define TMC_nr_tformat (MESA_FORMAT_YCBCR_REV + 1)
50 static const unsigned TMC_tformat
[ TMC_nr_tformat
] =
52 [MESA_FORMAT_ARGB8888
] = TMC_tformat_tw32
,
53 [MESA_FORMAT_RGB565
] = TMC_tformat_tw16
,
54 [MESA_FORMAT_ARGB4444
] = TMC_tformat_tw12
,
55 [MESA_FORMAT_ARGB1555
] = TMC_tformat_tw15
,
56 [MESA_FORMAT_AL88
] = TMC_tformat_tw8al
,
57 [MESA_FORMAT_I8
] = TMC_tformat_tw8a
,
58 [MESA_FORMAT_CI8
] = TMC_tformat_tw8
,
59 [MESA_FORMAT_YCBCR
] = TMC_tformat_tw422uyvy
,
60 [MESA_FORMAT_YCBCR_REV
] = TMC_tformat_tw422
,
65 mgaSetTexImages( mgaContextPtr mmesa
,
66 const struct gl_texture_object
* tObj
)
68 mgaTextureObjectPtr t
= (mgaTextureObjectPtr
) tObj
->DriverData
;
69 struct gl_texture_image
*baseImage
= tObj
->Image
[0][ tObj
->BaseLevel
];
74 GLint log2Width
, log2Height
;
78 /* Set the hardware texture format
80 #ifndef MGA_USE_TABLE_FOR_FORMAT
81 switch (baseImage
->TexFormat
->MesaFormat
) {
83 case MESA_FORMAT_ARGB8888
: txformat
= TMC_tformat_tw32
; break;
84 case MESA_FORMAT_RGB565
: txformat
= TMC_tformat_tw16
; break;
85 case MESA_FORMAT_ARGB4444
: txformat
= TMC_tformat_tw12
; break;
86 case MESA_FORMAT_ARGB1555
: txformat
= TMC_tformat_tw15
; break;
87 case MESA_FORMAT_AL88
: txformat
= TMC_tformat_tw8al
; break;
88 case MESA_FORMAT_I8
: txformat
= TMC_tformat_tw8a
; break;
89 case MESA_FORMAT_CI8
: txformat
= TMC_tformat_tw8
; break;
90 case MESA_FORMAT_YCBCR
: txformat
= TMC_tformat_tw422uyvy
; break;
91 case MESA_FORMAT_YCBCR_REV
: txformat
= TMC_tformat_tw422
; break;
94 _mesa_problem(NULL
, "unexpected texture format in %s", __FUNCTION__
);
98 if ( (baseImage
->TexFormat
->MesaFormat
>= TMC_nr_tformat
)
99 || (TMC_tformat
[ baseImage
->TexFormat
->MesaFormat
] == 0) )
101 _mesa_problem(NULL
, "unexpected texture format in %s", __FUNCTION__
);
105 txformat
= TMC_tformat
[ baseImage
->TexFormat
->MesaFormat
];
107 #endif /* MGA_USE_TABLE_FOR_FORMAT */
109 driCalculateTextureFirstLastLevel( (driTextureObject
*) t
);
110 if (tObj
->Target
== GL_TEXTURE_RECTANGLE_NV
) {
114 log2Width
= tObj
->Image
[0][t
->base
.firstLevel
]->WidthLog2
;
115 log2Height
= tObj
->Image
[0][t
->base
.firstLevel
]->HeightLog2
;
118 width
= tObj
->Image
[0][t
->base
.firstLevel
]->Width
;
119 height
= tObj
->Image
[0][t
->base
.firstLevel
]->Height
;
121 numLevels
= MIN2( t
->base
.lastLevel
- t
->base
.firstLevel
+ 1,
122 MGA_IS_G200(mmesa
) ? G200_TEX_MAXLEVELS
: G400_TEX_MAXLEVELS
);
126 for ( i
= 0 ; i
< numLevels
; i
++ ) {
127 const struct gl_texture_image
* const texImage
=
128 tObj
->Image
[0][ i
+ t
->base
.firstLevel
];
131 if (texImage
== NULL
)
134 size
= texImage
->Width
* texImage
->Height
*
135 baseImage
->TexFormat
->TexelBytes
;
137 t
->offsets
[i
] = totalSize
;
138 t
->base
.dirty_images
[0] |= (1<<i
);
140 /* All mipmaps must be 32-byte aligned */
141 totalSize
+= (size
+ 31) & ~31;
143 /* Since G400 calculates the offsets in hardware
144 * it can't handle more than one < 32 byte mipmap.
146 * Further testing has indicated that it can't
147 * handle any < 32 byte mipmaps.
149 if (MGA_IS_G400( mmesa
) && size
<= 32) {
155 /* save these values */
157 t
->base
.lastLevel
= t
->base
.firstLevel
+ numLevels
- 1;
158 t
->base
.totalSize
= totalSize
;
160 /* setup hardware register values */
161 t
->setup
.texctl
&= (TMC_tformat_MASK
& TMC_tpitch_MASK
162 & TMC_tpitchext_MASK
);
163 t
->setup
.texctl
|= txformat
;
166 /* Set the texture width. In order to support non-power of 2 textures and
167 * textures larger than 1024 texels wide, "linear" pitch must be used. For
168 * the linear pitch, if the width is 2048, a value of zero is used.
171 t
->setup
.texctl
|= TMC_tpitchlin_enable
;
172 t
->setup
.texctl
|= MGA_FIELD( TMC_tpitchext
, width
& (2048 - 1) );
175 /* G400 specifies the number of mip levels in a strange way. Since there
176 * are up to 11 levels, it requires 4 bits. Three of the bits are at the
177 * high end of TEXFILTER. The other bit is in the middle. Weird.
180 t
->setup
.texfilter
&= TF_mapnb_MASK
& TF_mapnbhigh_MASK
& TF_reserved_MASK
;
181 t
->setup
.texfilter
|= MGA_FIELD( TF_mapnb
, numLevels
& 0x7 );
182 t
->setup
.texfilter
|= MGA_FIELD( TF_mapnbhigh
, (numLevels
>> 3) & 0x1 );
184 /* warp texture registers */
185 ofs
= MGA_IS_G200(mmesa
) ? 28 : 11;
187 t
->setup
.texwidth
= (MGA_FIELD(TW_twmask
, width
- 1) |
188 MGA_FIELD(TW_rfw
, (10 - log2Width
- 8) & 63 ) |
189 MGA_FIELD(TW_tw
, (log2Width
+ ofs
) | 0x40 ));
191 t
->setup
.texheight
= (MGA_FIELD(TH_thmask
, height
- 1) |
192 MGA_FIELD(TH_rfh
, (10 - log2Height
- 8) & 63 ) |
193 MGA_FIELD(TH_th
, (log2Height
+ ofs
) | 0x40 ));
195 mgaUploadTexImages( mmesa
, t
);
199 /* ================================================================
200 * Texture unit state management
203 static void mgaUpdateTextureEnvG200( GLcontext
*ctx
, GLuint unit
)
205 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
206 struct gl_texture_object
*tObj
= ctx
->Texture
.Unit
[0]._Current
;
207 mgaTextureObjectPtr t
= (mgaTextureObjectPtr
) tObj
->DriverData
;
208 GLenum format
= tObj
->Image
[0][tObj
->BaseLevel
]->Format
;
210 if (tObj
!= ctx
->Texture
.Unit
[0].Current2D
&&
211 tObj
!= ctx
->Texture
.Unit
[0].CurrentRect
)
215 t
->setup
.texctl
&= ~TMC_tmodulate_enable
;
216 t
->setup
.texctl2
&= ~(TMC_decalblend_enable
|
218 TMC_decaldis_enable
);
220 switch (ctx
->Texture
.Unit
[0].EnvMode
) {
222 if (format
== GL_ALPHA
)
223 t
->setup
.texctl2
|= TMC_idecal_enable
;
225 if (format
== GL_RGB
|| format
== GL_LUMINANCE
)
226 mmesa
->hw
.alpha_sel
= AC_alphasel_diffused
;
228 mmesa
->hw
.alpha_sel
= AC_alphasel_fromtex
;
232 t
->setup
.texctl
|= TMC_tmodulate_enable
;
234 if (format
== GL_ALPHA
)
235 t
->setup
.texctl2
|= (TMC_idecal_enable
|
236 TMC_decaldis_enable
);
238 if (format
== GL_RGB
|| format
== GL_LUMINANCE
)
239 mmesa
->hw
.alpha_sel
= AC_alphasel_diffused
;
241 mmesa
->hw
.alpha_sel
= AC_alphasel_modulated
;
245 if (format
== GL_RGB
|| format
== GL_RGBA
)
246 t
->setup
.texctl2
|= TMC_decalblend_enable
;
248 t
->setup
.texctl2
|= TMC_idecal_enable
;
250 mmesa
->hw
.alpha_sel
= AC_alphasel_diffused
;
254 if (format
== GL_ALPHA
) {
255 t
->setup
.texctl2
|= TMC_idecal_enable
;
256 mmesa
->hw
.alpha_sel
= AC_alphasel_modulated
;
258 t
->texenv_fallback
= GL_TRUE
;
268 #define MGA_REPLACE 0
269 #define MGA_MODULATE 1
272 #define MGA_MAX_COMBFUNC 4
274 static const GLuint g400_color_combine
[][MGA_MAX_COMBFUNC
] =
283 (TD0_color_sel_arg1
|
284 TD0_alpha_arg2_diffuse
|
291 (TD0_color_arg2_diffuse
|
293 TD0_alpha_arg2_diffuse
|
300 (TD0_color_sel_arg1
|
301 TD0_alpha_arg2_diffuse
|
308 (TD0_color_arg2_diffuse
|
311 TD0_alpha_arg2_diffuse
|
322 (TD0_color_sel_arg1
|
323 TD0_alpha_arg2_prevstage
|
330 (TD0_color_arg2_prevstage
|
332 TD0_alpha_arg2_prevstage
|
339 (TD0_color_sel_arg1
|
340 TD0_alpha_arg2_prevstage
|
347 (TD0_color_arg2_prevstage
|
350 TD0_alpha_arg2_prevstage
|
355 static const GLuint g400_color_alpha_combine
[][MGA_MAX_COMBFUNC
] =
364 (TD0_color_sel_arg1
|
371 (TD0_color_arg2_diffuse
|
373 TD0_alpha_arg2_diffuse
|
377 * tmp = Cf ( 1 - As )
381 (TD0_color_arg2_diffuse
|
382 TD0_color_alpha_currtex
|
383 TD0_color_alpha1inv_enable
|
384 TD0_color_arg1mul_alpha1
|
385 TD0_color_blend_enable
|
386 TD0_color_arg1add_mulout
|
387 TD0_color_arg2add_mulout
|
390 TD0_alpha_arg2_diffuse
|
397 (TD0_color_arg2_diffuse
|
400 TD0_alpha_arg2_diffuse
|
411 (TD0_color_sel_arg1
|
418 (TD0_color_arg2_prevstage
|
420 TD0_alpha_arg2_prevstage
|
424 * tmp = Cp ( 1 - As )
428 (TD0_color_arg2_prevstage
|
429 TD0_color_alpha_currtex
|
430 TD0_color_alpha1inv_enable
|
431 TD0_color_arg1mul_alpha1
|
432 TD0_color_blend_enable
|
433 TD0_color_arg1add_mulout
|
434 TD0_color_arg2add_mulout
|
437 TD0_alpha_arg2_prevstage
|
444 (TD0_color_arg2_prevstage
|
447 TD0_alpha_arg2_prevstage
|
452 static const GLuint g400_alpha_combine
[][MGA_MAX_COMBFUNC
] =
461 (TD0_color_arg2_diffuse
|
469 (TD0_color_arg2_diffuse
|
471 TD0_alpha_arg2_diffuse
|
474 /* GL_DECAL (undefined)
478 (TD0_color_arg2_diffuse
|
480 TD0_alpha_arg2_diffuse
|
487 (TD0_color_arg2_diffuse
|
489 TD0_alpha_arg2_diffuse
|
500 (TD0_color_arg2_prevstage
|
508 (TD0_color_arg2_prevstage
|
510 TD0_alpha_arg2_prevstage
|
513 /* GL_DECAL (undefined)
517 (TD0_color_arg2_prevstage
|
519 TD0_alpha_arg2_prevstage
|
526 (TD0_color_arg2_prevstage
|
528 TD0_alpha_arg2_prevstage
|
533 static GLboolean
mgaUpdateTextureEnvBlend( GLcontext
*ctx
, int unit
)
535 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
536 const int source
= mmesa
->tmu_source
[unit
];
537 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[source
];
538 const struct gl_texture_object
*tObj
= texUnit
->_Current
;
539 GLuint
*reg
= ((GLuint
*)&mmesa
->setup
.tdualstage0
+ unit
);
540 GLenum format
= tObj
->Image
[0][tObj
->BaseLevel
]->Format
;
544 if (format
== GL_ALPHA
) {
546 *reg
|= (TD0_color_arg2_diffuse
|
549 *reg
|= (TD0_alpha_arg2_diffuse
|
554 /* C1 = Cf ( 1 - Cs ) */
555 *reg
|= (TD0_color_arg1_inv_enable
|
556 TD0_color_arg2_diffuse
|
559 if (format
== GL_RGB
|| format
== GL_LUMINANCE
) {
561 *reg
|= (TD0_alpha_arg2_diffuse
|
564 if (format
== GL_RGBA
|| format
== GL_LUMINANCE_ALPHA
) {
566 *reg
|= (TD0_alpha_arg2_diffuse
|
569 if (format
== GL_INTENSITY
) {
570 /* A1 = Af ( 1 - As ) */
571 *reg
|= (TD0_alpha_arg1_inv_enable
|
572 TD0_alpha_arg2_diffuse
|
576 if (RGB_ZERO(mmesa
->envcolor
[source
]) &&
577 (format
!= GL_INTENSITY
|| ALPHA_ZERO(mmesa
->envcolor
[source
])))
578 return GL_TRUE
; /* all done */
580 if (ctx
->Texture
._EnabledUnits
== 0x03)
581 return GL_FALSE
; /* need both units */
583 mmesa
->force_dualtex
= GL_TRUE
;
584 reg
= &mmesa
->setup
.tdualstage1
;
587 if (RGB_ZERO(mmesa
->envcolor
[source
])) {
589 *reg
|= (TD0_color_arg2_prevstage
|
592 if (RGB_ONE(mmesa
->envcolor
[source
])) {
594 *reg
|= (TD0_color_arg2_prevstage
|
598 if (RGBA_EQUAL(mmesa
->envcolor
[source
])) {
599 /* Cv = C1 + Cc Cs */
600 *reg
|= (TD0_color_arg2_prevstage
|
601 TD0_color_alpha_fcol
|
602 TD0_color_arg2mul_alpha2
|
603 TD0_color_arg1add_mulout
|
607 mmesa
->setup
.fcol
= mmesa
->envcolor
[source
];
612 if (format
!= GL_INTENSITY
|| ALPHA_ZERO(mmesa
->envcolor
[source
])) {
614 *reg
|= (TD0_alpha_arg2_prevstage
|
617 if (ALPHA_ONE(mmesa
->envcolor
[source
])) {
619 *reg
|= (TD0_alpha_arg2_prevstage
|
620 TD0_alpha_add_enable
|
629 static void mgaUpdateTextureEnvG400( GLcontext
*ctx
, GLuint unit
)
631 mgaContextPtr mmesa
= MGA_CONTEXT( ctx
);
632 const int source
= mmesa
->tmu_source
[unit
];
633 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[source
];
634 const struct gl_texture_object
*tObj
= texUnit
->_Current
;
635 GLuint
*reg
= ((GLuint
*)&mmesa
->setup
.tdualstage0
+ unit
);
636 mgaTextureObjectPtr t
= (mgaTextureObjectPtr
) tObj
->DriverData
;
637 GLenum format
= tObj
->Image
[0][tObj
->BaseLevel
]->Format
;
639 if (tObj
!= ctx
->Texture
.Unit
[source
].Current2D
&&
640 tObj
!= ctx
->Texture
.Unit
[source
].CurrentRect
)
643 switch (ctx
->Texture
.Unit
[source
].EnvMode
) {
645 if (format
== GL_ALPHA
) {
646 *reg
= g400_alpha_combine
[unit
][MGA_REPLACE
];
647 } else if (format
== GL_RGB
|| format
== GL_LUMINANCE
) {
648 *reg
= g400_color_combine
[unit
][MGA_REPLACE
];
650 *reg
= g400_color_alpha_combine
[unit
][MGA_REPLACE
];
655 if (format
== GL_ALPHA
) {
656 *reg
= g400_alpha_combine
[unit
][MGA_MODULATE
];
657 } else if (format
== GL_RGB
|| format
== GL_LUMINANCE
) {
658 *reg
= g400_color_combine
[unit
][MGA_MODULATE
];
660 *reg
= g400_color_alpha_combine
[unit
][MGA_MODULATE
];
665 if (format
== GL_RGB
) {
666 *reg
= g400_color_combine
[unit
][MGA_DECAL
];
667 } else if (format
== GL_RGBA
) {
668 *reg
= g400_color_alpha_combine
[unit
][MGA_DECAL
];
669 if (ctx
->Texture
._EnabledUnits
!= 0x03) {
670 /* Linear blending mode needs dual texturing enabled */
671 *(reg
+1) = (TD0_color_arg2_prevstage
|
673 TD0_alpha_arg2_prevstage
|
675 mmesa
->force_dualtex
= GL_TRUE
;
679 *reg
= g400_alpha_combine
[unit
][MGA_DECAL
];
684 if (format
== GL_ALPHA
) {
685 *reg
= g400_alpha_combine
[unit
][MGA_ADD
];
686 } else if (format
== GL_RGB
|| format
== GL_LUMINANCE
) {
687 *reg
= g400_color_combine
[unit
][MGA_ADD
];
688 } else if (format
== GL_RGBA
|| format
== GL_LUMINANCE_ALPHA
) {
689 *reg
= g400_color_alpha_combine
[unit
][MGA_ADD
];
690 } else if (format
== GL_INTENSITY
) {
695 *reg
= (TD0_color_arg2_diffuse
|
698 TD0_alpha_arg2_diffuse
|
699 TD0_alpha_add_enable
|
702 *reg
= (TD0_color_arg2_prevstage
|
705 TD0_alpha_arg2_prevstage
|
706 TD0_alpha_add_enable
|
713 if (!mgaUpdateTextureEnvBlend(ctx
, unit
))
714 t
->texenv_fallback
= GL_TRUE
;
718 if (!mgaUpdateTextureEnvCombine(ctx
, unit
))
719 t
->texenv_fallback
= GL_TRUE
;
726 static void disable_tex( GLcontext
*ctx
, int unit
)
728 mgaContextPtr mmesa
= MGA_CONTEXT( ctx
);
730 /* Texture unit disabled */
732 if ( mmesa
->CurrentTexObj
[unit
] != NULL
) {
733 /* The old texture is no longer bound to this texture unit.
737 mmesa
->CurrentTexObj
[unit
]->base
.bound
&= ~(1UL << unit
);
738 mmesa
->CurrentTexObj
[unit
] = NULL
;
741 if ( unit
!= 0 && !mmesa
->force_dualtex
) {
742 mmesa
->setup
.tdualstage1
= mmesa
->setup
.tdualstage0
;
745 if ( ctx
->Texture
._EnabledUnits
== 0 ) {
746 mmesa
->setup
.dwgctl
&= DC_opcod_MASK
;
747 mmesa
->setup
.dwgctl
|= DC_opcod_trap
;
748 mmesa
->hw
.alpha_sel
= AC_alphasel_diffused
;
751 mmesa
->dirty
|= MGA_UPLOAD_CONTEXT
| (MGA_UPLOAD_TEX0
<< unit
);
754 static GLboolean
enable_tex( GLcontext
*ctx
, int unit
)
756 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
757 const int source
= mmesa
->tmu_source
[unit
];
758 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[source
];
759 const struct gl_texture_object
*tObj
= texUnit
->_Current
;
760 mgaTextureObjectPtr t
= (mgaTextureObjectPtr
) tObj
->DriverData
;
762 /* Upload teximages (not pipelined)
764 if (t
->base
.dirty_images
[0]) {
765 FLUSH_BATCH( mmesa
);
766 mgaSetTexImages( mmesa
, tObj
);
767 if ( t
->base
.memBlock
== NULL
) {
775 static GLboolean
update_tex_common( GLcontext
*ctx
, int unit
)
777 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
778 const int source
= mmesa
->tmu_source
[unit
];
779 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[source
];
780 struct gl_texture_object
*tObj
= texUnit
->_Current
;
781 mgaTextureObjectPtr t
= (mgaTextureObjectPtr
) tObj
->DriverData
;
783 /* Fallback if there's a texture border */
784 if ( tObj
->Image
[0][tObj
->BaseLevel
]->Border
> 0 ) {
789 /* Update state if this is a different texture object to last
792 if ( mmesa
->CurrentTexObj
[unit
] != t
) {
793 if ( mmesa
->CurrentTexObj
[unit
] != NULL
) {
794 /* The old texture is no longer bound to this texture unit.
798 mmesa
->CurrentTexObj
[unit
]->base
.bound
&= ~(1UL << unit
);
801 mmesa
->CurrentTexObj
[unit
] = t
;
802 t
->base
.bound
|= (1UL << unit
);
804 driUpdateTextureLRU( (driTextureObject
*) t
); /* done too often */
809 mmesa
->setup
.tdualstage1
= mmesa
->setup
.tdualstage0
;
812 t
->texenv_fallback
= GL_FALSE
;
814 /* Set this before mgaUpdateTextureEnvG400() since
815 * GL_ARB_texture_env_crossbar may have to disable texturing.
817 mmesa
->setup
.dwgctl
&= DC_opcod_MASK
;
818 mmesa
->setup
.dwgctl
|= DC_opcod_texture_trap
;
820 /* FIXME: The Radeon has some cached state so that it can avoid calling
821 * FIXME: UpdateTextureEnv in some cases. Is that possible here?
823 if (MGA_IS_G400(mmesa
)) {
824 /* G400: Regardless of texture env mode, we use the alpha from the
825 * texture unit (AC_alphasel_fromtex) since it will have already
826 * been modulated by the incoming fragment color, if needed.
827 * We don't want (AC_alphasel_modulate) since that'll effectively
828 * do the modulation twice.
830 mmesa
->hw
.alpha_sel
= AC_alphasel_fromtex
;
832 mgaUpdateTextureEnvG400( ctx
, unit
);
834 mgaUpdateTextureEnvG200( ctx
, unit
);
837 t
->setup
.texctl2
&= TMC_dualtex_MASK
;
838 if (ctx
->Texture
._EnabledUnits
== 0x03 || mmesa
->force_dualtex
) {
839 t
->setup
.texctl2
|= TMC_dualtex_enable
;
842 mmesa
->dirty
|= MGA_UPLOAD_CONTEXT
| (MGA_UPLOAD_TEX0
<< unit
);
844 FALLBACK( ctx
, MGA_FALLBACK_BORDER_MODE
, t
->border_fallback
);
845 return !t
->border_fallback
&& !t
->texenv_fallback
;
849 static GLboolean
updateTextureUnit( GLcontext
*ctx
, int unit
)
851 mgaContextPtr mmesa
= MGA_CONTEXT( ctx
);
852 const int source
= mmesa
->tmu_source
[unit
];
853 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[source
];
856 if ( texUnit
->_ReallyEnabled
== TEXTURE_2D_BIT
||
857 texUnit
->_ReallyEnabled
== TEXTURE_RECT_BIT
) {
858 return(enable_tex( ctx
, unit
) &&
859 update_tex_common( ctx
, unit
));
861 else if ( texUnit
->_ReallyEnabled
) {
865 disable_tex( ctx
, unit
);
870 /* The G400 is now programmed quite differently wrt texture environment.
872 void mgaUpdateTextureState( GLcontext
*ctx
)
874 mgaContextPtr mmesa
= MGA_CONTEXT( ctx
);
878 mmesa
->force_dualtex
= GL_FALSE
;
879 mmesa
->fcol_used
= GL_FALSE
;
881 /* This works around a quirk with the MGA hardware. If only OpenGL
882 * TEXTURE1 is enabled, then the hardware TEXTURE0 must be used. The
883 * hardware TEXTURE1 can ONLY be used when hardware TEXTURE0 is also used.
886 mmesa
->tmu_source
[0] = 0;
887 mmesa
->tmu_source
[1] = 1;
889 if ((ctx
->Texture
._EnabledUnits
& 0x03) == 0x02) {
890 /* only texture 1 enabled */
891 mmesa
->tmu_source
[0] = 1;
892 mmesa
->tmu_source
[1] = 0;
895 for ( i
= 0, ok
= GL_TRUE
896 ; (i
< ctx
->Const
.MaxTextureUnits
) && ok
898 ok
= updateTextureUnit( ctx
, i
);
901 FALLBACK( ctx
, MGA_FALLBACK_TEXTURE
, !ok
);