# HG changeset patch # User Emmanuel Gil Peyrot # Date 1412524011 -7200 # Node ID 6e79756b7f42af44326197c8a00e10ac6b6f6974 # Parent cb8a443bc0466b003330edf50cd1064ab63181ab Don’t call gl*DebugGroup if it isn’t exposed by the driver. diff --git a/pytouhou/ui/opengl/backend.pxd b/pytouhou/ui/opengl/backend.pxd --- a/pytouhou/ui/opengl/backend.pxd +++ b/pytouhou/ui/opengl/backend.pxd @@ -6,5 +6,6 @@ cdef int major cdef int minor cdef int double_buffer cdef bint is_legacy +cdef bint use_debug_group cdef bint use_vao cdef str shader_header diff --git a/pytouhou/ui/opengl/backend.pyx b/pytouhou/ui/opengl/backend.pyx --- a/pytouhou/ui/opengl/backend.pyx +++ b/pytouhou/ui/opengl/backend.pyx @@ -12,7 +12,7 @@ GameRenderer = None def init(options): - global flavor, version, major, minor, double_buffer, is_legacy, use_vao, shader_header, GameRenderer + global flavor, version, major, minor, double_buffer, is_legacy, use_debug_group, use_vao, shader_header, GameRenderer flavor_name = options['flavor'] assert flavor_name in ('core', 'es', 'compatibility', 'legacy') @@ -27,6 +27,7 @@ def init(options): maybe_double_buffer = options['double-buffer'] double_buffer = maybe_double_buffer if maybe_double_buffer is not None else -1 + use_debug_group = (major == 4 and minor >= 3) or major > 4 use_vao = (major == 3 and minor >= 1) or major > 3 is_legacy = flavor_name == 'legacy' @@ -65,8 +66,10 @@ def create_window(title, x, y, width, he window = Window(title, x, y, width, height, flags) window.gl_create_context() + if use_debug_group: + glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "OpenGL initialisation") + # Initialize OpenGL - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "OpenGL initialisation") glEnable(GL_BLEND) if is_legacy: glEnable(GL_TEXTURE_2D) @@ -75,6 +78,8 @@ def create_window(title, x, y, width, he glEnableClientState(GL_COLOR_ARRAY) glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_TEXTURE_COORD_ARRAY) - glPopDebugGroup() + + if use_debug_group: + glPopDebugGroup() return window diff --git a/pytouhou/ui/opengl/background.pyx b/pytouhou/ui/opengl/background.pyx --- a/pytouhou/ui/opengl/background.pyx +++ b/pytouhou/ui/opengl/background.pyx @@ -26,7 +26,7 @@ from pytouhou.lib.opengl cimport \ glPushDebugGroup, GL_DEBUG_SOURCE_APPLICATION, glPopDebugGroup) from .sprite cimport get_sprite_rendering_data -from .backend cimport is_legacy, use_vao +from .backend cimport is_legacy, use_debug_group, use_vao cdef class BackgroundRenderer: @@ -46,7 +46,9 @@ cdef class BackgroundRenderer: def __init__(self): if not is_legacy: - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Background creation") + if use_debug_group: + glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Background creation") + glGenBuffers(1, &self.vbo) glGenBuffers(1, &self.ibo) @@ -55,7 +57,9 @@ cdef class BackgroundRenderer: glBindVertexArray(self.vao) self.set_state() glBindVertexArray(0) - glPopDebugGroup() + + if use_debug_group: + glPopDebugGroup() cdef void set_state(self) nogil: @@ -72,7 +76,9 @@ cdef class BackgroundRenderer: cdef void render_background(self): - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Background drawing") + if use_debug_group: + glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Background drawing") + if is_legacy: indices = self.indices glVertexPointer(3, GL_FLOAT, sizeof(Vertex), &self.vertex_buffer[0].x) @@ -97,7 +103,9 @@ cdef class BackgroundRenderer: else: glBindBuffer(GL_ARRAY_BUFFER, 0) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) - glPopDebugGroup() + + if use_debug_group: + glPopDebugGroup() cdef void load(self, background, Renderer renderer): @@ -144,7 +152,9 @@ cdef class BackgroundRenderer: self.vertex_buffer = realloc(vertex_buffer, nb_vertices * sizeof(Vertex)) self.indices = realloc(indices, nb_indices * sizeof(GLushort)) else: - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Background uploading") + if use_debug_group: + glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Background uploading") + glBindBuffer(GL_ARRAY_BUFFER, self.vbo) glBufferData(GL_ARRAY_BUFFER, nb_vertices * sizeof(Vertex), vertex_buffer, GL_STATIC_DRAW) glBindBuffer(GL_ARRAY_BUFFER, 0) @@ -152,4 +162,6 @@ cdef class BackgroundRenderer: glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.ibo) glBufferData(GL_ELEMENT_ARRAY_BUFFER, nb_indices * sizeof(GLushort), indices, GL_STATIC_DRAW) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) - glPopDebugGroup() + + if use_debug_group: + glPopDebugGroup() diff --git a/pytouhou/ui/opengl/gamerenderer.pyx b/pytouhou/ui/opengl/gamerenderer.pyx --- a/pytouhou/ui/opengl/gamerenderer.pyx +++ b/pytouhou/ui/opengl/gamerenderer.pyx @@ -28,7 +28,7 @@ from pytouhou.utils.maths cimport perspe from pytouhou.game.text cimport NativeText, GlyphCollection from .shaders.eosd import GameShader, BackgroundShader, PassthroughShader from .renderer cimport Texture -from .backend cimport is_legacy +from .backend cimport is_legacy, use_debug_group from collections import namedtuple Rect = namedtuple('Rect', 'x y w h') @@ -94,11 +94,15 @@ cdef class GameRenderer(Renderer): self.render_interface(game.interface, game.boss) if not is_legacy: - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Scaled rendering") + if use_debug_group: + glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Scaled rendering") + self.passthrough_shader.bind() self.passthrough_shader.uniform_matrix('mvp', self.interface_mvp) self.render_framebuffer(self.framebuffer) - glPopDebugGroup() + + if use_debug_group: + glPopDebugGroup() cdef void render_game(self, Game game): @@ -109,7 +113,8 @@ cdef class GameRenderer(Renderer): cdef unsigned char fog_r, fog_g, fog_b cdef Matrix *mvp - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Game rendering") + if use_debug_group: + glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Game rendering") game_x, game_y = game.interface.game_pos glViewport(game_x, game_y, game.width, game.height) @@ -209,7 +214,9 @@ cdef class GameRenderer(Renderer): self.render_quads([rect], [(color1, color1, color2, color2)], 0) glDisable(GL_SCISSOR_TEST) - glPopDebugGroup() + + if use_debug_group: + glPopDebugGroup() cdef void render_text(self, dict texts): @@ -240,7 +247,9 @@ cdef class GameRenderer(Renderer): elements = [] - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Interface rendering") + if use_debug_group: + glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Interface rendering") + if is_legacy: glMatrixMode(GL_MODELVIEW) glLoadMatrixf(self.interface_mvp) @@ -269,4 +278,6 @@ cdef class GameRenderer(Renderer): self.render_elements(elements) for label in labels: label.changed = False - glPopDebugGroup() + + if use_debug_group: + glPopDebugGroup() diff --git a/pytouhou/ui/opengl/renderer.pyx b/pytouhou/ui/opengl/renderer.pyx --- a/pytouhou/ui/opengl/renderer.pyx +++ b/pytouhou/ui/opengl/renderer.pyx @@ -40,7 +40,7 @@ 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_vao +from .backend cimport is_legacy, use_debug_group, use_vao from pytouhou.utils.helpers import get_logger @@ -118,7 +118,9 @@ cdef class Renderer: if not is_legacy: framebuffer_indices[:] = [0, 1, 2, 2, 3, 0] - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Renderer creation") + if use_debug_group: + glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Renderer creation") + glGenBuffers(1, &self.vbo) glGenBuffers(1, &self.framebuffer_vbo) glGenBuffers(1, &self.framebuffer_ibo) @@ -136,7 +138,9 @@ cdef class Renderer: glBindVertexArray(self.framebuffer_vao) self.set_framebuffer_state() glBindVertexArray(0) - glPopDebugGroup() + + if use_debug_group: + glPopDebugGroup() cdef void set_state(self) nogil: @@ -207,7 +211,9 @@ cdef class Renderer: nb_vertices += 4 - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Elements drawing") + if use_debug_group: + glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Elements drawing") + if is_legacy: glVertexPointer(3, GL_SHORT, sizeof(Vertex), &self.vertex_buffer[0].x) glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &self.vertex_buffer[0].u) @@ -247,7 +253,9 @@ cdef class Renderer: if not is_legacy and use_vao: glBindVertexArray(0) - glPopDebugGroup() + + if use_debug_group: + glPopDebugGroup() cdef void render_quads(self, rects, colors, GLuint texture): @@ -267,7 +275,9 @@ cdef class Renderer: buf[4*i+2] = Vertex(r.x + r.w, r.y + r.h, 0, 0, 1, 1, c3.r, c3.g, c3.b, c3.a) buf[4*i+3] = Vertex(r.x, r.y + r.h, 0, 0, 0, 1, c4.r, c4.g, c4.b, c4.a) - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Quads drawing") + if use_debug_group: + glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Quads drawing") + if is_legacy: glVertexPointer(3, GL_SHORT, sizeof(Vertex), &buf[0].x) glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &buf[0].u) @@ -285,7 +295,9 @@ cdef class Renderer: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glBindTexture(GL_TEXTURE_2D, texture) glDrawElements(GL_TRIANGLES, 6 * length, GL_UNSIGNED_SHORT, indices) - glPopDebugGroup() + + if use_debug_group: + glPopDebugGroup() cdef void render_framebuffer(self, Framebuffer fb): @@ -293,7 +305,8 @@ cdef class Renderer: assert not is_legacy - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Framebuffer drawing") + if use_debug_group: + glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Framebuffer drawing") glBindFramebuffer(GL_FRAMEBUFFER, 0) glViewport(self.x, self.y, self.width, self.height) @@ -322,7 +335,9 @@ cdef class Renderer: glBindVertexArray(0) else: glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) - glPopDebugGroup() + + if use_debug_group: + glPopDebugGroup() cdef class Framebuffer: @@ -332,7 +347,8 @@ cdef class Framebuffer: self.width = width self.height = height - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Framebuffer creation") + if use_debug_group: + glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Framebuffer creation") glGenTextures(1, &self.texture) glBindTexture(GL_TEXTURE_2D, self.texture) @@ -358,7 +374,8 @@ cdef class Framebuffer: assert glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE glBindFramebuffer(GL_FRAMEBUFFER, 0) - glPopDebugGroup() + if use_debug_group: + glPopDebugGroup() cpdef bind(self): glBindFramebuffer(GL_FRAMEBUFFER, self.fbo) diff --git a/pytouhou/ui/opengl/shader.pyx b/pytouhou/ui/opengl/shader.pyx --- a/pytouhou/ui/opengl/shader.pyx +++ b/pytouhou/ui/opengl/shader.pyx @@ -19,7 +19,7 @@ from pytouhou.lib.opengl cimport \ glPushDebugGroup, GL_DEBUG_SOURCE_APPLICATION, glPopDebugGroup) from libc.stdlib cimport malloc, free -from .backend cimport shader_header +from .backend cimport shader_header, use_debug_group class GLSLException(Exception): @@ -30,7 +30,8 @@ cdef class Shader: # vert and frag take arrays of source strings the arrays will be # concattenated into one string by OpenGL def __init__(self, vert=None, frag=None): - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Program creation") + if use_debug_group: + glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Program creation") # create the program handle self.handle = glCreateProgram() @@ -53,7 +54,8 @@ cdef class Shader: # attempt to link the program self.link() - glPopDebugGroup() + if use_debug_group: + glPopDebugGroup() cdef void create_shader(self, const GLchar *string, GLenum shader_type): cdef GLint temp diff --git a/pytouhou/ui/opengl/texture.pyx b/pytouhou/ui/opengl/texture.pyx --- a/pytouhou/ui/opengl/texture.pyx +++ b/pytouhou/ui/opengl/texture.pyx @@ -24,6 +24,8 @@ from pytouhou.lib.sdl import SDLError from pytouhou.formats.thtx import Texture #TODO: perhaps define that elsewhere? from pytouhou.game.text cimport NativeText +from .backend cimport use_debug_group + import os from pytouhou.utils.helpers import get_logger @@ -38,18 +40,26 @@ cdef class TextureManager: cdef void load(self, dict anms): - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Texture loading") + if use_debug_group: + glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Texture loading") + for anm in sorted(anms.values(), key=is_ascii): - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Loading textures from ANM") + if use_debug_group: + glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Loading textures from ANM") + for entry in anm: if entry.texture is None: texture = decode_png(self.loader, entry.first_name, entry.secondary_name) elif not isinstance(entry.texture, self.texture_class): texture = entry.texture entry.texture = self.texture_class(load_texture(texture), self.renderer) + + if use_debug_group: + glPopDebugGroup() + anms.clear() + + if use_debug_group: glPopDebugGroup() - glPopDebugGroup() - anms.clear() def is_ascii(anm): @@ -66,7 +76,9 @@ cdef class FontManager: cdef void load(self, dict labels): cdef NativeText label - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Text rendering") + if use_debug_group: + glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Text rendering") + for i, label in labels.items(): if label.texture is None: try: @@ -87,7 +99,9 @@ cdef class FontManager: texture = Texture(label.width, label.height, -4, surface.pixels) label.texture = self.texture_class(load_texture(texture), self.renderer) - glPopDebugGroup() + + if use_debug_group: + glPopDebugGroup() cdef decode_png(loader, first_name, secondary_name):