2 * GLX Hardware Device Driver for Intel i810
3 * Copyright (C) 1999 Keith Whitwell
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
21 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include "simple_list.h"
31 #include "texformat.h"
35 #include "swrast/swrast.h"
40 #include "i810screen.h"
43 #include "i810context.h"
45 #include "i810state.h"
46 #include "i810ioctl.h"
50 * Compute the 'S2.4' lod bias factor from the floating point OpenGL bias.
52 static GLuint
i810ComputeLodBias(GLfloat bias
)
54 int b
= (int) (bias
* 16.0) + 12;
59 return (GLuint
) (b
& MLC_LOD_BIAS_MASK
);
63 static void i810SetTexWrapping(i810TextureObjectPtr tex
,
64 GLenum swrap
, GLenum twrap
)
66 tex
->Setup
[I810_TEXREG_MCS
] &= ~(MCS_U_STATE_MASK
| MCS_V_STATE_MASK
);
70 tex
->Setup
[I810_TEXREG_MCS
] |= MCS_U_WRAP
;
73 case GL_CLAMP_TO_EDGE
:
74 tex
->Setup
[I810_TEXREG_MCS
] |= MCS_U_CLAMP
;
76 case GL_MIRRORED_REPEAT
:
77 tex
->Setup
[I810_TEXREG_MCS
] |= MCS_U_MIRROR
;
80 _mesa_problem(NULL
, "bad S wrap mode in %s", __FUNCTION__
);
85 tex
->Setup
[I810_TEXREG_MCS
] |= MCS_V_WRAP
;
88 case GL_CLAMP_TO_EDGE
:
89 tex
->Setup
[I810_TEXREG_MCS
] |= MCS_V_CLAMP
;
91 case GL_MIRRORED_REPEAT
:
92 tex
->Setup
[I810_TEXREG_MCS
] |= MCS_V_MIRROR
;
95 _mesa_problem(NULL
, "bad T wrap mode in %s", __FUNCTION__
);
100 static void i810SetTexFilter(i810ContextPtr imesa
,
101 i810TextureObjectPtr t
,
102 GLenum minf
, GLenum magf
,
105 t
->Setup
[I810_TEXREG_MF
] &= ~(MF_MIN_MASK
|
108 t
->Setup
[I810_TEXREG_MLC
] &= ~(MLC_LOD_BIAS_MASK
);
112 t
->Setup
[I810_TEXREG_MF
] |= MF_MIN_NEAREST
| MF_MIP_NONE
;
115 t
->Setup
[I810_TEXREG_MF
] |= MF_MIN_LINEAR
| MF_MIP_NONE
;
117 case GL_NEAREST_MIPMAP_NEAREST
:
118 t
->Setup
[I810_TEXREG_MF
] |= MF_MIN_NEAREST
| MF_MIP_NEAREST
;
119 if (magf
== GL_LINEAR
) {
120 /*bias -= 0.5;*/ /* this doesn't work too good */
123 case GL_LINEAR_MIPMAP_NEAREST
:
124 t
->Setup
[I810_TEXREG_MF
] |= MF_MIN_LINEAR
| MF_MIP_NEAREST
;
126 case GL_NEAREST_MIPMAP_LINEAR
:
128 t
->Setup
[I810_TEXREG_MF
] |= MF_MIN_NEAREST
| MF_MIP_LINEAR
;
130 t
->Setup
[I810_TEXREG_MF
] |= MF_MIN_NEAREST
| MF_MIP_DITHER
;
132 if (magf == GL_LINEAR) {
136 bias
-= 0.5; /* always biasing here looks better */
138 case GL_LINEAR_MIPMAP_LINEAR
:
140 t
->Setup
[I810_TEXREG_MF
] |= MF_MIN_LINEAR
| MF_MIP_LINEAR
;
142 t
->Setup
[I810_TEXREG_MF
] |= MF_MIN_LINEAR
| MF_MIP_DITHER
;
150 t
->Setup
[I810_TEXREG_MF
] |= MF_MAG_NEAREST
;
153 t
->Setup
[I810_TEXREG_MF
] |= MF_MAG_LINEAR
;
159 t
->Setup
[I810_TEXREG_MLC
] |= i810ComputeLodBias(bias
);
164 i810SetTexBorderColor( i810TextureObjectPtr t
, GLubyte color
[4] )
171 static i810TextureObjectPtr
172 i810AllocTexObj( GLcontext
*ctx
, struct gl_texture_object
*texObj
)
174 i810TextureObjectPtr t
;
175 i810ContextPtr imesa
= I810_CONTEXT(ctx
);
177 t
= CALLOC_STRUCT( i810_texture_object_t
);
178 texObj
->DriverData
= t
;
180 GLfloat bias
= ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
].LodBias
;
181 /* Initialize non-image-dependent parts of the state:
183 t
->base
.tObj
= texObj
;
184 t
->Setup
[I810_TEXREG_MI0
] = GFX_OP_MAP_INFO
;
185 t
->Setup
[I810_TEXREG_MI1
] = MI1_MAP_0
;
186 t
->Setup
[I810_TEXREG_MI2
] = MI2_DIMENSIONS_ARE_LOG2
;
187 t
->Setup
[I810_TEXREG_MLC
] = (GFX_OP_MAP_LOD_CTL
|
189 /*MLC_DITHER_WEIGHT_FULL |*/
190 MLC_DITHER_WEIGHT_12
|
191 MLC_UPDATE_LOD_BIAS
|
193 t
->Setup
[I810_TEXREG_MCS
] = (GFX_OP_MAP_COORD_SETS
|
195 MCS_UPDATE_NORMALIZED
|
196 MCS_NORMALIZED_COORDS
|
201 t
->Setup
[I810_TEXREG_MF
] = (GFX_OP_MAP_FILTER
|
203 MF_UPDATE_ANISOTROPIC
|
204 MF_UPDATE_MIP_FILTER
|
205 MF_UPDATE_MAG_FILTER
|
206 MF_UPDATE_MIN_FILTER
);
208 make_empty_list( & t
->base
);
210 i810SetTexWrapping( t
, texObj
->WrapS
, texObj
->WrapT
);
211 /*i830SetTexMaxAnisotropy( t, texObj->MaxAnisotropy );*/
212 i810SetTexFilter( imesa
, t
, texObj
->MinFilter
, texObj
->MagFilter
, bias
);
213 i810SetTexBorderColor( t
, texObj
->_BorderChan
);
220 static void i810TexParameter( GLcontext
*ctx
, GLenum target
,
221 struct gl_texture_object
*tObj
,
222 GLenum pname
, const GLfloat
*params
)
224 i810ContextPtr imesa
= I810_CONTEXT(ctx
);
225 i810TextureObjectPtr t
= (i810TextureObjectPtr
) tObj
->DriverData
;
230 if ( target
!= GL_TEXTURE_2D
)
233 /* Can't do the update now as we don't know whether to flush
234 * vertices or not. Setting imesa->new_state means that
235 * i810UpdateTextureState() will be called before any triangles are
236 * rendered. If a statechange has occurred, it will be detected at
237 * that point, and buffered vertices flushed.
240 case GL_TEXTURE_MIN_FILTER
:
241 case GL_TEXTURE_MAG_FILTER
:
243 GLfloat bias
= ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
].LodBias
;
244 i810SetTexFilter( imesa
, t
, tObj
->MinFilter
, tObj
->MagFilter
, bias
);
248 case GL_TEXTURE_WRAP_S
:
249 case GL_TEXTURE_WRAP_T
:
250 i810SetTexWrapping( t
, tObj
->WrapS
, tObj
->WrapT
);
253 case GL_TEXTURE_BORDER_COLOR
:
254 i810SetTexBorderColor( t
, tObj
->_BorderChan
);
257 case GL_TEXTURE_BASE_LEVEL
:
258 case GL_TEXTURE_MAX_LEVEL
:
259 case GL_TEXTURE_MIN_LOD
:
260 case GL_TEXTURE_MAX_LOD
:
261 /* This isn't the most efficient solution but there doesn't appear to
262 * be a nice alternative for Radeon. Since there's no LOD clamping,
263 * we just have to rely on loading the right subset of mipmap levels
264 * to simulate a clamped LOD.
266 I810_FIREVERTICES( I810_CONTEXT(ctx
) );
267 driSwapOutTextureObject( (driTextureObject
*) t
);
274 if (t
== imesa
->CurrentTexObj
[0]) {
275 I810_STATECHANGE( imesa
, I810_UPLOAD_TEX0
);
278 if (t
== imesa
->CurrentTexObj
[1]) {
279 I810_STATECHANGE( imesa
, I810_UPLOAD_TEX1
);
285 * Setup hardware bits for new texture environment settings.
288 * Determine whether or not \c param can be used instead of
289 * \c texUnit->EnvColor in the \c GL_TEXTURE_ENV_COLOR case.
291 static void i810TexEnv( GLcontext
*ctx
, GLenum target
,
292 GLenum pname
, const GLfloat
*param
)
294 i810ContextPtr imesa
= I810_CONTEXT( ctx
);
295 const GLuint unit
= ctx
->Texture
.CurrentUnit
;
296 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
298 /* Only one env color. Need a fallback if env colors are different
299 * and texture setup references env color in both units.
302 case GL_TEXTURE_ENV_COLOR
: {
306 UNCLAMPED_FLOAT_TO_RGBA_CHAN( c
, texUnit
->EnvColor
);
307 envColor
= PACK_COLOR_8888( c
[3], c
[0], c
[1], c
[2] );
309 if (imesa
->Setup
[I810_CTXREG_CF1
] != envColor
) {
310 I810_STATECHANGE(imesa
, I810_UPLOAD_CTX
);
311 imesa
->Setup
[I810_CTXREG_CF1
] = envColor
;
316 case GL_TEXTURE_ENV_MODE
:
317 imesa
->TexEnvImageFmt
[unit
] = 0; /* force recalc of env state */
320 case GL_TEXTURE_LOD_BIAS
: {
321 if ( texUnit
->_Current
!= NULL
) {
322 const struct gl_texture_object
*tObj
= texUnit
->_Current
;
323 i810TextureObjectPtr t
= (i810TextureObjectPtr
) tObj
->DriverData
;
325 t
->Setup
[I810_TEXREG_MLC
] &= ~(MLC_LOD_BIAS_MASK
);
326 t
->Setup
[I810_TEXREG_MLC
] |= i810ComputeLodBias(*param
);
339 static void i810TexImage1D( GLcontext
*ctx
, GLenum target
, GLint level
,
340 GLint internalFormat
,
341 GLint width
, GLint border
,
342 GLenum format
, GLenum type
,
343 const GLvoid
*pixels
,
344 const struct gl_pixelstore_attrib
*pack
,
345 struct gl_texture_object
*texObj
,
346 struct gl_texture_image
*texImage
)
348 i810TextureObjectPtr t
= (i810TextureObjectPtr
) texObj
->DriverData
;
350 i810SwapOutTexObj( imesa
, t
);
354 static void i810TexSubImage1D( GLcontext
*ctx
,
359 GLenum format
, GLenum type
,
360 const GLvoid
*pixels
,
361 const struct gl_pixelstore_attrib
*pack
,
362 struct gl_texture_object
*texObj
,
363 struct gl_texture_image
*texImage
)
369 static void i810TexImage2D( GLcontext
*ctx
, GLenum target
, GLint level
,
370 GLint internalFormat
,
371 GLint width
, GLint height
, GLint border
,
372 GLenum format
, GLenum type
, const GLvoid
*pixels
,
373 const struct gl_pixelstore_attrib
*packing
,
374 struct gl_texture_object
*texObj
,
375 struct gl_texture_image
*texImage
)
377 driTextureObject
*t
= (driTextureObject
*) texObj
->DriverData
;
379 I810_FIREVERTICES( I810_CONTEXT(ctx
) );
380 driSwapOutTextureObject( t
);
383 t
= (driTextureObject
*) i810AllocTexObj( ctx
, texObj
);
385 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
389 _mesa_store_teximage2d( ctx
, target
, level
, internalFormat
,
390 width
, height
, border
, format
, type
,
391 pixels
, packing
, texObj
, texImage
);
394 static void i810TexSubImage2D( GLcontext
*ctx
,
397 GLint xoffset
, GLint yoffset
,
398 GLsizei width
, GLsizei height
,
399 GLenum format
, GLenum type
,
400 const GLvoid
*pixels
,
401 const struct gl_pixelstore_attrib
*packing
,
402 struct gl_texture_object
*texObj
,
403 struct gl_texture_image
*texImage
)
405 driTextureObject
*t
= (driTextureObject
*)texObj
->DriverData
;
407 I810_FIREVERTICES( I810_CONTEXT(ctx
) );
408 driSwapOutTextureObject( t
);
410 _mesa_store_texsubimage2d(ctx
, target
, level
, xoffset
, yoffset
, width
,
411 height
, format
, type
, pixels
, packing
, texObj
,
416 static void i810BindTexture( GLcontext
*ctx
, GLenum target
,
417 struct gl_texture_object
*tObj
)
419 assert( (target
!= GL_TEXTURE_2D
) || (tObj
->DriverData
!= NULL
) );
423 static void i810DeleteTexture( GLcontext
*ctx
, struct gl_texture_object
*tObj
)
425 driTextureObject
* t
= (driTextureObject
*) tObj
->DriverData
;
427 i810ContextPtr imesa
= I810_CONTEXT( ctx
);
429 I810_FIREVERTICES( imesa
);
430 driDestroyTextureObject( t
);
432 /* Free mipmap images and the texture object itself */
433 _mesa_delete_texture_object(ctx
, tObj
);
437 * Choose a Mesa texture format to match the requested format.
439 * The i810 only supports 5 texture modes that are useful to Mesa. That
440 * makes this routine pretty simple.
442 static const struct gl_texture_format
*
443 i810ChooseTextureFormat( GLcontext
*ctx
, GLint internalFormat
,
444 GLenum format
, GLenum type
)
446 switch ( internalFormat
) {
456 case GL_COMPRESSED_RGBA
:
457 if ( ((format
== GL_BGRA
) && (type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
))
458 || ((format
== GL_RGBA
) && (type
== GL_UNSIGNED_SHORT_5_5_5_1
))
459 || (internalFormat
== GL_RGB5_A1
) ) {
460 return &_mesa_texformat_argb1555
;
462 return &_mesa_texformat_argb4444
;
466 case GL_COMPRESSED_RGB
:
474 return &_mesa_texformat_rgb565
;
481 case GL_COMPRESSED_ALPHA
:
488 case GL_COMPRESSED_LUMINANCE
:
490 case GL_LUMINANCE_ALPHA
:
491 case GL_LUMINANCE4_ALPHA4
:
492 case GL_LUMINANCE6_ALPHA2
:
493 case GL_LUMINANCE8_ALPHA8
:
494 case GL_LUMINANCE12_ALPHA4
:
495 case GL_LUMINANCE12_ALPHA12
:
496 case GL_LUMINANCE16_ALPHA16
:
497 case GL_COMPRESSED_LUMINANCE_ALPHA
:
503 case GL_COMPRESSED_INTENSITY
:
504 return &_mesa_texformat_al88
;
507 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
508 type
== GL_UNSIGNED_BYTE
)
509 return &_mesa_texformat_ycbcr
;
511 return &_mesa_texformat_ycbcr_rev
;
514 fprintf(stderr
, "unexpected texture format in %s\n", __FUNCTION__
);
518 return NULL
; /* never get here */
522 * Allocate a new texture object.
523 * Called via ctx->Driver.NewTextureObject.
524 * Note: this function will be called during context creation to
525 * allocate the default texture objects.
526 * Note: we could use containment here to 'derive' the driver-specific
527 * texture object from the core mesa gl_texture_object. Not done at this time.
529 static struct gl_texture_object
*
530 i810NewTextureObject( GLcontext
*ctx
, GLuint name
, GLenum target
)
532 struct gl_texture_object
*obj
;
533 obj
= _mesa_new_texture_object(ctx
, name
, target
);
534 i810AllocTexObj( ctx
, obj
);
538 void i810InitTextureFuncs( struct dd_function_table
*functions
)
540 functions
->ChooseTextureFormat
= i810ChooseTextureFormat
;
541 functions
->TexImage2D
= i810TexImage2D
;
542 functions
->TexSubImage2D
= i810TexSubImage2D
;
543 functions
->BindTexture
= i810BindTexture
;
544 functions
->NewTextureObject
= i810NewTextureObject
;
545 functions
->DeleteTexture
= i810DeleteTexture
;
546 functions
->TexParameter
= i810TexParameter
;
547 functions
->TexEnv
= i810TexEnv
;
548 functions
->IsTextureResident
= driIsTextureResident
;