xonotic/misc/tools/compress-texture
2010-08-09 14:03:34 +02:00

50 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
# usage: compress-texture tool compression in.png out.dds
# example: compress-texture compressonator dxt1 foo.jpg foo.dds
echo >&2 "$0 $*"
tool=$1; shift
format=$1; shift
src=$1; shift
dst=$1; shift
c=
f=
case "$tool" in
compressonator-dxtc|compressonator-atic)
case "$tool" in
*-dxtc) c="-codec DXTC.dll" ;;
*-atic) c="-codec ATICompressor.dll" ;;
esac
case "$format" in
dxt1) f="+fourCC DXT1" ;;
dxt3) f="+fourCC DXT3" ;;
dxt5) f="+fourCC DXT5" ;;
esac
dir=`mktemp -d "$HOME/.wine/drive_c/compressonator.XXXXXX"`
dir_dos="C:/${dir##*/}"
ext=${src##*.}
cp "$src" "$dir/src.$ext"
# compressonator and wine suck, so we sometimes have to retry :(
for retry in 1 2 3 4 5; do
wine "c:/Program Files/AMD/The Compressonator 1.50/TheCompressonator.exe" -convert -mipmaps "$dir_dos/src.$ext" "$dir_dos/dst.dds" $c $f "$@" -mipper BoxFilter.dll
if mv "$dir/dst.dds" "$dst"; then
break
fi
done
rm -rf "$dir"
[ -f "$dst" ]
;;
nvcompress)
case "$format" in
dxt1) f="-bc1" ;;
dxt3) f="-alpha -bc3" ;;
dxt5) f="-alpha -bc5" ;;
esac
nvcompress $f "$@" "$src" "$dst"
;;
esac