summaryrefslogtreecommitdiff
path: root/platform/qt
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-05-13 13:15:45 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-05-13 13:28:49 +0300
commitd36111abedf0d13d6078e6c75d55668bb8786141 (patch)
treed5ff63171ead36e675de058fe2416b5af3f253c4 /platform/qt
parent3d4e0d66fea188c61f33fbf234eeaebc50bc9e40 (diff)
downloadqtlocation-mapboxgl-d36111abedf0d13d6078e6c75d55668bb8786141.tar.gz
[Qt] Initialize GL extensions on MapWindow
QMapboxGL relies on its embedding widget to call for the GL extensions initialization function. Fixes #5024.
Diffstat (limited to 'platform/qt')
-rw-r--r--platform/qt/README.md6
-rw-r--r--platform/qt/app/mapwindow.cpp5
-rw-r--r--platform/qt/app/mapwindow.hpp2
-rw-r--r--platform/qt/include/qmapbox.hpp2
-rw-r--r--platform/qt/platform.gyp4
-rw-r--r--platform/qt/src/qmapbox.cpp9
6 files changed, 24 insertions, 4 deletions
diff --git a/platform/qt/README.md b/platform/qt/README.md
index 4ba27016f6..56f9301b31 100644
--- a/platform/qt/README.md
+++ b/platform/qt/README.md
@@ -30,6 +30,12 @@ to provide it by setting the environment variable `MAPBOX_ACCESS_TOKEN`:
export MAPBOX_ACCESS_TOKEN=MYTOKEN
+#### Using QMapboxGL
+
+`QMapboxGL` is a [QObject](http://doc.qt.io/qt-5/qobject.html) - [MapWindow](https://github.com/mapbox/mapbox-gl-native/blob/master/platform/qt/app/mapwindow.hpp) provides an example [QGLWidget](http://doc.qt.io/qt-5/qglwidget.html) that contains a `QMapboxGL` object. If you use `QMapboxGL` in non-standard Qt widgets, make sure to initialize the GL extensions required by Mapbox whenever possible:
+
+ QMapbox::initializeGLExtensions();
+
#### Linux
For Linux (Ubuntu) desktop, together with these [build
diff --git a/platform/qt/app/mapwindow.cpp b/platform/qt/app/mapwindow.cpp
index 78d740393f..3e0b373db3 100644
--- a/platform/qt/app/mapwindow.cpp
+++ b/platform/qt/app/mapwindow.cpp
@@ -142,6 +142,11 @@ void MapWindow::wheelEvent(QWheelEvent *ev)
ev->accept();
}
+void MapWindow::initializeGL()
+{
+ QMapbox::initializeGLExtensions();
+}
+
void MapWindow::resizeGL(int w, int h)
{
m_map.resize(QSize(w, h));
diff --git a/platform/qt/app/mapwindow.hpp b/platform/qt/app/mapwindow.hpp
index a42a5a323f..452d302eb3 100644
--- a/platform/qt/app/mapwindow.hpp
+++ b/platform/qt/app/mapwindow.hpp
@@ -30,6 +30,8 @@ private:
void mousePressEvent(QMouseEvent *ev) final;
void mouseMoveEvent(QMouseEvent *ev) final;
void wheelEvent(QWheelEvent *ev) final;
+
+ void initializeGL() final;
void resizeGL(int w, int h) final;
void paintGL() final;
diff --git a/platform/qt/include/qmapbox.hpp b/platform/qt/include/qmapbox.hpp
index cffc6f87cd..f2cf363ea3 100644
--- a/platform/qt/include/qmapbox.hpp
+++ b/platform/qt/include/qmapbox.hpp
@@ -60,9 +60,7 @@ typedef void (*CustomLayerInitializeFunction)(void* context) ;
typedef void (*CustomLayerRenderFunction)(void* context, const CustomLayerRenderParameters&);
typedef void (*CustomLayerDeinitializeFunction)(void* context);
-#if QT_VERSION >= 0x050000
Q_DECL_EXPORT void initializeGLExtensions();
-#endif
}
diff --git a/platform/qt/platform.gyp b/platform/qt/platform.gyp
index 8b6cdd5918..04b5c20ab3 100644
--- a/platform/qt/platform.gyp
+++ b/platform/qt/platform.gyp
@@ -129,9 +129,13 @@
['<(qt_version_major) == 4', {
'variables': {
'cflags': [
+ '<@(qt_opengl_cflags)',
# Qt4 generates code with unused variables.
'-Wno-unused-variable',
],
+ 'ldflags': [
+ '<@(qt_opengl_ldflags)',
+ ],
},
}],
['<(qt_version_major) == 5', {
diff --git a/platform/qt/src/qmapbox.cpp b/platform/qt/src/qmapbox.cpp
index bc60ce3e5a..17ddbe4ca5 100644
--- a/platform/qt/src/qmapbox.cpp
+++ b/platform/qt/src/qmapbox.cpp
@@ -7,6 +7,8 @@
#if QT_VERSION >= 0x050000
#include <QOpenGLContext>
+#else
+#include <QGLContext>
#endif
// mbgl::MapMode
@@ -39,14 +41,17 @@ Q_DECL_EXPORT QList<QPair<QString, QString>>& defaultStyles()
return styles;
}
-#if QT_VERSION >= 0x050000
Q_DECL_EXPORT void initializeGLExtensions()
{
mbgl::gl::InitializeExtensions([](const char* name) {
+#if QT_VERSION >= 0x050000
QOpenGLContext* thisContext = QOpenGLContext::currentContext();
return thisContext->getProcAddress(name);
+#else
+ const QGLContext* thisContext = QGLContext::currentContext();
+ return reinterpret_cast<mbgl::gl::glProc>(thisContext->getProcAddress(name));
+#endif
});
}
-#endif
}