changeset 582:6e79756b7f42

Don’t call gl*DebugGroup if it isn’t exposed by the driver.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 05 Oct 2014 17:46:51 +0200
parents cb8a443bc046
children 47cf4e3d159d
files pytouhou/ui/opengl/backend.pxd pytouhou/ui/opengl/backend.pyx pytouhou/ui/opengl/background.pyx pytouhou/ui/opengl/gamerenderer.pyx pytouhou/ui/opengl/renderer.pyx pytouhou/ui/opengl/shader.pyx pytouhou/ui/opengl/texture.pyx
diffstat 7 files changed, 99 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/ui/opengl/backend.pxd	Sun Sep 07 13:26:41 2014 +0200
+++ b/pytouhou/ui/opengl/backend.pxd	Sun Oct 05 17:46:51 2014 +0200
@@ -6,5 +6,6 @@
 cdef int minor
 cdef int double_buffer
 cdef bint is_legacy
+cdef bint use_debug_group
 cdef bint use_vao
 cdef str shader_header
--- a/pytouhou/ui/opengl/backend.pyx	Sun Sep 07 13:26:41 2014 +0200
+++ b/pytouhou/ui/opengl/backend.pyx	Sun Oct 05 17:46:51 2014 +0200
@@ -12,7 +12,7 @@
 
 
 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 @@
 
     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 @@
     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 @@
         glEnableClientState(GL_COLOR_ARRAY)
         glEnableClientState(GL_VERTEX_ARRAY)
         glEnableClientState(GL_TEXTURE_COORD_ARRAY)
-    glPopDebugGroup()
+
+    if use_debug_group:
+        glPopDebugGroup()
 
     return window
--- a/pytouhou/ui/opengl/background.pyx	Sun Sep 07 13:26:41 2014 +0200
+++ b/pytouhou/ui/opengl/background.pyx	Sun Oct 05 17:46:51 2014 +0200
@@ -26,7 +26,7 @@
           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 @@
 
     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 @@
                 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 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 @@
             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 @@
             self.vertex_buffer = <Vertex*> realloc(vertex_buffer, nb_vertices * sizeof(Vertex))
             self.indices = <GLushort*> 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 @@
             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()
--- a/pytouhou/ui/opengl/gamerenderer.pyx	Sun Sep 07 13:26:41 2014 +0200
+++ b/pytouhou/ui/opengl/gamerenderer.pyx	Sun Oct 05 17:46:51 2014 +0200
@@ -28,7 +28,7 @@
 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 @@
         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 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 @@
             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 @@
 
         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(<GLfloat*>self.interface_mvp)
@@ -269,4 +278,6 @@
         self.render_elements(elements)
         for label in labels:
             label.changed = False
-        glPopDebugGroup()
+
+        if use_debug_group:
+            glPopDebugGroup()
--- a/pytouhou/ui/opengl/renderer.pyx	Sun Sep 07 13:26:41 2014 +0200
+++ b/pytouhou/ui/opengl/renderer.pyx	Sun Oct 05 17:46:51 2014 +0200
@@ -40,7 +40,7 @@
 
 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 @@
         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 @@
                 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 @@
 
             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 @@
 
         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 @@
             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 @@
         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 @@
 
         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 @@
             glBindVertexArray(0)
         else:
             glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)
-        glPopDebugGroup()
+
+        if use_debug_group:
+            glPopDebugGroup()
 
 
 cdef class Framebuffer:
@@ -332,7 +347,8 @@
         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 @@
         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)
--- a/pytouhou/ui/opengl/shader.pyx	Sun Sep 07 13:26:41 2014 +0200
+++ b/pytouhou/ui/opengl/shader.pyx	Sun Oct 05 17:46:51 2014 +0200
@@ -19,7 +19,7 @@
           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 @@
     # 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 @@
         # 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
--- a/pytouhou/ui/opengl/texture.pyx	Sun Sep 07 13:26:41 2014 +0200
+++ b/pytouhou/ui/opengl/texture.pyx	Sun Oct 05 17:46:51 2014 +0200
@@ -24,6 +24,8 @@
 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 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 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 @@
 
                 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):