diff options
Diffstat (limited to 'platform/default/glfw_view.cpp')
-rw-r--r-- | platform/default/glfw_view.cpp | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp index 044181e8c8..47551d786f 100644 --- a/platform/default/glfw_view.cpp +++ b/platform/default/glfw_view.cpp @@ -4,6 +4,7 @@ #include <mbgl/style/transition_options.hpp> #include <mbgl/gl/gl.hpp> #include <mbgl/gl/extension.hpp> +#include <mbgl/gl/context.hpp> #include <mbgl/platform/log.hpp> #include <mbgl/platform/platform.hpp> #include <mbgl/util/string.hpp> @@ -124,13 +125,21 @@ GLFWView::~GLFWView() { glfwTerminate(); } -void GLFWView::initialize(mbgl::Map *map_) { - View::initialize(map_); +void GLFWView::setMap(mbgl::Map *map_) { + map = map_; map->addAnnotationIcon("default_marker", makeSpriteImage(22, 22, 1)); } +void GLFWView::updateViewBinding() { + getContext().bindFramebuffer.setCurrentValue(0); + getContext().viewport.setCurrentValue( + { 0, 0, static_cast<uint16_t>(fbWidth), static_cast<uint16_t>(fbHeight) }); +} + void GLFWView::bind() { - MBGL_CHECK_ERROR(glBindFramebuffer(GL_FRAMEBUFFER, 0)); + getContext().bindFramebuffer = 0; + getContext().viewport = { 0, 0, static_cast<uint16_t>(fbWidth), + static_cast<uint16_t>(fbHeight) }; } void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action, int mods) { @@ -365,8 +374,8 @@ void GLFWView::onWindowResize(GLFWwindow *window, int width, int height) { GLFWView *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window)); view->width = width; view->height = height; - - view->map->update(mbgl::Update::Dimensions); + view->map->setSize({{ static_cast<uint16_t>(view->width), + static_cast<uint16_t>(view->height) }}); } void GLFWView::onFramebufferResize(GLFWwindow *window, int width, int height) { @@ -374,7 +383,11 @@ void GLFWView::onFramebufferResize(GLFWwindow *window, int width, int height) { view->fbWidth = width; view->fbHeight = height; - view->map->update(mbgl::Update::Repaint); + // This is only triggered when the framebuffer is resized, but not the window. It can + // happen when you move the window between screens with a different pixel ratio. + // We are forcing a repaint my invalidating the view, which triggers a rerender with the + // new framebuffer dimensions. + view->invalidate(); } void GLFWView::onMouseClick(GLFWwindow *window, int button, int action, int modifiers) { @@ -440,15 +453,15 @@ void GLFWView::run() { const double started = glfwGetTime(); glfwMakeContextCurrent(window); - glViewport(0, 0, fbWidth, fbHeight); - map->render(); + updateViewBinding(); + map->render(*this); glfwSwapBuffers(window); report(1000 * (glfwGetTime() - started)); if (benchmark) { - map->update(mbgl::Update::Repaint); + invalidate(); } dirty = false; |