Mercurial > touhou
changeset 397:c5ba11ede097
Don’t duplicate values in sprite rendering data.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 06 Feb 2013 21:41:05 +0100 |
parents | 34a91f918e7c |
children | 8d252cdb495f |
files | pytouhou/ui/background.pyx pytouhou/ui/renderer.pyx pytouhou/ui/sprite.pyx |
diffstat | 3 files changed, 14 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/pytouhou/ui/background.pyx +++ b/pytouhou/ui/background.pyx @@ -36,11 +36,11 @@ cpdef object get_background_rendering_da for ox, oy, oz, model_id, model in background.object_instances: for ox2, oy2, oz2, width_override, height_override, sprite in model: #TODO: view frustum culling - key, (vertices2, uvs2, colors2) = get_sprite_rendering_data(sprite) + key, (vertices2, (left, right, bottom, top), colors2) = get_sprite_rendering_data(sprite) vertices.extend([(x + ox + ox2, y + oy + oy2, z + oz + oz2) for x, y, z in vertices2]) - uvs.extend(uvs2) - colors.extend(colors2) + uvs.extend((left, bottom, right, bottom, right, top, left, top)) + colors.extend(colors2 * 4) nb_vertices = len(vertices) vertices_s = pack(str(3 * nb_vertices) + 'f', *chain(*vertices))
--- a/pytouhou/ui/renderer.pyx +++ b/pytouhou/ui/renderer.pyx @@ -70,12 +70,12 @@ cdef class Renderer: # Pack data in buffer (x1, y1, z1), (x2, y2, z2), (x3, y3, z3), (x4, y4, z4) = vertices - r1, g1, b1, a1, r2, g2, b2, a2, r3, g3, b3, a3, r4, g4, b4, a4 = colors - u1, v1, u2, v2, u3, v3, u4, v4 = uvs - self.vertex_buffer[nb_vertices] = Vertex(x1 + ox, y1 + oy, z1, u1, v1, r1, g1, b1, a1) - self.vertex_buffer[nb_vertices+1] = Vertex(x2 + ox, y2 + oy, z2, u2, v2, r2, g2, b2, a2) - self.vertex_buffer[nb_vertices+2] = Vertex(x3 + ox, y3 + oy, z3, u3, v3, r3, g3, b3, a3) - self.vertex_buffer[nb_vertices+3] = Vertex(x4 + ox, y4 + oy, z4, u4, v4, r4, g4, b4, a4) + left, right, bottom, top = uvs + r, g, b, a = colors + self.vertex_buffer[nb_vertices] = Vertex(x1 + ox, y1 + oy, z1, left, bottom, r, g, b, a) + self.vertex_buffer[nb_vertices+1] = Vertex(x2 + ox, y2 + oy, z2, right, bottom, r, g, b, a) + self.vertex_buffer[nb_vertices+2] = Vertex(x3 + ox, y3 + oy, z3, right, top, r, g, b, a) + self.vertex_buffer[nb_vertices+3] = Vertex(x4 + ox, y4 + oy, z4, left, top, r, g, b, a) # Add indices index = nb_vertices
--- a/pytouhou/ui/sprite.pyx +++ b/pytouhou/ui/sprite.pyx @@ -59,16 +59,16 @@ cpdef object get_sprite_rendering_data(o x_1 = 1. / sprite.anm.size[0] y_1 = 1. / sprite.anm.size[1] tox, toy = sprite.texoffsets - uvs = [tx * x_1 + tox, 1. - (ty * y_1 + toy), - (tx + tw) * x_1 + tox, 1. - (ty * y_1 + toy), - (tx + tw) * x_1 + tox, 1. - ((ty + th) * y_1 + toy), - tx * x_1 + tox, 1. - ((ty + th) * y_1 + toy)] + uvs = (tx * x_1 + tox, + (tx + tw) * x_1 + tox, + 1. - (ty * y_1 + toy), + 1. - ((ty + th) * y_1 + toy)) (x1, x2 , x3, x4), (y1, y2, y3, y4), (z1, z2, z3, z4), _ = vertmat.data key = sprite.anm.texture, sprite.blendfunc r, g, b = sprite.color - values = ((x1, y1, z1), (x2, y2, z2), (x3, y3, z3), (x4, y4, z4)), uvs, [r, g, b, sprite.alpha] * 4 + values = ((x1, y1, z1), (x2, y2, z2), (x3, y3, z3), (x4, y4, z4)), uvs, (r, g, b, sprite.alpha) sprite._rendering_data = key, values sprite.changed = False