Mercurial > touhou
comparison pytouhou/ui/opengl/renderer.pyx @ 593:974decb8df4f
Only selects between GL_TRIANGLE_STRIP and GL_TRIANGLES once, in the backend.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 16 Oct 2014 21:40:54 +0200 |
parents | e15672733c93 |
children | 3c2f96f1d715 |
comparison
equal
deleted
inserted
replaced
592:19d930f9e3f0 | 593:974decb8df4f |
---|---|
20 (glVertexPointer, glTexCoordPointer, glColorPointer, | 20 (glVertexPointer, glTexCoordPointer, glColorPointer, |
21 glVertexAttribPointer, glEnableVertexAttribArray, glBlendFunc, | 21 glVertexAttribPointer, glEnableVertexAttribArray, glBlendFunc, |
22 glBindTexture, glDrawElements, glBindBuffer, glBufferData, | 22 glBindTexture, glDrawElements, glBindBuffer, glBufferData, |
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, GL_TRIANGLES, | 25 GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_TEXTURE_2D, glGenBuffers, |
26 GL_TRIANGLE_STRIP, glGenBuffers, glDeleteBuffers, | 26 glDeleteBuffers, GLuint, glDeleteTextures, glGenVertexArrays, |
27 GLuint, glDeleteTextures, glGenVertexArrays, glDeleteVertexArrays, | 27 glDeleteVertexArrays, glBindVertexArray, glPushDebugGroup, |
28 glBindVertexArray, glPushDebugGroup, GL_DEBUG_SOURCE_APPLICATION, | 28 GL_DEBUG_SOURCE_APPLICATION, glPopDebugGroup) |
29 glPopDebugGroup) | |
30 | 29 |
31 from pytouhou.lib.sdl import SDLError | 30 from pytouhou.lib.sdl import SDLError |
32 | 31 |
33 from pytouhou.game.element cimport Element | 32 from pytouhou.game.element cimport Element |
34 from .sprite cimport get_sprite_rendering_data | 33 from .sprite cimport get_sprite_rendering_data |
35 from .backend cimport is_legacy, use_debug_group, use_vao, use_primitive_restart | 34 from .backend cimport primitive_mode, is_legacy, use_debug_group, use_vao, use_primitive_restart |
36 | 35 |
37 from pytouhou.utils.helpers import get_logger | 36 from pytouhou.utils.helpers import get_logger |
38 | 37 |
39 logger = get_logger(__name__) | 38 logger = get_logger(__name__) |
40 | 39 |
211 | 210 |
212 if blendfunc != previous_blendfunc: | 211 if blendfunc != previous_blendfunc: |
213 glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc]) | 212 glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc]) |
214 if texture != previous_texture: | 213 if texture != previous_texture: |
215 glBindTexture(GL_TEXTURE_2D, self.textures[texture]) | 214 glBindTexture(GL_TEXTURE_2D, self.textures[texture]) |
216 glDrawElements(GL_TRIANGLE_STRIP if use_primitive_restart else GL_TRIANGLES, nb_indices, GL_UNSIGNED_SHORT, self.indices[texture][blendfunc]) | 215 glDrawElements(primitive_mode, nb_indices, GL_UNSIGNED_SHORT, self.indices[texture][blendfunc]) |
217 | 216 |
218 previous_blendfunc = blendfunc | 217 previous_blendfunc = blendfunc |
219 previous_texture = texture | 218 previous_texture = texture |
220 | 219 |
221 glBindTexture(GL_TEXTURE_2D, 0) | 220 glBindTexture(GL_TEXTURE_2D, 0) |
229 | 228 |
230 cdef void render_quads(self, rects, colors, GLuint texture): | 229 cdef void render_quads(self, rects, colors, GLuint texture): |
231 # There is nothing that batch more than two quads on the same texture, currently. | 230 # There is nothing that batch more than two quads on the same texture, currently. |
232 cdef Vertex buf[8] | 231 cdef Vertex buf[8] |
233 cdef unsigned short indices[12] | 232 cdef unsigned short indices[12] |
234 indices[:] = [0, 1, 2, 2, 3, 0, 4, 5, 6, 6, 7, 4] | 233 if use_primitive_restart: |
234 indices[:] = [0, 1, 2, 3, 0xffff, 4, 5, 6, 7, 0, 0, 0] | |
235 else: | |
236 indices[:] = [0, 1, 2, 2, 3, 0, 4, 5, 6, 6, 7, 4] | |
235 | 237 |
236 length = len(rects) | 238 length = len(rects) |
237 assert length == len(colors) | 239 assert length == len(colors) |
238 | 240 |
239 for i, r in enumerate(rects): | 241 for i, r in enumerate(rects): |
259 if use_vao: | 261 if use_vao: |
260 glBindVertexArray(self.vao) | 262 glBindVertexArray(self.vao) |
261 else: | 263 else: |
262 self.set_state() | 264 self.set_state() |
263 | 265 |
266 nb_indices = 5 * length - 1 if use_primitive_restart else 6 * length | |
264 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) | 267 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) |
265 glBindTexture(GL_TEXTURE_2D, texture) | 268 glBindTexture(GL_TEXTURE_2D, texture) |
266 glDrawElements(GL_TRIANGLES, 6 * length, GL_UNSIGNED_SHORT, indices) | 269 glDrawElements(primitive_mode, nb_indices, GL_UNSIGNED_SHORT, indices) |
267 | 270 |
268 if use_debug_group: | 271 if use_debug_group: |
269 glPopDebugGroup() | 272 glPopDebugGroup() |