12 inline void OverlayBMP(Document & doc, const char * input, const char * output, const Rect & bounds = Rect(0,0,1,1), const Colour & c = Colour(0.f,0.f,0.f,1.f))
16 View view(doc, scr, bounds, c);
21 scr.ScreenShot(output);
25 inline void MainLoop(Document & doc, const Rect & bounds = Rect(0,0,1,1), const Colour & c = Colour(0.f,0.f,0.f,1.f))
27 // order is important... segfaults occur when screen (which inits GL) is not constructed first -_-
29 View view(doc,scr, bounds, c);
30 scr.DebugFontInit("DejaVuSansMono.ttf");
31 scr.SetMouseHandler([&](int x, int y, int buttons, int wheel) // [?] wtf
33 static bool oldButtonDown = false;
34 static int oldx, oldy;
35 if (buttons == 3 && !oldButtonDown)
38 view.ToggleGPUTransform();
43 if (buttons == 2 && !oldButtonDown)
46 view.ToggleGPURendering();
50 if (buttons && !oldButtonDown)
52 // We're beginning a drag.
56 scr.SetMouseCursor(Screen::CursorMove);
60 view.Translate(Real(oldx-x)/Real(scr.ViewportWidth()), Real(oldy-y)/Real(scr.ViewportHeight()));
64 oldButtonDown = false;
65 scr.SetMouseCursor(Screen::CursorArrow);
72 view.ScaleAroundPoint(Real(x)/Real(scr.ViewportWidth()),Real(y)/Real(scr.ViewportHeight()), expf(-wheel/20.f));
77 double total_cpu_time = 0;
78 double total_gpu_time = 0;
79 double total_real_time = 0;
80 struct timespec real_clock_start;
81 struct timespec real_clock_now;
82 struct timespec real_clock_prev;
83 clock_gettime(CLOCK_MONOTONIC_RAW, &real_clock_start);
84 real_clock_now = real_clock_start;
86 double data_rate = -1; // period between data output to stdout (if <= 0 there will be no output)
87 uint64_t data_points = 0;
89 while (scr.PumpEvents())
91 real_clock_prev = real_clock_now;
94 //view.ForceBoundsDirty();
95 //view.ForceBufferDirty();
96 //view.ForceRenderDirty();
98 view.Render(scr.ViewportWidth(), scr.ViewportHeight());
100 double cpu_frame = scr.GetLastFrameTimeCPU();
101 double gpu_frame = scr.GetLastFrameTimeGPU();
102 clock_gettime(CLOCK_MONOTONIC_RAW, &real_clock_now);
103 double real_frame = (real_clock_now.tv_sec - real_clock_prev.tv_sec) + 1e-9*(real_clock_now.tv_nsec - real_clock_prev.tv_nsec);
106 total_real_time += real_frame; total_cpu_time += cpu_frame; total_gpu_time += gpu_frame;
107 if (data_rate > 0 && total_real_time > data_rate*(data_points+1))
109 printf("%lu\t%f\t%f\t%f\t%f\t%f\t%f\n", (uint64_t)frames, total_real_time, total_cpu_time, total_gpu_time, real_frame, cpu_frame, gpu_frame);
112 scr.DebugFontPrintF("Rendered frame %lu\n", (uint64_t)frames);
113 scr.DebugFontPrintF("[CPU] Render took %lf ms (%lf FPS) (total %lf s, avg FPS %lf)\n", cpu_frame*1e3, 1.0/cpu_frame, total_cpu_time,frames/total_cpu_time);
114 scr.DebugFontPrintF("[GPU] Render took %lf ms (%lf FPS) (total %lf s, avg FPS %lf)\n", gpu_frame*1e3, 1.0/gpu_frame, total_gpu_time, frames/total_gpu_time);
115 scr.DebugFontPrintF("[REALTIME] Render+Present+Cruft took %lf ms (%lf FPS) (total %lf s, avg FPS %lf)\n", real_frame*1e3, 1.0/real_frame, total_real_time,frames/total_real_time);
116 scr.DebugFontPrintF("View bounds: %s\n", view.GetBounds().Str().c_str());
118 if (view.UsingGPUTransform())
120 scr.DebugFontPrint("Doing coordinate transform on the GPU.\n");
124 scr.DebugFontPrint("Doing coordinate transform on the CPU.\n");
126 if (view.UsingGPURendering())
128 scr.DebugFontPrint("Doing rendering using GPU.\n");
132 scr.DebugFontPrint("Doing rendering using CPU.\n");