Automatic Texture Compression

Hi
Can I use automatic tetxture compression with the function gluBuild2DMipmaps()? As an example:
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_COMPRESSED_RGBA, targa_texture.width, targa_texture.height, GL_RGBA, GL_UNSIGNED_BYTE, targa_texture.imageData );

Is this command sufficient to compress the textures?
Note: I don’t want to save the compressed data to the disk. I want to use it directly in my app.
-Ehsan-

That function doesn’t compress the texture, it builds the mipmaps (as the name suggest). Refer to the documentation. If you want texture compression, you may be interested in GL_EXT_texture_compression_s3tc

So I should use glTexImage2D to compress the textures? What format should I use if I want to build the mipmaps after the texture has been compressed?
-Ehsan-

I don’t use texture compression currently. But if I understood you well, I don’t see why you want to compress the texture during runtime. It should definately slow things down. What do you want to do ?

Oh, sorry, I misunderstood your question… Anyway, you can’t use gluBuildMipmaps this way, although you may try. If you use TexImage2D directly, you will have to compute each mipmap manually and upload it using the “level” parameter (level is 0 for the base texture, 1 for the first mip-map etc). The problem is: the driver is not guarantied to compress the image. I was recently playing with the s3tc compression, and the driver was not compressing the images where it should. I would advice you to use a custom compressor like squish or nvidia dxt tools

Hi Jide,
You mean This type of compression compresses the textures in each frame?–I load the texture data once and I use glTexImage2D() for each texture once. So should I load the compressed data from a file like DDS file and use glCompressedTexImage2D() to load it in VRAM?If it’s correct, what about the older graphic cards?Can I use the DDS files in older graphic cards such as Radeon 7000 or GeForce 4MX?
Zengar,
Does your graphic card support the EXT_texture_compression_s3tc extension? If yes, why it doesn’t compress your textures?
-Ehsan-

Of course it supports the extension :-/ All cards from radeon 700 and geforce 256 support it. But it just won’t compress the image. I guess the driver was ignoring the hint( a reasonable behavior, if you ask me).
http://www.delphi3d.net/hardware/extsupport.php?extension=GL_EXT_texture_compression_s3tc

Not sure this helps, but on my card the following code auto compresses just fine:

	gluBuild2DMipmaps(GL_TEXTURE_2D, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);

and for each mip level you can sanity check it works with these calls

int res, format, size;
For each mip level
glGetTexLevelParameteriv(GL_TEXTURE_2D, mip, GL_TEXTURE_COMPRESSED_ARB, &res);
glGetTexLevelParameteriv(GL_TEXTURE_2D, mip, GL_TEXTURE_INTERNAL_FORMAT, &format);
glGetTexLevelParameteriv(GL_TEXTURE_2D, mip, GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB, &size);

//need to calculate mipSize yourself

if(res && format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT && size == mipSize){ //all is good }

Originally posted by crouchingchicken:
Not sure this helps, but on my card the following code auto compresses just fine:

	gluBuild2DMipmaps(GL_TEXTURE_2D, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);

But Zengar said that I can not use gluBuild2DMipmaps() to compress the texture. What should I do? Use this function or don’t use it? :confused:
What does happen if compression fails?
-Ehsan-

I suggest you try it out, I may be wrong :slight_smile: You should still use an off-line compressor if you want a) hight quality b) high loading speed

Compression cannot fail, as long as your texture sizes are powers of two.

Read the spec of GL_EXT_texture_compression_s3tc.

Originally posted by Zengar:
I suggest you try it out, I may be wrong :slight_smile: You should still use an off-line compressor if you want a) hight quality b) high loading speed
What about the older graphic cards such as NVIDIA TNT2 or ATI Radeon 7000? I’m afraid that they don’t process it.
-Ehsan-

They don’t, thats why you must have a rollback. Or at least, don’t depend 100% on a single method. You will render your application useless on some cases.

Originally posted by Ehsan Kamrani:
What about the older graphic cards such as NVIDIA TNT2 or ATI Radeon 7000?
You can write your own decompressor that will convert the texture to ordinary rgba texture when the hw does not support compressed ones. This way the capable hw will get all advantages of off-line compressed textures and the program will still run on old hw.