summaryrefslogtreecommitdiff
path: root/platform/qt/src/qmapboxgl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/qt/src/qmapboxgl.cpp')
-rw-r--r--platform/qt/src/qmapboxgl.cpp84
1 files changed, 51 insertions, 33 deletions
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index 73a1771908..edda1f9599 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -6,6 +6,7 @@
#include <mbgl/annotation/annotation.hpp>
#include <mbgl/gl/gl.hpp>
+#include <mbgl/gl/context.hpp>
#include <mbgl/map/camera.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/style/conversion.hpp>
@@ -23,6 +24,7 @@
#if QT_VERSION >= 0x050000
#include <QGuiApplication>
#include <QWindow>
+#include <QOpenGLFramebufferObject>
#else
#include <QCoreApplication>
#endif
@@ -271,7 +273,7 @@ void QMapboxGLSettings::setAccessToken(const QString &token)
Constructs a QMapboxGL object with \a settings and sets \a parent as the parent
object. The \a settings cannot be changed after the object is constructed.
*/
-QMapboxGL::QMapboxGL(QObject *parent, const QMapboxGLSettings &settings)
+QMapboxGL::QMapboxGL(QObject *parent, const QMapboxGLSettings &settings, const QSize& size, qreal pixelRatio)
: QObject(parent)
{
// Multiple QMapboxGL running on the same thread
@@ -280,7 +282,7 @@ QMapboxGL::QMapboxGL(QObject *parent, const QMapboxGLSettings &settings)
loop.setLocalData(std::make_shared<mbgl::util::RunLoop>());
}
- d_ptr = new QMapboxGLPrivate(this, settings);
+ d_ptr = new QMapboxGLPrivate(this, settings, size, pixelRatio);
}
QMapboxGL::~QMapboxGL()
@@ -602,15 +604,14 @@ void QMapboxGL::rotateBy(const QPointF &first, const QPointF &second)
mbgl::ScreenCoordinate { second.x(), second.y() });
}
-void QMapboxGL::resize(const QSize& size)
+void QMapboxGL::resize(const QSize& size, const QSize& framebufferSize)
{
- QSize converted = size / d_ptr->getPixelRatio();
- if (d_ptr->size == converted) return;
+ if (d_ptr->size == size && d_ptr->fbSize == framebufferSize) return;
- glViewport(0, 0, converted.width(), converted.height());
+ d_ptr->size = size;
+ d_ptr->fbSize = framebufferSize;
- d_ptr->size = converted;
- d_ptr->mapObj->update(mbgl::Update::Dimensions);
+ d_ptr->mapObj->setSize({{ static_cast<uint16_t>(size.width()), static_cast<uint16_t>(size.height()) }});
}
void QMapboxGL::addAnnotationIcon(const QString &name, const QImage &sprite)
@@ -793,19 +794,29 @@ void QMapboxGL::setFilter(const QString& layer_, const QVariant& filter_)
qWarning() << "Layer doesn't support filters";
}
+#if QT_VERSION >= 0x050000
+void QMapboxGL::render(QOpenGLFramebufferObject *fbo)
+{
+ d_ptr->dirty = false;
+ d_ptr->updateFramebufferBinding(fbo);
+ d_ptr->mapObj->render(*d_ptr);
+}
+#else
void QMapboxGL::render()
{
d_ptr->dirty = false;
- d_ptr->mapObj->render();
+ d_ptr->mapObj->render(*d_ptr);
}
+#endif
void QMapboxGL::connectionEstablished()
{
d_ptr->connectionEstablished();
}
-QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settings)
+QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settings, const QSize &size_, qreal pixelRatio)
: QObject(q)
+ , size(size_)
, q_ptr(q)
, fileSourceObj(std::make_unique<mbgl::DefaultFileSource>(
settings.cacheDatabasePath().toStdString(),
@@ -813,7 +824,8 @@ QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settin
settings.cacheDatabaseMaximumSize()))
, threadPool(4)
, mapObj(std::make_unique<mbgl::Map>(
- *this, *this, getPixelRatio(), *fileSourceObj, threadPool,
+ *this, std::array<uint16_t, 2>{{ static_cast<uint16_t>(size.width()), static_cast<uint16_t>(size.height()) }},
+ pixelRatio, *fileSourceObj, threadPool,
static_cast<mbgl::MapMode>(settings.mapMode()),
static_cast<mbgl::GLContextMode>(settings.contextMode()),
static_cast<mbgl::ConstrainMode>(settings.constrainMode()),
@@ -830,36 +842,42 @@ QMapboxGLPrivate::~QMapboxGLPrivate()
{
}
-float QMapboxGLPrivate::getPixelRatio() const
-{
#if QT_VERSION >= 0x050000
- // QWindow is the most reliable pixel ratio because QGuiApplication returns
- // the maximum pixel ratio of all available QScreen objects - this is not
- // valid for cases e.g. where two or more QScreen objects with different
- // pixel ratios are present and the window shows on the screen with lower
- // pixel ratio.
- static const float pixelRatio = QGuiApplication::allWindows().first()->devicePixelRatio();
-#else
- static const float pixelRatio = 1.0;
-#endif
- return pixelRatio;
+void QMapboxGLPrivate::updateFramebufferBinding(QOpenGLFramebufferObject *fbo_)
+{
+ fbo = fbo_;
+ if (fbo) {
+ getContext().bindFramebuffer.setDirty();
+ getContext().viewport.setCurrentValue(
+ { 0, 0, static_cast<uint16_t>(fbo->width()), static_cast<uint16_t>(fbo->height()) });
+ } else {
+ getContext().bindFramebuffer.setCurrentValue(0);
+ getContext().viewport.setCurrentValue({ 0, 0, static_cast<uint16_t>(fbSize.width()),
+ static_cast<uint16_t>(fbSize.height()) });
+ }
}
void QMapboxGLPrivate::bind()
{
- MBGL_CHECK_ERROR(glBindFramebuffer(GL_FRAMEBUFFER, 0));
-}
-
-std::array<uint16_t, 2> QMapboxGLPrivate::getSize() const
-{
- return {{ static_cast<uint16_t>(size.width()), static_cast<uint16_t>(size.height()) }};
+ if (fbo) {
+ fbo->bind();
+ getContext().bindFramebuffer.setDirty();
+ getContext().viewport = { 0, 0, static_cast<uint16_t>(fbo->width()),
+ static_cast<uint16_t>(fbo->height()) };
+ } else {
+ getContext().bindFramebuffer = 0;
+ getContext().viewport = { 0, 0, static_cast<uint16_t>(fbSize.width()),
+ static_cast<uint16_t>(fbSize.height()) };
+ }
}
-
-std::array<uint16_t, 2> QMapboxGLPrivate::getFramebufferSize() const
+#else
+void QMapboxGLPrivate::bind()
{
- return {{ static_cast<uint16_t>(size.width() * getPixelRatio()),
- static_cast<uint16_t>(size.height() * getPixelRatio()) }};
+ getContext().bindFramebuffer = 0;
+ getContext().viewport = { 0, 0, static_cast<uint16_t>(fbSize.width()),
+ static_cast<uint16_t>(fbSize.height()) };
}
+#endif
void QMapboxGLPrivate::invalidate()
{