]> git.cworth.org Git - fips/commitdiff
Avoid inserting timer queries while constructing a display list
authorCarl Worth <cworth@cworth.org>
Fri, 24 May 2013 18:11:15 +0000 (11:11 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 30 May 2013 20:09:57 +0000 (13:09 -0700)
We only want to time actual drawing operations. When between glNewList
and glEndList, calls that look like drawing operations are not really,
instead these are just calls that are being recorded to be later
executed with glCallList. (And it won't work to put our timer queries
inside the display list.)

So, track when we are within glNewList/glEndList and don't add timer
queries.  Instead, we will time these operations as a whole with a
timer query around the glCallList call itself.

glwrap.c
libfips.sym

index a90ef8c4707b9f67f13de51495534aa6d6d5258a..8e8b64d193194aa8ffd7a127e00d59448d8f0a36 100644 (file)
--- a/glwrap.c
+++ b/glwrap.c
@@ -47,6 +47,8 @@
 
 #include "dlwrap.h"
 
+static int inside_new_list = 0;
+
 void *
 glwrap_lookup (char *name)
 {
@@ -65,13 +67,17 @@ glwrap_lookup (char *name)
        return dlwrap_real_dlsym (libgl_handle, name);
 }
 
-/* Execute a glBegineQuery/glEndQuery pair around an OpenGL call. */
-#define TIMED_DEFER(function,...) do {                 \
-       unsigned counter;                               \
-       counter = metrics_add_counter ();               \
-       glBeginQuery (GL_TIME_ELAPSED, counter);        \
-       GLWRAP_DEFER(function, __VA_ARGS__);            \
-       glEndQuery (GL_TIME_ELAPSED);                   \
+/* Execute a glBeginQuery/glEndQuery pair around an OpenGL call. */
+#define TIMED_DEFER(function,...) do {                                 \
+       if (! inside_new_list) {                                        \
+               unsigned counter;                                       \
+               counter = metrics_add_counter ();                       \
+               glBeginQuery (GL_TIME_ELAPSED, counter);                \
+       }                                                               \
+       GLWRAP_DEFER(function, __VA_ARGS__);                            \
+       if (! inside_new_list) {                                        \
+               glEndQuery (GL_TIME_ELAPSED);                           \
+       }                                                               \
 } while (0);
 
 /* Thanks to apitrace source code for the list of OpenGL draw calls. */
@@ -358,6 +364,22 @@ glEnd (void)
        }
 }
 
+/* And we need to track display lists to avoid inserting queries
+ * inside the list while it's being constructed. */
+void
+glNewList (GLuint list, GLenum mode)
+{
+       inside_new_list = 1;
+       GLWRAP_DEFER (glNewList, list, mode);
+}
+
+void
+glEndList (void)
+{
+       GLWRAP_DEFER (glEndList);
+       inside_new_list = 0;
+}
+
 void
 glDrawPixels (GLsizei width, GLsizei height, GLenum format,
              GLenum type, const GLvoid *pixels)
index 6ad13377293c4210102fc31e85d46a48caa6542a..f703cb761039ec1c685bbc6c0041bb557ba295d5 100644 (file)
@@ -36,6 +36,8 @@ global:
        glClear;
        glBegin;
        glEnd;
+       glNewList;
+       glEndList;
        glDrawPixels;
        glBlitFramebuffer;
        glBlitFramebufferEXT;