comparison pytouhou/ui/opengl/renderer.pyx @ 611:a6a191e371c7

Add back a GL_QUADS path for legacy applications.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 21 Dec 2014 19:15:59 +0100
parents 3c2f96f1d715
children a6af3ff86612
comparison
equal deleted inserted replaced
610:1b31169dc344 611:a6a191e371c7
23 GL_ARRAY_BUFFER, GL_DYNAMIC_DRAW, GL_UNSIGNED_BYTE, 23 GL_ARRAY_BUFFER, GL_DYNAMIC_DRAW, GL_UNSIGNED_BYTE,
24 GL_UNSIGNED_SHORT, GL_SHORT, GL_FLOAT, GL_SRC_ALPHA, 24 GL_UNSIGNED_SHORT, GL_SHORT, GL_FLOAT, GL_SRC_ALPHA,
25 GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_TEXTURE_2D, glGenBuffers, 25 GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_TEXTURE_2D, glGenBuffers,
26 glDeleteBuffers, GLuint, glDeleteTextures, glGenVertexArrays, 26 glDeleteBuffers, GLuint, glDeleteTextures, glGenVertexArrays,
27 glDeleteVertexArrays, glBindVertexArray, glPushDebugGroup, 27 glDeleteVertexArrays, glBindVertexArray, glPushDebugGroup,
28 GL_DEBUG_SOURCE_APPLICATION, glPopDebugGroup) 28 GL_DEBUG_SOURCE_APPLICATION, glPopDebugGroup, glDrawArrays)
29 29
30 from pytouhou.lib.sdl import SDLError 30 from pytouhou.lib.sdl import SDLError
31 31
32 from pytouhou.game.element cimport Element 32 from pytouhou.game.element cimport Element
33 from .sprite cimport get_sprite_rendering_data 33 from .sprite cimport get_sprite_rendering_data
159 self.vertex_buffer[nb_vertices+1] = Vertex(x2 + ox, y2 + oy, z2, 0, data.right, data.bottom, r, g, b, a) 159 self.vertex_buffer[nb_vertices+1] = Vertex(x2 + ox, y2 + oy, z2, 0, data.right, data.bottom, r, g, b, a)
160 self.vertex_buffer[nb_vertices+2] = Vertex(x4 + ox, y4 + oy, z4, 0, data.left, data.top, r, g, b, a) 160 self.vertex_buffer[nb_vertices+2] = Vertex(x4 + ox, y4 + oy, z4, 0, data.left, data.top, r, g, b, a)
161 self.vertex_buffer[nb_vertices+3] = Vertex(x3 + ox, y3 + oy, z3, 0, data.right, data.top, r, g, b, a) 161 self.vertex_buffer[nb_vertices+3] = Vertex(x3 + ox, y3 + oy, z3, 0, data.right, data.top, r, g, b, a)
162 162
163 # Add indices 163 # Add indices
164 if use_primitive_restart: 164 if is_legacy:
165 rec[next_indice] = nb_vertices
166 rec[next_indice+1] = nb_vertices + 1
167 rec[next_indice+2] = nb_vertices + 3
168 rec[next_indice+3] = nb_vertices + 2
169 self.last_indices[key] += 4
170 elif use_primitive_restart:
165 rec[next_indice] = nb_vertices 171 rec[next_indice] = nb_vertices
166 rec[next_indice+1] = nb_vertices + 1 172 rec[next_indice+1] = nb_vertices + 1
167 rec[next_indice+2] = nb_vertices + 2 173 rec[next_indice+2] = nb_vertices + 2
168 rec[next_indice+3] = nb_vertices + 3 174 rec[next_indice+3] = nb_vertices + 3
169 rec[next_indice+4] = 0xFFFF 175 rec[next_indice+4] = 0xFFFF
228 234
229 cdef void render_quads(self, rects, colors, GLuint texture) except *: 235 cdef void render_quads(self, rects, colors, GLuint texture) except *:
230 # There is nothing that batch more than two quads on the same texture, currently. 236 # There is nothing that batch more than two quads on the same texture, currently.
231 cdef Vertex buf[8] 237 cdef Vertex buf[8]
232 cdef unsigned short indices[12] 238 cdef unsigned short indices[12]
233 if use_primitive_restart: 239
234 indices[:] = [0, 1, 2, 3, 0xffff, 4, 5, 6, 7, 0, 0, 0] 240 if not is_legacy:
235 else: 241 if use_primitive_restart:
236 indices[:] = [0, 1, 2, 2, 3, 0, 4, 5, 6, 6, 7, 4] 242 indices[:] = [0, 1, 2, 3, 0xffff, 4, 5, 6, 7, 0, 0, 0]
243 else:
244 indices[:] = [0, 1, 2, 2, 3, 0, 4, 5, 6, 6, 7, 4]
237 245
238 length = len(rects) 246 length = len(rects)
239 assert length == len(colors) 247 assert length == len(colors)
240 248
241 for i, r in enumerate(rects): 249 for i, r in enumerate(rects):
261 if use_vao: 269 if use_vao:
262 glBindVertexArray(self.vao) 270 glBindVertexArray(self.vao)
263 else: 271 else:
264 self.set_state() 272 self.set_state()
265 273
266 nb_indices = 5 * length - 1 if use_primitive_restart else 6 * length
267 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) 274 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
268 glBindTexture(GL_TEXTURE_2D, texture) 275 glBindTexture(GL_TEXTURE_2D, texture)
269 glDrawElements(primitive_mode, nb_indices, GL_UNSIGNED_SHORT, indices) 276
277 if is_legacy:
278 glDrawArrays(primitive_mode, 0, 4 * length)
279 else:
280 nb_indices = 5 * length - 1 if use_primitive_restart else 6 * length
281 glDrawElements(primitive_mode, nb_indices, GL_UNSIGNED_SHORT, indices)
270 282
271 if use_debug_group: 283 if use_debug_group:
272 glPopDebugGroup() 284 glPopDebugGroup()