[sldev] Reformatting Textures for the cache

Tinker LaFollette tinker_lafollette at shaum.com
Thu Mar 22 07:44:38 PDT 2007


On 3/22/07, Tim Shephard <tshephard at gmail.com> wrote:
> > /cache/6c/48/94/6c489466-3058-6475-6b1b-e5fc1d49f1f3.tga
> >
>
> You want to open a file for every texture you need to decode?  Yiiikes.

How about this: have one big cache file for each image *size* cached.
Each cache file is divided into fixed cells containing the
uncompressed images. So your lookup would be UUID =>
(width,height,depth,cell#), e.g.:

    6c489466-3058-6475-6b1b-e5fc1d49f1f3 => 256,512,32,37

and you would go to the file /cache/images/256-512-32 (which may
already be open) and retrieve the image from the 37th cell of that
file.

Because all image dimensions are powers of two, you won't have a
combinatorial explosion of image sizes. (You could reduce the number
of cache files by storing 256x512 and 512x256, etc., in the same
file.)  Because the files are divided into fixed cells, you can delete
and insert images within the cache file without fragmentation.

(Not knowing much about image file formats, I'm making the naive and
probably wrong assumption that uncompressed images of the same
dimensions occupy the same number of bytes. Even if it's not strictly
true, it might be close enough to true if we can live with a little
padding.)


More information about the SLDev mailing list