comparison pytouhou/ui/renderer.pyx @ 395:43413d4ff05b

Don’t change the vertex attributes for each texture.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 06 Feb 2013 21:01:45 +0100
parents 346614f788f1
children 34a91f918e7c
comparison
equal deleted inserted replaced
394:346614f788f1 395:43413d4ff05b
80 index = nb_vertices 80 index = nb_vertices
81 rec.extend((index, index + 1, index + 2, index + 2, index + 3, index)) 81 rec.extend((index, index + 1, index + 2, index + 2, index + 3, index))
82 82
83 nb_vertices += 4 83 nb_vertices += 4
84 84
85 if self.use_fixed_pipeline:
86 glVertexPointer(3, GL_INT, sizeof(Vertex), <long> &self.vertex_buffer[0].x)
87 glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), <long> &self.vertex_buffer[0].u)
88 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), <long> &self.vertex_buffer[0].r)
89 else:
90 glVertexAttribPointer(0, 3, GL_INT, False, sizeof(Vertex), <long> &self.vertex_buffer[0].x)
91 glEnableVertexAttribArray(0)
92 glVertexAttribPointer(1, 2, GL_FLOAT, False, sizeof(Vertex), <long> &self.vertex_buffer[0].u)
93 glEnableVertexAttribArray(1)
94 glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, True, sizeof(Vertex), <long> &self.vertex_buffer[0].r)
95 glEnableVertexAttribArray(2)
96
85 for (texture_key, blendfunc), indices in indices_by_texture.items(): 97 for (texture_key, blendfunc), indices in indices_by_texture.items():
86 if self.use_fixed_pipeline:
87 glVertexPointer(3, GL_INT, sizeof(Vertex), <long> &self.vertex_buffer[0].x)
88 glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), <long> &self.vertex_buffer[0].u)
89 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), <long> &self.vertex_buffer[0].r)
90 else:
91 glVertexAttribPointer(0, 3, GL_INT, False, sizeof(Vertex), <long> &self.vertex_buffer[0].x)
92 glEnableVertexAttribArray(0)
93 glVertexAttribPointer(1, 2, GL_FLOAT, False, sizeof(Vertex), <long> &self.vertex_buffer[0].u)
94 glEnableVertexAttribArray(1)
95 glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, True, sizeof(Vertex), <long> &self.vertex_buffer[0].r)
96 glEnableVertexAttribArray(2)
97
98 nb_indices = len(indices) 98 nb_indices = len(indices)
99 indices = pack(str(nb_indices) + 'H', *indices) 99 indices = pack(str(nb_indices) + 'H', *indices)
100 glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc]) 100 glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc])
101 glBindTexture(GL_TEXTURE_2D, self.texture_manager[texture_key]) 101 glBindTexture(GL_TEXTURE_2D, self.texture_manager[texture_key])
102 glDrawElements(GL_TRIANGLES, nb_indices, GL_UNSIGNED_SHORT, indices) 102 glDrawElements(GL_TRIANGLES, nb_indices, GL_UNSIGNED_SHORT, indices)