X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=glretrace_main.cpp;h=3a900927a128a3d6d46ec0055002d03f964f7fe6;hb=f682e19bee94eb69a5cfc8b2db17d7f1ebb10c2b;hp=7f7b876d5a6231021458d24408caca5605a905a4;hpb=0568897c39dca167706825219e284a396be956a7;p=apitrace diff --git a/glretrace_main.cpp b/glretrace_main.cpp index 7f7b876..3a90092 100644 --- a/glretrace_main.cpp +++ b/glretrace_main.cpp @@ -35,7 +35,7 @@ namespace glretrace { -bool double_buffer = false; +bool double_buffer = true; bool insideGlBeginEnd = false; Trace::Parser parser; glws::WindowSystem *ws = NULL; @@ -50,6 +50,7 @@ bool wait = false; bool benchmark = false; const char *compare_prefix = NULL; const char *snapshot_prefix = NULL; +enum frequency snapshot_frequency = FREQUENCY_NEVER; unsigned dump_state = ~0; @@ -129,10 +130,16 @@ void snapshot(unsigned call_no) { } if (snapshot_prefix) { - char filename[PATH_MAX]; - snprintf(filename, sizeof filename, "%s%010u.png", snapshot_prefix, call_no); - if (src->writePNG(filename) && retrace::verbosity >= 0) { - std::cout << "Wrote " << filename << "\n"; + if (snapshot_prefix[0] == '-' && snapshot_prefix[1] == 0) { + char comment[21]; + snprintf(comment, sizeof comment, "%u", call_no); + src->writePNM(std::cout, comment); + } else { + char filename[PATH_MAX]; + snprintf(filename, sizeof filename, "%s%010u.png", snapshot_prefix, call_no); + if (src->writePNG(filename) && retrace::verbosity >= 0) { + std::cout << "Wrote " << filename << "\n"; + } } } @@ -148,11 +155,15 @@ void snapshot(unsigned call_no) { void frame_complete(unsigned call_no) { ++frame; - snapshot(call_no); + if (snapshot_frequency == FREQUENCY_FRAME || + snapshot_frequency == FREQUENCY_FRAMEBUFFER) { + snapshot(call_no); + } } static void display(void) { + startTime = OS::GetTime(); Trace::Call *call; while ((call = parser.parse_call())) { @@ -211,10 +222,12 @@ static void usage(void) { "Usage: glretrace [OPTION] TRACE\n" "Replay TRACE.\n" "\n" - " -b benchmark (no glgeterror; no messages)\n" + " -b benchmark mode (no error checking or warning messages)\n" " -c PREFIX compare against snapshots\n" - " -db use a double buffer visual\n" - " -s PREFIX take snapshots\n" + " -db use a double buffer visual (default)\n" + " -sb use a single buffer visual\n" + " -s PREFIX take snapshots; `-` for PNM stdout output\n" + " -S FREQUENCY snapshot frequency: frame (default), framebuffer, or draw\n" " -v verbose output\n" " -D CALLNO dump state at specific call no\n" " -w wait on final frame\n"; @@ -239,16 +252,43 @@ int main(int argc, char **argv) retrace::verbosity = -1; } else if (!strcmp(arg, "-c")) { compare_prefix = argv[++i]; + if (snapshot_frequency == FREQUENCY_NEVER) { + snapshot_frequency = FREQUENCY_FRAME; + } } else if (!strcmp(arg, "-D")) { dump_state = atoi(argv[++i]); retrace::verbosity = -2; } else if (!strcmp(arg, "-db")) { double_buffer = true; + } else if (!strcmp(arg, "-sb")) { + double_buffer = false; } else if (!strcmp(arg, "--help")) { usage(); return 0; } else if (!strcmp(arg, "-s")) { snapshot_prefix = argv[++i]; + if (snapshot_frequency == FREQUENCY_NEVER) { + snapshot_frequency = FREQUENCY_FRAME; + } + if (snapshot_prefix[0] == '-' && snapshot_prefix[1] == 0) { + retrace::verbosity = -2; + } + } else if (!strcmp(arg, "-S")) { + arg = argv[++i]; + if (!strcmp(arg, "frame")) { + snapshot_frequency = FREQUENCY_FRAME; + } else if (!strcmp(arg, "framebuffer")) { + snapshot_frequency = FREQUENCY_FRAMEBUFFER; + } else if (!strcmp(arg, "draw")) { + snapshot_frequency = FREQUENCY_DRAW; + } else { + std::cerr << "error: unknown frequency " << arg << "\n"; + usage(); + return 1; + } + if (snapshot_prefix == NULL) { + snapshot_prefix = ""; + } } else if (!strcmp(arg, "-v")) { ++retrace::verbosity; } else if (!strcmp(arg, "-w")) { @@ -264,11 +304,14 @@ int main(int argc, char **argv) visual = ws->createVisual(double_buffer); for ( ; i < argc; ++i) { - if (parser.open(argv[i])) { - startTime = OS::GetTime(); - display(); - parser.close(); + if (!parser.open(argv[i])) { + std::cerr << "error: failed to open " << argv[i] << "\n"; + return 1; } + + display(); + + parser.close(); } return 0;