comparison pytouhou/ui/texture.pyx @ 449:d56536ef28e8

Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 03 Aug 2013 15:49:11 +0200
parents 40d5f3083ebc
children 6864a38b2413
comparison
equal deleted inserted replaced
448:3bc37791f0a2 449:d56536ef28e8
27 27
28 class TextureId(int): 28 class TextureId(int):
29 def __del__(self): 29 def __del__(self):
30 cdef GLuint texture = self 30 cdef GLuint texture = self
31 glDeleteTextures(1, &texture) 31 glDeleteTextures(1, &texture)
32 self.renderer.remove_texture(self)
32 33
33 34
34 class TextureManager(object): 35 class TextureManager(object):
35 def __init__(self, loader=None): 36 def __init__(self, loader=None, renderer=None):
36 self.loader = loader 37 self.loader = loader
38 self.renderer = renderer
37 39
38 40
39 def load(self, anm_list): 41 def load(self, anm_list):
40 for anm in anm_list: 42 for anm in sorted(anm_list, key=lambda x: x[0].first_name.endswith('ascii.png')):
41 for entry in anm: 43 for entry in anm:
42 if not hasattr(entry, 'texture'): 44 if not hasattr(entry, 'texture'):
43 texture = decode_png(self.loader, entry.first_name, entry.secondary_name) 45 texture = decode_png(self.loader, entry.first_name, entry.secondary_name)
44 entry.texture = load_texture(texture) 46 entry.texture = load_texture(texture)
45 elif not isinstance(entry.texture, TextureId): 47 elif not isinstance(entry.texture, TextureId):
46 entry.texture = load_texture(entry.texture) 48 entry.texture = load_texture(entry.texture)
49 self.renderer.add_texture(entry.texture)
50 entry.texture.renderer = self.renderer
47 51
48 52
49 cdef decode_png(loader, first_name, secondary_name): 53 cdef decode_png(loader, first_name, secondary_name):
50 image_file = load_png(loader.get_file(os.path.basename(first_name))) 54 image_file = load_png(loader.get_file(os.path.basename(first_name)))
51 width, height = image_file.width, image_file.height 55 width, height = image_file.width, image_file.height