diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-04-30 12:01:26 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-04-30 12:01:26 +0200 |
commit | 1216a061d3e46eae983a38e42e71115e5c9faef6 (patch) | |
tree | 7ddb57f2885072db82657dc56dff64e49e28db76 /common/glfw_view.cpp | |
parent | ddc359f006c47e2a503b616d27e22f5d29c13e5b (diff) | |
download | qtlocation-mapboxgl-1216a061d3e46eae983a38e42e71115e5c9faef6.tar.gz |
move to libuv for the rendering loop
Diffstat (limited to 'common/glfw_view.cpp')
-rw-r--r-- | common/glfw_view.cpp | 66 |
1 files changed, 14 insertions, 52 deletions
diff --git a/common/glfw_view.cpp b/common/glfw_view.cpp index d3034016fc..cfa1156a1c 100644 --- a/common/glfw_view.cpp +++ b/common/glfw_view.cpp @@ -1,39 +1,7 @@ #include "glfw_view.hpp" - -#ifndef HAVE_KQUEUE -# if defined(__APPLE__) || \ - defined(__DragonFly__) || \ - defined(__FreeBSD__) || \ - defined(__OpenBSD__) || \ - defined(__NetBSD__) -# define HAVE_KQUEUE 1 -# endif -#endif - -#ifndef HAVE_EPOLL -# if defined(__linux__) -# define HAVE_EPOLL 1 -# endif -#endif - -#if defined(HAVE_KQUEUE) || defined(HAVE_EPOLL) - -#if defined(HAVE_KQUEUE) -# include <sys/types.h> -# include <sys/event.h> -# include <sys/time.h> -#endif - -#if defined(HAVE_EPOLL) -# include <sys/epoll.h> -#endif - -#endif - - MapView::MapView(llmr::Settings &settings, bool fullscreen) - : fullscreen(fullscreen), settings(settings), map(settings) {} + : fullscreen(fullscreen), settings(settings), map(*this) {} MapView::~MapView() { glfwTerminate(); } @@ -77,20 +45,17 @@ void MapView::init() { glfwGetFramebufferSize(window, &fb_width, &fb_height); settings.load(); - map.setup(); resize(window, 0, 0); - glfwSwapInterval(1); - - map.loadSettings(); - glfwSetCursorPosCallback(window, mousemove); glfwSetMouseButtonCallback(window, mouseclick); glfwSetWindowSizeCallback(window, resize); glfwSetFramebufferSizeCallback(window, resize); glfwSetScrollCallback(window, scroll); glfwSetKeyCallback(window, key); + + glfwMakeContextCurrent(nullptr); } void MapView::key(GLFWwindow *window, int key, int /*scancode*/, int action, int mods) { @@ -152,7 +117,6 @@ void MapView::resize(GLFWwindow *window, int, int) { glfwGetFramebufferSize(window, &fb_width, &fb_height); mapView->map.resize(width, height, (float)fb_width / (float)width, fb_width, fb_height); - mapView->map.update(); } void MapView::mouseclick(GLFWwindow *window, int button, int action, int modifiers) { @@ -199,17 +163,11 @@ int MapView::run() { map.start(); while (!glfwWindowShouldClose(window)) { - if (map.clean.test_and_set() == false) { - // This branch is executed when the previous value of the "clean" - // flag is false (i.e. it is unclean == dirty). - try { - map.render(); - } - catch (std::exception &ex) { - fprintf(stderr, "exception: %s\n", ex.what()); - } + if (map.swapped.test_and_set() == false) { glfwSwapBuffers(window); + map.rendered.clear(); fps(); + map.rerender(); } glfwWaitEvents(); @@ -220,6 +178,14 @@ int MapView::run() { return 0; } +void MapView::make_active() { + glfwMakeContextCurrent(window); +} + +void MapView::swap() { + glfwPostEmptyEvent(); +} + void MapView::fps() { static int frames = 0; static double time_elapsed = 0; @@ -267,9 +233,5 @@ void show_debug_image(std::string name, const char *data, size_t width, size_t h glfwMakeContextCurrent(current_window); } -void restart() { - glfwPostEmptyEvent(); -} - } } |