From: Carl Worth <cworth@cworth.org>
Date: Fri, 24 May 2013 18:10:12 +0000 (-0700)
Subject: Avoid trying to start a timer query within glBegin/glEnd
X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=e7e5c4643bbf59b0df88356ef5c511ebe764ff58;p=fips

Avoid trying to start a timer query within glBegin/glEnd

Instead, treat the entire sequence from glBegin..glEnd as a single drawing
operation and execute the timer query around the whole thing.
---

diff --git a/glwrap.c b/glwrap.c
index beb1c97..a90ef8c 100644
--- a/glwrap.c
+++ b/glwrap.c
@@ -332,10 +332,30 @@ glClear (GLbitfield mask)
 	TIMED_DEFER (glClear, mask);
 }
 
+/* We can't just use TIMED_DEFER for glBegin/glEnd since the
+ * glBeginQuery/glEndQuery calls must both be outside
+ * glBegin/glEnd. */
+void
+glBegin (GLenum mode)
+{
+	if (! inside_new_list)
+	{
+		unsigned counter;
+		counter = metrics_add_counter ();
+		glBeginQuery (GL_TIME_ELAPSED, counter);
+	}
+
+	GLWRAP_DEFER (glBegin, mode);
+}
+
 void
 glEnd (void)
 {
-	TIMED_DEFER (glEnd,);
+	GLWRAP_DEFER (glEnd);
+
+	if (! inside_new_list) {
+		glEndQuery (GL_TIME_ELAPSED);
+	}
 }
 
 void
diff --git a/libfips.sym b/libfips.sym
index 773d9c3..6ad1337 100644
--- a/libfips.sym
+++ b/libfips.sym
@@ -34,6 +34,7 @@ global:
 	glCallList;
 	glCallLists;
 	glClear;
+	glBegin;
 	glEnd;
 	glDrawPixels;
 	glBlitFramebuffer;