+ View view(doc, scr, bounds, c);
+ if (input != NULL)
+ scr.RenderBMP(input);
+ view.Render();
+ if (output != NULL)
+ scr.ScreenShot(output);
+ scr.Present();
+}
+
+// It is the only way.
+// Dear god what have I done
+void RatCatcher(int x, int y, int buttons, int wheel, Screen * scr, View * view)
+{
+ static bool oldButtonDown = false;
+ static int oldx, oldy;
+ if (buttons == 3 && !oldButtonDown)
+ {
+ oldButtonDown = true;
+ view->ToggleGPUTransform();
+ oldx = x;
+ oldy = y;
+ return;
+ }
+ if (buttons == 2 && !oldButtonDown)
+ {
+ oldButtonDown = true;
+ view->ToggleGPURendering();
+ oldx = x;
+ oldy = y;
+ }
+ if (buttons && !oldButtonDown)
+ {
+ // We're beginning a drag.
+ oldButtonDown = true;
+ oldx = x;
+ oldy = y;
+ scr->SetMouseCursor(Screen::CursorMove);
+ }
+ if (buttons)
+ {
+ view->Translate(Real(oldx-x)/Real(scr->ViewportWidth()), Real(oldy-y)/Real(scr->ViewportHeight()));
+ }
+ else
+ {
+ oldButtonDown = false;
+ scr->SetMouseCursor(Screen::CursorArrow);
+ }
+ oldx = x;
+ oldy = y;
+
+ if (wheel)
+ {
+ view->ScaleAroundPoint(Real(x)/Real(scr->ViewportWidth()),Real(y)/Real(scr->ViewportHeight()), Real(expf(-wheel/20.f)));
+ }
+}
+
+
+inline void MainLoop(Document & doc, Screen & scr, View & view, int max_frames = -1)
+{
+ // order is important... segfaults occur when screen (which inits GL) is not constructed first -_-
+ DebugScript script;
+
+ scr.DebugFontInit("fonts/DejaVuSansMono.ttf");
+ scr.SetMouseHandler(RatCatcher);
+
+ if (script_filename)
+ {
+ script.Load(script_filename);
+ }
+
+ double total_cpu_time = 0;
+ double total_gpu_time = 0;
+ double total_real_time = 0;
+ struct timespec real_clock_start;
+ struct timespec real_clock_now;
+ struct timespec real_clock_prev;
+ clock_gettime(CLOCK_MONOTONIC_RAW, &real_clock_start);
+ real_clock_now = real_clock_start;
+ double frames = 0;
+ double data_rate = 0; // period between data output to stdout (if <= 0 there will be no output)
+ uint64_t data_points = 0;
+ setbuf(stdout, NULL);
+ int frame_number = 0;
+ while (scr.PumpEvents() && (max_frames < 0 || frame_number++ < max_frames))