From dcf0b4840cda0a66f932647753e3206e16feb576 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 13 Jun 2015 12:35:58 -0400 Subject: [PATCH] More robust mipmap fix --- korman/exporter/material.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/korman/exporter/material.py b/korman/exporter/material.py index 39e62f1..00b4ded 100644 --- a/korman/exporter/material.py +++ b/korman/exporter/material.py @@ -272,13 +272,20 @@ class MaterialConverter: compression = plBitmap.kDirectXCompression dxt = plBitmap.kDXT5 if key.use_alpha or key.calc_alpha else plBitmap.kDXT1 - # HACK ATTACK! + # Major Workaround Ahoy # There is a bug in Cyan's level size algorithm that causes it to not allocate enough memory - # for the color block in a 1x1 DXT5 mipmap. To fix that, we will reduce the number of levels - # by one, such that we don't even produce a 1x1 mipmap. DXT images need to have at least 4 pixels anyway... - # We can't fix the real source of the bug because the values generated by the algo are - # used to read from the file. Can't fixed close source games :( - numLevels -= 1 + # for the color block in certain mipmaps. I personally have encountered an access violation on + # 1x1 DXT5 mip levels -- the code only allocates an alpha block and not a color block. Paradox + # reports that if any dimension is smaller than 4px in a mip level, OpenGL doesn't like Cyan generated + # data. So, we're going to lop off the last two mip levels, which should be 1px and 2px as the smallest. + # This bug is basically unfixable without crazy hacks because of the way Plasma reads in texture data. + # " I feel like any texture at a 1x1 level is essentially academic. I mean, JPEG/DXT + # doesn't even compress that, and what is it? Just the average color of the whole + # texture in a single pixel?" + # :) + if key.mipmap: + # If your mipmap only has 2 levels (or less), then you deserve to phail... + numLevels = max(numLevels - 2, 2) # Grab the image data from OpenGL and stuff it into the plBitmap with _GLTexture(image) as glimage: