comparison pytouhou/ui/opengl/renderer.pyx @ 532:dacdcca59b66

Don’t put back the rendering data into a tuple, use a specialised struct inside Sprite to pass it to the renderer.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 19 Dec 2013 21:55:26 +0100
parents c0b3f8709f74
children 63440d1e0717
comparison
equal deleted inserted replaced
531:a7dc55ad9380 532:dacdcca59b66
116 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(framebuffer_indices), framebuffer_indices, GL_STATIC_DRAW) 116 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(framebuffer_indices), framebuffer_indices, GL_STATIC_DRAW)
117 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) 117 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)
118 118
119 119
120 cdef void render_elements(self, elements): 120 cdef void render_elements(self, elements):
121 cdef int key 121 cdef Element element
122 cdef short x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, ox, oy
123 cdef float left, right, bottom, top
124 cdef unsigned char r, g, b, a
125 122
126 nb_elements = find_objects(self, elements) 123 nb_elements = find_objects(self, elements)
127 if not nb_elements: 124 if not nb_elements:
128 return 125 return
129 126
130 nb_vertices = 0 127 nb_vertices = 0
131 memset(self.last_indices, 0, sizeof(self.last_indices)) 128 memset(self.last_indices, 0, sizeof(self.last_indices))
132 129
133 for element_idx in xrange(nb_elements): 130 for element_idx in xrange(nb_elements):
134 element = <object>self.elements[element_idx] 131 element = <object>self.elements[element_idx]
135 sprite = element.sprite 132 ox, oy = <short>element.x, <short>element.y
136 ox, oy = element.x, element.y 133 data = get_sprite_rendering_data(element.sprite)
137 key, (vertices, uvs, colors) = get_sprite_rendering_data(sprite) 134 key = data.key
138 135
139 blendfunc = key & 1 136 blendfunc = key & 1
140 texture = key >> 1 137 texture = key >> 1
141 138
142 rec = self.indices[texture][blendfunc] 139 rec = self.indices[texture][blendfunc]
143 next_indice = self.last_indices[key] 140 next_indice = self.last_indices[key]
144 141
145 # Pack data in buffer 142 # Pack data in buffer
146 x1, x2, x3, x4, y1, y2, y3, y4, z1, z2, z3, z4 = vertices 143 x1, x2, x3, x4, y1, y2, y3, y4, z1, z2, z3, z4 = <short>data.pos[0], <short>data.pos[1], <short>data.pos[2], <short>data.pos[3], <short>data.pos[4], <short>data.pos[5], <short>data.pos[6], <short>data.pos[7], <short>data.pos[8], <short>data.pos[9], <short>data.pos[10], <short>data.pos[11]
147 left, right, bottom, top = uvs 144 r, g, b, a = data.color[0], data.color[1], data.color[2], data.color[3]
148 r, g, b, a = colors 145 self.vertex_buffer[nb_vertices] = Vertex(x1 + ox, y1 + oy, z1, 0, data.left, data.bottom, r, g, b, a)
149 self.vertex_buffer[nb_vertices] = Vertex(x1 + ox, y1 + oy, z1, 0, left, bottom, r, g, b, a) 146 self.vertex_buffer[nb_vertices+1] = Vertex(x2 + ox, y2 + oy, z2, 0, data.right, data.bottom, r, g, b, a)
150 self.vertex_buffer[nb_vertices+1] = Vertex(x2 + ox, y2 + oy, z2, 0, right, bottom, r, g, b, a) 147 self.vertex_buffer[nb_vertices+2] = Vertex(x3 + ox, y3 + oy, z3, 0, data.right, data.top, r, g, b, a)
151 self.vertex_buffer[nb_vertices+2] = Vertex(x3 + ox, y3 + oy, z3, 0, right, top, r, g, b, a) 148 self.vertex_buffer[nb_vertices+3] = Vertex(x4 + ox, y4 + oy, z4, 0, data.left, data.top, r, g, b, a)
152 self.vertex_buffer[nb_vertices+3] = Vertex(x4 + ox, y4 + oy, z4, 0, left, top, r, g, b, a)
153 149
154 # Add indices 150 # Add indices
155 rec[next_indice] = nb_vertices 151 rec[next_indice] = nb_vertices
156 rec[next_indice+1] = nb_vertices + 1 152 rec[next_indice+1] = nb_vertices + 1
157 rec[next_indice+2] = nb_vertices + 2 153 rec[next_indice+2] = nb_vertices + 2