Index: src/mesa/drivers/dri/i810/i810tex.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/i810/i810tex.c,v retrieving revision 1.8 diff -u -r1.8 i810tex.c --- src/mesa/drivers/dri/i810/i810tex.c 8 Apr 2004 08:54:24 -0000 1.8 +++ src/mesa/drivers/dri/i810/i810tex.c 16 May 2005 23:13:28 -0000 @@ -431,10 +431,10 @@ } static const struct gl_texture_format * -i810ChooseTextureFormat( GLcontext *ctx, GLint internalFormat, +i810ChooseTextureFormat( GLcontext *ctx, GLint *internalFormat, GLenum format, GLenum type ) { - switch ( internalFormat ) { + switch ( *internalFormat ) { case 4: case GL_RGBA: case GL_COMPRESSED_RGBA: Index: src/mesa/drivers/dri/i830/i830_tex.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/i830/i830_tex.c,v retrieving revision 1.11 diff -u -r1.11 i830_tex.c --- src/mesa/drivers/dri/i830/i830_tex.c 7 Oct 2004 23:30:29 -0000 1.11 +++ src/mesa/drivers/dri/i830/i830_tex.c 16 May 2005 23:13:28 -0000 @@ -539,17 +539,23 @@ static const struct gl_texture_format * -i830ChooseTextureFormat( GLcontext *ctx, GLint internalFormat, +i830ChooseTextureFormat( GLcontext *ctx, GLint *internalFormat, GLenum format, GLenum type ) { i830ContextPtr imesa = I830_CONTEXT( ctx ); const GLboolean do32bpt = ( imesa->i830Screen->cpp == 4 && imesa->i830Screen->textureSize > 4*1024*1024); + const GLboolean haveSoftDXTn = ctx->Mesa_DXTn; - switch ( internalFormat ) { + switch ( *internalFormat ) { + case GL_COMPRESSED_RGBA: + if ( haveSoftDXTn ) { + *internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + return &_mesa_texformat_rgba_dxt5; + } + /* fall through */ case 4: case GL_RGBA: - case GL_COMPRESSED_RGBA: if ( format == GL_BGRA ) { if ( type == GL_UNSIGNED_INT_8_8_8_8_REV ) { return &_mesa_texformat_argb8888; @@ -563,9 +569,14 @@ } return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444; + case GL_COMPRESSED_RGB: + if ( haveSoftDXTn ) { + *internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; + return &_mesa_texformat_rgb_dxt1; + } + /* fall through */ case 3: case GL_RGB: - case GL_COMPRESSED_RGB: if ( format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5 ) { return &_mesa_texformat_rgb565; } Index: src/mesa/drivers/dri/i915/intel_tex.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/i915/intel_tex.c,v retrieving revision 1.7 diff -u -r1.7 intel_tex.c --- src/mesa/drivers/dri/i915/intel_tex.c 6 Jan 2005 14:35:44 -0000 1.7 +++ src/mesa/drivers/dri/i915/intel_tex.c 16 May 2005 23:13:28 -0000 @@ -448,17 +448,23 @@ static const struct gl_texture_format * -intelChooseTextureFormat( GLcontext *ctx, GLint internalFormat, +intelChooseTextureFormat( GLcontext *ctx, GLint *internalFormat, GLenum format, GLenum type ) { intelContextPtr intel = INTEL_CONTEXT( ctx ); const GLboolean do32bpt = ( intel->intelScreen->cpp == 4 && intel->intelScreen->textureSize > 4*1024*1024); + const GLboolean haveSoftDXTn = ctx->Mesa_DXTn; - switch ( internalFormat ) { + switch ( *internalFormat ) { + case GL_COMPRESSED_RGBA: + if ( haveSoftDXTn ) { + *internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + return &_mesa_texformat_rgba_dxt5; + } + /* fall through */ case 4: case GL_RGBA: - case GL_COMPRESSED_RGBA: if ( format == GL_BGRA ) { if ( type == GL_UNSIGNED_INT_8_8_8_8_REV ) { return &_mesa_texformat_argb8888; @@ -472,9 +478,14 @@ } return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444; + case GL_COMPRESSED_RGB: + if ( haveSoftDXTn ) { + *internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; + return &_mesa_texformat_rgb_dxt1; + } + /* fall through */ case 3: case GL_RGB: - case GL_COMPRESSED_RGB: if ( format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5 ) { return &_mesa_texformat_rgb565; } @@ -576,7 +587,7 @@ default: fprintf(stderr, "unexpected texture format %s in %s\n", - _mesa_lookup_enum_by_nr(internalFormat), + _mesa_lookup_enum_by_nr(*internalFormat), __FUNCTION__); return NULL; } Index: src/mesa/drivers/dri/mach64/mach64_tex.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/mach64/mach64_tex.c,v retrieving revision 1.4 diff -u -r1.4 mach64_tex.c --- src/mesa/drivers/dri/mach64/mach64_tex.c 31 May 2004 00:58:34 -0000 1.4 +++ src/mesa/drivers/dri/mach64/mach64_tex.c 16 May 2005 23:13:29 -0000 @@ -140,14 +140,14 @@ /* Called by the _mesa_store_teximage[123]d() functions. */ static const struct gl_texture_format * -mach64ChooseTextureFormat( GLcontext *ctx, GLint internalFormat, +mach64ChooseTextureFormat( GLcontext *ctx, GLint *internalFormat, GLenum format, GLenum type ) { mach64ContextPtr mmesa = MACH64_CONTEXT(ctx); (void) format; (void) type; - switch ( internalFormat ) { + switch ( *internalFormat ) { case GL_ALPHA: case GL_ALPHA4: case GL_ALPHA8: Index: src/mesa/drivers/dri/mga/mgatex.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/mga/mgatex.c,v retrieving revision 1.9 diff -u -r1.9 mgatex.c --- src/mesa/drivers/dri/mga/mgatex.c 26 Jan 2004 23:57:19 -0000 1.9 +++ src/mesa/drivers/dri/mga/mgatex.c 16 May 2005 23:13:29 -0000 @@ -162,7 +162,7 @@ static const struct gl_texture_format * -mgaChooseTextureFormat( GLcontext *ctx, GLint internalFormat, +mgaChooseTextureFormat( GLcontext *ctx, GLint *internalFormat, GLenum format, GLenum type ) { mgaContextPtr mmesa = MGA_CONTEXT(ctx); @@ -172,7 +172,7 @@ ( mmesa->texture_depth == DRI_CONF_TEXTURE_DEPTH_FORCE_16 ); (void) format; - switch ( internalFormat ) { + switch ( *internalFormat ) { case 4: case GL_RGBA: case GL_COMPRESSED_RGBA: Index: src/mesa/drivers/dri/r128/r128_tex.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r128/r128_tex.c,v retrieving revision 1.16 diff -u -r1.16 r128_tex.c --- src/mesa/drivers/dri/r128/r128_tex.c 14 Dec 2004 09:11:53 -0000 1.16 +++ src/mesa/drivers/dri/r128/r128_tex.c 16 May 2005 23:13:29 -0000 @@ -175,7 +175,7 @@ /* Called by the _mesa_store_teximage[123]d() functions. */ static const struct gl_texture_format * -r128ChooseTextureFormat( GLcontext *ctx, GLint internalFormat, +r128ChooseTextureFormat( GLcontext *ctx, GLint *internalFormat, GLenum format, GLenum type ) { r128ContextPtr rmesa = R128_CONTEXT(ctx); @@ -186,7 +186,7 @@ (void) format; (void) type; - switch ( internalFormat ) { + switch ( *internalFormat ) { /* non-sized formats with alpha */ case GL_INTENSITY: case GL_COMPRESSED_INTENSITY: Index: src/mesa/drivers/dri/r200/r200_tex.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r200/r200_tex.c,v retrieving revision 1.20 diff -u -r1.20 r200_tex.c --- src/mesa/drivers/dri/r200/r200_tex.c 7 Oct 2004 23:30:30 -0000 1.20 +++ src/mesa/drivers/dri/r200/r200_tex.c 16 May 2005 23:13:31 -0000 @@ -307,7 +307,7 @@ static const struct gl_texture_format * -r200ChooseTextureFormat( GLcontext *ctx, GLint internalFormat, +r200ChooseTextureFormat( GLcontext *ctx, GLint *internalFormat, GLenum format, GLenum type ) { r200ContextPtr rmesa = R200_CONTEXT(ctx); @@ -315,12 +315,18 @@ ( rmesa->texture_depth == DRI_CONF_TEXTURE_DEPTH_32 ); const GLboolean force16bpt = ( rmesa->texture_depth == DRI_CONF_TEXTURE_DEPTH_FORCE_16 ); + const GLboolean haveSoftDXTn = ctx->Mesa_DXTn; (void) format; - switch ( internalFormat ) { + switch ( *internalFormat ) { + case GL_COMPRESSED_RGBA: + if ( haveSoftDXTn ) { + *internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + return &_mesa_texformat_rgba_dxt5; + } + /* fall through */ case 4: case GL_RGBA: - case GL_COMPRESSED_RGBA: switch ( type ) { case GL_UNSIGNED_INT_10_10_10_2: case GL_UNSIGNED_INT_2_10_10_10_REV: @@ -335,9 +341,14 @@ return do32bpt ? _dri_texformat_rgba8888 : _dri_texformat_argb4444; } + case GL_COMPRESSED_RGB: + if ( haveSoftDXTn ) { + *internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; + return &_mesa_texformat_rgb_dxt1; + } + /* fall through */ case 3: case GL_RGB: - case GL_COMPRESSED_RGB: switch ( type ) { case GL_UNSIGNED_SHORT_4_4_4_4: case GL_UNSIGNED_SHORT_4_4_4_4_REV: Index: src/mesa/drivers/dri/r200/r200_texstate.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r200/r200_texstate.c,v retrieving revision 1.19 diff -u -r1.19 r200_texstate.c --- src/mesa/drivers/dri/r200/r200_texstate.c 10 Feb 2005 22:36:06 -0000 1.19 +++ src/mesa/drivers/dri/r200/r200_texstate.c 16 May 2005 23:13:34 -0000 @@ -207,15 +207,15 @@ if ((t->pp_txformat & R200_TXFORMAT_FORMAT_MASK) == R200_TXFORMAT_DXT1) { /* RGB_DXT1/RGBA_DXT1, 8 bytes per block */ if ((texImage->Width + 3) < 8) /* width one block */ - size = texImage->CompressedSize * 4; + size = texImage->ImageSize * 4; else if ((texImage->Width + 3) < 16) - size = texImage->CompressedSize * 2; - else size = texImage->CompressedSize; + size = texImage->ImageSize * 2; + else size = texImage->ImageSize; } else /* DXT3/5, 16 bytes per block */ if ((texImage->Width + 3) < 8) - size = texImage->CompressedSize * 2; - else size = texImage->CompressedSize; + size = texImage->ImageSize * 2; + else size = texImage->ImageSize; } else if (tObj->Target == GL_TEXTURE_RECTANGLE_NV) { size = ((texImage->Width * texelBytes + 63) & ~63) * texImage->Height; Index: src/mesa/drivers/dri/radeon/radeon_tex.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/radeon/radeon_tex.c,v retrieving revision 1.15 diff -u -r1.15 radeon_tex.c --- src/mesa/drivers/dri/radeon/radeon_tex.c 7 Oct 2004 23:30:30 -0000 1.15 +++ src/mesa/drivers/dri/radeon/radeon_tex.c 16 May 2005 23:13:38 -0000 @@ -269,7 +269,7 @@ static const struct gl_texture_format * -radeonChooseTextureFormat( GLcontext *ctx, GLint internalFormat, +radeonChooseTextureFormat( GLcontext *ctx, GLint *internalFormat, GLenum format, GLenum type ) { radeonContextPtr rmesa = RADEON_CONTEXT(ctx); @@ -277,12 +277,18 @@ ( rmesa->texture_depth == DRI_CONF_TEXTURE_DEPTH_32 ); const GLboolean force16bpt = ( rmesa->texture_depth == DRI_CONF_TEXTURE_DEPTH_FORCE_16 ); + const GLboolean haveSoftDXTn = ctx->Mesa_DXTn; (void) format; - switch ( internalFormat ) { + switch ( *internalFormat ) { + case GL_COMPRESSED_RGBA: + if ( haveSoftDXTn ) { + *internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + return &_mesa_texformat_rgba_dxt5; + } + /* fall through */ case 4: case GL_RGBA: - case GL_COMPRESSED_RGBA: switch ( type ) { case GL_UNSIGNED_INT_10_10_10_2: case GL_UNSIGNED_INT_2_10_10_10_REV: @@ -297,9 +303,14 @@ return do32bpt ? _dri_texformat_rgba8888 : _dri_texformat_argb4444; } + case GL_COMPRESSED_RGB: + if ( haveSoftDXTn ) { + *internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; + return &_mesa_texformat_rgb_dxt1; + } + /* fall through */ case 3: case GL_RGB: - case GL_COMPRESSED_RGB: switch ( type ) { case GL_UNSIGNED_SHORT_4_4_4_4: case GL_UNSIGNED_SHORT_4_4_4_4_REV: Index: src/mesa/drivers/dri/radeon/radeon_texstate.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/radeon/radeon_texstate.c,v retrieving revision 1.14 diff -u -r1.14 radeon_texstate.c --- src/mesa/drivers/dri/radeon/radeon_texstate.c 10 Feb 2005 22:36:07 -0000 1.14 +++ src/mesa/drivers/dri/radeon/radeon_texstate.c 16 May 2005 23:13:43 -0000 @@ -215,15 +215,15 @@ if ((t->pp_txformat & RADEON_TXFORMAT_FORMAT_MASK) == RADEON_TXFORMAT_DXT1) { /* RGB_DXT1/RGBA_DXT1, 8 bytes per block */ if ((texImage->Width + 3) < 8) /* width one block */ - size = texImage->CompressedSize * 4; + size = texImage->ImageSize * 4; else if ((texImage->Width + 3) < 16) - size = texImage->CompressedSize * 2; - else size = texImage->CompressedSize; + size = texImage->ImageSize * 2; + else size = texImage->ImageSize; } else /* DXT3/5, 16 bytes per block */ if ((texImage->Width + 3) < 8) - size = texImage->CompressedSize * 2; - else size = texImage->CompressedSize; + size = texImage->ImageSize * 2; + else size = texImage->ImageSize; } else if (tObj->Target == GL_TEXTURE_RECTANGLE_NV) { size = ((texImage->Width * texelBytes + 63) & ~63) * texImage->Height; Index: src/mesa/drivers/dri/savage/savage_xmesa.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/savage/savage_xmesa.c,v retrieving revision 1.47 diff -u -r1.47 savage_xmesa.c --- src/mesa/drivers/dri/savage/savage_xmesa.c 4 May 2005 20:11:38 -0000 1.47 +++ src/mesa/drivers/dri/savage/savage_xmesa.c 16 May 2005 23:13:43 -0000 @@ -532,15 +532,16 @@ #endif driInitExtensions( ctx, common_extensions, GL_TRUE ); - if (savageScreen->chipset >= S3_SAVAGE4) + if (savageScreen->chipset >= S3_SAVAGE4) { driInitExtensions( ctx, s4_extensions, GL_FALSE ); - if (ctx->Mesa_DXTn || - driQueryOptionb (&imesa->optionCache, "force_s3tc_enable")) { - _mesa_enable_extension( ctx, "GL_S3_s3tc" ); - if (savageScreen->chipset >= S3_SAVAGE4) - /* This extension needs DXT3 and DTX5 support in hardware. - * Not available on Savage3D/MX/IX. */ + /* S3TC extensions need DXT3 and/or DTX5-support in hardware. + * Not available on Savage3D/MX/IX. These chips can only support + * generic RGB compression with DXT1. */ + if (ctx->Mesa_DXTn || + driQueryOptionb (&imesa->optionCache, "force_s3tc_enable")) { + _mesa_enable_extension( ctx, "GL_S3_s3tc" ); _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" ); + } } savageDDInitStateFuncs( ctx ); Index: src/mesa/drivers/dri/savage/savagetex.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/savage/savagetex.c,v retrieving revision 1.37 diff -u -r1.37 savagetex.c --- src/mesa/drivers/dri/savage/savagetex.c 1 May 2005 14:29:16 -0000 1.37 +++ src/mesa/drivers/dri/savage/savagetex.c 16 May 2005 23:13:46 -0000 @@ -562,6 +562,8 @@ 0, /* IndexBits */ 0, /* DepthBits */ 2, /* TexelBytes */ + NULL, NULL, NULL, /* ImageSizeFunc, RowStrideFunc, ImageAddrFunc + * filled in by savageDDInitTextureFuncs */ _savage_texstore_a1114444, /* StoreTexImageFunc */ NULL, NULL, NULL, NULL, NULL, NULL /* FetchTexel* filled in by * savageDDInitTextureFuncs */ @@ -579,6 +581,8 @@ 0, /* IndexBits */ 0, /* DepthBits */ 4, /* TexelBytes */ + NULL, NULL, NULL, /* ImageSizeFunc, RowStrideFunc, ImageAddrFunc + * filled in by savageDDInitTextureFuncs */ _savage_texstore_a1118888, /* StoreTexImageFunc */ NULL, NULL, NULL, NULL, NULL, NULL /* FetchTexel* filled in by * savageDDInitTextureFuncs */ @@ -685,7 +689,7 @@ /* Called by the _mesa_store_teximage[123]d() functions. */ static const struct gl_texture_format * -savageChooseTextureFormat( GLcontext *ctx, GLint internalFormat, +savageChooseTextureFormat( GLcontext *ctx, GLint *internalFormat, GLenum format, GLenum type ) { savageContextPtr imesa = SAVAGE_CONTEXT(ctx); @@ -694,12 +698,18 @@ const GLboolean force16bpt = ( imesa->texture_depth == DRI_CONF_TEXTURE_DEPTH_FORCE_16 ); const GLboolean isSavage4 = (imesa->savageScreen->chipset >= S3_SAVAGE4); + const GLboolean haveSoftDXTn = ctx->Mesa_DXTn; (void) format; - switch ( internalFormat ) { + switch ( *internalFormat ) { + case GL_COMPRESSED_RGBA: + if ( isSavage4 && haveSoftDXTn ) { + *internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + return &_mesa_texformat_rgba_dxt5; + } + /* older Savages fall through ... */ case 4: case GL_RGBA: - case GL_COMPRESSED_RGBA: switch ( type ) { case GL_UNSIGNED_INT_10_10_10_2: case GL_UNSIGNED_INT_2_10_10_10_REV: @@ -714,9 +724,14 @@ return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444; } + case GL_COMPRESSED_RGB: + if ( haveSoftDXTn ) { + *internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; + return &_mesa_texformat_rgb_dxt1; + } + /* fall through */ case 3: case GL_RGB: - case GL_COMPRESSED_RGB: switch ( type ) { case GL_UNSIGNED_SHORT_4_4_4_4: case GL_UNSIGNED_SHORT_4_4_4_4_REV: @@ -832,15 +847,11 @@ case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: return &_mesa_texformat_rgba_dxt1; + case GL_RGBA_S3TC: + case GL_RGBA4_S3TC: case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: return &_mesa_texformat_rgba_dxt3; - case GL_RGBA_S3TC: - case GL_RGBA4_S3TC: - if (!isSavage4) - /* Not the best choice but Savage3D/MX/IX don't support DXT3 or DXT5. */ - return &_mesa_texformat_rgba_dxt1; - /* fall through */ case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: return &_mesa_texformat_rgba_dxt5; @@ -2107,6 +2118,9 @@ /* Texel fetching with our custom texture formats works just like * the standard argb formats. */ + _savage_texformat_a1114444.ImageSize = _mesa_texformat_argb4444.ImageSize; + _savage_texformat_a1114444.RowStride = _mesa_texformat_argb4444.RowStride; + _savage_texformat_a1114444.ImageAddr = _mesa_texformat_argb4444.ImageAddr; _savage_texformat_a1114444.FetchTexel1D = _mesa_texformat_argb4444.FetchTexel1D; _savage_texformat_a1114444.FetchTexel2D = _mesa_texformat_argb4444.FetchTexel2D; _savage_texformat_a1114444.FetchTexel3D = _mesa_texformat_argb4444.FetchTexel3D; @@ -2114,6 +2128,9 @@ _savage_texformat_a1114444.FetchTexel2Df= _mesa_texformat_argb4444.FetchTexel2Df; _savage_texformat_a1114444.FetchTexel3Df= _mesa_texformat_argb4444.FetchTexel3Df; + _savage_texformat_a1118888.ImageSize = _mesa_texformat_argb8888.ImageSize; + _savage_texformat_a1118888.RowStride = _mesa_texformat_argb8888.RowStride; + _savage_texformat_a1118888.ImageAddr = _mesa_texformat_argb8888.ImageAddr; _savage_texformat_a1118888.FetchTexel1D = _mesa_texformat_argb8888.FetchTexel1D; _savage_texformat_a1118888.FetchTexel2D = _mesa_texformat_argb8888.FetchTexel2D; _savage_texformat_a1118888.FetchTexel3D = _mesa_texformat_argb8888.FetchTexel3D; Index: src/mesa/drivers/dri/sis/sis_tex.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/sis/sis_tex.c,v retrieving revision 1.7 diff -u -r1.7 sis_tex.c --- src/mesa/drivers/dri/sis/sis_tex.c 24 May 2004 20:48:27 -0000 1.7 +++ src/mesa/drivers/dri/sis/sis_tex.c 16 May 2005 23:13:48 -0000 @@ -212,11 +212,11 @@ } static const struct gl_texture_format * -sisChooseTextureFormat( GLcontext *ctx, GLint internalFormat, +sisChooseTextureFormat( GLcontext *ctx, GLint *internalFormat, GLenum format, GLenum type ) { /* XXX 16-bit internal texture formats? */ - switch ( internalFormat ) { + switch ( *internalFormat ) { case GL_ALPHA: case GL_ALPHA4: case GL_ALPHA8: Index: src/mesa/drivers/dri/tdfx/tdfx_tex.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/tdfx/tdfx_tex.c,v retrieving revision 1.28 diff -u -r1.28 tdfx_tex.c --- src/mesa/drivers/dri/tdfx/tdfx_tex.c 6 Jan 2005 07:36:56 -0000 1.28 +++ src/mesa/drivers/dri/tdfx/tdfx_tex.c 16 May 2005 23:13:54 -0000 @@ -714,13 +714,13 @@ static const struct gl_texture_format * -tdfxChooseTextureFormat( GLcontext *ctx, GLint internalFormat, +tdfxChooseTextureFormat( GLcontext *ctx, GLint *internalFormat, GLenum srcFormat, GLenum srcType ) { tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); const GLboolean allow32bpt = TDFX_IS_NAPALM(fxMesa); - switch (internalFormat) { + switch (*internalFormat) { case GL_ALPHA: case GL_ALPHA4: case GL_ALPHA8: @@ -758,7 +758,11 @@ case GL_RGB5: return &_mesa_texformat_rgb565; case GL_COMPRESSED_RGB: - /* intentional fall-through */ + if ( TDFX_IS_NAPALM( fxMesa ) ) { + *internalFormat = GL_COMPRESSED_RGB_FXT1_3DFX; + return &_mesa_texformat_rgb_fxt1; + } + /* intentional fall through */ case 3: case GL_RGB: if ( srcFormat == GL_RGB && srcType == GL_UNSIGNED_SHORT_5_6_5 ) { @@ -775,7 +779,11 @@ case GL_RGBA4: return &_mesa_texformat_argb4444; case GL_COMPRESSED_RGBA: - /* intentional fall-through */ + if ( TDFX_IS_NAPALM( fxMesa ) ) { + *internalFormat = GL_COMPRESSED_RGBA_FXT1_3DFX; + return &_mesa_texformat_rgba_fxt1; + } + /* intentional fall through */ case 4: case GL_RGBA: if ( srcFormat == GL_BGRA ) { @@ -1307,23 +1315,21 @@ * be correct, since it would mess with "compressedSize". * Ditto for GL_RGBA[4]_S3TC, which is always mapped to DXT3. */ - if (texImage->IsCompressed) { - switch (internalFormat) { - case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: - case GL_RGB_S3TC: - case GL_RGB4_S3TC: - internalFormat = GL_COMPRESSED_RGB_FXT1_3DFX; - break; - case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - case GL_RGBA_S3TC: - case GL_RGBA4_S3TC: - internalFormat = GL_COMPRESSED_RGBA_FXT1_3DFX; - } - texImage->IntFormat = internalFormat; + switch (internalFormat) { + case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: + case GL_RGB_S3TC: + case GL_RGB4_S3TC: + texImage->IntFormat = internalFormat = GL_COMPRESSED_RGB_FXT1_3DFX; + break; + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + case GL_RGBA_S3TC: + case GL_RGBA4_S3TC: + texImage->IntFormat = internalFormat = GL_COMPRESSED_RGBA_FXT1_3DFX; } #endif +/* This is now done in ChooseTextureFormat. #if FX_TC_NAPALM if (fxMesa->type >= GR_SSTTYPE_Voodoo4) { GLenum texNapalm = 0; @@ -1338,29 +1344,26 @@ } } #endif +*/ /* choose the texture format */ assert(ctx->Driver.ChooseTextureFormat); texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx, - internalFormat, format, type); + &internalFormat, format, type); + texImage->IntFormat = internalFormat; assert(texImage->TexFormat); mml->glideFormat = fxGlideFormat(texImage->TexFormat->MesaFormat); ti->info.format = mml->glideFormat; texImage->FetchTexelc = fxFetchFunction(texImage->TexFormat->MesaFormat); texelBytes = texImage->TexFormat->TexelBytes; + texImage->IsCompressed = (texImage->TexFormat->TexelBytes == 0); + texImage->ImageSize = + (*texImage->TexFormat->ImageSize)(texImage->TexFormat, + mml->width, mml->height, 1); + dstRowStride = (*texImage->TexFormat->RowStride)(texImage->TexFormat, + mml->width); + texImage->Data = MESA_PBUFFER_ALLOC(texImage->ImageSize); - if (texImage->IsCompressed) { - texImage->CompressedSize = _mesa_compressed_texture_size(ctx, - mml->width, - mml->height, - 1, - internalFormat); - dstRowStride = _mesa_compressed_row_stride(internalFormat, mml->width); - texImage->Data = MESA_PBUFFER_ALLOC(texImage->CompressedSize); - } else { - dstRowStride = mml->width * texelBytes; - texImage->Data = MESA_PBUFFER_ALLOC(mml->width * mml->height * texelBytes); - } if (!texImage->Data) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); return; @@ -1472,11 +1475,9 @@ assert(texImage->Format); texelBytes = texImage->TexFormat->TexelBytes; - if (texImage->IsCompressed) { - dstRowStride = _mesa_compressed_row_stride(texImage->IntFormat, mml->width); - } else { - dstRowStride = mml->width * texelBytes; - } + + dstRowStride = (*texImage->TexFormat->RowStride)(texImage->TexFormat, + mml->width); if (mml->wScale != 1 || mml->hScale != 1) { /* need to rescale subimage to match mipmap level's rescale factors */ @@ -1645,7 +1646,11 @@ /* choose the texture format */ assert(ctx->Driver.ChooseTextureFormat); texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx, - internalFormat, -1/*format*/, -1/*type*/); + &internalFormat, -1/*format*/, -1/*type*/); + /* The internal format must not be a generic compressed format. + * The driver must not change the internal format. + */ + assert(internalFormat == texImage->IntFormat); assert(texImage->TexFormat); /* Determine the appropriate Glide texel format, @@ -1655,14 +1660,15 @@ ti->info.format = mml->glideFormat; texImage->FetchTexelc = fxFetchFunction(texImage->TexFormat->MesaFormat); + texImage->IsCompressed = (texImage->TexFormat->TexelBytes == 0); + texImage->ImageSize = + (*texImage->TexFormat->ImageSize)(texImage->TexFormat, + mml->width, mml->height, 1); + assert(texImage->IsCompressed); + /* allocate new storage for texture image, if needed */ if (!texImage->Data) { - texImage->CompressedSize = _mesa_compressed_texture_size(ctx, - mml->width, - mml->height, - 1, - internalFormat); - texImage->Data = MESA_PBUFFER_ALLOC(texImage->CompressedSize); + texImage->Data = MESA_PBUFFER_ALLOC(texImage->ImageSize); if (!texImage->Data) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2D"); return; @@ -1685,10 +1691,11 @@ * we replicate the data over the padded area. * For now, we take 2) + 3) but texelfetchers will be wrong! */ - GLuint srcRowStride = _mesa_compressed_row_stride(internalFormat, width); + GLuint srcRowStride = + (*texImage->TexFormat->RowStride)(texImage->TexFormat, width); - GLuint destRowStride = _mesa_compressed_row_stride(internalFormat, - mml->width); + GLuint destRowStride = + (*texImage->TexFormat->RowStride)(texImage->TexFormat, mml->width); _mesa_upscale_teximage2d(srcRowStride, (height+3) / 4, destRowStride, (mml->height+3) / 4, @@ -1696,7 +1703,7 @@ texImage->Data); ti->padded = GL_TRUE; } else { - MEMCPY(texImage->Data, data, texImage->CompressedSize); + MEMCPY(texImage->Data, data, texImage->ImageSize); } /* GL_SGIS_generate_mipmap */ @@ -1736,14 +1743,15 @@ mml = TDFX_TEXIMAGE_DATA(texImage); assert(mml); - srcRowStride = _mesa_compressed_row_stride(texImage->IntFormat, width); + srcRowStride = (*texImage->TexFormat->RowStride)(texImage->TexFormat, + width); - destRowStride = _mesa_compressed_row_stride(texImage->IntFormat, - mml->width); - dest = _mesa_compressed_image_address(xoffset, yoffset, 0, - texImage->IntFormat, - mml->width, - (GLubyte*) texImage->Data); + destRowStride = (*texImage->TexFormat->RowStride)(texImage->TexFormat, + mml->width); + dest = (*texImage->TexFormat->ImageAddr)(xoffset, yoffset, 0, + texImage->TexFormat, + mml->width, mml->height, + (GLubyte*) texImage->Data); rows = height / 4; /* [dBorca] hardcoded 4, but works for FXT1/DXTC */ @@ -1757,10 +1765,11 @@ * see fxDDCompressedTexImage2D for caveats */ if (mml->wScale != 1 || mml->hScale != 1) { - srcRowStride = _mesa_compressed_row_stride(texImage->IntFormat, texImage->Width); - - destRowStride = _mesa_compressed_row_stride(texImage->IntFormat, - mml->width); + srcRowStride = (*texImage->TexFormat->RowStride)(texImage->TexFormat, + texImage->Width); + + destRowStride = (*texImage->TexFormat->RowStride)(texImage->TexFormat, + mml->width); _mesa_upscale_teximage2d(srcRowStride, texImage->Height / 4, destRowStride, mml->height / 4, 1, texImage->Data, destRowStride, Index: src/mesa/drivers/dri/unichrome/via_tex.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/unichrome/via_tex.c,v retrieving revision 1.8 diff -u -r1.8 via_tex.c --- src/mesa/drivers/dri/unichrome/via_tex.c 22 Mar 2005 14:25:55 -0000 1.8 +++ src/mesa/drivers/dri/unichrome/via_tex.c 16 May 2005 23:13:59 -0000 @@ -48,19 +48,25 @@ #include "via_3d_reg.h" static const struct gl_texture_format * -viaChooseTexFormat( GLcontext *ctx, GLint internalFormat, +viaChooseTexFormat( GLcontext *ctx, GLint *internalFormat, GLenum format, GLenum type ) { struct via_context *vmesa = VIA_CONTEXT(ctx); const GLboolean do32bpt = ( vmesa->viaScreen->bitsPerPixel == 32 /* && vmesa->viaScreen->textureSize > 4*1024*1024 */ ); + const GLboolean haveSoftDXTn = ctx->Mesa_DXTn; - switch ( internalFormat ) { + switch ( *internalFormat ) { + case GL_COMPRESSED_RGBA: + if ( haveSoftDXTn ) { + *internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + return &_mesa_texformat_rgba_dxt5; + } + /* fall through */ case 4: case GL_RGBA: - case GL_COMPRESSED_RGBA: if ( format == GL_BGRA ) { if ( type == GL_UNSIGNED_INT_8_8_8_8_REV || type == GL_UNSIGNED_BYTE ) { @@ -80,9 +86,14 @@ } return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444; + case GL_COMPRESSED_RGB: + if ( haveSoftDXTn ) { + *internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; + return &_mesa_texformat_rgb_dxt1; + } + /* fall through */ case 3: case GL_RGB: - case GL_COMPRESSED_RGB: if ( format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5 ) { return &_mesa_texformat_rgb565; } @@ -190,7 +201,7 @@ default: fprintf(stderr, "unexpected texture format %s in %s\n", - _mesa_lookup_enum_by_nr(internalFormat), + _mesa_lookup_enum_by_nr(*internalFormat), __FUNCTION__); return NULL; } @@ -660,7 +671,7 @@ struct via_context *vmesa = VIA_CONTEXT(ctx); GLint postConvWidth = width; GLint postConvHeight = height; - GLint texelBytes, sizeInBytes; + GLint texelBytes; struct via_texture_object *viaObj = (struct via_texture_object *)texObj; struct via_texture_image *viaImage = (struct via_texture_image *)texImage; int heaps[3], nheaps, i; @@ -676,7 +687,7 @@ } /* choose the texture format */ - texImage->TexFormat = viaChooseTexFormat(ctx, internalFormat, + texImage->TexFormat = viaChooseTexFormat(ctx, &texImage->IntFormat, format, type); assert(texImage->TexFormat); @@ -691,22 +702,19 @@ } texelBytes = texImage->TexFormat->TexelBytes; - - /* Minimum pitch of 32 bytes */ - if (postConvWidth * texelBytes < 32) { + texImage->IsCompressed = (texImage->TexFormat->TexelBytes == 0); + if (!texImage->IsCompressed && postConvWidth * texelBytes < 32) { + /* Minimum pitch of 32 bytes */ postConvWidth = 32 / texelBytes; texImage->RowStride = postConvWidth; } + texImage->ImageSize = + (*texImage->TexFormat->ImageSize)(texImage->TexFormat, + postConvWidth, postConvHeight, 1); assert(texImage->RowStride == postConvWidth); viaImage->pitchLog2 = logbase2(postConvWidth * texelBytes); - /* allocate memory */ - if (texImage->IsCompressed) - sizeInBytes = texImage->CompressedSize; - else - sizeInBytes = postConvWidth * postConvHeight * texelBytes; - /* Attempt to allocate texture memory directly, otherwise use main * memory and this texture will always be a fallback. FIXME! @@ -741,7 +749,7 @@ if (VIA_DEBUG & DEBUG_TEXTURE) fprintf(stderr, "try %s (obj %s)\n", get_memtype_name(heaps[i]), get_memtype_name(viaObj->memType)); - viaImage->texMem = via_alloc_texture(vmesa, sizeInBytes, heaps[i]); + viaImage->texMem = via_alloc_texture(vmesa, texImage->ImageSize, heaps[i]); } if (!viaImage->texMem) { @@ -750,7 +758,7 @@ } if (VIA_DEBUG & DEBUG_TEXTURE) - fprintf(stderr, "upload %d bytes to %s\n", sizeInBytes, + fprintf(stderr, "upload %d bytes to %s\n", texImage->ImageSize, get_memtype_name(viaImage->texMem->memType)); viaImage->texMem->image = viaImage; @@ -782,7 +790,8 @@ GLint dstRowStride, dstImageStride = 0; GLboolean success; if (texImage->IsCompressed) { - dstRowStride = _mesa_compressed_row_stride(texImage->IntFormat,width); + dstRowStride = (*texImage->TexFormat->RowStride)(texImage->TexFormat, + width); } else { dstRowStride = postConvWidth * texImage->TexFormat->TexelBytes; Index: src/mesa/main/dd.h =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/main/dd.h,v retrieving revision 1.98 diff -u -r1.98 dd.h --- src/mesa/main/dd.h 4 May 2005 20:11:39 -0000 1.98 +++ src/mesa/main/dd.h 16 May 2005 23:13:59 -0000 @@ -185,7 +185,7 @@ * pointer to an appropriate gl_texture_format. */ const struct gl_texture_format *(*ChooseTextureFormat)( GLcontext *ctx, - GLint internalFormat, GLenum srcFormat, GLenum srcType ); + GLint *internalFormat, GLenum srcFormat, GLenum srcType ); /** * Called by glTexImage1D(). Index: src/mesa/main/mtypes.h =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/main/mtypes.h,v retrieving revision 1.211 diff -u -r1.211 mtypes.h --- src/mesa/main/mtypes.h 12 May 2005 10:28:43 -0000 1.211 +++ src/mesa/main/mtypes.h 16 May 2005 23:14:03 -0000 @@ -1172,6 +1172,33 @@ const struct gl_pixelstore_attrib *srcPacking); +/** + * TexImage size function. This computes the size of texture images + * in compressed and uncompressed formats. + */ +typedef GLuint (*ImageSizeFunc)( const struct gl_texture_format *texFormat, + GLuint width, GLuint height, GLuint depth ); + + +/** + * TexImage row-stride function. This computes the row stride of texture + * images in compressed and uncompressed formats. + * Note: This only makes sense for constant-ratio compression. + */ +typedef GLuint (*RowStrideFunc)( const struct gl_texture_format *texFormat, + GLuint width ); + + +/** + * TexImage pixel address function. This computes a texel address in + * a compressed or uncompressed image as closely as possible. + * Note: This only makes sense for constant-ratio compression. + */ +typedef GLubyte *(*ImageAddrFunc)( GLuint col, GLuint row, GLuint img, + const struct gl_texture_format *texFormat, + GLuint width, GLuint height, GLubyte *data ); + + /** * Texture format record @@ -1196,6 +1223,9 @@ GLubyte DepthBits; GLuint TexelBytes; /**< Bytes per texel, 0 if compressed format */ + ImageSizeFunc ImageSize; + RowStrideFunc RowStride; + ImageAddrFunc ImageAddr; StoreTexImageFunc StoreImage; @@ -1255,7 +1285,7 @@ FetchTexelFuncF FetchTexelf; /**< Float texel fetch function pointer */ GLboolean IsCompressed; /**< GL_ARB_texture_compression */ - GLuint CompressedSize; /**< GL_ARB_texture_compression */ + GLuint ImageSize; /**< GL_ARB_texture_compression */ /** * \name For device driver: Index: src/mesa/main/texcompress_fxt1.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/main/texcompress_fxt1.c,v retrieving revision 1.24 diff -u -r1.24 texcompress_fxt1.c --- src/mesa/main/texcompress_fxt1.c 7 May 2005 17:06:50 -0000 1.24 +++ src/mesa/main/texcompress_fxt1.c 16 May 2005 23:14:09 -0000 @@ -61,6 +61,51 @@ /** + * Called via TexFormat->ImageSize to compute the size of FXT1 images. + */ +static GLuint +image_size_fxt1( const struct gl_texture_format *texFormat, + GLuint width, GLuint height, GLuint depth ) +{ + (void) texFormat; + ASSERT(depth == 1); + /* Width rounded up to multiples of 8, height to multiples of 4 */ + width = (width + 7) & ~7; + height = (height + 3) & ~3; + /* 128 bits per 8x4 tile of RGB[A] texels */ + return width * height / 2; +} + +/** + * Called via TexFormat->RowStride to compute the row stride of FXT1 images. + */ +static GLuint +row_stride_fxt1( const struct gl_texture_format *texFormat, + GLuint width ) +{ + (void) texFormat; + /* 128 bits per 8x4 tile of RGB[A] texels */ + return ((width + 7) / 8) * 16; +} + +/** + * Called via TexFormat->ImageAddr to compute texel addresses in FXT1 images. + */ +static GLubyte * +image_addr_fxt1( GLuint col, GLuint row, GLuint img, + const struct gl_texture_format *texFormat, + GLuint width, GLuint height, GLubyte *data ) +{ + (void) texFormat; + (void) img; + (void) height; + /* We try to spot a "complete" subtexture "above" ROW, COL; + * this texture is given by appropriate rounding of WIDTH x ROW. + * Then we just add the amount left (usually on the left). */ + return data + 16 * (((width + 7) / 8) * (row / 4) + col / 8); +} + +/** * Called via TexFormat->StoreImage to store an RGB_FXT1 texture. */ static GLboolean @@ -102,9 +147,9 @@ srcType) / sizeof(GLchan); } - dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0, - GL_COMPRESSED_RGB_FXT1_3DFX, - texWidth, (GLubyte *) dstAddr); + dst = image_addr_fxt1(dstXoffset, dstYoffset, 0, dstFormat, + texWidth, 0 /* height doesn't matter for 2D addr */, + (GLubyte *) dstAddr); fxt1_encode(srcWidth, srcHeight, 3, pixels, srcRowStride, dst, dstRowStride); @@ -158,9 +203,9 @@ srcType) / sizeof(GLchan); } - dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0, - GL_COMPRESSED_RGBA_FXT1_3DFX, - texWidth, (GLubyte *) dstAddr); + dst = image_addr_fxt1(dstXoffset, dstYoffset, 0, dstFormat, + texWidth, 0 /* height doesn't matter for 2D addr */, + (GLubyte *) dstAddr); fxt1_encode(srcWidth, srcHeight, 4, pixels, srcRowStride, dst, dstRowStride); @@ -235,6 +280,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 0, /* TexelBytes */ + image_size_fxt1, /* ImageSizeFunc */ + row_stride_fxt1, /* RowStrideFunc */ + image_addr_fxt1, /* ImageAddrFunc */ texstore_rgb_fxt1, /* StoreTexImageFunc */ NULL, /*impossible*/ /* FetchTexel1D */ fetch_texel_2d_rgb_fxt1, /* FetchTexel2D */ @@ -257,6 +305,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 0, /* TexelBytes */ + image_size_fxt1, /* ImageSizeFunc */ + row_stride_fxt1, /* RowStrideFunc */ + image_addr_fxt1, /* ImageAddrFunc */ texstore_rgba_fxt1, /* StoreTexImageFunc */ NULL, /*impossible*/ /* FetchTexel1D */ fetch_texel_2d_rgba_fxt1, /* FetchTexel2D */ Index: src/mesa/main/texcompress_s3tc.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/main/texcompress_s3tc.c,v retrieving revision 1.7 diff -u -r1.7 texcompress_s3tc.c --- src/mesa/main/texcompress_s3tc.c 18 Oct 2004 07:54:09 -0000 1.7 +++ src/mesa/main/texcompress_s3tc.c 16 May 2005 23:14:10 -0000 @@ -126,6 +126,51 @@ } /** + * Called via TexFormat->ImageSize to compute the size of DXT1 images. + */ +static GLuint +image_size_dxt1( const struct gl_texture_format *texFormat, + GLuint width, GLuint height, GLuint depth ) +{ + (void) texFormat; + ASSERT(depth == 1); + /* Width and height rounded up to multiples of 4 */ + width = (width + 3) & ~3; + height = (height + 3) & ~3; + /* 64 bits per 4x4 tile of RGB[A] texels */ + return width * height / 2; +} + +/** + * Called via TexFormat->RowStride to compute the row stride of DXT1 images. + */ +static GLuint +row_stride_dxt1( const struct gl_texture_format *texFormat, + GLuint width ) +{ + (void) texFormat; + /* 64 bits per 4x4 tile of RGB[A] texels */ + return ((width + 3) / 4) * 8; +} + +/** + * Called via TexFormat->ImageAddr to compute texel addresses in DXT1 images. + */ +static GLubyte * +image_addr_dxt1( GLuint col, GLuint row, GLuint img, + const struct gl_texture_format *texFormat, + GLuint width, GLuint height, GLubyte *data ) +{ + (void) texFormat; + (void) img; + (void) height; + /* We try to spot a "complete" subtexture "above" ROW, COL; + * this texture is given by appropriate rounding of WIDTH x ROW. + * Then we just add the amount left (usually on the left). */ + return data + 8 * (((width + 3) / 4) * (row / 4) + col / 4); +} + +/** * Called via TexFormat->StoreImage to store an RGB_DXT1 texture. */ static GLboolean @@ -167,9 +212,9 @@ srcType) / sizeof(GLchan); } - dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0, - GL_COMPRESSED_RGB_S3TC_DXT1_EXT, - texWidth, (GLubyte *) dstAddr); + dst = image_addr_dxt1(dstXoffset, dstYoffset, 0, dstFormat, + texWidth, 0 /* height doesn't matter for 2D addr */, + (GLubyte *) dstAddr); if (ext_tx_compress_dxtn) { (*ext_tx_compress_dxtn)(3, srcWidth, srcHeight, pixels, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, dst, dstRowStride); @@ -227,9 +272,9 @@ srcType) / sizeof(GLchan); } - dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0, - GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, - texWidth, (GLubyte *) dstAddr); + dst = image_addr_dxt1(dstXoffset, dstYoffset, 0, dstFormat, + texWidth, 0 /* height doesn't matter for 2D addr */, + (GLubyte *) dstAddr); if (ext_tx_compress_dxtn) { (*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, dst, dstRowStride); } @@ -245,6 +290,51 @@ /** + * Called via TexFormat->ImageSize to compute the size of DXT3/5 images. + */ +static GLuint +image_size_dxt3( const struct gl_texture_format *texFormat, + GLuint width, GLuint height, GLuint depth ) +{ + (void) texFormat; + ASSERT(depth == 1); + /* Width and height rounded up to multiples of 4 */ + width = (width + 3) & ~3; + height = (height + 3) & ~3; + /* 128 bits per 4x4 tile of RGB[A] texels */ + return width * height; +} + +/** + * Called via TexFormat->RowStride to compute the row stride of DXT3/5 images. + */ +static GLuint +row_stride_dxt3( const struct gl_texture_format *texFormat, + GLuint width ) +{ + (void) texFormat; + /* 128 bits per 4x4 tile of RGB[A] texels */ + return ((width + 3) / 4) * 16; +} + +/** + * Called via TexFormat->ImageAddr to compute texel addresses in DXT3/5 images. + */ +static GLubyte * +image_addr_dxt3( GLuint col, GLuint row, GLuint img, + const struct gl_texture_format *texFormat, + GLuint width, GLuint height, GLubyte *data ) +{ + (void) texFormat; + (void) img; + (void) height; + /* We try to spot a "complete" subtexture "above" ROW, COL; + * this texture is given by appropriate rounding of WIDTH x ROW. + * Then we just add the amount left (usually on the left). */ + return data + 16 * (((width + 3) / 4) * (row / 4) + col / 4); +} + +/** * Called via TexFormat->StoreImage to store an RGBA_DXT3 texture. */ static GLboolean @@ -285,9 +375,9 @@ srcType) / sizeof(GLchan); } - dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0, - GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, - texWidth, (GLubyte *) dstAddr); + dst = image_addr_dxt3(dstXoffset, dstYoffset, 0, dstFormat, + texWidth, 0 /* height doesn't matter for 2D addr */, + (GLubyte *) dstAddr); if (ext_tx_compress_dxtn) { (*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, dst, dstRowStride); } @@ -343,9 +433,9 @@ srcType) / sizeof(GLchan); } - dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0, - GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, - texWidth, (GLubyte *) dstAddr); + dst = image_addr_dxt3(dstXoffset, dstYoffset, 0, dstFormat, + texWidth, 0 /* height doesn't matter for 2D addr */, + (GLubyte *) dstAddr); if (ext_tx_compress_dxtn) { (*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, dst, dstRowStride); } @@ -479,6 +569,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 0, /* TexelBytes */ + image_size_dxt1, /* ImageSizeFunc */ + row_stride_dxt1, /* RowStrideFunc */ + image_addr_dxt1, /* ImageAddrFunc */ texstore_rgb_dxt1, /* StoreTexImageFunc */ NULL, /*impossible*/ /* FetchTexel1D */ fetch_texel_2d_rgb_dxt1, /* FetchTexel2D */ @@ -501,6 +594,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 0, /* TexelBytes */ + image_size_dxt1, /* ImageSizeFunc */ + row_stride_dxt1, /* RowStrideFunc */ + image_addr_dxt1, /* ImageAddrFunc */ texstore_rgba_dxt1, /* StoreTexImageFunc */ NULL, /*impossible*/ /* FetchTexel1D */ fetch_texel_2d_rgba_dxt1, /* FetchTexel2D */ @@ -523,6 +619,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 0, /* TexelBytes */ + image_size_dxt3, /* ImageSizeFunc */ + row_stride_dxt3, /* RowStrideFunc */ + image_addr_dxt3, /* ImageAddrFunc */ texstore_rgba_dxt3, /* StoreTexImageFunc */ NULL, /*impossible*/ /* FetchTexel1D */ fetch_texel_2d_rgba_dxt3, /* FetchTexel2D */ @@ -545,6 +644,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 0, /* TexelBytes */ + image_size_dxt3,/*same as DXT3*/ /* ImageSizeFunc */ + row_stride_dxt3,/*same as DXT3*/ /* RowStrideFunc */ + image_addr_dxt3,/*same as DXT3*/ /* ImageAddrFunc */ texstore_rgba_dxt5, /* StoreTexImageFunc */ NULL, /*impossible*/ /* FetchTexel1D */ fetch_texel_2d_rgba_dxt5, /* FetchTexel2D */ Index: src/mesa/main/texformat.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/main/texformat.c,v retrieving revision 1.35 diff -u -r1.35 texformat.c --- src/mesa/main/texformat.c 4 May 2005 20:11:40 -0000 1.35 +++ src/mesa/main/texformat.c 16 May 2005 23:14:10 -0000 @@ -56,6 +56,40 @@ #include "texformat_tmp.h" /** + * Default ImageSizeFunc for uncompressed texture formats + */ +static GLuint image_size( const struct gl_texture_format *texFormat, + GLuint width, GLuint height, GLuint depth ) +{ + ASSERT(texFormat->TexelBytes); + return width * height * depth * texFormat->TexelBytes; +} +/** + * Default RowStrideFunc for uncompressed texture formats + */ +static GLuint row_stride( const struct gl_texture_format *texFormat, + GLuint width ) +{ + ASSERT(texFormat->TexelBytes); + return width * texFormat->TexelBytes; +} +/** + * Default ImageAddrFunc for uncompressed texture formats + */ +static GLubyte *image_addr( GLuint col, GLuint row, GLuint img, + const struct gl_texture_format *texFormat, + GLuint width, GLuint height, GLubyte *data ) +{ + GLuint imgStride, rowStride, texelStride; + ASSERT(texFormat->TexelBytes); + texelStride = texFormat->TexelBytes; + rowStride = width * texelStride; + imgStride = height * rowStride; + return data + img*imgStride + row*rowStride + col*texelStride; +} + + +/** * Null texel fetch function. * * Have to have this so the FetchTexel function pointer is never NULL. @@ -107,6 +141,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 4 * sizeof(GLchan), /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_rgba, /* StoreTexImageFunc */ fetch_texel_1d_rgba, /* FetchTexel1D */ fetch_texel_2d_rgba, /* FetchTexel2D */ @@ -130,6 +167,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 3 * sizeof(GLchan), /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_rgba,/*yes*/ /* StoreTexImageFunc */ fetch_texel_1d_rgb, /* FetchTexel1D */ fetch_texel_2d_rgb, /* FetchTexel2D */ @@ -153,6 +193,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ sizeof(GLchan), /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_rgba,/*yes*/ /* StoreTexImageFunc */ fetch_texel_1d_alpha, /* FetchTexel1D */ fetch_texel_2d_alpha, /* FetchTexel2D */ @@ -176,6 +219,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ sizeof(GLchan), /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_rgba,/*yes*/ /* StoreTexImageFunc */ fetch_texel_1d_luminance, /* FetchTexel1D */ fetch_texel_2d_luminance, /* FetchTexel2D */ @@ -199,6 +245,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 2 * sizeof(GLchan), /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_rgba,/*yes*/ /* StoreTexImageFunc */ fetch_texel_1d_luminance_alpha, /* FetchTexel1D */ fetch_texel_2d_luminance_alpha, /* FetchTexel2D */ @@ -222,6 +271,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ sizeof(GLchan), /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_rgba,/*yes*/ /* StoreTexImageFunc */ fetch_texel_1d_intensity, /* FetchTexel1D */ fetch_texel_2d_intensity, /* FetchTexel2D */ @@ -245,6 +297,9 @@ 0, /* IndexBits */ sizeof(GLfloat) * 8, /* DepthBits */ sizeof(GLfloat), /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_depth_component_float32,/* StoreTexImageFunc */ fetch_null_texel, /* FetchTexel1D */ fetch_null_texel, /* FetchTexel1D */ @@ -268,6 +323,9 @@ 0, /* IndexBits */ sizeof(GLushort) * 8, /* DepthBits */ sizeof(GLushort), /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_depth_component16, /* StoreTexImageFunc */ fetch_null_texel, /* FetchTexel1D */ fetch_null_texel, /* FetchTexel1D */ @@ -291,6 +349,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 4 * sizeof(GLfloat), /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_rgba_float32, /* StoreTexImageFunc */ fetch_texel_1d_rgba_f32, /* FetchTexel1D */ fetch_texel_2d_rgba_f32, /* FetchTexel1D */ @@ -314,6 +375,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 4 * sizeof(GLhalfARB), /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_rgba_float16, /* StoreTexImageFunc */ fetch_texel_1d_rgba_f16, /* FetchTexel1D */ fetch_texel_2d_rgba_f16, /* FetchTexel1D */ @@ -337,6 +401,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 3 * sizeof(GLfloat), /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_rgba_float32,/*yes*/ /* StoreTexImageFunc */ fetch_texel_1d_rgb_f32, /* FetchTexel1D */ fetch_texel_2d_rgb_f32, /* FetchTexel1D */ @@ -360,6 +427,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 3 * sizeof(GLhalfARB), /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_rgba_float16,/*yes*/ /* StoreTexImageFunc */ fetch_texel_1d_rgb_f16, /* FetchTexel1D */ fetch_texel_2d_rgb_f16, /* FetchTexel1D */ @@ -383,6 +453,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 1 * sizeof(GLfloat), /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_rgba_float32,/*yes*/ /* StoreTexImageFunc */ fetch_texel_1d_alpha_f32, /* FetchTexel1D */ fetch_texel_2d_alpha_f32, /* FetchTexel1D */ @@ -406,6 +479,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 1 * sizeof(GLhalfARB), /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_rgba_float16,/*yes*/ /* StoreTexImageFunc */ fetch_texel_1d_alpha_f16, /* FetchTexel1D */ fetch_texel_2d_alpha_f16, /* FetchTexel1D */ @@ -429,6 +505,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 1 * sizeof(GLfloat), /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_rgba_float32,/*yes*/ /* StoreTexImageFunc */ fetch_texel_1d_luminance_f32, /* FetchTexel1D */ fetch_texel_2d_luminance_f32, /* FetchTexel2D */ @@ -452,6 +531,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 1 * sizeof(GLhalfARB), /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_rgba_float16,/*yes*/ /* StoreTexImageFunc */ fetch_texel_1d_luminance_f16, /* FetchTexel1D */ fetch_texel_2d_luminance_f16, /* FetchTexel2D */ @@ -475,6 +557,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 2 * sizeof(GLfloat), /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_rgba_float32, /* StoreTexImageFunc */ fetch_texel_1d_luminance_alpha_f32, /* FetchTexel1D */ fetch_texel_2d_luminance_alpha_f32, /* FetchTexel2D */ @@ -498,6 +583,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 2 * sizeof(GLhalfARB), /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_rgba_float16, /* StoreTexImageFunc */ fetch_texel_1d_luminance_alpha_f16, /* FetchTexel1D */ fetch_texel_2d_luminance_alpha_f16, /* FetchTexel2D */ @@ -521,6 +609,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 1 * sizeof(GLfloat), /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_rgba_float32,/*yes*/ /* StoreTexImageFunc */ fetch_texel_1d_intensity_f32, /* FetchTexel1D */ fetch_texel_2d_intensity_f32, /* FetchTexel2D */ @@ -544,6 +635,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 1 * sizeof(GLhalfARB), /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_rgba_float16,/*yes*/ /* StoreTexImageFunc */ fetch_texel_1d_intensity_f16, /* FetchTexel1D */ fetch_texel_2d_intensity_f16, /* FetchTexel2D */ @@ -575,6 +669,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 4, /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_rgba8888, /* StoreTexImageFunc */ fetch_texel_1d_rgba8888, /* FetchTexel1D */ fetch_texel_2d_rgba8888, /* FetchTexel2D */ @@ -598,6 +695,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 4, /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_rgba8888, /* StoreTexImageFunc */ fetch_texel_1d_rgba8888_rev, /* FetchTexel1D */ fetch_texel_2d_rgba8888_rev, /* FetchTexel2D */ @@ -621,6 +721,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 4, /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_argb8888, /* StoreTexImageFunc */ fetch_texel_1d_argb8888, /* FetchTexel1D */ fetch_texel_2d_argb8888, /* FetchTexel2D */ @@ -644,6 +747,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 4, /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_argb8888, /* StoreTexImageFunc */ fetch_texel_1d_argb8888_rev, /* FetchTexel1D */ fetch_texel_2d_argb8888_rev, /* FetchTexel2D */ @@ -667,6 +773,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 3, /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_rgb888, /* StoreTexImageFunc */ fetch_texel_1d_rgb888, /* FetchTexel1D */ fetch_texel_2d_rgb888, /* FetchTexel2D */ @@ -690,6 +799,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 3, /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_bgr888, /* StoreTexImageFunc */ fetch_texel_1d_bgr888, /* FetchTexel1D */ fetch_texel_2d_bgr888, /* FetchTexel2D */ @@ -713,6 +825,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 2, /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_rgb565, /* StoreTexImageFunc */ fetch_texel_1d_rgb565, /* FetchTexel1D */ fetch_texel_2d_rgb565, /* FetchTexel2D */ @@ -736,6 +851,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 2, /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_rgb565, /* StoreTexImageFunc */ fetch_texel_1d_rgb565_rev, /* FetchTexel1D */ fetch_texel_2d_rgb565_rev, /* FetchTexel2D */ @@ -759,6 +877,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 2, /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_argb4444, /* StoreTexImageFunc */ fetch_texel_1d_argb4444, /* FetchTexel1D */ fetch_texel_2d_argb4444, /* FetchTexel2D */ @@ -782,6 +903,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 2, /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_argb4444, /* StoreTexImageFunc */ fetch_texel_1d_argb4444_rev, /* FetchTexel1D */ fetch_texel_2d_argb4444_rev, /* FetchTexel2D */ @@ -805,6 +929,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 2, /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_argb1555, /* StoreTexImageFunc */ fetch_texel_1d_argb1555, /* FetchTexel1D */ fetch_texel_2d_argb1555, /* FetchTexel2D */ @@ -828,6 +955,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 2, /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_argb1555, /* StoreTexImageFunc */ fetch_texel_1d_argb1555_rev, /* FetchTexel1D */ fetch_texel_2d_argb1555_rev, /* FetchTexel2D */ @@ -851,6 +981,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 2, /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_al88, /* StoreTexImageFunc */ fetch_texel_1d_al88, /* FetchTexel1D */ fetch_texel_2d_al88, /* FetchTexel2D */ @@ -874,6 +1007,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 2, /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_al88, /* StoreTexImageFunc */ fetch_texel_1d_al88_rev, /* FetchTexel1D */ fetch_texel_2d_al88_rev, /* FetchTexel2D */ @@ -897,6 +1033,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 1, /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_rgb332, /* StoreTexImageFunc */ fetch_texel_1d_rgb332, /* FetchTexel1D */ fetch_texel_2d_rgb332, /* FetchTexel2D */ @@ -920,6 +1059,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 1, /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_a8, /* StoreTexImageFunc */ fetch_texel_1d_a8, /* FetchTexel1D */ fetch_texel_2d_a8, /* FetchTexel2D */ @@ -943,6 +1085,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 1, /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_a8,/*yes*/ /* StoreTexImageFunc */ fetch_texel_1d_l8, /* FetchTexel1D */ fetch_texel_2d_l8, /* FetchTexel2D */ @@ -966,6 +1111,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 1, /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_a8,/*yes*/ /* StoreTexImageFunc */ fetch_texel_1d_i8, /* FetchTexel1D */ fetch_texel_2d_i8, /* FetchTexel2D */ @@ -989,6 +1137,9 @@ 8, /* IndexBits */ 0, /* DepthBits */ 1, /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_ci8, /* StoreTexImageFunc */ fetch_texel_1d_ci8, /* FetchTexel1D */ fetch_texel_2d_ci8, /* FetchTexel2D */ @@ -1012,6 +1163,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 2, /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_ycbcr, /* StoreTexImageFunc */ fetch_texel_1d_ycbcr, /* FetchTexel1D */ fetch_texel_2d_ycbcr, /* FetchTexel2D */ @@ -1035,6 +1189,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 2, /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ _mesa_texstore_ycbcr, /* StoreTexImageFunc */ fetch_texel_1d_ycbcr_rev, /* FetchTexel1D */ fetch_texel_2d_ycbcr_rev, /* FetchTexel2D */ @@ -1065,6 +1222,9 @@ 0, /* IndexBits */ 0, /* DepthBits */ 0, /* TexelBytes */ + image_size, /* ImageSizeFunc */ + row_stride, /* RowStrideFunc */ + image_addr, /* ImageAddrFunc */ NULL, /* StoreTexImageFunc */ fetch_null_texel, /* FetchTexel1D */ fetch_null_texel, /* FetchTexel2D */ Index: src/mesa/main/teximage.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/main/teximage.c,v retrieving revision 1.167 diff -u -r1.167 teximage.c --- src/mesa/main/teximage.c 22 Mar 2005 14:27:10 -0000 1.167 +++ src/mesa/main/teximage.c 16 May 2005 23:14:14 -0000 @@ -1002,7 +1002,7 @@ img->FetchTexelc = NULL; img->FetchTexelf = NULL; img->IsCompressed = 0; - img->CompressedSize = 0; + img->ImageSize = 0; } @@ -1049,12 +1049,14 @@ img->Height2 = height - 2 * border; /*1 << img->HeightLog2;*/ img->Depth2 = depth - 2 * border; /*1 << img->DepthLog2;*/ img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2); +/* img->IsCompressed = is_compressed_format(ctx, internalFormat); if (img->IsCompressed) img->CompressedSize = ctx->Driver.CompressedTextureSize(ctx, width, height, depth, internalFormat); else img->CompressedSize = 0; +*/ if ((width == 1 || _mesa_bitcount(width - 2 * border) == 1) && (height == 1 || _mesa_bitcount(height - 2 * border) == 1) && @@ -2092,7 +2094,11 @@ postConvWidth, 1, 1, border, internalFormat); texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx, - internalFormat, format, type); + &texImage->IntFormat, format, type); + texImage->IsCompressed = (texImage->TexFormat->TexelBytes == 0); + texImage->ImageSize = + (*texImage->TexFormat->ImageSize)(texImage->TexFormat, + postConvWidth, 1, 1); } } else { @@ -2195,7 +2201,11 @@ postConvWidth, postConvHeight, 1, border, internalFormat); texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx, - internalFormat, format, type); + &texImage->IntFormat, format, type); + texImage->IsCompressed = (texImage->TexFormat->TexelBytes == 0); + texImage->ImageSize = + (*texImage->TexFormat->ImageSize)(texImage->TexFormat, + postConvWidth, postConvHeight, 1); } } else { @@ -2281,10 +2291,15 @@ } else { /* no error, set the tex image parameters */ - _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1, + _mesa_init_teximage_fields(ctx, target, texImage, + width, height, depth, border, internalFormat); texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx, - internalFormat, format, type); + &texImage->IntFormat, format, type); + texImage->IsCompressed = (texImage->TexFormat->TexelBytes == 0); + texImage->ImageSize = + (*texImage->TexFormat->ImageSize)(texImage->TexFormat, + width, height, depth); } } else { Index: src/mesa/main/texstate.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/main/texstate.c,v retrieving revision 1.118 diff -u -r1.118 texstate.c --- src/mesa/main/texstate.c 8 Feb 2005 14:44:01 -0000 1.118 +++ src/mesa/main/texstate.c 16 May 2005 23:14:20 -0000 @@ -1764,7 +1764,7 @@ case GL_TEXTURE_COMPRESSED_IMAGE_SIZE: if (ctx->Extensions.ARB_texture_compression) { if (img->IsCompressed && !isProxy) - *params = img->CompressedSize; + *params = img->ImageSize; else _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexLevelParameter[if]v(pname)"); Index: src/mesa/main/texstore.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/main/texstore.c,v retrieving revision 1.95 diff -u -r1.95 texstore.c --- src/mesa/main/texstore.c 16 May 2005 23:01:09 -0000 1.95 +++ src/mesa/main/texstore.c 16 May 2005 23:14:24 -0000 @@ -2186,7 +2186,6 @@ struct gl_texture_image *texImage) { GLint postConvWidth = width; - GLint sizeInBytes; (void) border; if (ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) { @@ -2195,18 +2194,19 @@ /* choose the texture format */ assert(ctx->Driver.ChooseTextureFormat); - texImage->TexFormat = ctx->Driver.ChooseTextureFormat(ctx, internalFormat, - format, type); + texImage->TexFormat = + ctx->Driver.ChooseTextureFormat(ctx, &texImage->IntFormat, + format, type); assert(texImage->TexFormat); texImage->FetchTexelc = texImage->TexFormat->FetchTexel1D; texImage->FetchTexelf = texImage->TexFormat->FetchTexel1Df; + texImage->IsCompressed = (texImage->TexFormat->TexelBytes == 0); + texImage->ImageSize = + (*texImage->TexFormat->ImageSize)(texImage->TexFormat, + postConvWidth, 1, 1); /* allocate memory */ - if (texImage->IsCompressed) - sizeInBytes = texImage->CompressedSize; - else - sizeInBytes = postConvWidth * texImage->TexFormat->TexelBytes; - texImage->Data = MESA_PBUFFER_ALLOC(sizeInBytes); + texImage->Data = MESA_PBUFFER_ALLOC(texImage->ImageSize); if (!texImage->Data) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D"); return; @@ -2271,7 +2271,7 @@ struct gl_texture_image *texImage) { GLint postConvWidth = width, postConvHeight = height; - GLint texelBytes, sizeInBytes; + GLint texelBytes; (void) border; if (ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) { @@ -2281,20 +2281,21 @@ /* choose the texture format */ assert(ctx->Driver.ChooseTextureFormat); - texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx, - internalFormat, format, type); + texImage->TexFormat = + (*ctx->Driver.ChooseTextureFormat)(ctx, &texImage->IntFormat, + format, type); assert(texImage->TexFormat); texImage->FetchTexelc = texImage->TexFormat->FetchTexel2D; texImage->FetchTexelf = texImage->TexFormat->FetchTexel2Df; + texImage->IsCompressed = (texImage->TexFormat->TexelBytes == 0); + texImage->ImageSize = + (*texImage->TexFormat->ImageSize)(texImage->TexFormat, + postConvWidth, postConvHeight, 1); texelBytes = texImage->TexFormat->TexelBytes; /* allocate memory */ - if (texImage->IsCompressed) - sizeInBytes = texImage->CompressedSize; - else - sizeInBytes = postConvWidth * postConvHeight * texelBytes; - texImage->Data = MESA_PBUFFER_ALLOC(sizeInBytes); + texImage->Data = MESA_PBUFFER_ALLOC(texImage->ImageSize); if (!texImage->Data) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); return; @@ -2311,12 +2312,8 @@ else { GLint dstRowStride, dstImageStride = 0; GLboolean success; - if (texImage->IsCompressed) { - dstRowStride = _mesa_compressed_row_stride(texImage->IntFormat,width); - } - else { - dstRowStride = postConvWidth * texImage->TexFormat->TexelBytes; - } + dstRowStride = (*texImage->TexFormat->RowStride)(texImage->TexFormat, + postConvWidth); ASSERT(texImage->TexFormat->StoreImage); success = texImage->TexFormat->StoreImage(ctx, 2, texImage->Format, texImage->TexFormat, @@ -2356,25 +2353,26 @@ struct gl_texture_object *texObj, struct gl_texture_image *texImage) { - GLint texelBytes, sizeInBytes; + GLint texelBytes; (void) border; /* choose the texture format */ assert(ctx->Driver.ChooseTextureFormat); - texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx, - internalFormat, format, type); + texImage->TexFormat = + (*ctx->Driver.ChooseTextureFormat)(ctx, &texImage->IntFormat, + format, type); assert(texImage->TexFormat); texImage->FetchTexelc = texImage->TexFormat->FetchTexel3D; texImage->FetchTexelf = texImage->TexFormat->FetchTexel3Df; + texImage->IsCompressed = (texImage->TexFormat->TexelBytes == 0); + texImage->ImageSize = + (*texImage->TexFormat->ImageSize)(texImage->TexFormat, + width, height, depth); texelBytes = texImage->TexFormat->TexelBytes; /* allocate memory */ - if (texImage->IsCompressed) - sizeInBytes = texImage->CompressedSize; - else - sizeInBytes = width * height * depth * texelBytes; - texImage->Data = MESA_PBUFFER_ALLOC(sizeInBytes); + texImage->Data = MESA_PBUFFER_ALLOC(texImage->ImageSize); if (!texImage->Data) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D"); return; @@ -2391,12 +2389,12 @@ else { GLint dstRowStride, dstImageStride; GLboolean success; + dstRowStride = (*texImage->TexFormat->RowStride)(texImage->TexFormat, + width); if (texImage->IsCompressed) { - dstRowStride = _mesa_compressed_row_stride(texImage->IntFormat,width); dstImageStride = 0; } else { - dstRowStride = width * texImage->TexFormat->TexelBytes; dstImageStride = dstRowStride * height; } ASSERT(texImage->TexFormat->StoreImage); @@ -2491,13 +2489,8 @@ { GLint dstRowStride = 0, dstImageStride = 0; GLboolean success; - if (texImage->IsCompressed) { - dstRowStride = _mesa_compressed_row_stride(texImage->IntFormat, - texImage->Width); - } - else { - dstRowStride = texImage->Width * texImage->TexFormat->TexelBytes; - } + dstRowStride = (*texImage->TexFormat->RowStride)(texImage->TexFormat, + texImage->Width); ASSERT(texImage->TexFormat->StoreImage); success = texImage->TexFormat->StoreImage(ctx, 2, texImage->Format, texImage->TexFormat, @@ -2544,13 +2537,12 @@ { GLint dstRowStride, dstImageStride; GLboolean success; + dstRowStride = (*texImage->TexFormat->RowStride)(texImage->TexFormat, + texImage->Width); if (texImage->IsCompressed) { - dstRowStride = _mesa_compressed_row_stride(texImage->IntFormat, - texImage->Width); dstImageStride = 0; /* XXX fix */ } else { - dstRowStride = texImage->Width * texImage->TexFormat->TexelBytes; dstImageStride = dstRowStride * texImage->Height; } ASSERT(texImage->TexFormat->StoreImage); @@ -2626,10 +2618,19 @@ /* choose the texture format */ assert(ctx->Driver.ChooseTextureFormat); texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx, - internalFormat, 0, 0); + &internalFormat, 0, 0); + /* The internal format must not be a generic compressed format. + * (Should this be checked in _mesa_CompressedTexImage2DARB?) + * The driver must not change the internal format. + */ + assert(internalFormat == texImage->IntFormat); assert(texImage->TexFormat); texImage->FetchTexelc = texImage->TexFormat->FetchTexel2D; texImage->FetchTexelf = texImage->TexFormat->FetchTexel2Df; + texImage->IsCompressed = (texImage->TexFormat->TexelBytes == 0); + texImage->ImageSize = + (*texImage->TexFormat->ImageSize)(texImage->TexFormat, + width, height, 1); /* allocate storage */ texImage->Data = MESA_PBUFFER_ALLOC(imageSize); @@ -2645,7 +2646,7 @@ return; /* copy the data */ - ASSERT(texImage->CompressedSize == (GLuint) imageSize); + ASSERT(texImage->ImageSize == (GLuint) imageSize); MEMCPY(texImage->Data, data, imageSize); /* GL_SGIS_generate_mipmap */ @@ -2739,15 +2740,16 @@ if (!data) return; - srcRowStride = _mesa_compressed_row_stride(texImage->IntFormat, width); + srcRowStride = (*texImage->TexFormat->RowStride)(texImage->TexFormat, + width); src = (const GLubyte *) data; - destRowStride = _mesa_compressed_row_stride(texImage->IntFormat, - texImage->Width); - dest = _mesa_compressed_image_address(xoffset, yoffset, 0, - texImage->IntFormat, - texImage->Width, - (GLubyte*) texImage->Data); + destRowStride = (*texImage->TexFormat->RowStride)(texImage->TexFormat, + texImage->Width); + dest = (*texImage->TexFormat->ImageAddr)(xoffset, yoffset, 0, + texImage->TexFormat, + texImage->Width, texImage->Height, + (GLubyte*) texImage->Data); bytesPerRow = srcRowStride; rows = height / 4; @@ -3690,8 +3692,8 @@ * Setup src and dest data pointers. */ if (dstImage->IsCompressed) { - ASSERT(dstImage->CompressedSize > 0); /* set by init_teximage_fields*/ - dstImage->Data = MESA_PBUFFER_ALLOC(dstImage->CompressedSize); + ASSERT(dstImage->ImageSize > 0); /* set by init_teximage_fields*/ + dstImage->Data = MESA_PBUFFER_ALLOC(dstImage->ImageSize); if (!dstImage->Data) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "generating mipmaps"); return; @@ -3750,8 +3752,8 @@ GLubyte *temp; /* compress image from dstData into dstImage->Data */ const GLenum srcFormat = convertFormat->BaseFormat; - GLint dstRowStride = _mesa_compressed_row_stride(srcImage->IntFormat, - dstWidth); + GLint dstRowStride = (*dstImage->TexFormat->RowStride)( + dstImage->TexFormat, dstWidth) ASSERT(srcFormat == GL_RGB || srcFormat == GL_RGBA); dstImage->TexFormat->StoreImage(ctx, 2, dstImage->Format, dstImage->TexFormat, @@ -4022,7 +4024,7 @@ if (ctx->Pack.BufferObj->Name) { /* pack texture image into a PBO */ GLubyte *buf; - if ((const GLubyte *) img + texImage->CompressedSize > + if ((const GLubyte *) img + texImage->ImageSize > (const GLubyte *) ctx->Pack.BufferObj->Size) { _mesa_error(ctx, GL_INVALID_OPERATION, "glGetCompressedTexImage(invalid PBO access)"); @@ -4045,7 +4047,7 @@ } /* just memcpy, no pixelstore or pixel transfer */ - MEMCPY(img, texImage->Data, texImage->CompressedSize); + MEMCPY(img, texImage->Data, texImage->ImageSize); if (ctx->Pack.BufferObj->Name) { ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,