The attached patch provides s3tc (and broken fxt) texture compression
support on the i8xx (x>30) chipsets,
You need to apply the radeon/r200 patch from Roland first, Roland do you
want to merge this patch into yours?
So far I've tested this with texcmp - thats how I know FXT doesn't work,
do we have support for FXT in Mesa?
do I have any chance of getting ut2004 demo going on an i865 chipset?
at the moment I'm missing some floors and things..
Dave.
--
David Airlie, Software Engineer
http://www.skynet.ie/~airlied / airlied at skynet.ie
pam_smb / Linux DECstation / Linux VAX / ILUG person
diff -ur Mesa/src/mesa/drivers/dri/i830/i830_context.c
new_mesa/Mesa/src/mesa/drivers/dri/i830/i830_context.c
--- Mesa/src/mesa/drivers/dri/i830/i830_context.c 2004-05-14 04:24:20.000000000
+1000
+++ new_mesa/Mesa/src/mesa/drivers/dri/i830/i830_context.c 2004-05-24
20:59:51.743669808 +1000
@@ -290,6 +290,10 @@
12,
GL_FALSE );
+ /* adjust max texture size a bit. Hack, but I really want to use larger textures
+ which will work just fine in 99.999999% of all cases, especially with texture
compression... */
+ if (ctx->Const.MaxTextureLevels < 12) ctx->Const.MaxTextureLevels += 1;
+
ctx->Const.MaxTextureMaxAnisotropy = 2.0;
ctx->Const.MinLineWidth = 1.0;
@@ -371,6 +375,16 @@
_math_matrix_ctr (&imesa->ViewportMatrix);
driInitExtensions( ctx, card_extensions, GL_TRUE );
+ if (imesa->glCtx->Mesa_DXTn) {
+ _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
+ /* Don't advertise FXT1 - doesn't work yet - airlied */
+ /* _mesa_enable_extension( ctx, "GL_3DFX_texture_compression_FXT1" );*/
+ _mesa_enable_extension( ctx, "GL_S3_s3tc" );
+ }
+ else if (driQueryOptionb (&imesa->optionCache, "force_s3tc_enable")) {
+ _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
+ }
+
/* XXX these should really go right after _mesa_init_driver_functions() */
i830DDInitStateFuncs( ctx );
i830InitTriFuncs (ctx);
diff -ur Mesa/src/mesa/drivers/dri/i830/i830_screen.c
new_mesa/Mesa/src/mesa/drivers/dri/i830/i830_screen.c
--- Mesa/src/mesa/drivers/dri/i830/i830_screen.c 2004-05-09 14:38:42.000000000
+1000
+++ new_mesa/Mesa/src/mesa/drivers/dri/i830/i830_screen.c 2004-05-24
13:07:10.000000000 +1000
@@ -58,9 +58,10 @@
DRI_CONF_BEGIN
DRI_CONF_SECTION_PERFORMANCE
DRI_CONF_MAX_TEXTURE_UNITS(4,2,4)
+ DRI_CONF_FORCE_S3TC_ENABLE(false)
DRI_CONF_SECTION_END
DRI_CONF_END;
-const GLuint __driNConfigOptions = 1;
+const GLuint __driNConfigOptions = 2;
#ifdef USE_NEW_INTERFACE
static PFNGLXCREATECONTEXTMODES create_context_modes = NULL;
diff -ur Mesa/src/mesa/drivers/dri/i830/i830_tex.c
new_mesa/Mesa/src/mesa/drivers/dri/i830/i830_tex.c
--- Mesa/src/mesa/drivers/dri/i830/i830_tex.c 2004-04-08 18:54:24.000000000 +1000
+++ new_mesa/Mesa/src/mesa/drivers/dri/i830/i830_tex.c 2004-05-24 20:53:19.376318712
+1000
@@ -418,6 +418,101 @@
}
+
+static void i830CompressedTexImage2D( GLcontext *ctx, GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint height, GLint border,
+ GLsizei imageSize, const GLvoid *data,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage )
+{
+ driTextureObject * t = (driTextureObject *) texObj->DriverData;
+ GLuint face;
+
+ /* which cube face or ordinary 2D image */
+ switch (target) {
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
+ face = (GLuint) target - (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X;
+ ASSERT(face < 6);
+ break;
+ default:
+ face = 0;
+ }
+
+ if ( t != NULL ) {
+ driSwapOutTextureObject( t );
+ }
+ else {
+ t = (driTextureObject *) i830AllocTexObj( texObj );
+ if (!t) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2D");
+ return;
+ }
+ }
+
+ texImage->IsClientData = GL_FALSE;
+
+ if (I830_DEBUG & DEBUG_TEXTURE)
+ fprintf(stderr, "%s: Using normal storage\n", __FUNCTION__);
+
+ _mesa_store_compressed_teximage2d(ctx, target, level, internalFormat, width,
+ height, border, imageSize, data, texObj,
texImage);
+
+ t->dirty_images[face] |= (1 << level);
+}
+
+
+static void i830CompressedTexSubImage2D( GLcontext *ctx, GLenum target, GLint level,
+ GLint xoffset, GLint yoffset,
+ GLsizei width, GLsizei height,
+ GLenum format,
+ GLsizei imageSize, const GLvoid *data,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage )
+{
+ driTextureObject * t = (driTextureObject *) texObj->DriverData;
+ GLuint face;
+
+
+ /* which cube face or ordinary 2D image */
+ switch (target) {
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
+ face = (GLuint) target - (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X;
+ ASSERT(face < 6);
+ break;
+ default:
+ face = 0;
+ }
+
+ assert( t ); /* this _should_ be true */
+ if ( t ) {
+ driSwapOutTextureObject( t );
+ }
+ else {
+ t = (driTextureObject *) i830AllocTexObj( texObj );
+ if (!t) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexSubImage2D");
+ return;
+ }
+ }
+
+ _mesa_store_compressed_texsubimage2d(ctx, target, level, xoffset, yoffset, width,
+ height, format, imageSize, data, texObj, texImage);
+
+ t->dirty_images[face] |= (1 << level);
+}
+
+
static void i830BindTexture( GLcontext *ctx, GLenum target,
struct gl_texture_object *tObj )
{
@@ -543,6 +638,41 @@
else
return &_mesa_texformat_ycbcr_rev;
+ case GL_COMPRESSED_RGB_FXT1_3DFX:
+ return &_mesa_texformat_rgb_fxt1;
+ case GL_COMPRESSED_RGBA_FXT1_3DFX:
+ return &_mesa_texformat_rgba_fxt1;
+
+ case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
+ return &_mesa_texformat_rgb_dxt1;
+
+ case GL_RGB_S3TC:
+ case GL_RGB4_S3TC:
+ /* only return this format if software compression/decompression is available,
since
+ no app will ever use this for precompressed textures */
+ /* if (ctx->Mesa_DXTn) */
+ return &_mesa_texformat_rgb_dxt1;
+ /* else */
+ /* mesa will crash if we return uncompressed format unfortunately */
+ /* return do32bpt ? &_mesa_texformat_rgba8888 : &_mesa_texformat_rgb565;
*/
+
+ case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
+ return &_mesa_texformat_rgba_dxt1;
+
+ case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
+ return &_mesa_texformat_rgba_dxt3;
+
+ case GL_RGBA_S3TC:
+ case GL_RGBA4_S3TC:
+ /* if (ctx->Mesa_DXTn) */
+ return &_mesa_texformat_rgba_dxt3;
+ /* else */
+ /* mesa will crash if we return uncompressed format unfortunately */
+ /* return do32bpt ? &_mesa_texformat_rgba8888 :
&_mesa_texformat_argb4444; */
+
+ case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
+ return &_mesa_texformat_rgba_dxt5;
+
default:
fprintf(stderr, "unexpected texture format in %s\n", __FUNCTION__);
return NULL;
@@ -579,4 +709,6 @@
functions->TexParameter = i830TexParameter;
functions->TexEnv = i830TexEnv;
functions->IsTextureResident = driIsTextureResident;
+ functions->CompressedTexImage2D = i830CompressedTexImage2D;
+ functions->CompressedTexSubImage2D = i830CompressedTexSubImage2D;
}
diff -ur Mesa/src/mesa/drivers/dri/i830/i830_texmem.c
new_mesa/Mesa/src/mesa/drivers/dri/i830/i830_texmem.c
--- Mesa/src/mesa/drivers/dri/i830/i830_texmem.c 2004-05-08 03:30:31.000000000
+1000
+++ new_mesa/Mesa/src/mesa/drivers/dri/i830/i830_texmem.c 2004-05-24
20:45:37.860479784 +1000
@@ -111,6 +111,12 @@
memcpy( dst, src, t->Pitch * image->Height );
}
+ else if (image->IsCompressed) {
+ GLubyte *dst = (GLubyte *)(t->BufAddr + t->image[0][hwlevel].offset);
+ GLubyte *src = (GLubyte *)image->Data;
+
+ memcpy( dst, src, image->CompressedSize );
+ }
else switch (image->TexFormat->TexelBytes) {
case 1:
{
@@ -147,7 +153,7 @@
}
}
break;
-
+
default:
fprintf(stderr, "%s: Not supported texel size %d\n",
__FUNCTION__, image->TexFormat->TexelBytes);
diff -ur Mesa/src/mesa/drivers/dri/i830/i830_texstate.c
new_mesa/Mesa/src/mesa/drivers/dri/i830/i830_texstate.c
--- Mesa/src/mesa/drivers/dri/i830/i830_texstate.c 2004-05-13 02:29:55.000000000
+1000
+++ new_mesa/Mesa/src/mesa/drivers/dri/i830/i830_texstate.c 2004-05-24
20:55:08.854675472 +1000
@@ -111,7 +111,26 @@
textureFormat = (MAPSURF_422 | MT_422_YCRCB_SWAPY | /* ??? */
TM0S1_COLORSPACE_CONVERSION);
break;
-
+
+ case MESA_FORMAT_RGB_FXT1:
+ case MESA_FORMAT_RGBA_FXT1:
+ t->texelBytes = 1;
+ textureFormat = (MAPSURF_COMPRESSED | MT_COMPRESS_FXT1);
+ break;
+ case MESA_FORMAT_RGB_DXT1:
+ case MESA_FORMAT_RGBA_DXT1:
+ t->texelBytes = 2;
+ textureFormat = (MAPSURF_COMPRESSED | MT_COMPRESS_DXT1);
+ break;
+ case MESA_FORMAT_RGBA_DXT3:
+ t->texelBytes = 4;
+ textureFormat = (MAPSURF_COMPRESSED | MT_COMPRESS_DXT2_3);
+ break;
+
+ case MESA_FORMAT_RGBA_DXT5:
+ t->texelBytes = 4;
+ textureFormat = (MAPSURF_COMPRESSED | MT_COMPRESS_DXT4_5);
+ break;
default:
fprintf(stderr, "%s: bad image format\n", __FUNCTION__);
free( t );