1 /* $XFree86: xc/lib/GL/mesa/src/drv/gamma/gamma_texstate.c,v 1.5 2002/11/05 17:46:07 tsi Exp $ */
9 #include "simple_list.h"
13 #include "gamma_context.h"
15 static void gammaSetTexImages( gammaContextPtr gmesa
,
16 struct gl_texture_object
*tObj
)
18 GLuint height
, width
, pitch
, i
, log_pitch
;
19 gammaTextureObjectPtr t
= (gammaTextureObjectPtr
) tObj
->DriverData
;
20 const struct gl_texture_image
*baseImage
= tObj
->Image
[0][tObj
->BaseLevel
];
21 GLint firstLevel
, lastLevel
, numLevels
;
22 GLint log2Width
, log2Height
;
24 /* fprintf(stderr, "%s\n", __FUNCTION__); */
28 /* Compute which mipmap levels we really want to send to the hardware.
29 * This depends on the base image size, GL_TEXTURE_MIN_LOD,
30 * GL_TEXTURE_MAX_LOD, GL_TEXTURE_BASE_LEVEL, and GL_TEXTURE_MAX_LEVEL.
31 * Yes, this looks overly complicated, but it's all needed.
33 if (tObj
->MinFilter
== GL_LINEAR
|| tObj
->MinFilter
== GL_NEAREST
) {
34 firstLevel
= lastLevel
= tObj
->BaseLevel
;
37 firstLevel
= tObj
->BaseLevel
+ (GLint
) (tObj
->MinLod
+ 0.5);
38 firstLevel
= MAX2(firstLevel
, tObj
->BaseLevel
);
39 lastLevel
= tObj
->BaseLevel
+ (GLint
) (tObj
->MaxLod
+ 0.5);
40 lastLevel
= MAX2(lastLevel
, tObj
->BaseLevel
);
41 lastLevel
= MIN2(lastLevel
, tObj
->BaseLevel
+ baseImage
->MaxLog2
);
42 lastLevel
= MIN2(lastLevel
, tObj
->MaxLevel
);
43 lastLevel
= MAX2(firstLevel
, lastLevel
); /* need at least one level */
46 /* save these values */
47 t
->firstLevel
= firstLevel
;
48 t
->lastLevel
= lastLevel
;
50 numLevels
= lastLevel
- firstLevel
+ 1;
52 log2Width
= tObj
->Image
[0][firstLevel
]->WidthLog2
;
53 log2Height
= tObj
->Image
[0][firstLevel
]->HeightLog2
;
56 /* Figure out the amount of memory required to hold all the mipmap
57 * levels. Choose the smallest pitch to accomodate the largest
60 width
= tObj
->Image
[0][firstLevel
]->Width
* t
->texelBytes
;
61 for (pitch
= 32, log_pitch
=2 ; pitch
< width
; pitch
*= 2 )
64 /* All images must be loaded at this pitch. Count the number of
67 for ( height
= i
= 0 ; i
< numLevels
; i
++ ) {
68 t
->image
[i
].image
= tObj
->Image
[0][firstLevel
+ i
];
69 t
->image
[i
].offset
= height
* pitch
;
70 t
->image
[i
].internalFormat
= baseImage
->Format
;
71 height
+= t
->image
[i
].image
->Height
;
72 t
->TextureBaseAddr
[i
] = /* ??? */
73 (unsigned long)(t
->image
[i
].offset
+ t
->BufAddr
) << 5;
78 t
->totalSize
= height
*pitch
;
80 gmesa
->dirty
|= GAMMA_UPLOAD_TEX0
/* | GAMMA_UPLOAD_TEX1*/;
82 gammaUploadTexImages( gmesa
, t
);
85 static void gammaUpdateTexEnv( GLcontext
*ctx
, GLuint unit
)
87 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
88 const struct gl_texture_object
*tObj
= texUnit
->_Current
;
89 const GLuint format
= tObj
->Image
[0][tObj
->BaseLevel
]->Format
;
90 gammaTextureObjectPtr t
= (gammaTextureObjectPtr
)tObj
->DriverData
;
93 /* fprintf(stderr, "%s\n", __FUNCTION__); */
95 tc
= t
->TextureColorMode
& ~(TCM_BaseFormatMask
| TCM_ApplicationMask
);
99 tc
|= TCM_BaseFormat_RGB
;
102 tc
|= TCM_BaseFormat_Lum
;
105 tc
|= TCM_BaseFormat_Alpha
;
107 case GL_LUMINANCE_ALPHA
:
108 tc
|= TCM_BaseFormat_LumAlpha
;
111 tc
|= TCM_BaseFormat_Intensity
;
114 tc
|= TCM_BaseFormat_RGBA
;
120 switch (texUnit
->EnvMode
) {
137 fprintf(stderr
, "unknown tex env mode");
141 t
->TextureColorMode
= tc
;
147 static void gammaUpdateTexUnit( GLcontext
*ctx
, GLuint unit
)
149 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
150 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
152 /* fprintf(stderr, "%s\n", __FUNCTION__); */
154 if (texUnit
->_ReallyEnabled
== TEXTURE_2D_BIT
)
156 struct gl_texture_object
*tObj
= texUnit
->_Current
;
157 gammaTextureObjectPtr t
= (gammaTextureObjectPtr
)tObj
->DriverData
;
159 /* Upload teximages (not pipelined)
161 if (t
->dirty_images
) {
162 gammaSetTexImages( gmesa
, tObj
);
164 FALLBACK( gmesa
, GAMMA_FALLBACK_TEXTURE
, GL_TRUE
);
170 if (tObj
->Image
[0][tObj
->BaseLevel
]->Border
> 0) {
171 FALLBACK( gmesa
, GAMMA_FALLBACK_TEXTURE
, GL_TRUE
);
176 /* Update state if this is a different texture object to last
179 if (gmesa
->CurrentTexObj
[unit
] != t
) {
180 gmesa
->dirty
|= GAMMA_UPLOAD_TEX0
/* << unit */;
181 gmesa
->CurrentTexObj
[unit
] = t
;
182 gammaUpdateTexLRU( gmesa
, t
); /* done too often */
185 /* Update texture environment if texture object image format or
186 * texture environment state has changed.
188 if (tObj
->Image
[0][tObj
->BaseLevel
]->Format
!= gmesa
->TexEnvImageFmt
[unit
]) {
189 gmesa
->TexEnvImageFmt
[unit
] = tObj
->Image
[0][tObj
->BaseLevel
]->Format
;
190 gammaUpdateTexEnv( ctx
, unit
);
193 else if (texUnit
->_ReallyEnabled
) {
194 FALLBACK( gmesa
, GAMMA_FALLBACK_TEXTURE
, GL_TRUE
);
196 else /*if (gmesa->CurrentTexObj[unit])*/ {
197 gmesa
->CurrentTexObj
[unit
] = 0;
198 gmesa
->TexEnvImageFmt
[unit
] = 0;
199 gmesa
->dirty
&= ~(GAMMA_UPLOAD_TEX0
<<unit
);
204 void gammaUpdateTextureState( GLcontext
*ctx
)
206 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
207 /* fprintf(stderr, "%s\n", __FUNCTION__); */
208 FALLBACK( gmesa
, GAMMA_FALLBACK_TEXTURE
, GL_FALSE
);
209 gammaUpdateTexUnit( ctx
, 0 );
211 gammaUpdateTexUnit( ctx
, 1 );