From 48b47f9d242f76e944986df08a16c083bce47bef Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 3 Sep 2009 09:32:38 +1000 Subject: Make it easier to test examples with EGL. Currently -graphicssystem opengl is not very reliable with EGL, so we've added a -opengl option to qmlviewer which sets the viewport of the view to a QGLWidget and allows for GL testing. --- tools/qmlviewer/main.cpp | 5 +++++ tools/qmlviewer/qmlviewer.cpp | 18 ++++++++++++++++++ tools/qmlviewer/qmlviewer.h | 1 + tools/qmlviewer/qmlviewer.pro | 5 +++++ 4 files changed, 29 insertions(+) diff --git a/tools/qmlviewer/main.cpp b/tools/qmlviewer/main.cpp index a4ed054..87d1232 100644 --- a/tools/qmlviewer/main.cpp +++ b/tools/qmlviewer/main.cpp @@ -41,6 +41,7 @@ void usage() qWarning(" -netcache ......................... set disk cache to size bytes"); qWarning(" -translation ........... set the language to run in"); qWarning(" -L ........................... prepend to the library search path"); + qWarning(" -opengl .................................. use a QGLWidget for the viewport"); qWarning(" "); qWarning(" Press F1 for interactive help"); exit(1); @@ -79,6 +80,7 @@ int main(int argc, char ** argv) bool devkeys = false; int cache = 0; QString translationFile; + bool useGL = false; for (int i = 1; i < argc; ++i) { QString arg = argv[i]; @@ -114,6 +116,8 @@ int main(int argc, char ** argv) usage(); translationFile = argv[i + 1]; ++i; + } else if (arg == "-opengl") { + useGL = true; } else if (arg == "-L") { libraries << QString(argv[++i]); } else if (arg[0] != '-') { @@ -130,6 +134,7 @@ int main(int argc, char ** argv) } QmlViewer viewer(0, frameless ? Qt::FramelessWindowHint : Qt::Widget); + viewer.setUseGL(useGL); foreach (QString lib, libraries) viewer.addLibraryPath(lib); viewer.setNetworkCacheSize(cache); diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index 272ebcb..3ae9a97 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -45,6 +45,10 @@ #include #include "proxysettings.h" +#ifdef GL_SUPPORTED +#include +#endif + QT_BEGIN_NAMESPACE class PreviewDeviceSkin : public DeviceSkin @@ -1003,6 +1007,20 @@ void QmlViewer::setNetworkCacheSize(int size) } } +void QmlViewer::setUseGL(bool useGL) +{ +#ifdef GL_SUPPORTED + if (useGL) { + QGLFormat format = QGLFormat::defaultFormat(); + format.setSampleBuffers(false); + + QGLWidget *glWidget = new QGLWidget(format); + glWidget->setAutoFillBackground(false); + canvas->setViewport(glWidget); + } +#endif +} + QT_END_NAMESPACE #include "qmlviewer.moc" diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h index c03c09f..e85acfa 100644 --- a/tools/qmlviewer/qmlviewer.h +++ b/tools/qmlviewer/qmlviewer.h @@ -43,6 +43,7 @@ public: void setDeviceKeys(bool); void setNetworkCacheSize(int size); void addLibraryPath(const QString& lib); + void setUseGL(bool use); QStringList builtinSkins() const; diff --git a/tools/qmlviewer/qmlviewer.pro b/tools/qmlviewer/qmlviewer.pro index bcf361e..77cae97 100644 --- a/tools/qmlviewer/qmlviewer.pro +++ b/tools/qmlviewer/qmlviewer.pro @@ -7,6 +7,11 @@ QT += declarative \ network \ sql +contains(QT_CONFIG, opengl) { + QT += opengl + DEFINES += GL_SUPPORTED +} + # Input HEADERS += qmlviewer.h \ proxysettings.h -- cgit v0.12