S3TC Compression and gluBuild2DMipmaps

Hallo!

I use S3TC compression for my app. It seems to work fine, but I can not generate mipmaps

  if (m_Compression && m_CompressionLevel != None)
  {
  	// here a more advanced way
  	if (mipmap)
  	{
  		// At this point we must check if the image format is RGB or RGBA
  		if (temp->type == RGB)
  		{
  			// Here we only can do DXTC1 compression
  			gluBuild2DMipmaps (GL_TEXTURE_2D, temp->bpp, temp->width, temp->height, 0x83F0, GL_UNSIGNED_BYTE, temp->data);
  		}
  		else
  		{
  			// so here we can use any supported DXT-compression
  			switch (m_CompressionLevel)
  			{
  				case S3TC_DXTC1:
  					gluBuild2DMipmaps (GL_TEXTURE_2D, temp->bpp, temp->width, temp->height, 0x83F1, GL_UNSIGNED_BYTE, temp->data);

  				case S3TC_DXTC3:
  					gluBuild2DMipmaps (GL_TEXTURE_2D, temp->bpp, temp->width, temp->height, 0x83F2, GL_UNSIGNED_BYTE, temp->data);

  				case S3TC_DXTC5:
  					gluBuild2DMipmaps (GL_TEXTURE_2D, temp->bpp, temp->width, temp->height, 0x83F3, GL_UNSIGNED_BYTE, temp->data);
  			};

  		}
  	}
  	else
  	{
  		// At this point we must check if the image format is RGB or RGBA
  		if (temp->type == RGB)
  		{
  			// Here we only can do DXTC1 compression
  			glTexImage2D (GL_TEXTURE_2D, 0, 0x83F0, temp->width, temp->height, 0, temp->type, GL_UNSIGNED_BYTE, temp->data);
  		}
  		else
  		{
  			switch (m_CompressionLevel)
  			{
  				case S3TC_DXTC1:
  					glTexImage2D (GL_TEXTURE_2D, 0, 0x83F1, temp->width, temp->height, 0, temp->type, GL_UNSIGNED_BYTE, temp->data);

  				case S3TC_DXTC3:
  					glTexImage2D (GL_TEXTURE_2D, 0, 0x83F2, temp->width, temp->height, 0, temp->type, GL_UNSIGNED_BYTE, temp->data);

  				case S3TC_DXTC5:
  					glTexImage2D (GL_TEXTURE_2D, 0, 0x83F3, temp->width, temp->height, 0, temp->type, GL_UNSIGNED_BYTE, temp->data);
  			};
  		}
  	}
  }

gluBuild2DMipmaps does not work with compressed formats. If you want mipmaps, either make them yourself or use SGIS_generate_mipmap.

Thanks - i will use SGIS_generate_mipmap

The best thing is to store the mipmaps in the file and just load them instead of generating them at loadtime through the driver. It’ll give you both better quality and lower load times. NVidia has a great plugin for this that exports .dds files.

Could you give me the link to this plugin?

Originally posted by Austrian Coder:
Could you give me the link to this plugin?

http://developer.nvidia.com/view.asp?IO=ps_texture_compression_plugin

Originally posted by Bob:
gluBuild2DMipmaps does not work with compressed formats. If you want mipmaps, either make them yourself or use SGIS_generate_mipmap.

I cannot believe this. I use S3TC with gluBuild2DMipmaps and it works just fine.
AND i see a difference between compressed textures and not-compressed 16/32 Bit textures, so it has to work.

I have a GF2 Ti, with (i think) the latest drivers.

Jan.

Of course it works, all gluBuild2DMipmaps does is generate successively halved versions of your source image and call glTexImage2D at successively increasing mipmap ‘level’ targets for each one with the format parameters you pass in. GLU is just a utility layer which uses standard opengl functions - it it’s not voodoo magic. Check the mesa source code to see the logic.
Obviously it would be more efficient to store your mipmaps, but you don’t have to use the dds format - roll your own format.

@Jan2000: It doesent work… there is no texture seen on the screen

[This message has been edited by Austrian Coder (edited 01-31-2003).]

>>all gluBuild2DMipmaps does is generate successively halved versions of your source image and call glTexImage2D at successively increasing mipmap ‘level’ targets for each one with the format parameters you pass in<<

this will not work (as i found out though i didnt try glmipmaps but my own mipmap routine) with compressed textures the minimin sized texture is 4x4 not 1x1
thus it goes 8x8 -> 4x4 -> 4x4 -> 4x4.
check the texture compression spec for further details also theres a pdf on nvidias site IIRC

I cannot believe this. I use S3TC with gluBuild2DMipmaps and it works just fine.
AND i see a difference between compressed textures and not-compressed 16/32 Bit textures, so it has to work.

Are you giving gluBuild2DMipmaps a compressed or uncompressed image? If you give it uncompressed, I can see why it works for you. Try give it a precompressed image (that is, a compressed format as third last parameter) and see what happens.

…all gluBuild2DMipmaps does is generate successively halved versions of your source image and call glTexImage2D…

And that is the problem here. If gluBuild2DMipmaps doesn’t know about compressed formats, it can’t scale the image for you.

Originally posted by zed:
this will not work (as i found out though i didnt try glmipmaps but my own mipmap routine) with compressed textures the minimin sized texture is 4x4 not 1x1
thus it goes 8x8 -> 4x4 -> 4x4 -> 4x4.
check the texture compression spec for further details also theres a pdf on nvidias site IIRC

Actually the drivers (or the dds plugin) should be able to compress a 1x1 texture. And when you give it to the dimensions (Height and width) of the texture with glCompressedTexImage2D you can actually give 1x1 but you have to give the correct size of the pointed data (which is a 4x4 block in that case).

Beware!

The code that sits in the driver and compresses images at run time does a FAST job, not an ACCURATE job. You will get much higher quality if you use a Photoshop plug-in to save your image out as S3TC compressed DDS files, and load those directly using CompressedTexSubImage().

The DDS exporter nVIDIA has on their site is fairly useful; it lets you determine what filter to use for MIP map generation, fading MIP maps to a certain color/alpha, etc. It can also normalize each MIP map level on export, which is obviously useful for normal maps (which should be stored in 24 bits format, not compressed).

Give it a try. DDS files are really simple to load, too!

Edit: for cards which dont’ support S3TC compression under OpenGL, such as the Wildcat VP, the DDS format is very simple to decompress in software. Thus, load compressed image from disk, then decompress in software if card doesn’t support S3TC compression format.

[This message has been edited by jwatte (edited 01-31-2003).]