4
4
mirror of https://github.com/H-uru/korman.git synced 2025-07-14 22:36:52 +00:00

More robust mipmap fix

This commit is contained in:
2015-06-13 12:35:58 -04:00
parent 92e2eddff6
commit dcf0b4840c

View File

@ -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.
# "<Deledrius> 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: