- Artists prefer to use formats like TGA for editing textures. Easy to edit and has nice alpha channel support. The files are usually named "*.tga"
- Releases (and users on slow connections) prefer small optimized formats. Let these files be named "*.dds"
- Material scripts (and a lot of other places) need a single file name.
So how to get that single filename to load tga for artists and something else for end users? With the same name?
Here is my solution:
- All image references that need this functionality should end with "shi" (for ShortHike Image).
- The artist creates a file "path/to/image.tga" and enters it into a material script as "path/to/image.shi".
- I run a custom Archive implementation. It encapsulates a standard archive (a FileSystem in my case) that is created at the same time when my custom Archive is created.
- The custom archive passes most calls through to the FileSystemArchive. Except when someone looks for a "foo.shi" file. In exists() it looks if "foo.dds" or "foo.tga" exists and if it can find either one returns true.
- When "path/to/image.shi" is opened it returns an empty named MemoryDataStream("path/to/image.shi", (void*)NULL, 0).
- My custom ImageCodec is registered to handle "shi" files. When it is asked to decode an image it looks first for the ".tga" file and if found asks the TGA ImageCoded to decode it. If again it's a ".dds" file asks the DDS image codec to decode it.
The actual formats are naturally arbitrary. You could even have the codec check for three or four file formats if you wanted to. Or splice together images from two different files (like jpg for RGB and zip for A). Also, I haven't implemented a custom MemoryDataStream that would encode the resourcegroup, as currently that is hardcoded for me. But that would be a few lines of code anyway.
Suggestions and feedback? Is there an easier way to do this? (It took just a few hours to write so you really need to try..)
