]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/export_texture.py
Refactor handling of texture storage properties in the Blender exporter
[libs/gl.git] / blender / io_mspgl / export_texture.py
index 8e107a718a3644dba03ffc13393c587470c95f97..2269e27ae175a514670c70a295aaada994228dbb 100644 (file)
@@ -38,9 +38,8 @@ class TextureExporter:
                if tex_node.use_mipmap:
                        tex_res.statements.append(Statement("generate_mipmap", True))
 
-               colorspace = image.colorspace_settings.name
-               if len(channels)==1 and colorspace=='sRGB':
-                       raise Exception("Unsupported configuration on texture {}: Grayscale with sRGB".format(image.name))
+               from .texture import Texture
+               texture = Texture(tex_node, channels)
 
                invert_mask = sum(1<<i for i, c in enumerate(channels) if c[0]=='~')
 
@@ -61,17 +60,10 @@ class TextureExporter:
                if not invert_mask and channels==native_channels:
                        if not tex_node.use_mipmap:
                                tex_res.statements.append(Statement("mipmap_levels", 1))
-                       srgb = "_srgb" if colorspace=='sRGB' else ""
+                       srgb = "_srgb" if texture.srgb else ""
                        tex_res.statements.append(Statement("external_image"+srgb, fn))
                else:
-                       if len(channels)==4:
-                               fmt = 'SRGB8_ALPHA8' if colorspace=='sRGB' else 'RGBA8'
-                       elif len(channels)==1:
-                               fmt = 'LUMINANCE8' if channels[0]=='Y' else 'R8'
-                       else:
-                               fmt = 'SRGB8' if colorspace=='sRGB' else 'RGB8'
-
-                       tex_res.statements.append(Statement("storage", Token(fmt), image.size[0], image.size[1]))
+                       tex_res.statements.append(Statement("storage", Token(texture.pixelformat), texture.width, texture.height))
 
                        pixels = tuple(image.pixels)
                        texdata = ""