comparison pytouhou/ui/renderer.pyx @ 426:5d7bb2fd74f7

Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 16 Jul 2013 21:11:35 +0200
parents d8630c086926
children 878273a984c4
comparison
equal deleted inserted replaced
425:1104dc2553ee 426:5d7bb2fd74f7
25 GL_UNSIGNED_SHORT, GL_INT, GL_FLOAT, GL_SRC_ALPHA, 25 GL_UNSIGNED_SHORT, GL_INT, GL_FLOAT, GL_SRC_ALPHA,
26 GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_TEXTURE_2D, GL_TRIANGLES, 26 GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_TEXTURE_2D, GL_TRIANGLES,
27 glGenBuffers) 27 glGenBuffers)
28 28
29 from .sprite cimport get_sprite_rendering_data 29 from .sprite cimport get_sprite_rendering_data
30 from .texture cimport TextureManager 30 from .texture import TextureManager
31 31
32 32
33 MAX_ELEMENTS = 640*4*3 33 MAX_ELEMENTS = 640*4*3
34 34
35 35
98 glVertexAttribPointer(1, 2, GL_FLOAT, False, sizeof(Vertex), <void*>12) 98 glVertexAttribPointer(1, 2, GL_FLOAT, False, sizeof(Vertex), <void*>12)
99 glEnableVertexAttribArray(1) 99 glEnableVertexAttribArray(1)
100 glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, True, sizeof(Vertex), <void*>20) 100 glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, True, sizeof(Vertex), <void*>20)
101 glEnableVertexAttribArray(2) 101 glEnableVertexAttribArray(2)
102 102
103 for (texture_key, blendfunc), indices in indices_by_texture.items(): 103 for (texture, blendfunc), indices in indices_by_texture.items():
104 104
105 #TODO: find a more elegent way. 105 #TODO: find a more elegent way.
106 nb_indices = len(indices) 106 nb_indices = len(indices)
107 new_indices = <unsigned short*> malloc(nb_indices * sizeof(unsigned short)) 107 new_indices = <unsigned short*> malloc(nb_indices * sizeof(unsigned short))
108 for i in xrange(nb_indices): 108 for i in xrange(nb_indices):
109 new_indices[i] = indices[i] 109 new_indices[i] = indices[i]
110 110
111 glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc]) 111 glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc])
112 glBindTexture(GL_TEXTURE_2D, self.texture_manager[texture_key]) 112 glBindTexture(GL_TEXTURE_2D, texture)
113 glDrawElements(GL_TRIANGLES, nb_indices, GL_UNSIGNED_SHORT, new_indices) 113 glDrawElements(GL_TRIANGLES, nb_indices, GL_UNSIGNED_SHORT, new_indices)
114 free(new_indices) 114 free(new_indices)
115 115
116 if not self.use_fixed_pipeline: 116 if not self.use_fixed_pipeline:
117 glBindBuffer(GL_ARRAY_BUFFER, 0) 117 glBindBuffer(GL_ARRAY_BUFFER, 0)