comparison pytouhou/opengl/sprite.py @ 125:0313ca2c50e9

Small refactoring and massive performance improvements
author Thibaut Girka <thib@sitedethib.com>
date Sat, 10 Sep 2011 15:04:47 +0200
parents 4300a832f033
children
comparison
equal deleted inserted replaced
124:f06e96dbed4e 125:0313ca2c50e9
55 vertmat.translate(*sprite.dest_offset) 55 vertmat.translate(*sprite.dest_offset)
56 56
57 x_1 = 1. / sprite.anm.size[0] 57 x_1 = 1. / sprite.anm.size[0]
58 y_1 = 1. / sprite.anm.size[1] 58 y_1 = 1. / sprite.anm.size[1]
59 tox, toy = sprite.texoffsets 59 tox, toy = sprite.texoffsets
60 uvs = [(tx * x_1 + tox, 1. - (ty * y_1) + toy), 60 uvs = [tx * x_1 + tox, 1. - (ty * y_1) + toy,
61 ((tx + tw) * x_1 + tox, 1. - (ty * y_1) + toy), 61 (tx + tw) * x_1 + tox, 1. - (ty * y_1) + toy,
62 ((tx + tw) * x_1 + tox, 1. - ((ty + th) * y_1 + toy)), 62 (tx + tw) * x_1 + tox, 1. - ((ty + th) * y_1 + toy),
63 (tx * x_1 + tox, 1. - ((ty + th) * y_1 + toy))] 63 tx * x_1 + tox, 1. - ((ty + th) * y_1 + toy)]
64 64
65 d = vertmat.data 65 (x1, x2 , x3, x4), (y1, y2, y3, y4), (z1, z2, z3, z4), _ = vertmat.data
66 assert (d[3][0], d[3][1], d[3][2], d[3][3]) == (1., 1., 1., 1.)
67 66
68 key = (sprite.anm.first_name, sprite.anm.secondary_name), sprite.blendfunc 67 key = (sprite.anm.first_name, sprite.anm.secondary_name), sprite.blendfunc
69 values = zip(d[0], d[1], d[2]), uvs, [(sprite.color[0], sprite.color[1], sprite.color[2], sprite.alpha)] * 4 68 r, g, b = sprite.color
69 values = ((x1, y1, z1), (x2, y2, z2), (x3, y3, z3), (x4, y4, z4)), uvs, [r, g, b, sprite.alpha] * 4
70 sprite._rendering_data = key, values 70 sprite._rendering_data = key, values
71 sprite._changed = False 71 sprite._changed = False
72 72
73 return sprite._rendering_data 73 return sprite._rendering_data
74 74