8 #include "simple_list.h"
12 #include "gamma_context.h"
14 static void gammaSetTexImages( gammaContextPtr gmesa
,
15 struct gl_texture_object
*tObj
)
17 GLuint height
, width
, pitch
, i
, log_pitch
;
18 gammaTextureObjectPtr t
= (gammaTextureObjectPtr
) tObj
->DriverData
;
19 const struct gl_texture_image
*baseImage
= tObj
->Image
[0][tObj
->BaseLevel
];
20 GLint firstLevel
, lastLevel
, numLevels
;
21 GLint log2Width
, log2Height
;
23 /* fprintf(stderr, "%s\n", __FUNCTION__); */
27 /* Compute which mipmap levels we really want to send to the hardware.
28 * This depends on the base image size, GL_TEXTURE_MIN_LOD,
29 * GL_TEXTURE_MAX_LOD, GL_TEXTURE_BASE_LEVEL, and GL_TEXTURE_MAX_LEVEL.
30 * Yes, this looks overly complicated, but it's all needed.
32 if (tObj
->MinFilter
== GL_LINEAR
|| tObj
->MinFilter
== GL_NEAREST
) {
33 firstLevel
= lastLevel
= tObj
->BaseLevel
;
36 firstLevel
= tObj
->BaseLevel
+ (GLint
) (tObj
->MinLod
+ 0.5);
37 firstLevel
= MAX2(firstLevel
, tObj
->BaseLevel
);
38 lastLevel
= tObj
->BaseLevel
+ (GLint
) (tObj
->MaxLod
+ 0.5);
39 lastLevel
= MAX2(lastLevel
, tObj
->BaseLevel
);
40 lastLevel
= MIN2(lastLevel
, tObj
->BaseLevel
+ baseImage
->MaxLog2
);
41 lastLevel
= MIN2(lastLevel
, tObj
->MaxLevel
);
42 lastLevel
= MAX2(firstLevel
, lastLevel
); /* need at least one level */
45 /* save these values */
46 t
->firstLevel
= firstLevel
;
47 t
->lastLevel
= lastLevel
;
49 numLevels
= lastLevel
- firstLevel
+ 1;
51 log2Width
= tObj
->Image
[0][firstLevel
]->WidthLog2
;
52 log2Height
= tObj
->Image
[0][firstLevel
]->HeightLog2
;
55 /* Figure out the amount of memory required to hold all the mipmap
56 * levels. Choose the smallest pitch to accomodate the largest
59 width
= tObj
->Image
[0][firstLevel
]->Width
* t
->texelBytes
;
60 for (pitch
= 32, log_pitch
=2 ; pitch
< width
; pitch
*= 2 )
63 /* All images must be loaded at this pitch. Count the number of
66 for ( height
= i
= 0 ; i
< numLevels
; i
++ ) {
67 t
->image
[i
].image
= tObj
->Image
[0][firstLevel
+ i
];
68 t
->image
[i
].offset
= height
* pitch
;
69 t
->image
[i
].internalFormat
= baseImage
->Format
;
70 height
+= t
->image
[i
].image
->Height
;
71 t
->TextureBaseAddr
[i
] = /* ??? */
72 (unsigned long)(t
->image
[i
].offset
+ t
->BufAddr
) << 5;
77 t
->totalSize
= height
*pitch
;
79 gmesa
->dirty
|= GAMMA_UPLOAD_TEX0
/* | GAMMA_UPLOAD_TEX1*/;
81 gammaUploadTexImages( gmesa
, t
);
84 static void gammaUpdateTexEnv( GLcontext
*ctx
, GLuint unit
)
86 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
87 const struct gl_texture_object
*tObj
= texUnit
->_Current
;
88 const GLuint format
= tObj
->Image
[0][tObj
->BaseLevel
]->Format
;
89 gammaTextureObjectPtr t
= (gammaTextureObjectPtr
)tObj
->DriverData
;
92 /* fprintf(stderr, "%s\n", __FUNCTION__); */
94 tc
= t
->TextureColorMode
& ~(TCM_BaseFormatMask
| TCM_ApplicationMask
);
98 tc
|= TCM_BaseFormat_RGB
;
101 tc
|= TCM_BaseFormat_Lum
;
104 tc
|= TCM_BaseFormat_Alpha
;
106 case GL_LUMINANCE_ALPHA
:
107 tc
|= TCM_BaseFormat_LumAlpha
;
110 tc
|= TCM_BaseFormat_Intensity
;
113 tc
|= TCM_BaseFormat_RGBA
;
119 switch (texUnit
->EnvMode
) {
136 fprintf(stderr
, "unknown tex env mode");
140 t
->TextureColorMode
= tc
;
146 static void gammaUpdateTexUnit( GLcontext
*ctx
, GLuint unit
)
148 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
149 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
151 /* fprintf(stderr, "%s\n", __FUNCTION__); */
153 if (texUnit
->_ReallyEnabled
== TEXTURE_2D_BIT
)
155 struct gl_texture_object
*tObj
= texUnit
->_Current
;
156 gammaTextureObjectPtr t
= (gammaTextureObjectPtr
)tObj
->DriverData
;
158 /* Upload teximages (not pipelined)
160 if (t
->dirty_images
) {
161 gammaSetTexImages( gmesa
, tObj
);
163 FALLBACK( gmesa
, GAMMA_FALLBACK_TEXTURE
, GL_TRUE
);
169 if (tObj
->Image
[0][tObj
->BaseLevel
]->Border
> 0) {
170 FALLBACK( gmesa
, GAMMA_FALLBACK_TEXTURE
, GL_TRUE
);
175 /* Update state if this is a different texture object to last
178 if (gmesa
->CurrentTexObj
[unit
] != t
) {
179 gmesa
->dirty
|= GAMMA_UPLOAD_TEX0
/* << unit */;
180 gmesa
->CurrentTexObj
[unit
] = t
;
181 gammaUpdateTexLRU( gmesa
, t
); /* done too often */
184 /* Update texture environment if texture object image format or
185 * texture environment state has changed.
187 if (tObj
->Image
[0][tObj
->BaseLevel
]->Format
!= gmesa
->TexEnvImageFmt
[unit
]) {
188 gmesa
->TexEnvImageFmt
[unit
] = tObj
->Image
[0][tObj
->BaseLevel
]->Format
;
189 gammaUpdateTexEnv( ctx
, unit
);
192 else if (texUnit
->_ReallyEnabled
) {
193 FALLBACK( gmesa
, GAMMA_FALLBACK_TEXTURE
, GL_TRUE
);
195 else /*if (gmesa->CurrentTexObj[unit])*/ {
196 gmesa
->CurrentTexObj
[unit
] = 0;
197 gmesa
->TexEnvImageFmt
[unit
] = 0;
198 gmesa
->dirty
&= ~(GAMMA_UPLOAD_TEX0
<<unit
);
203 void gammaUpdateTextureState( GLcontext
*ctx
)
205 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
206 /* fprintf(stderr, "%s\n", __FUNCTION__); */
207 FALLBACK( gmesa
, GAMMA_FALLBACK_TEXTURE
, GL_FALSE
);
208 gammaUpdateTexUnit( ctx
, 0 );
210 gammaUpdateTexUnit( ctx
, 1 );