diff options
author | Daniel Borca <[email protected]> | 2003-11-21 09:56:50 +0000 |
---|---|---|
committer | Daniel Borca <[email protected]> | 2003-11-21 09:56:50 +0000 |
commit | 663a9e1b7ef7b8384abe2f81e1a8749b942f6d3a (patch) | |
tree | b106ee1b0d50acc49060d11e3b5a578f22df1575 | |
parent | 8b07e9d8a4342ec2a24fec37932398189ef80eb5 (diff) |
more texture compression
-rw-r--r-- | src/mesa/drivers/glide/fxdd.c | 2 | ||||
-rw-r--r-- | src/mesa/drivers/glide/fxddtex.c | 23 | ||||
-rw-r--r-- | src/mesa/main/extensions.c | 1 | ||||
-rw-r--r-- | src/mesa/main/mtypes.h | 1 | ||||
-rw-r--r-- | src/mesa/main/texcompress.c | 65 | ||||
-rw-r--r-- | src/mesa/main/texformat.c | 18 | ||||
-rw-r--r-- | src/mesa/main/teximage.c | 16 |
7 files changed, 100 insertions, 26 deletions
diff --git a/src/mesa/drivers/glide/fxdd.c b/src/mesa/drivers/glide/fxdd.c index f4090122f5a..61d530cd785 100644 --- a/src/mesa/drivers/glide/fxdd.c +++ b/src/mesa/drivers/glide/fxdd.c @@ -1458,7 +1458,7 @@ fxDDInitExtensions(GLcontext * ctx) if (fxMesa->type >= GR_SSTTYPE_Voodoo4) { _mesa_enable_extension(ctx, "GL_3DFX_texture_compression_FXT1"); _mesa_enable_extension(ctx, "GL_EXT_texture_compression_s3tc"); - /*_mesa_enable_extension(ctx, "GL_S3_s3tc");*/ + _mesa_enable_extension(ctx, "GL_S3_s3tc"); } if (fxMesa->HaveCmbExt) { diff --git a/src/mesa/drivers/glide/fxddtex.c b/src/mesa/drivers/glide/fxddtex.c index b84f8d4a9dc..da1e73d029c 100644 --- a/src/mesa/drivers/glide/fxddtex.c +++ b/src/mesa/drivers/glide/fxddtex.c @@ -832,7 +832,11 @@ GLboolean fxDDIsCompressedFormat ( GLcontext *ctx, GLenum internalFormat ) (internalFormat == GL_COMPRESSED_RGB_S3TC_DXT1_EXT) || (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) || (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT3_EXT) || - (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)) { + (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT) || + (internalFormat == GL_RGB_S3TC) || + (internalFormat == GL_RGB4_S3TC) || + (internalFormat == GL_RGBA_S3TC) || + (internalFormat == GL_RGBA4_S3TC)) { return GL_TRUE; } @@ -876,8 +880,11 @@ GLuint fxDDCompressedTextureSize (GLcontext *ctx, switch (format) { case GL_COMPRESSED_RGB_FXT1_3DFX: case GL_COMPRESSED_RGBA_FXT1_3DFX: - /* round up to multiples of 8, 4 */ - size = ((width + 7) / 8) * ((height + 3) / 4) * 16; + /* round up width to next multiple of 8, height to next multiple of 4 */ + width = (width + 7) & ~7; + height = (height + 3) & ~3; + /* 16 bytes per 8x4 tile of RGB[A] texels */ + size = width * height / 2; /* Textures smaller than 8x4 will effectively be made into 8x4 and * take 16 bytes. */ @@ -886,11 +893,13 @@ GLuint fxDDCompressedTextureSize (GLcontext *ctx, return size; case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + case GL_RGB_S3TC: + case GL_RGB4_S3TC: /* round up width, height to next multiple of 4 */ width = (width + 3) & ~3; height = (height + 3) & ~3; /* 8 bytes per 4x4 tile of RGB[A] texels */ - size = (width * height * 8) / 16; + size = width * height / 2; /* Textures smaller than 4x4 will effectively be made into 4x4 and * take 8 bytes. */ @@ -899,6 +908,8 @@ GLuint fxDDCompressedTextureSize (GLcontext *ctx, return size; case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + case GL_RGBA_S3TC: + case GL_RGBA4_S3TC: /* round up width, height to next multiple of 4 */ width = (width + 3) & ~3; height = (height + 3) & ~3; @@ -1053,10 +1064,14 @@ fxDDChooseTextureFormat( GLcontext *ctx, GLint internalFormat, return &_mesa_texformat_argb1555; /* GL_EXT_texture_compression_s3tc */ case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: + case GL_RGB_S3TC: + case GL_RGB4_S3TC: return &_mesa_texformat_rgb_dxt1; case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: return &_mesa_texformat_rgba_dxt1; case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + case GL_RGBA_S3TC: + case GL_RGBA4_S3TC: return &_mesa_texformat_rgba_dxt3; case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: return &_mesa_texformat_rgba_dxt5; diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index 05ae619ea28..fa7a33e0c0d 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -143,6 +143,7 @@ static const struct { { OFF, "GL_SGIX_shadow", F(SGIX_shadow) }, { OFF, "GL_SGIX_shadow_ambient", F(SGIX_shadow_ambient) }, { OFF, "GL_SUN_multi_draw_arrays", F(EXT_multi_draw_arrays) }, + { OFF, "GL_S3_s3tc", F(S3_s3tc) }, }; diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index a36a2182577..23ff3548c24 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1815,6 +1815,7 @@ struct gl_extensions GLboolean SGIX_shadow_ambient; /* or GL_ARB_shadow_ambient */ GLboolean TDFX_texture_compression_FXT1; GLboolean APPLE_client_storage; + GLboolean S3_s3tc; /*@}*/ /* The extension string */ const GLubyte *String; diff --git a/src/mesa/main/texcompress.c b/src/mesa/main/texcompress.c index 3e06275c930..4c6eaae4cf3 100644 --- a/src/mesa/main/texcompress.c +++ b/src/mesa/main/texcompress.c @@ -73,6 +73,17 @@ _mesa_get_compressed_formats( GLcontext *ctx, GLint *formats ) n += 3; } } + if (ctx->Extensions.S3_s3tc) { + if (formats) { + formats[n++] = GL_RGB_S3TC; + formats[n++] = GL_RGB4_S3TC; + formats[n++] = GL_RGBA_S3TC; + formats[n++] = GL_RGBA4_S3TC; + } + else { + n += 4; + } + } } return n; } @@ -100,11 +111,16 @@ _mesa_compressed_texture_size( GLcontext *ctx, return ctx->Driver.CompressedTextureSize(ctx, width, height, depth, format); } + ASSERT(depth == 1); + switch (format) { case GL_COMPRESSED_RGB_FXT1_3DFX: case GL_COMPRESSED_RGBA_FXT1_3DFX: - /* round up to multiples of 8, 4 */ - size = ((width + 7) / 8) * ((height + 3) / 4) * 16; + /* round up width to next multiple of 8, height to next multiple of 4 */ + width = (width + 7) & ~7; + height = (height + 3) & ~3; + /* 16 bytes per 8x4 tile of RGB[A] texels */ + size = width * height / 2; /* Textures smaller than 8x4 will effectively be made into 8x4 and * take 16 bytes. */ @@ -113,12 +129,13 @@ _mesa_compressed_texture_size( GLcontext *ctx, return size; case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + case GL_RGB_S3TC: + case GL_RGB4_S3TC: /* round up width, height to next multiple of 4 */ width = (width + 3) & ~3; height = (height + 3) & ~3; - ASSERT(depth == 1); /* 8 bytes per 4x4 tile of RGB[A] texels */ - size = (width * height * 8) / 16; + size = width * height / 2; /* Textures smaller than 4x4 will effectively be made into 4x4 and * take 8 bytes. */ @@ -127,10 +144,11 @@ _mesa_compressed_texture_size( GLcontext *ctx, return size; case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + case GL_RGBA_S3TC: + case GL_RGBA4_S3TC: /* round up width, height to next multiple of 4 */ width = (width + 3) & ~3; height = (height + 3) & ~3; - ASSERT(depth == 1); /* 16 bytes per 4x4 tile of RGBA texels */ size = width * height; /* simple! */ /* Textures smaller than 4x4 will effectively be made into 4x4 and @@ -156,26 +174,29 @@ _mesa_compressed_texture_size( GLcontext *ctx, GLint _mesa_compressed_row_stride(GLenum format, GLsizei width) { - GLint bytesPerTile, stride; + GLint stride; switch (format) { case GL_COMPRESSED_RGB_FXT1_3DFX: case GL_COMPRESSED_RGBA_FXT1_3DFX: - bytesPerTile = 16; + stride = ((width + 7) / 8) * 16; /* 16 bytes per 8x4 tile */ break; case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - bytesPerTile = 8; + case GL_RGB_S3TC: + case GL_RGB4_S3TC: + stride = ((width + 3) / 4) * 8; /* 8 bytes per 4x4 tile */ break; case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - bytesPerTile = 16; + case GL_RGBA_S3TC: + case GL_RGBA4_S3TC: + stride = ((width + 3) / 4) * 16; /* 16 bytes per 4x4 tile */ break; default: return 0; } - stride = ((width + 3) / 4) * bytesPerTile; return stride; } @@ -198,33 +219,39 @@ _mesa_compressed_image_address(GLint col, GLint row, GLint img, GLenum format, GLsizei width, const GLubyte *image) { - GLint bytesPerTile, stride; GLubyte *addr; - ASSERT((row & 3) == 0); - ASSERT((col & 3) == 0); (void) img; + /* 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). + * + * Example for X*Y microtiles (Z bytes each) + * offset = Z * (((width + X - 1) / X) * (row / Y) + col / X); + */ + switch (format) { case GL_COMPRESSED_RGB_FXT1_3DFX: case GL_COMPRESSED_RGBA_FXT1_3DFX: - bytesPerTile = 16; + addr = (GLubyte *) image + 16 * (((width + 7) / 8) * (row / 4) + col / 8); break; case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - bytesPerTile = 8; + case GL_RGB_S3TC: + case GL_RGB4_S3TC: + addr = (GLubyte *) image + 8 * (((width + 3) / 4) * (row / 4) + col / 4); break; case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - bytesPerTile = 16; + case GL_RGBA_S3TC: + case GL_RGBA4_S3TC: + addr = (GLubyte *) image + 16 * (((width + 3) / 4) * (row / 4) + col / 4); break; default: return 0; } - stride = ((width + 3) / 4) * bytesPerTile; - - addr = (GLubyte *) image + (row / 4) * stride + (col / 4) * bytesPerTile; return addr; } diff --git a/src/mesa/main/texformat.c b/src/mesa/main/texformat.c index 0000767f4cc..7af0b1cdf48 100644 --- a/src/mesa/main/texformat.c +++ b/src/mesa/main/texformat.c @@ -874,7 +874,7 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat, _mesa_problem(ctx, "texture compression extension not enabled"); if (ctx->Extensions.TDFX_texture_compression_FXT1) return &_mesa_texformat_rgb_fxt1; - else if (ctx->Extensions.EXT_texture_compression_s3tc) + else if (ctx->Extensions.EXT_texture_compression_s3tc || ctx->Extensions.S3_s3tc) return &_mesa_texformat_rgb_dxt1; return &_mesa_texformat_rgb; case GL_COMPRESSED_RGBA_ARB: @@ -882,7 +882,7 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat, _mesa_problem(ctx, "texture compression extension not enabled"); if (ctx->Extensions.TDFX_texture_compression_FXT1) return &_mesa_texformat_rgba_fxt1; - else if (ctx->Extensions.EXT_texture_compression_s3tc) + else if (ctx->Extensions.EXT_texture_compression_s3tc || ctx->Extensions.S3_s3tc) return &_mesa_texformat_rgba_dxt3; /* Not rgba_dxt1! See the spec */ return &_mesa_texformat_rgba; @@ -927,6 +927,20 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat, else return NULL; + /* GL_S3_s3tc */ + case GL_RGB_S3TC: + case GL_RGB4_S3TC: + if (ctx->Extensions.S3_s3tc) + return &_mesa_texformat_rgb_dxt1; + else + return NULL; + case GL_RGBA_S3TC: + case GL_RGBA4_S3TC: + if (ctx->Extensions.S3_s3tc) + return &_mesa_texformat_rgba_dxt3; + else + return NULL; + default: _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()"); return NULL; diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c index efe197e13ec..ec08168fc02 100644 --- a/src/mesa/main/teximage.c +++ b/src/mesa/main/teximage.c @@ -274,6 +274,18 @@ _mesa_base_tex_format( GLcontext *ctx, GLint format ) return GL_RGBA; else return -1; + case GL_RGB_S3TC: + case GL_RGB4_S3TC: + if (ctx->Extensions.S3_s3tc) + return GL_RGB; + else + return -1; + case GL_RGBA_S3TC: + case GL_RGBA4_S3TC: + if (ctx->Extensions.S3_s3tc) + return GL_RGBA; + else + return -1; case GL_YCBCR_MESA: if (ctx->Extensions.MESA_ycbcr_texture) @@ -387,6 +399,10 @@ is_compressed_format(GLcontext *ctx, GLenum internalFormat) case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + case GL_RGB_S3TC: + case GL_RGB4_S3TC: + case GL_RGBA_S3TC: + case GL_RGBA4_S3TC: return GL_TRUE; default: if (ctx->Driver.IsCompressedFormat) { |