diff pytouhou/ui/opengl/renderer.pyx @ 579:b8df946d394d

Add grouping for OpenGL calls, making traces much more readable.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 17 Aug 2014 16:16:58 +0200
parents c759b97f4f81
children 6e79756b7f42
line wrap: on
line diff
--- a/pytouhou/ui/opengl/renderer.pyx
+++ b/pytouhou/ui/opengl/renderer.pyx
@@ -33,7 +33,8 @@ from pytouhou.lib.opengl cimport \
           GL_FRAMEBUFFER_COMPLETE, glClear, GL_COLOR_BUFFER_BIT,
           GL_DEPTH_BUFFER_BIT, GLuint, glDeleteTextures,
           GL_ELEMENT_ARRAY_BUFFER, GL_STATIC_DRAW, glGenVertexArrays,
-          glDeleteVertexArrays, glBindVertexArray)
+          glDeleteVertexArrays, glBindVertexArray, glPushDebugGroup,
+          GL_DEBUG_SOURCE_APPLICATION, glPopDebugGroup)
 
 from pytouhou.lib.sdl import SDLError
 
@@ -117,6 +118,7 @@ cdef class Renderer:
         if not is_legacy:
             framebuffer_indices[:] = [0, 1, 2, 2, 3, 0]
 
+            glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Renderer creation")
             glGenBuffers(1, &self.vbo)
             glGenBuffers(1, &self.framebuffer_vbo)
             glGenBuffers(1, &self.framebuffer_ibo)
@@ -134,6 +136,7 @@ cdef class Renderer:
                 glBindVertexArray(self.framebuffer_vao)
                 self.set_framebuffer_state()
                 glBindVertexArray(0)
+            glPopDebugGroup()
 
 
     cdef void set_state(self) nogil:
@@ -204,6 +207,7 @@ cdef class Renderer:
 
             nb_vertices += 4
 
+        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)
@@ -243,6 +247,7 @@ cdef class Renderer:
 
         if not is_legacy and use_vao:
             glBindVertexArray(0)
+        glPopDebugGroup()
 
 
     cdef void render_quads(self, rects, colors, GLuint texture):
@@ -262,6 +267,7 @@ 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 is_legacy:
             glVertexPointer(3, GL_SHORT, sizeof(Vertex), &buf[0].x)
             glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &buf[0].u)
@@ -279,6 +285,7 @@ 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()
 
 
     cdef void render_framebuffer(self, Framebuffer fb):
@@ -286,6 +293,8 @@ cdef class Renderer:
 
         assert not is_legacy
 
+        glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Framebuffer drawing")
+
         glBindFramebuffer(GL_FRAMEBUFFER, 0)
         glViewport(self.x, self.y, self.width, self.height)
         glBlendFunc(GL_ONE, GL_ZERO)
@@ -313,6 +322,7 @@ cdef class Renderer:
             glBindVertexArray(0)
         else:
             glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)
+        glPopDebugGroup()
 
 
 cdef class Framebuffer:
@@ -322,6 +332,8 @@ cdef class Framebuffer:
         self.width = width
         self.height = height
 
+        glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Framebuffer creation")
+
         glGenTextures(1, &self.texture)
         glBindTexture(GL_TEXTURE_2D, self.texture)
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
@@ -346,5 +358,7 @@ cdef class Framebuffer:
         assert glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE
         glBindFramebuffer(GL_FRAMEBUFFER, 0)
 
+        glPopDebugGroup()
+
     cpdef bind(self):
         glBindFramebuffer(GL_FRAMEBUFFER, self.fbo)