Mercurial > touhou
changeset 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 | 19d930f9e3f0 |
children | 12756994a92c |
files | pytouhou/ui/opengl/backend.pxd pytouhou/ui/opengl/backend.pyx pytouhou/ui/opengl/background.pyx pytouhou/ui/opengl/renderer.pyx |
diffstat | 4 files changed, 26 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/pytouhou/ui/opengl/backend.pxd +++ b/pytouhou/ui/opengl/backend.pxd @@ -1,10 +1,12 @@ from pytouhou.lib.sdl cimport SDL_GLprofile +from pytouhou.lib.opengl cimport GLenum_mode cdef SDL_GLprofile profile cdef int major cdef int minor cdef int double_buffer cdef bint is_legacy +cdef GLenum_mode primitive_mode cdef bint use_debug_group cdef bint use_vao cdef bint use_framebuffer_blit
--- a/pytouhou/ui/opengl/backend.pyx +++ b/pytouhou/ui/opengl/backend.pyx @@ -9,7 +9,7 @@ from pytouhou.lib.opengl cimport \ glPushDebugGroup, GL_DEBUG_SOURCE_APPLICATION, glPopDebugGroup, epoxy_gl_version, epoxy_is_desktop_gl, epoxy_has_gl_extension, GL_PRIMITIVE_RESTART, glPrimitiveRestartIndex, glPixelStorei, - GL_PACK_INVERT_MESA) + GL_PACK_INVERT_MESA, GL_TRIANGLE_STRIP, GL_TRIANGLES) GameRenderer = None @@ -48,7 +48,9 @@ def init(options): def discover_features(): '''Discover which features are supported by our context.''' - global use_debug_group, use_vao, use_primitive_restart, use_pack_invert, shader_header + global use_debug_group, use_vao, use_primitive_restart, use_pack_invert + global primitive_mode + global shader_header version = epoxy_gl_version() is_desktop = epoxy_is_desktop_gl() @@ -59,6 +61,8 @@ def discover_features(): use_framebuffer_blit = (is_desktop and version >= 30) use_pack_invert = epoxy_has_gl_extension('GL_MESA_pack_invert') + primitive_mode = GL_TRIANGLE_STRIP if use_primitive_restart else GL_TRIANGLES + if is_desktop: # gl_FragColor isn’t supported anymore starting with GLSL 4.2. if version >= 42:
--- a/pytouhou/ui/opengl/background.pyx +++ b/pytouhou/ui/opengl/background.pyx @@ -20,14 +20,13 @@ from pytouhou.lib.opengl cimport \ glBindTexture, glBindBuffer, glBufferData, GL_ARRAY_BUFFER, GL_STATIC_DRAW, GL_UNSIGNED_BYTE, GL_FLOAT, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_TEXTURE_2D, glGenBuffers, glEnable, - glDisable, GL_DEPTH_TEST, glDrawElements, GL_TRIANGLES, - GL_UNSIGNED_SHORT, GL_ELEMENT_ARRAY_BUFFER, glDeleteBuffers, - glGenVertexArrays, glDeleteVertexArrays, glBindVertexArray, - glPushDebugGroup, GL_DEBUG_SOURCE_APPLICATION, glPopDebugGroup, - GL_TRIANGLE_STRIP) + glDisable, GL_DEPTH_TEST, glDrawElements, GL_UNSIGNED_SHORT, + GL_ELEMENT_ARRAY_BUFFER, glDeleteBuffers, glGenVertexArrays, + glDeleteVertexArrays, glBindVertexArray, glPushDebugGroup, + GL_DEBUG_SOURCE_APPLICATION, glPopDebugGroup) from .sprite cimport get_sprite_rendering_data -from .backend cimport is_legacy, use_debug_group, use_vao, use_primitive_restart +from .backend cimport primitive_mode, is_legacy, use_debug_group, use_vao, use_primitive_restart cdef class BackgroundRenderer: @@ -95,7 +94,7 @@ cdef class BackgroundRenderer: glEnable(GL_DEPTH_TEST) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glBindTexture(GL_TEXTURE_2D, self.texture) - glDrawElements(GL_TRIANGLE_STRIP if use_primitive_restart else GL_TRIANGLES, self.nb_indices, GL_UNSIGNED_SHORT, indices) + glDrawElements(primitive_mode, self.nb_indices, GL_UNSIGNED_SHORT, indices) glDisable(GL_DEPTH_TEST) if not is_legacy:
--- a/pytouhou/ui/opengl/renderer.pyx +++ b/pytouhou/ui/opengl/renderer.pyx @@ -22,17 +22,16 @@ from pytouhou.lib.opengl cimport \ glBindTexture, glDrawElements, glBindBuffer, glBufferData, GL_ARRAY_BUFFER, GL_DYNAMIC_DRAW, GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_FLOAT, GL_SRC_ALPHA, - GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_TEXTURE_2D, GL_TRIANGLES, - GL_TRIANGLE_STRIP, glGenBuffers, glDeleteBuffers, - GLuint, glDeleteTextures, glGenVertexArrays, glDeleteVertexArrays, - glBindVertexArray, glPushDebugGroup, GL_DEBUG_SOURCE_APPLICATION, - glPopDebugGroup) + GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_TEXTURE_2D, glGenBuffers, + glDeleteBuffers, GLuint, glDeleteTextures, glGenVertexArrays, + glDeleteVertexArrays, glBindVertexArray, glPushDebugGroup, + GL_DEBUG_SOURCE_APPLICATION, glPopDebugGroup) from pytouhou.lib.sdl import SDLError from pytouhou.game.element cimport Element from .sprite cimport get_sprite_rendering_data -from .backend cimport is_legacy, use_debug_group, use_vao, use_primitive_restart +from .backend cimport primitive_mode, is_legacy, use_debug_group, use_vao, use_primitive_restart from pytouhou.utils.helpers import get_logger @@ -213,7 +212,7 @@ cdef class Renderer: glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc]) if texture != previous_texture: glBindTexture(GL_TEXTURE_2D, self.textures[texture]) - glDrawElements(GL_TRIANGLE_STRIP if use_primitive_restart else GL_TRIANGLES, nb_indices, GL_UNSIGNED_SHORT, self.indices[texture][blendfunc]) + glDrawElements(primitive_mode, nb_indices, GL_UNSIGNED_SHORT, self.indices[texture][blendfunc]) previous_blendfunc = blendfunc previous_texture = texture @@ -231,7 +230,10 @@ cdef class Renderer: # There is nothing that batch more than two quads on the same texture, currently. cdef Vertex buf[8] cdef unsigned short indices[12] - indices[:] = [0, 1, 2, 2, 3, 0, 4, 5, 6, 6, 7, 4] + if use_primitive_restart: + indices[:] = [0, 1, 2, 3, 0xffff, 4, 5, 6, 7, 0, 0, 0] + else: + indices[:] = [0, 1, 2, 2, 3, 0, 4, 5, 6, 6, 7, 4] length = len(rects) assert length == len(colors) @@ -261,9 +263,10 @@ cdef class Renderer: else: self.set_state() + nb_indices = 5 * length - 1 if use_primitive_restart else 6 * length glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glBindTexture(GL_TEXTURE_2D, texture) - glDrawElements(GL_TRIANGLES, 6 * length, GL_UNSIGNED_SHORT, indices) + glDrawElements(primitive_mode, nb_indices, GL_UNSIGNED_SHORT, indices) if use_debug_group: glPopDebugGroup()