]> git.cworth.org Git - apitrace/blobdiff - glretrace_main.cpp
Use CPack for packaging.
[apitrace] / glretrace_main.cpp
index 1f3e594c0cbc96f75b072abeea525d71b84f2cc7..e8567dc53ad5125a54511e107e9e5d6684dc8162 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:
@@ -103,7 +106,7 @@ checkGlError(void) {
 static void snapshot(Image::Image &image) {
     GLint drawbuffer = double_buffer ? GL_BACK : GL_FRONT;
     GLint readbuffer = double_buffer ? GL_BACK : GL_FRONT;
-    glGetIntegerv(GL_READ_BUFFER, &drawbuffer);
+    glGetIntegerv(GL_DRAW_BUFFER, &drawbuffer);
     glGetIntegerv(GL_READ_BUFFER, &readbuffer);
     glReadBuffer(drawbuffer);
     glReadPixels(0, 0, image.width, image.height, GL_RGBA, GL_UNSIGNED_BYTE, image.pixels);
@@ -112,14 +115,14 @@ static void snapshot(Image::Image &image) {
 }
 
 
-static void frame_complete(void) {
+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();
 }
 
 
@@ -161,39 +157,19 @@ static void display(void) {
     while ((call = parser.parse_call())) {
         const std::string &name = call->name();
 
-        if ((name[0] == 'w' && name[1] == 'g' && name[2] == 'l') ||
-            (name[0] == 'g' && name[1] == 'l' && name[2] == 'X')) {
-            // XXX: We ignore the majority of the OS-specific calls for now
-            if (name == "glXSwapBuffers" ||
-                name == "wglSwapBuffers") {
-                if (retrace::verbosity >= 1) {
-                    std::cout << *call;
-                    std::cout.flush();
-                };
-                frame_complete();
-                if (double_buffer)
-                    drawable->swapBuffers();
-                else
-                    glFlush();
-            } else if (name == "glXMakeCurrent" ||
-                       name == "wglMakeCurrent") {
-                glFlush();
-                if (!double_buffer) {
-                    frame_complete();
-                }
-            } else {
-                continue;
-            }
+        if (retrace::verbosity >= 1) {
+            std::cout << *call;
+            std::cout.flush();
         }
 
-        if (name == "glFlush") {
-            glFlush();
-            if (!double_buffer) {
-                frame_complete();
-            }
+        if (name[0] == 'w' && name[1] == 'g' && name[2] == 'l') {
+            glretrace::retrace_call_wgl(*call);
+        }
+        else if (name[0] == 'g' && name[1] == 'l' && name[2] == 'X') {
+            glretrace::retrace_call_glx(*call);
+        } else {
+            retrace::retrace_call(*call);
         }
-        
-        retrace::retrace_call(*call);
 
         if (!insideGlBeginEnd && call->no >= dump_state) {
             state_dump(std::cout);