]> git.tdb.fi Git - libs/gl.git/commitdiff
Have the maketex script take texture parameters as options
authorMikko Rasa <tdb@tdb.fi>
Fri, 4 Oct 2013 11:11:35 +0000 (14:11 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 4 Oct 2013 11:11:35 +0000 (14:11 +0300)
scripts/maketex.py

index 8c7d5a199def423855c23e6d4f7cad0738ed8036..04de1d38a57d51cc2e25c2ea16f8e5896481283a 100755 (executable)
@@ -13,7 +13,7 @@ def escape(str):
                        result += c
        return result;
 
-def make_tex(fn):
+def make_tex(fn, filter="LINEAR", anisotropy=0, wrap=None):
        import Image
 
        img = Image.open(fn)
@@ -25,7 +25,13 @@ def make_tex(fn):
                fmt = "LUMINANCE"
 
        result = "storage %s %d %d;\n"%(fmt, img.size[0], img.size[1])
-       result += "min_filter LINEAR;\n"
+       result += "filter %s;\n"%filter
+       if "MIPMAP" in filter:
+               result += "generate_mipmap true;\n"
+       if anisotropy:
+               result += "max_anisotropy %d;\n"%anisotropy
+       if wrap:
+               result += "wrap %s;\n"%wrap
        result += "raw_data \""
        data = list(img.getdata())
        for y in range(img.size[1]):
@@ -36,11 +42,24 @@ def make_tex(fn):
        return result
 
 if __name__=="__main__":
-       import sys
        import os
+       import argparse
 
-       if len(sys.argv)<2:
-               print "Usage: %s <image>"%sys.argv[0]
-       else:
-               out = file(os.path.splitext(sys.argv[1])[0]+".tex", "w")
-               out.write(make_tex(sys.argv[1]))
+       parser = argparse.ArgumentParser()
+       parser.add_argument("-o", "--output", metavar="FILE", help="Output filename")
+       parser.add_argument("-f", "--filter", choices=["NEAREST", "LINEAR", "MIPMAP"], default="LINEAR", help="Filtering mode")
+       parser.add_argument("-a", "--anisotropy", metavar="NUMBER", help="Maximum anisotropy, 0 = disable")
+       parser.add_argument("-w", "--wrap", choices=["REPEAT", "CLAMP_TO_EDGE", "MIRRORED_REPEAT"], help="Wrapping mode")
+       parser.add_argument("image")
+
+       args = parser.parse_args()
+
+       filter = args.filter
+       if filter=="MIPMAP":
+               filter = "LINEAR_MIPMAP_LINEAR"
+
+       out_fn = args.output
+       if not out_fn:
+               out_fn = os.path.splitext(args.image)[0]+".tex2d"
+       out = file(out_fn, "w")
+       out.write(make_tex(args.image, filter, args.anisotropy, args.wrap))