Browse Source

Move the slow part of alpha testing into korlib

pull/11/head
Adam Johnson 9 years ago
parent
commit
2d7d58ee39
  1. 8
      korman/exporter/material.py
  2. 8
      korman/korlib/texture.py

8
korman/exporter/material.py

@ -577,13 +577,7 @@ class MaterialConverter:
else: else:
# Using bpy.types.Image.pixels is VERY VERY VERY slow... # Using bpy.types.Image.pixels is VERY VERY VERY slow...
with korlib.GLTexture(image) as glimage: with korlib.GLTexture(image) as glimage:
data = glimage.get_level_data(quiet=True) result = glimage.has_alpha
for i in range(3, len(data), 4):
if data[i] != 255:
result = True
break
else:
result = False
self._alphatest[image] = result self._alphatest[image] = result
return result return result

8
korman/korlib/texture.py

@ -95,3 +95,11 @@ class GLTexture:
else: else:
bgl.glGetTexLevelParameteriv(bgl.GL_TEXTURE_2D, level, param, buf) bgl.glGetTexLevelParameteriv(bgl.GL_TEXTURE_2D, level, param, buf)
return int(buf[0]) return int(buf[0])
@property
def has_alpha(self):
data = self.get_level_data(quiet=True)
for i in range(3, len(data), 4):
if data[i] != 255:
return True
return False

Loading…
Cancel
Save