PDA

View Full Version : manual ARB_texture_compression comp/decomp



remdul
03-17-2007, 03:24 AM
Is there code available for offline compression/decompresion to/from the GL_ARB_texture_compression format?

I'm interested in distributing textures with my software in compressed format (glGetCompressedTexImageARB), but if I do so I need to decompress them manually for machines on which the extension is not available.
I know this isn't really smart, but want to try anyway (for-fun).

If there isn't any code publicly available, could someone provide me details on the compression scheme so I can reverse engineer it? I'll share my code if I succeed. :)

Harvey_Birdman
03-17-2007, 04:54 AM
If I'm understanding you correctly, I think you're heading down the wrong track. The actual compression method used is dependant on the individual machines drivers/hardware. If you compress textures on your machine with the algorithm implemented in your driver, you may not be able to decompress it on another machine.

remdul
03-17-2007, 05:15 AM
I thought it did too, but someone here said that it should work*.

I too have my doubts, the spec isn't that clear and suggests there is room for the vendors to play with, just not sure to what degree.

* Edit: I was referring to this thread:
http://www.opengl.org/discussion_boards/ubb/ultimatebb.php?ubb=get_topic;f=3;t=015012#000023
Tamlin, if you read this, I'm interested in hearing your long answer. :)

ector
03-17-2007, 05:58 AM
Texture compression is standardized and games have been distributed with precompressed textures for years. In D3D you simply use the textool to create compressed .dds files, and then everything is taken care of for you. As for OpenGL, I have never used compressed textures with it, so... you'll have to wait for a better answer :)

remdul
03-17-2007, 06:05 AM
Yes, that's what I was hoping to achieve, something along the lines of the DDS format with a simple tool to do the conversion.

Jan
03-17-2007, 07:54 AM
If you have Photoshop, you can use nVidias tools to compress your textures and store them in DDS-format.

To decompress your textures manually, you might want to take a look at nVidias code, AFAIK there is open-source stuff, though i am not sure. Other than that, there are some other libraries, too. I think DevIL (formerly known as OpenIL), allows you to load DDS files. DevIL is open source, so you might find what you are looking for, in there.

All current games distribute there textures in compressed form. Today most use the DDS format, because it also decreases load-times. Also precompressing the textures can yield better quality, than using the built in compressors of the GPU.

Jan.

remdul
03-17-2007, 09:39 AM
I'm aware of that, but I'm trying to do that with ARB_texture_compression instead of DDS compressed textures.

Can someone please confirm whether or not ARB_tex_compression compressed textures are cross-compatible between vendors/drivers?

(I have checked out Mesa3d in the mean while, and it apears this extension is not implemented, no hints there either.)

Nicolas Lelong
03-17-2007, 11:52 AM
Actually, the ARB_texture_compression extension provides an API to handle compressed textures but does not define/specify any compression format.

The most used compression formats are in the DXTC family (also known as S3TC). The compression formats are exposed by additional extensions, see for example the 'EXT_texture_compression_s3tc' extension.

DXTC/S3TC is supported by all NVidia/ATI cards at least since GeForce 1 I think. I'm not familiar with other platforms but it really is the most used compression format nowadays.

For offline (de)compression, you can use the OpenGL driver or alternate libraries such as
Simon Brown\'s squish (http://www.sjbrown.co.uk/?code=squish) or intel/id code (http://www.intel.com/cd/ids/developer/asmo-na/eng/324337.htm)

For more information on DXTC formats, you can have a look here (http://en.wikipedia.org/wiki/Texture_compression) .

HTH, cheers

ebray99
03-17-2007, 02:03 PM
Also, just to eliminate any confusion, S3TC and DXT formats are the same thing. Why/how the name changed to DXTC, I'm not sure. Perhaps because S3 is a company name?

Kevin B

Zengar
03-17-2007, 03:25 PM
DXTC stands for DirectX Texture Compression

I would recommend the latest Nvidia DXT library, it is open-source now, offering some very good quality and performance

ebray99
03-17-2007, 07:02 PM
I'm aware of what it stands for, and out of curiosity, does anyone know how it got called that? It seems kinda messed up to associate that texture compression with DirectX, when really it's completely unrelated (other than the fact that MS exposes the hardware functionality in DX).

Is Microsoft going to start calling other texture formats DXA8R8G8B8? Maybe they should just claim IEEE standards as their own and just brand floating point numbers used by graphics cards DXFP.

But I digress.

Kevin B

tamlin
03-17-2007, 08:19 PM
remdul: Yes, it is pretty standard, but you need to query (when downloading) and supply (when uploading) the actual, internal DXTn format. That was what I referred to when I wrote it's universally supported - there simply isn't a 3D card+driver combo I'm aware of that handles compressed textures, but doesn't do DXTn compression (and therefore reuse it) in OpenGL.

So while there by OpenGL specification isn't a promise, if the hardware supports DXTn and it's supported on Windows (at least all current consumer offerings), I'd say that if the OpenGL implemenation also supports texture compression at all it's DXTn (there really aren't many performant options to it).

In practice, I'd say you can depend upon it. If compression is supported, DXTn is.

Zengar: I didn't know nvidia had released their DXT lib src. Thanks for pointing it out! (Do you have a direct URL, or is it only in the SDK? My google-fu only found mentions of it, but no direct link).

V-man
03-18-2007, 03:14 AM
Originally posted by ebray99:
Is Microsoft going to start calling other texture formats DXA8R8G8B8? Maybe they should just claim IEEE standards as their own and just brand floating point numbers used by graphics cards DXFP.

But I digress.

Kevin B S3TC was invented by S3 and I guess they licensed it to MS which renamed it.
I'm sure they didn't like the name S3.
It's the usual not invented here, but brand it as MS.

Zengar
03-18-2007, 06:34 AM
@tamlin: looks like it is only available to registered developers for the time being. Do you have an account?

Humus
03-18-2007, 11:53 AM
Originally posted by remdul:
I'm interested in distributing textures with my software in compressed format (glGetCompressedTexImageARB), but if I do so I need to decompress them manually for machines on which the extension is not available.
I know this isn't really smart, but want to try anyway (for-fun).There's nothing wrong with that approach. Today all cards have supported DXTC for many generations, so coding for them and providing a decompression workaround for older cards if you care about them is perfectly acceptable practice IMHO. That's what my framework does anyway. If you want some simple decoding code I have it in my framework:
http://www.humus.ca/index.php?page=3D

It's quite simple to decode actually, and you could easily write your own from the specification in the Appendix of GL_EXT_texture_compression_s3tc (http://www.opengl.org/registry/specs/EXT/texture_compression_s3tc.txt)

Humus
03-18-2007, 11:56 AM
Originally posted by remdul:
I'm aware of that, but I'm trying to do that with ARB_texture_compression instead of DDS compressed textures.DDS is perfect format for distributing compressed textures and is it's the same compression as used in GL_EXT_texture_compression_s3tc.

Humus
03-18-2007, 12:04 PM
Originally posted by ebray99:
I'm aware of what it stands for, and out of curiosity, does anyone know how it got called that? It seems kinda messed up to associate that texture compression with DirectX, when really it's completely unrelated (other than the fact that MS exposes the hardware functionality in DX).

Is Microsoft going to start calling other texture formats DXA8R8G8B8?Microsoft licensed S3TC from S3. DirectX is a vendor-neutral API though, so it wouldn't look good to call it S3TC I suppose. I guess DXTC was more natural in that context, but if it makes you any happier, in DX10 it's not called DXTC anymore, but BC (as in Block Compression). Basically:
DXT1 -> BC1
DXT3 -> BC2
DXT5 -> BC3
ATI1N -> BC4
ATI2N -> BC5

Humus
03-18-2007, 12:08 PM
Originally posted by tamlin:
So while there by OpenGL specification isn't a promise, if the hardware supports DXTn and it's supported on Windows (at least all current consumer offerings), I'd say that if the OpenGL implemenation also supports texture compression at all it's DXTn (there really aren't many performant options to it).

In practice, I'd say you can depend upon it. If compression is supported, DXTn is.Let's not make it harder than it is. Just check for GL_EXT_texture_compression_s3tc instead of GL_ARB_texture_compression. Problem solved. If GL_EXT_texture_compression_s3tc is supported you can supply precompressed textures in S3TC format, otherwise you cannot.

remdul
03-19-2007, 01:25 AM
Allright, thanks very much for the replies.

So ARB_texture_compression is really just S3TC/DXTC under the hood (on most implementations)? I wasn't aware of that, but it makes perfect sense.

Thanks.

Humus
03-19-2007, 07:24 AM
No. ARB_texture_compression is a generic interface with no particular format. ARB_texture_compression alone does not mean you can use S3TC. EXT_texture_compression_s3tc is an extension on top of the ARB_texture_compression interface that exposes S3TC specifically, so that's the extension you're looking for.

jra101
03-19-2007, 11:20 AM
Originally posted by remdul:
I'm aware of that, but I'm trying to do that with ARB_texture_compression instead of DDS compressed textures.
DDS is just a file format, it can store uncompressed textures, DXTC/S3TC (same format) textures, cubemaps, 3D textures, textures with mipmaps, etc...

The S3TC/DXTC texture compression algorithm has been standardized for quite a while, you can load an image compressed with this algorithm using any GPU that supports ARB_texture_compression and EXT_texture_compression_s3tc. Pretty much any GPU you can get these days supports both of these extensions:

http://delphi3d.net/hardware/extsupport.php?extension=GL_EXT_texture_compressio n_s3tc

There are quite a few tools you can use to compress your existing images offline including dxtex (included in the DirectX SDK), NVIDIA Photoshop Plugins, NVIDIA Texture Tools (now supports hardware accelerated DXTC/S3TC compression using CUDA), as well as the other tools linked in earlier posts.

knackered
03-19-2007, 11:22 AM
3dlabs cards never supported dxtc - not even the realizms.

PkK
03-19-2007, 04:02 PM
On Linux most cards don't support S3TC. The proprietary Nvidia drivers do, but the free drivers used for all the older cards as well as all Intel (and that's the biggest craphics chip vendor) and most ATI cards do not by default. You have to install an additional library to get S3TC with these drivers and that's illegal for many countries including the USA.

remdul
03-21-2007, 06:10 AM
Originally posted by Humus:
No. ARB_texture_compression is a generic interface with no particular format. ARB_texture_compression alone does not mean you can use S3TC. EXT_texture_compression_s3tc is an extension on top of the ARB_texture_compression interface that exposes S3TC specifically, so that's the extension you're looking for. Thanks, that's exactly what I meant to say. A vendor could use *any* algorythm/format for ARB compression. But if S3TC is supported anyway, it just layers on top of that extension, without making any guarantees about the format. That's also what I meant in my first post; it not being smart trying to use ARB compression instead of the other formats while fixed formats are available anyway.

So DDS/3STC/DXTC is the way to go. I did not really like the DDS format, and this is why I considered creating a similar toolset for ARB compression, thinking it was an independent algo with a fixed format, which it ain't (in fact, the exact opposite).

Well, thanks for clearing it all up. :)

knackered
03-21-2007, 09:19 AM
dds is a great format. serves all your needs - cubemaps, compression, and pre-generated mipmaps.

simongreen
03-27-2007, 07:30 AM
Since we're talking about DXT, you might want check out this example from our SDK, which does realtime DXT compression on the GPU using integer textures at around 1Gpixel/second:

http://developer.download.nvidia.com/SDK/10/opengl/samples.html#compress_DXT

knackered
03-27-2007, 11:04 AM
do your drivers use that technique when I submit RGB data with a compressed internal format?

simongreen
03-28-2007, 10:39 AM
Originally posted by knackered:
do your drivers use that technique when I submit RGB data with a compressed internal format? No, our drivers currently do compression on the CPU using a higher quality algorithm. The algorithm used in the GPU sample isn't really optimized for image quality.

We did however just release a new version of our texture tools which can optionally use CUDA to accelerate offline high-quality DXT compression by up to 10x:
http://developer.nvidia.com/object/texture_tools.html