workaround for sometimes failing wine
[xonotic/xonotic.git] / misc / tools / compress-texture
1 #!/bin/sh
2
3 # usage: compress-texture tool compression in.png out.dds
4 # example: compress-texture compressonator dxt1 foo.jpg foo.dds
5
6 echo >&2 "$0 $*"
7
8 tool=$1; shift
9 format=$1; shift
10 src=$1; shift
11 dst=$1; shift
12
13 c=
14 f=
15 case "$tool" in
16         compressonator-dxtc|compressonator-atic)
17                 case "$tool" in
18                         *-dxtc) c="-codec DXTC.dll" ;;
19                         *-atic) c="-codec ATICompressor.dll" ;;
20                 esac
21                 case "$format" in
22                         dxt1) f="+fourCC DXT1" ;;
23                         dxt3) f="+fourCC DXT3" ;;
24                         dxt5) f="+fourCC DXT5" ;;
25                 esac
26                 dir=`mktemp -d "$HOME/.wine/drive_c/compressonator.XXXXXX"`
27                 dir_dos="C:/${dir##*/}"
28                 ext=${src##*.}
29                 cp "$src" "$dir/src.$ext"
30
31                 # compressonator and wine suck, so we sometimes have to retry :(
32                 for retry in 1 2 3 4 5; do
33                         wine "$HOME/.wine/drive_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
34                         if mv "$dir/dst.dds" "$dst"; then
35                                 break
36                         fi
37                 done
38                 rm -rf "$dir"
39                 [ -f "$dst" ]
40                 ;;
41         nvcompress)
42                 case "$format" in
43                         dxt1) f="-bc1" ;;
44                         dxt3) f="-alpha -bc3" ;;
45                         dxt5) f="-alpha -bc5" ;;
46                 esac
47                 nvcompress $f "$@" "$src" "$dst"
48                 ;;
49 esac