]> git.cworth.org Git - apitrace/blobdiff - glretrace_main.cpp
Plugging some memory leaks
[apitrace] / glretrace_main.cpp
index a2d2bdd75fdd47808f6577cd28d992dcec22f163..a18d1cd6a472a56cd3858c87126e65f981cfd680 100644 (file)
@@ -43,7 +43,6 @@ glws::Drawable *drawable = NULL;
 glws::Context *context = NULL;
 
 int window_width = 256, window_height = 256;
-bool reshape_window = false;
 
 unsigned frame = 0;
 long long startTime = 0;
@@ -56,7 +55,7 @@ const char *snapshot_prefix = NULL;
 unsigned dump_state = ~0;
 
 void
-checkGlError(void) {
+checkGlError(int callIdx) {
     if (benchmark || insideGlBeginEnd) {
         return;
     }
@@ -66,6 +65,10 @@ checkGlError(void) {
         return;
     }
 
+    if (callIdx >= 0) {
+        std::cerr << callIdx << ": ";
+    }
+
     std::cerr << "warning: glGetError() = ";
     switch (error) {
     case GL_INVALID_ENUM:
@@ -112,14 +115,14 @@ static void snapshot(Image::Image &image) {
 }
 
 
-static void frame_complete(void) {
+static void frame_complete(unsigned call_no) {
     ++frame;
     
-    if (!reshape_window && (snapshot_prefix || compare_prefix)) {
+    if (snapshot_prefix || compare_prefix) {
         Image::Image *ref = NULL;
         if (compare_prefix) {
             char filename[PATH_MAX];
-            snprintf(filename, sizeof filename, "%s%04u.png", compare_prefix, frame);
+            snprintf(filename, sizeof filename, "%s%010u.png", compare_prefix, call_no);
             ref = Image::readPNG(filename);
             if (!ref) {
                 return;
@@ -133,25 +136,18 @@ static void frame_complete(void) {
 
         if (snapshot_prefix) {
             char filename[PATH_MAX];
-            snprintf(filename, sizeof filename, "%s%04u.png", snapshot_prefix, frame);
+            snprintf(filename, sizeof filename, "%s%010u.png", snapshot_prefix, call_no);
             if (src.writePNG(filename) && retrace::verbosity >= 0) {
                 std::cout << "Wrote " << filename << "\n";
             }
         }
 
         if (ref) {
-            std::cout << "Frame " << frame << " average precision of " << src.compare(*ref) << " bits\n";
+            std::cout << "Snapshot " << call_no << " average precision of " << src.compare(*ref) << " bits\n";
             delete ref;
         }
     }
-    
-    if (reshape_window) {
-        // XXX: doesn't quite work
-        drawable->resize(window_width, window_height);
-        reshape_window = false;
-    }
 
-    ws->processEvents();
 }
 
 
@@ -160,6 +156,7 @@ static void display(void) {
 
     while ((call = parser.parse_call())) {
         const std::string &name = call->name();
+        bool skipCall = false;
 
         if ((name[0] == 'w' && name[1] == 'g' && name[2] == 'l') ||
             (name[0] == 'g' && name[1] == 'l' && name[2] == 'X')) {
@@ -170,7 +167,7 @@ static void display(void) {
                     std::cout << *call;
                     std::cout.flush();
                 };
-                frame_complete();
+                frame_complete(call->no);
                 if (double_buffer)
                     drawable->swapBuffers();
                 else
@@ -179,21 +176,22 @@ static void display(void) {
                        name == "wglMakeCurrent") {
                 glFlush();
                 if (!double_buffer) {
-                    frame_complete();
+                    frame_complete(call->no);
                 }
-            } else {
-                continue;
             }
+            skipCall = true;
         }
 
         if (name == "glFlush") {
             glFlush();
             if (!double_buffer) {
-                frame_complete();
+                frame_complete(call->no);
             }
         }
-        
-        retrace::retrace_call(*call);
+
+        if (!skipCall) {
+            retrace::retrace_call(*call);
+        }
 
         if (!insideGlBeginEnd && call->no >= dump_state) {
             state_dump(std::cout);