Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[Qt] Initialize GL extensions on MapWindow
Browse files Browse the repository at this point in the history
QMapboxGL relies on its embedding widget to call for the GL extensions
initialization function.

Fixes #5024.
  • Loading branch information
brunoabinader committed May 13, 2016
1 parent 3d4e0d6 commit d36111a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
6 changes: 6 additions & 0 deletions platform/qt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions platform/qt/app/mapwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions platform/qt/app/mapwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ protected slots:
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;

Expand Down
2 changes: 0 additions & 2 deletions platform/qt/include/qmapbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

}

Expand Down
4 changes: 4 additions & 0 deletions platform/qt/platform.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
9 changes: 7 additions & 2 deletions platform/qt/src/qmapbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#if QT_VERSION >= 0x050000
#include <QOpenGLContext>
#else
#include <QGLContext>
#endif

// mbgl::MapMode
Expand Down Expand Up @@ -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

}

0 comments on commit d36111a

Please sign in to comment.