]> git.cworth.org Git - fips/blobdiff - glwrap.c
Avoid inserting timer queries while constructing a display list
[fips] / glwrap.c
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)