summaryrefslogtreecommitdiff
path: root/platform/default/glfw_view.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/default/glfw_view.cpp')
-rw-r--r--platform/default/glfw_view.cpp37
1 files changed, 26 insertions, 11 deletions
diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp
index 078c26feef..8453845d1e 100644
--- a/platform/default/glfw_view.cpp
+++ b/platform/default/glfw_view.cpp
@@ -15,7 +15,8 @@ void glfwError(int error, const char *description) {
assert(false);
}
-GLFWView::GLFWView(bool fullscreen_) : fullscreen(fullscreen_) {
+GLFWView::GLFWView(bool fullscreen_, bool benchmark_)
+ : fullscreen(fullscreen_), benchmark(benchmark_) {
glfwSetErrorCallback(glfwError);
std::srand(std::time(0));
@@ -28,6 +29,9 @@ GLFWView::GLFWView(bool fullscreen_) : fullscreen(fullscreen_) {
GLFWmonitor *monitor = nullptr;
if (fullscreen) {
monitor = glfwGetPrimaryMonitor();
+ auto videoMode = glfwGetVideoMode(monitor);
+ width = videoMode->width;
+ height = videoMode->height;
}
#ifdef DEBUG
@@ -56,7 +60,13 @@ GLFWView::GLFWView(bool fullscreen_) : fullscreen(fullscreen_) {
glfwSetWindowUserPointer(window, this);
glfwMakeContextCurrent(window);
- glfwSwapInterval(1);
+ if (benchmark) {
+ // Disables vsync on platforms that support it.
+ glfwSwapInterval(0);
+ } else {
+ glfwSwapInterval(1);
+ }
+
glfwSetCursorPosCallback(window, onMouseMove);
glfwSetMouseButtonCallback(window, onMouseClick);
@@ -336,7 +346,12 @@ void GLFWView::run() {
glfwWaitEvents();
const bool dirty = !clean.test_and_set();
if (dirty) {
+ const double started = glfwGetTime();
map->renderSync();
+ report(1000 * (glfwGetTime() - started));
+ if (benchmark) {
+ map->setNeedsRepaint();
+ }
map->nudgeTransitions();
}
}
@@ -373,20 +388,20 @@ void GLFWView::invalidate() {
void GLFWView::swap() {
glfwSwapBuffers(window);
- fps();
}
-void GLFWView::fps() {
- static int frames = 0;
- static double timeElapsed = 0;
-
+void GLFWView::report(float duration) {
frames++;
- double currentTime = glfwGetTime();
+ frameTime += duration;
- if (currentTime - timeElapsed >= 1) {
- mbgl::Log::Info(mbgl::Event::OpenGL, "FPS: %4.2f", frames / (currentTime - timeElapsed));
- timeElapsed = currentTime;
+ const double currentTime = glfwGetTime();
+ if (currentTime - lastReported >= 1) {
+ frameTime /= frames;
+ mbgl::Log::Info(mbgl::Event::OpenGL, "Frame time: %6.2fms (%6.2f fps)", frameTime,
+ 1000 / frameTime);
frames = 0;
+ frameTime = 0;
+ lastReported = currentTime;
}
}