summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSarah Smith <sarah.j.smith@nokia.com>2011-10-02 18:18:42 +1000
committerQt by Nokia <qt-info@nokia.com>2011-10-03 11:47:31 +0200
commitaa6850d950e8523c47cacdaf54c918de53299d80 (patch)
treed40864bc3a4b3e8cf07010be32c5ee0625d95e93
parent2b61e0a75b09f8dc05b298069da43d477db69910 (diff)
Fixes for surface vs QOpenGLContext & QWindow.
With the qt5 refactor branch going in the ability to get a QPaintDevice has gone away - this was really a "relic from the desktop days". Painting still applies for FBO's and so on, but in the case of QML we are on an SG view and there is no paint device there. So move the QGLView to using a QWindow and QOpenGLContext as well to follow suit and replace all the logic in surface stuff to cope with that. Also update all examples, demos, tutorials and tests. Change-Id: Ie8dbeb97c87ef0821326fb7ccf5d5d4b1f90fd06 Reviewed-on: http://codereview.qt-project.org/5900 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Sarah Jane Smith <sarah.j.smith@nokia.com>
-rw-r--r--demos/qt3d/cubehouse/cubeview.cpp2
-rw-r--r--demos/qt3d/cubehouse/cubeview.h2
-rw-r--r--demos/qt3d/cubehouse/main.cpp36
-rw-r--r--demos/qt3d/pageflip/pageflip.cpp121
-rw-r--r--demos/qt3d/photobrowser3d/main.cpp29
-rw-r--r--demos/qt3d/photobrowser3d/qatlas.cpp2
-rw-r--r--demos/qt3d/photobrowser3d/qatlas.h3
-rw-r--r--demos/qt3d/photobrowser3d/qfocusadaptor.cpp4
-rw-r--r--demos/qt3d/photobrowser3d/thumbnailnode.cpp4
-rw-r--r--demos/qt3d/shapes/shapes.cpp129
-rw-r--r--demos/qt3d/teaservice/teaservice.cpp67
-rw-r--r--demos/quick3d/robo_bounce/main.cpp2
-rw-r--r--examples/qt3d/basket/basketview.cpp2
-rw-r--r--examples/qt3d/basket/basketview.h3
-rw-r--r--examples/qt3d/basket/main.cpp35
-rw-r--r--examples/qt3d/builder/builder.cpp2
-rw-r--r--examples/qt3d/builder/builder.h2
-rw-r--r--examples/qt3d/builder/main.cpp29
-rw-r--r--examples/qt3d/cube/cubeview.cpp2
-rw-r--r--examples/qt3d/cube/cubeview.h2
-rw-r--r--examples/qt3d/cube/main.cpp29
-rw-r--r--examples/qt3d/cylinder/cylinderview.cpp2
-rw-r--r--examples/qt3d/cylinder/cylinderview.h2
-rw-r--r--examples/qt3d/cylinder/main.cpp29
-rw-r--r--examples/qt3d/geometry/geometryview.cpp4
-rw-r--r--examples/qt3d/geometry/geometryview.h2
-rw-r--r--examples/qt3d/geometry/main.cpp29
-rw-r--r--examples/qt3d/nesting/cubeview.cpp8
-rw-r--r--examples/qt3d/nesting/cubeview.h6
-rw-r--r--examples/qt3d/nesting/main.cpp29
-rw-r--r--examples/qt3d/solarsystem/main.cpp29
-rw-r--r--examples/qt3d/solarsystem/solarsystem.cpp2
-rw-r--r--examples/qt3d/solarsystem/solarsystem.h2
-rw-r--r--examples/qt3d/tank/main.cpp29
-rw-r--r--examples/qt3d/tank/tankview.cpp5
-rw-r--r--examples/qt3d/tank/tankview.h2
-rw-r--r--examples/qt3d/teapot/main.cpp29
-rw-r--r--examples/qt3d/teapot/teapotview.h2
-rw-r--r--examples/quick3d/basket/qml/Basket.qml2
-rw-r--r--pkg.pri2
-rw-r--r--src/imports/threed/viewport.cpp8
-rw-r--r--src/quick3d/quick3d.pro2
-rw-r--r--src/threed/painting/qglpainter.cpp59
-rw-r--r--src/threed/painting/qglpainter.h12
-rw-r--r--src/threed/painting/qglpainter_p.h10
-rw-r--r--src/threed/surfaces/qglabstractsurface.cpp187
-rw-r--r--src/threed/surfaces/qglabstractsurface.h29
-rw-r--r--src/threed/surfaces/qglcontextsurface.cpp70
-rw-r--r--src/threed/surfaces/qglcontextsurface_p.h14
-rw-r--r--src/threed/surfaces/qgldrawbuffersurface.cpp10
-rw-r--r--src/threed/surfaces/qgldrawbuffersurface_p.h1
-rw-r--r--src/threed/surfaces/qglframebufferobjectsurface.cpp121
-rw-r--r--src/threed/surfaces/qglframebufferobjectsurface.h14
-rw-r--r--src/threed/surfaces/qglmaskedsurface.cpp14
-rw-r--r--src/threed/surfaces/qglmaskedsurface_p.h2
-rw-r--r--src/threed/surfaces/qglpaintersurface.cpp27
-rw-r--r--src/threed/surfaces/qglpaintersurface_p.h11
-rw-r--r--src/threed/surfaces/qglpixelbuffersurface.cpp28
-rw-r--r--src/threed/surfaces/qglpixelbuffersurface.h4
-rw-r--r--src/threed/surfaces/qglsubsurface.cpp17
-rw-r--r--src/threed/surfaces/qglsubsurface.h2
-rw-r--r--src/threed/surfaces/qglwidgetsurface.cpp146
-rw-r--r--src/threed/surfaces/qglwindowsurface.cpp175
-rw-r--r--src/threed/surfaces/qglwindowsurface.h (renamed from src/threed/surfaces/qglwidgetsurface.h)20
-rw-r--r--src/threed/surfaces/surfaces.pri7
-rw-r--r--src/threed/textures/qgltextureutils_p.h2
-rw-r--r--src/threed/viewing/qglview.cpp214
-rw-r--r--src/threed/viewing/qglview.h21
-rw-r--r--tests/auto/threed/qgeometrydata/qgeometrydata.pro2
-rw-r--r--tests/auto/threed/qgeometrydata/tst_qgeometrydata.cpp3
-rw-r--r--tests/auto/threed/qglabstractsurface/qglabstractsurface.pro2
-rw-r--r--tests/auto/threed/qglabstractsurface/tst_qglabstractsurface.cpp147
-rw-r--r--tests/auto/threed/qglmaterial/qglmaterial.pro2
-rw-r--r--tests/auto/threed/qglmaterial/tst_qglmaterial.cpp27
-rw-r--r--tests/auto/threed/qglpainter/qglpainter.pro2
-rw-r--r--tests/auto/threed/qglpainter/qgltestwidget.cpp14
-rw-r--r--tests/auto/threed/qglpainter/qgltestwidget.h5
-rw-r--r--tests/auto/threed/qglpainter/tst_qglpainter.cpp70
-rw-r--r--tests/auto/threed/qglrender/qglrender.pro2
-rw-r--r--tests/auto/threed/qglrender/tst_qglrender.cpp4
-rw-r--r--tests/auto/threed/qglscenenode/qglscenenode.pro2
-rw-r--r--tests/auto/threed/qglscenenode/tst_qglscenenode.cpp30
-rw-r--r--tests/manual/displaymodel/qml/tst_displaymodel.qml2
-rw-r--r--tests/shared/qmlres.h2
-rw-r--r--tutorials/qt3d/cube1/cubeview.cpp2
-rw-r--r--tutorials/qt3d/cube1/cubeview.h2
-rw-r--r--tutorials/qt3d/cube2/cubeview.cpp2
-rw-r--r--tutorials/qt3d/cube2/cubeview.h2
-rw-r--r--tutorials/qt3d/cube3/cubeview.cpp2
-rw-r--r--tutorials/qt3d/cube3/cubeview.h2
-rw-r--r--tutorials/qt3d/cube4/cubeview.cpp2
-rw-r--r--tutorials/qt3d/cube4/cubeview.h2
-rw-r--r--tutorials/qt3d/penguin/modelview.h2
-rw-r--r--tutorials/qt3d/penguin_advanced/modelview.cpp2
-rw-r--r--tutorials/qt3d/penguin_advanced/modelview.h2
95 files changed, 1519 insertions, 768 deletions
diff --git a/demos/qt3d/cubehouse/cubeview.cpp b/demos/qt3d/cubehouse/cubeview.cpp
index 994222dce..492ceae89 100644
--- a/demos/qt3d/cubehouse/cubeview.cpp
+++ b/demos/qt3d/cubehouse/cubeview.cpp
@@ -52,7 +52,7 @@
//#define PROJECTOR_CAMERA_DEBUG_MARKERS
-CubeView::CubeView(QWidget *parent)
+CubeView::CubeView(QWindow *parent)
: QGLView(parent), scene(0), cube(0), teapot(0), room(0),
sensitivity(0.1f),
lightParameters(0),
diff --git a/demos/qt3d/cubehouse/cubeview.h b/demos/qt3d/cubehouse/cubeview.h
index 52517ea15..d6f5fb1f9 100644
--- a/demos/qt3d/cubehouse/cubeview.h
+++ b/demos/qt3d/cubehouse/cubeview.h
@@ -54,7 +54,7 @@ class CubeView : public QGLView
Q_OBJECT
Q_PROPERTY(qreal cubeAngle READ cubeAngle WRITE setCubeAngle)
public:
- CubeView(QWidget *parent = 0);
+ CubeView(QWindow *parent = 0);
~CubeView() {}
void setShowFrameRate(bool value) { showFrameRate = value; }
diff --git a/demos/qt3d/cubehouse/main.cpp b/demos/qt3d/cubehouse/main.cpp
index b8603a504..6cf02e22c 100644
--- a/demos/qt3d/cubehouse/main.cpp
+++ b/demos/qt3d/cubehouse/main.cpp
@@ -46,20 +46,40 @@ int main(int argc, char *argv[])
{
QApplication app(argc, argv);
CubeView view;
- if (QApplication::arguments().contains(QLatin1String("-framerate")))
+
+ QStringList args = QCoreApplication::arguments();
+ if (args.contains(QLatin1String("-framerate")))
view.setShowFrameRate(true);
- if (QApplication::arguments().contains(QLatin1String("-projectivetexture")))
+ if (args.contains(QLatin1String("-projectivetexture")))
view.setProjectiveTextureEffect(true);
- if (QApplication::arguments().contains(QLatin1String("-stereo")))
+ if (args.contains(QLatin1String("-stereo")))
view.setStereo(true);
else if (view.stereoType() != QGLView::RedCyanAnaglyph)
view.setStereo(true);
- if (QApplication::arguments().contains(QLatin1String("-maximize")))
- view.showMaximized();
- else if (QApplication::arguments().contains(QLatin1String("-fullscreen")))
- view.showFullScreen();
+ int w_pos = args.indexOf(QLatin1String("-width"));
+ int h_pos = args.indexOf(QLatin1String("-height"));
+ if (w_pos >= 0 && h_pos >= 0)
+ {
+ bool ok = true;
+ int w = args.at(w_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse width argument:" << args;
+ return 1;
+ }
+ int h = args.at(h_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse height argument:" << args;
+ return 1;
+ }
+ view.resize(w, h);
+ }
else
- view.show();
+ {
+ view.resize(800, 600);
+ }
+ view.show();
return app.exec();
}
diff --git a/demos/qt3d/pageflip/pageflip.cpp b/demos/qt3d/pageflip/pageflip.cpp
index 395e2c35e..904277cb2 100644
--- a/demos/qt3d/pageflip/pageflip.cpp
+++ b/demos/qt3d/pageflip/pageflip.cpp
@@ -51,26 +51,34 @@
class PageFlipGradientEffect;
-class PageFlipView : public QGLWidget
+class PageFlipView : public QWindow
{
Q_OBJECT
public:
- PageFlipView(QWidget *parent = 0);
+ PageFlipView(QWindow *parent = 0);
~PageFlipView();
void setBlend(bool value) { blend = value; }
void setVertical(bool value) { vertical = value; }
+public Q_SLOTS:
+ void update();
+
protected:
void resizeGL(int width, int height);
void initializeGL();
void paintGL();
+
+ void exposeEvent(QExposeEvent *e);
void mousePressEvent(QMouseEvent *e);
private slots:
void animate();
private:
+ void ensureContext();
+ void setAlphaValue(QGLPainter *painter, GLfloat value);
+
bool blend;
bool vertical;
@@ -91,7 +99,10 @@ private:
PageFlipGradientEffect *effect;
- void setAlphaValue(QGLPainter *painter, GLfloat value);
+ QOpenGLContext *context;
+ bool initialised;
+ QSurfaceFormat format;
+ bool updateQueued;
};
class PageFlipGradientEffect : public QGLShaderProgramEffect
@@ -103,9 +114,17 @@ public:
void setAlphaValue(GLfloat value);
};
-PageFlipView::PageFlipView(QWidget *parent)
- : QGLWidget(parent)
+PageFlipView::PageFlipView(QWindow *parent)
+ : QWindow(parent)
+ , context(0)
+ , initialised(false)
+ , updateQueued(false)
{
+ format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
+ format.setDepthBufferSize(24);
+ setSurfaceType(QWindow::OpenGLSurface);
+ setFormat(format);
+
posn = 0.0f;
blend = false;
vertical = false;
@@ -128,6 +147,25 @@ PageFlipView::~PageFlipView()
delete effect;
}
+void PageFlipView::exposeEvent(QExposeEvent *e)
+{
+ Q_UNUSED(e);
+
+ updateQueued = false;
+ ensureContext();
+
+ QRect rect = geometry();
+ resizeGL(rect.width(), rect.height());
+
+ if (!initialised)
+ initializeGL();
+
+ paintGL();
+
+ if (format.swapBehavior() == QSurfaceFormat::DoubleBuffer)
+ context->swapBuffers(this);
+}
+
void PageFlipView::resizeGL(int width, int height)
{
glViewport(0, 0, width, height);
@@ -165,13 +203,15 @@ void PageFlipView::initializeGL()
pageFlipMath.setStartCorner(PageFlipMath::VerticalBottomRight);
else
pageFlipMath.setStartCorner(PageFlipMath::BottomRight);
+
+ initialised = true;
}
void PageFlipView::paintGL()
{
QGLPainter painter(this);
- QRect rect = this->rect();
+ QRect rect = this->geometry();
int midx = rect.width() / 2;
int topy = (rect.height() - pageSize.height()) / 2;
@@ -299,7 +339,7 @@ void PageFlipView::mousePressEvent(QMouseEvent *e)
}
if (changed)
posn = 0.0f;
- QGLWidget::mousePressEvent(e);
+ QWindow::mousePressEvent(e);
}
void PageFlipView::animate()
@@ -309,7 +349,16 @@ void PageFlipView::animate()
posn = 0.0f;
colorIndex = (colorIndex + 2) % 4;
}
- updateGL();
+ update();
+}
+
+void PageFlipView::update()
+{
+ if (!updateQueued)
+ {
+ updateQueued = true;
+ QApplication::postEvent(this, new QExposeEvent(geometry()));
+ }
}
void PageFlipView::setAlphaValue(QGLPainter *painter, GLfloat value)
@@ -360,21 +409,63 @@ void PageFlipGradientEffect::setAlphaValue(GLfloat value)
program()->setUniformValue("alphaValue", value);
}
+inline void PageFlipView::ensureContext()
+{
+ if (!context)
+ {
+ context = new QOpenGLContext();
+ context->setFormat(format);
+#ifndef QT_NO_DEBUG_STREAM
+ QSurfaceFormat oldFormat = format;
+#endif
+ context->create();
+ // TODO: is it possible that the platform will downgrade the actual
+ // format, or will it just fail if it can't deliver the actual format
+ format = context->format();
+#ifndef QT_NO_DEBUG_STREAM
+ if (oldFormat != format)
+ qWarning() << "Could not create context requested:\n"
+ << oldFormat << "\nactual format:\n" << format;
+#endif
+ }
+ context->makeCurrent(this);
+}
+
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
PageFlipView view;
- if (QApplication::arguments().contains(QLatin1String("-blend")))
+
+ QStringList args = QCoreApplication::arguments();
+ if (args.contains(QLatin1String("-blend")))
view.setBlend(true);
- if (QApplication::arguments().contains(QLatin1String("-vertical")))
+ if (args.contains(QLatin1String("-vertical")))
view.setVertical(true);
- if (QApplication::arguments().contains(QLatin1String("-maximize")))
- view.showMaximized();
- else if (QApplication::arguments().contains(QLatin1String("-fullscreen")))
- view.showFullScreen();
+ int w_pos = args.indexOf("-width");
+ int h_pos = args.indexOf("-height");
+ if (w_pos >= 0 && h_pos >= 0)
+ {
+ bool ok = true;
+ int w = args.at(w_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse width argument:" << args;
+ return 1;
+ }
+ int h = args.at(h_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse height argument:" << args;
+ return 1;
+ }
+ view.resize(w, h);
+ }
else
- view.show();
+ {
+ view.resize(800, 600);
+ }
+ view.show();
return app.exec();
}
diff --git a/demos/qt3d/photobrowser3d/main.cpp b/demos/qt3d/photobrowser3d/main.cpp
index 7a840727c..9e0edd873 100644
--- a/demos/qt3d/photobrowser3d/main.cpp
+++ b/demos/qt3d/photobrowser3d/main.cpp
@@ -61,12 +61,31 @@ int main(int argc, char *argv[])
if (view.stereoType() != QGLView::RedCyanAnaglyph)
view.camera()->setEyeSeparation(0.3f);
- if (QApplication::arguments().contains(QLatin1String("-maximize")))
- view.showMaximized();
- else if (QApplication::arguments().contains(QLatin1String("-fullscreen")))
- view.showFullScreen();
+ QStringList args = QCoreApplication::arguments();
+ int w_pos = args.indexOf("-width");
+ int h_pos = args.indexOf("-height");
+ if (w_pos >= 0 && h_pos >= 0)
+ {
+ bool ok = true;
+ int w = args.at(w_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse width argument:" << args;
+ return 1;
+ }
+ int h = args.at(h_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse height argument:" << args;
+ return 1;
+ }
+ view.resize(w, h);
+ }
else
- view.show();
+ {
+ view.resize(800, 600);
+ }
+ view.show();
result = app.exec();
}
diff --git a/demos/qt3d/photobrowser3d/qatlas.cpp b/demos/qt3d/photobrowser3d/qatlas.cpp
index 24c9b6a32..d8522c99c 100644
--- a/demos/qt3d/photobrowser3d/qatlas.cpp
+++ b/demos/qt3d/photobrowser3d/qatlas.cpp
@@ -83,7 +83,7 @@ void QAtlas::initialize(QGLPainter *painter)
Q_UNUSED(painter);
if (!m_initialized)
{
- m_data = new QGLFramebufferObject(m_size);
+ m_data = new QOpenGLFramebufferObject(m_size);
m_renderTarget = new QGLFramebufferObjectSurface(m_data);
m_tex = QGLTexture2D::fromTextureId(m_data->texture(), m_size);
m_material->setTexture(m_tex, 1);
diff --git a/demos/qt3d/photobrowser3d/qatlas.h b/demos/qt3d/photobrowser3d/qatlas.h
index 693a63b4d..4c7c14a79 100644
--- a/demos/qt3d/photobrowser3d/qatlas.h
+++ b/demos/qt3d/photobrowser3d/qatlas.h
@@ -43,6 +43,7 @@
#define QATLAS_H
#include <QSize>
+#include <QtGui/QOpenGLFramebufferObject>
#include "qarray.h"
#include "qgeometrydata.h"
@@ -88,7 +89,7 @@ public:
private:
QSize m_size;
- QGLFramebufferObject *m_data;
+ QOpenGLFramebufferObject *m_data;
QGLFramebufferObjectSurface *m_renderTarget;
QAreaAllocator *m_allocator;
QGLTexture2D *m_tex;
diff --git a/demos/qt3d/photobrowser3d/qfocusadaptor.cpp b/demos/qt3d/photobrowser3d/qfocusadaptor.cpp
index 64e93c61a..c45ab8f3e 100644
--- a/demos/qt3d/photobrowser3d/qfocusadaptor.cpp
+++ b/demos/qt3d/photobrowser3d/qfocusadaptor.cpp
@@ -156,8 +156,8 @@ void QFocusAdaptor::calculateValues()
QSizeF v = cam->viewSize();
- qreal vh = d->view->rect().height();
- qreal vw = d->view->rect().width();
+ qreal vh = d->view->geometry().height();
+ qreal vw = d->view->geometry().width();
if (!qFuzzyIsNull(vw - vh))
{
qreal asp = vh / vw;
diff --git a/demos/qt3d/photobrowser3d/thumbnailnode.cpp b/demos/qt3d/photobrowser3d/thumbnailnode.cpp
index f80bec8c1..2199fc037 100644
--- a/demos/qt3d/photobrowser3d/thumbnailnode.cpp
+++ b/demos/qt3d/photobrowser3d/thumbnailnode.cpp
@@ -158,11 +158,11 @@ void ThumbnailNode::draw(QGLPainter *painter)
{
QGLSceneNode *p = qobject_cast<QGLSceneNode*>(parent());
Q_ASSERT_X(p && p->userEffect() && (!hasEffect()),
- "ThumbnailNode::draw", "Should only inherit parents ThumbnailEffect");
+ Q_FUNC_INFO, "Should only inherit parents ThumbnailEffect");
ThumbnailEffect *effect = static_cast<ThumbnailEffect*>(p->userEffect());
Q_ASSERT_X(effect && effect->name() == QLatin1String("ThumbnailEffect"),
- "ThumbnailNode::draw", "Can only be drawn with custom ThumbnailEffect");
+ Q_FUNC_INFO, "Can only be drawn with custom ThumbnailEffect");
if (m_defaultMaterial == -1)
m_defaultMaterial = materialIndex();
diff --git a/demos/qt3d/shapes/shapes.cpp b/demos/qt3d/shapes/shapes.cpp
index afe355597..4da051a38 100644
--- a/demos/qt3d/shapes/shapes.cpp
+++ b/demos/qt3d/shapes/shapes.cpp
@@ -50,19 +50,29 @@
#include <QImage>
#include <QPainter>
#include <QDebug>
+#include <QtGui/QFontDatabase>
-class ShapesWidget : public QGLWidget
+#include <QtGui/QWindow>
+#include <QtGui/QOpenGLContext>
+#include <QtGui/QSurfaceFormat>
+
+class ShapesWidget : public QWindow
{
Q_OBJECT
public:
- ShapesWidget(QWidget *parent = 0);
+ ShapesWidget(QWindow *parent = 0);
~ShapesWidget();
protected:
+ void exposeEvent(QExposeEvent *);
+
+ void resizeGL(int w, int h);
void initializeGL();
void paintGL();
private:
+ void ensureContext();
+
void paintPoints(QGLPainter *painter, const QRect& rect);
void paintLines(QGLPainter *painter, const QRect& rect);
void paintLineStrip(QGLPainter *painter, const QRect& rect);
@@ -82,12 +92,23 @@ private:
QGLSceneNode *teapot;
QGLLightModel oneSidedModel;
QGLLightModel twoSidedModel;
+
+ QOpenGLContext *context;
+ bool initialised;
+ QSurfaceFormat format;
};
-ShapesWidget::ShapesWidget(QWidget *parent)
- : QGLWidget(parent)
+ShapesWidget::ShapesWidget(QWindow *parent)
+ : QWindow(parent)
+ , context(0)
+ , initialised(false)
{
setWindowTitle(tr("GL Primitive Shapes"));
+ format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
+ format.setDepthBufferSize(24);
+ setSurfaceType(QWindow::OpenGLSurface);
+ setFormat(format);
+
oneSidedModel.setModel(QGLLightModel::OneSided);
twoSidedModel.setModel(QGLLightModel::TwoSided);
}
@@ -97,9 +118,33 @@ ShapesWidget::~ShapesWidget()
delete scene;
}
+void ShapesWidget::exposeEvent(QExposeEvent *e)
+{
+ Q_UNUSED(e);
+
+ ensureContext();
+
+ QRect rect = geometry();
+ resizeGL(rect.width(), rect.height());
+
+ if (!initialised)
+ initializeGL();
+
+ paintGL();
+
+ if (format.swapBehavior() == QSurfaceFormat::DoubleBuffer)
+ context->swapBuffers(this);
+}
+
+void ShapesWidget::resizeGL(int w, int h)
+{
+ glViewport(0, 0, w, h);
+}
+
void ShapesWidget::initializeGL()
{
- QGLPainter painter(this);
+ QGLPainter painter;
+ painter.begin();
painter.setLightModel(&twoSidedModel);
painter.setFaceColor(QGL::FrontFaces, QColor(170, 202, 0));
@@ -111,6 +156,8 @@ void ShapesWidget::initializeGL()
builder << QGL::Smooth << QGLTeapot();
teapot = builder.currentNode();
scene = builder.finalizedSceneNode();
+
+ initialised = true;
}
void ShapesWidget::paintGL()
@@ -122,11 +169,11 @@ void ShapesWidget::paintGL()
glDisable(GL_DEPTH_TEST);
QMatrix4x4 projm;
- projm.ortho(rect());
+ projm.ortho(geometry());
painter.projectionMatrix() = projm;
painter.modelViewMatrix().setToIdentity();
- QRect wrect = rect();
+ QRect wrect = geometry();
int boxw = wrect.width() / 3;
int boxh = wrect.height() / 3;
@@ -365,12 +412,11 @@ void ShapesWidget::paintTeapot(QGLPainter *painter, const QRect& rect)
void ShapesWidget::drawText
(QGLPainter *painter, const QRect& posn, const QString& str)
{
- QFontMetrics metrics = fontMetrics();
+ QFont f = QApplication::font();
+ QFontMetrics metrics(f);
QRect rect = metrics.boundingRect(str);
rect.adjust(0, 0, 1, 1);
- QFont f = font();
-
QImage image(rect.size(), QImage::Format_ARGB32);
image.fill(0);
QPainter p2(&image);
@@ -408,18 +454,67 @@ void ShapesWidget::drawText
glBindTexture(GL_TEXTURE_2D, 0);
}
+void ShapesWidget::ensureContext()
+{
+ if (!context)
+ {
+ format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
+ context = new QOpenGLContext();
+ context->setFormat(format);
+#ifndef QT_NO_DEBUG_STREAM
+ QSurfaceFormat oldFormat = format;
+#endif
+ context->create();
+ // TODO: is it possible that the platform will downgrade the actual
+ // format, or will it just fail if it can't deliver the actual format
+ format = context->format();
+#ifndef QT_NO_DEBUG_STREAM
+ if (oldFormat.swapBehavior() != format.swapBehavior())
+ qWarning() << "Could not create context for swap behavior"
+ << oldFormat.swapBehavior();
+#endif
+ context->makeCurrent(this);
+ }
+ else
+ {
+ context->makeCurrent(this);
+ }
+}
+
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- ShapesWidget w;
-
- if (QApplication::arguments().contains(QLatin1String("-maximize")))
- w.showMaximized();
- else if (QApplication::arguments().contains(QLatin1String("-fullscreen")))
- w.showFullScreen();
+ ShapesWidget view;
+
+ QStringList args = QCoreApplication::arguments();
+ int w_pos = args.indexOf("-width");
+ int h_pos = args.indexOf("-height");
+ if (w_pos >= 0 && h_pos >= 0)
+ {
+ bool ok = true;
+ int w = args.at(w_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse width argument:" << args;
+ return 1;
+ }
+ int h = args.at(h_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse height argument:" << args;
+ return 1;
+ }
+ view.resize(w, h);
+ }
else
- w.show();
+ {
+ view.resize(800, 600);
+ }
+ view.show();
+
return app.exec();
}
+
+
#include "shapes.moc"
diff --git a/demos/qt3d/teaservice/teaservice.cpp b/demos/qt3d/teaservice/teaservice.cpp
index 53baf5ffc..560ea3640 100644
--- a/demos/qt3d/teaservice/teaservice.cpp
+++ b/demos/qt3d/teaservice/teaservice.cpp
@@ -46,6 +46,8 @@
#include <QKeyEvent>
#include <QAction>
#include <QDebug>
+#include <QtCore/QTimer>
+
#include "qglview.h"
#include "meshobject.h"
#include "sceneobject.h"
@@ -285,7 +287,7 @@ class TeaServiceView : public QGLView
{
Q_OBJECT
public:
- TeaServiceView(QWidget *parent=0);
+ TeaServiceView(QWindow *parent=0);
public slots:
void standardLighting();
@@ -300,14 +302,14 @@ private:
TeaService *teaService;
};
-TeaServiceView::TeaServiceView(QWidget *parent)
+TeaServiceView::TeaServiceView(QWindow *parent)
: QGLView(parent)
{
teaService = new TeaService(this);
setOption(QGLView::ObjectPicking, true);
- connect(teaService, SIGNAL(changed()), this, SLOT(updateGL()));
+ connect(teaService, SIGNAL(changed()), this, SLOT(update()));
}
void TeaServiceView::initializeGL(QGLPainter *painter)
@@ -323,13 +325,13 @@ void TeaServiceView::paintGL(QGLPainter *painter)
void TeaServiceView::standardLighting()
{
teaService->changeMaterials(false);
- updateGL();
+ update();
}
void TeaServiceView::perPixelLighting()
{
teaService->changeMaterials(true);
- updateGL();
+ update();
}
void TeaServiceView::keyPressEvent(QKeyEvent *e)
@@ -338,7 +340,7 @@ void TeaServiceView::keyPressEvent(QKeyEvent *e)
// The Tab key turns the ShowPicking option on and off,
// which helps show what the pick buffer looks like.
setOption(QGLView::ShowPicking, ((options() & QGLView::ShowPicking) == 0));
- updateGL();
+ update();
}
QGLView::keyPressEvent(e);
}
@@ -346,33 +348,46 @@ void TeaServiceView::keyPressEvent(QKeyEvent *e)
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- QMainWindow mainw;
- mainw.setMinimumSize(850, 480);
- mainw.setWindowTitle(QLatin1String("Tea Service"));
TeaServiceView view;
- mainw.setCentralWidget(&view);
- view.setFocus();
-
- view.camera()->setEye(QVector3D(0, 3, 10));
-
- QMenu *menu = mainw.menuBar()->addMenu(QLatin1String("Effects"));
+ QStringList args = QCoreApplication::arguments();
+ int w_pos = args.indexOf("-width");
+ int h_pos = args.indexOf("-height");
+ if (w_pos >= 0 && h_pos >= 0)
+ {
+ bool ok = true;
+ int w = args.at(w_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse width argument:" << args;
+ return 1;
+ }
+ int h = args.at(h_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse height argument:" << args;
+ return 1;
+ }
+ view.resize(w, h);
+ }
+ else
+ {
+ view.resize(800, 600);
+ }
+ view.show();
- QAction *standardLighting = new QAction(QLatin1String("Standard lighting"), &mainw);
- menu->addAction(standardLighting);
- QObject::connect(standardLighting, SIGNAL(triggered()), &view, SLOT(standardLighting()));
+ // TODO: QWindow has no setFocus function
+ // view.setFocus();
- QAction *perPixelLighting = new QAction(QLatin1String("Per-pixel lighting"), &mainw);
- menu->addAction(perPixelLighting);
- QObject::connect(perPixelLighting, SIGNAL(triggered()), &view, SLOT(perPixelLighting()));
+ view.camera()->setEye(QVector3D(0, 3, 10));
- menu->addSeparator();
+ if (args.contains("-per-pixel-lighting"))
+ {
+ QTimer::singleShot(0, &view, SLOT(perPixelLighting()));
+ }
- QAction *exitAction = new QAction(QLatin1String("E&xit"), &mainw);
- menu->addAction(exitAction);
- QObject::connect(exitAction, SIGNAL(triggered()), &app, SLOT(quit()));
+ view.show();
- mainw.show();
return app.exec();
}
diff --git a/demos/quick3d/robo_bounce/main.cpp b/demos/quick3d/robo_bounce/main.cpp
index 807c3d14d..fb0a2b361 100644
--- a/demos/quick3d/robo_bounce/main.cpp
+++ b/demos/quick3d/robo_bounce/main.cpp
@@ -41,4 +41,4 @@
#include "../qmlres.h"
-QUICK3D_EXAMPLE_MAIN("qrc:///qml/desktop.qml")
+QUICK3D_EXAMPLE_MAIN("qml/desktop.qml")
diff --git a/examples/qt3d/basket/basketview.cpp b/examples/qt3d/basket/basketview.cpp
index 41b20dfbb..f4680dbf8 100644
--- a/examples/qt3d/basket/basketview.cpp
+++ b/examples/qt3d/basket/basketview.cpp
@@ -45,7 +45,7 @@
#include "qglbuilder.h"
#include "qglscenenode.h"
-BasketView::BasketView(QWidget *parent)
+BasketView::BasketView(QWindow *parent)
: QGLView(parent)
, m_angle(0)
{
diff --git a/examples/qt3d/basket/basketview.h b/examples/qt3d/basket/basketview.h
index 03a8d61fd..b52b2f36e 100644
--- a/examples/qt3d/basket/basketview.h
+++ b/examples/qt3d/basket/basketview.h
@@ -44,6 +44,7 @@
#include "qglview.h"
class QGLSceneNode;
+class QWindow;
//! [1]
class BasketView : public QGLView
@@ -55,7 +56,7 @@ public:
void setAngle(qreal angle) { m_angle = angle; update(); }
//! [1]
- BasketView(QWidget *parent = 0);
+ BasketView(QWindow *parent = 0);
~BasketView();
protected:
diff --git a/examples/qt3d/basket/main.cpp b/examples/qt3d/basket/main.cpp
index a97b10775..43551279f 100644
--- a/examples/qt3d/basket/main.cpp
+++ b/examples/qt3d/basket/main.cpp
@@ -38,22 +38,43 @@
**
****************************************************************************/
-#include <QApplication>
+#include <QtGui/QGuiApplication>
+#include <QtCore/QtDebug>
+
#include "basketview.h"
int main(int argc, char *argv[])
{
- QApplication app(argc, argv);
+ QGuiApplication app(argc, argv);
BasketView view;
if (view.stereoType() != QGLView::RedCyanAnaglyph)
view.camera()->setEyeSeparation(0.3f);
- if (QApplication::arguments().contains(QLatin1String("-maximize")))
- view.showMaximized();
- else if (QApplication::arguments().contains(QLatin1String("-fullscreen")))
- view.showFullScreen();
+ QStringList args = QCoreApplication::arguments();
+ int w_pos = args.indexOf("-width");
+ int h_pos = args.indexOf("-height");
+ if (w_pos >= 0 && h_pos >= 0)
+ {
+ bool ok = true;
+ int w = args.at(w_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse width argument:" << args;
+ return 1;
+ }
+ int h = args.at(h_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse height argument:" << args;
+ return 1;
+ }
+ view.resize(w, h);
+ }
else
- view.show();
+ {
+ view.resize(800, 600);
+ }
+ view.show();
return app.exec();
}
diff --git a/examples/qt3d/builder/builder.cpp b/examples/qt3d/builder/builder.cpp
index 3628b4d43..a780bf35d 100644
--- a/examples/qt3d/builder/builder.cpp
+++ b/examples/qt3d/builder/builder.cpp
@@ -50,7 +50,7 @@
#include <QtCore/qmath.h>
-BuilderView::BuilderView(QWidget *parent)
+BuilderView::BuilderView(QWindow *parent)
: QGLView(parent)
, canScene(new QGLSceneNode(this))
{
diff --git a/examples/qt3d/builder/builder.h b/examples/qt3d/builder/builder.h
index a54dea6bf..1f4e00590 100644
--- a/examples/qt3d/builder/builder.h
+++ b/examples/qt3d/builder/builder.h
@@ -50,7 +50,7 @@ class BuilderView : public QGLView
{
Q_OBJECT
public:
- BuilderView(QWidget *parent = 0);
+ BuilderView(QWindow *parent = 0);
~BuilderView();
protected:
diff --git a/examples/qt3d/builder/main.cpp b/examples/qt3d/builder/main.cpp
index 46c68467e..a773471e7 100644
--- a/examples/qt3d/builder/main.cpp
+++ b/examples/qt3d/builder/main.cpp
@@ -49,12 +49,31 @@ int main(int argc, char *argv[])
if (view.stereoType() != QGLView::RedCyanAnaglyph)
view.camera()->setEyeSeparation(0.3f);
- if (QApplication::arguments().contains(QLatin1String("-maximize")))
- view.showMaximized();
- else if (QApplication::arguments().contains(QLatin1String("-fullscreen")))
- view.showFullScreen();
+ QStringList args = QCoreApplication::arguments();
+ int w_pos = args.indexOf("-width");
+ int h_pos = args.indexOf("-height");
+ if (w_pos >= 0 && h_pos >= 0)
+ {
+ bool ok = true;
+ int w = args.at(w_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse width argument:" << args;
+ return 1;
+ }
+ int h = args.at(h_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse height argument:" << args;
+ return 1;
+ }
+ view.resize(w, h);
+ }
else
- view.show();
+ {
+ view.resize(800, 600);
+ }
+ view.show();
return app.exec();
}
diff --git a/examples/qt3d/cube/cubeview.cpp b/examples/qt3d/cube/cubeview.cpp
index e8de75168..09a07eafe 100644
--- a/examples/qt3d/cube/cubeview.cpp
+++ b/examples/qt3d/cube/cubeview.cpp
@@ -44,7 +44,7 @@
#include <QtCore/qurl.h>
-CubeView::CubeView(QWidget *parent)
+CubeView::CubeView(QWindow *parent)
: QGLView(parent)
{
QGLBuilder builder;
diff --git a/examples/qt3d/cube/cubeview.h b/examples/qt3d/cube/cubeview.h
index 8996fd342..c184ff046 100644
--- a/examples/qt3d/cube/cubeview.h
+++ b/examples/qt3d/cube/cubeview.h
@@ -49,7 +49,7 @@ class CubeView : public QGLView
{
Q_OBJECT
public:
- CubeView(QWidget *parent = 0);
+ CubeView(QWindow *parent = 0);
~CubeView();
protected:
diff --git a/examples/qt3d/cube/main.cpp b/examples/qt3d/cube/main.cpp
index bad1c4c4f..dd9bc45da 100644
--- a/examples/qt3d/cube/main.cpp
+++ b/examples/qt3d/cube/main.cpp
@@ -48,12 +48,31 @@ int main(int argc, char *argv[])
if (view.stereoType() != QGLView::RedCyanAnaglyph)
view.camera()->setEyeSeparation(0.3f);
- if (QApplication::arguments().contains(QLatin1String("-maximize")))
- view.showMaximized();
- else if (QApplication::arguments().contains(QLatin1String("-fullscreen")))
- view.showFullScreen();
+ QStringList args = QCoreApplication::arguments();
+ int w_pos = args.indexOf("-width");
+ int h_pos = args.indexOf("-height");
+ if (w_pos >= 0 && h_pos >= 0)
+ {
+ bool ok = true;
+ int w = args.at(w_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse width argument:" << args;
+ return 1;
+ }
+ int h = args.at(h_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse height argument:" << args;
+ return 1;
+ }
+ view.resize(w, h);
+ }
else
- view.show();
+ {
+ view.resize(800, 600);
+ }
+ view.show();
return app.exec();
}
diff --git a/examples/qt3d/cylinder/cylinderview.cpp b/examples/qt3d/cylinder/cylinderview.cpp
index 2b347ab68..a5db58364 100644
--- a/examples/qt3d/cylinder/cylinderview.cpp
+++ b/examples/qt3d/cylinder/cylinderview.cpp
@@ -44,7 +44,7 @@
#include "qglcylinder.h"
#include <QtCore/qurl.h>
-CylinderView::CylinderView(QWidget *parent)
+CylinderView::CylinderView(QWindow *parent)
: QGLView(parent)
{
QGLBuilder builder;
diff --git a/examples/qt3d/cylinder/cylinderview.h b/examples/qt3d/cylinder/cylinderview.h
index c2f4824b9..828772d78 100644
--- a/examples/qt3d/cylinder/cylinderview.h
+++ b/examples/qt3d/cylinder/cylinderview.h
@@ -49,7 +49,7 @@ class CylinderView : public QGLView
{
Q_OBJECT
public:
- CylinderView(QWidget *parent = 0);
+ CylinderView(QWindow *parent = 0);
~CylinderView();
protected:
diff --git a/examples/qt3d/cylinder/main.cpp b/examples/qt3d/cylinder/main.cpp
index 39297a53d..8b95e76a6 100644
--- a/examples/qt3d/cylinder/main.cpp
+++ b/examples/qt3d/cylinder/main.cpp
@@ -48,12 +48,31 @@ int main(int argc, char *argv[])
if (view.stereoType() != QGLView::RedCyanAnaglyph)
view.camera()->setEyeSeparation(0.3f);
- if (QApplication::arguments().contains(QLatin1String("-maximize")))
- view.showMaximized();
- else if (QApplication::arguments().contains(QLatin1String("-fullscreen")))
- view.showFullScreen();
+ QStringList args = QCoreApplication::arguments();
+ int w_pos = args.indexOf("-width");
+ int h_pos = args.indexOf("-height");
+ if (w_pos >= 0 && h_pos >= 0)
+ {
+ bool ok = true;
+ int w = args.at(w_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse width argument:" << args;
+ return 1;
+ }
+ int h = args.at(h_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse height argument:" << args;
+ return 1;
+ }
+ view.resize(w, h);
+ }
else
- view.show();
+ {
+ view.resize(800, 600);
+ }
+ view.show();
return app.exec();
}
diff --git a/examples/qt3d/geometry/geometryview.cpp b/examples/qt3d/geometry/geometryview.cpp
index 762e56fcd..4c690e4ef 100644
--- a/examples/qt3d/geometry/geometryview.cpp
+++ b/examples/qt3d/geometry/geometryview.cpp
@@ -55,7 +55,7 @@
#include "qglmaterialcollection.h"
#include "qgraphicsscale3d.h"
-GeometryView::GeometryView(QWidget *parent)
+GeometryView::GeometryView(QWindow *parent)
: QGLView(parent)
, timer(new QTimer(this))
{
@@ -118,5 +118,5 @@ void GeometryView::paintGL(QGLPainter *painter)
void GeometryView::rotate()
{
angle = (angle + 2) % 360;
- updateGL();
+ update();
}
diff --git a/examples/qt3d/geometry/geometryview.h b/examples/qt3d/geometry/geometryview.h
index 822a7a409..631d48598 100644
--- a/examples/qt3d/geometry/geometryview.h
+++ b/examples/qt3d/geometry/geometryview.h
@@ -57,7 +57,7 @@ class GeometryView : public QGLView
{
Q_OBJECT
public:
- GeometryView(QWidget *parent = 0);
+ GeometryView(QWindow *parent = 0);
~GeometryView();
protected:
diff --git a/examples/qt3d/geometry/main.cpp b/examples/qt3d/geometry/main.cpp
index 725066bb4..6b8ea814d 100644
--- a/examples/qt3d/geometry/main.cpp
+++ b/examples/qt3d/geometry/main.cpp
@@ -48,12 +48,31 @@ int main(int argc, char *argv[])
if (view.stereoType() != QGLView::RedCyanAnaglyph)
view.camera()->setEyeSeparation(0.3f);
- if (QApplication::arguments().contains(QLatin1String("-maximize")))
- view.showMaximized();
- else if (QApplication::arguments().contains(QLatin1String("-fullscreen")))
- view.showFullScreen();
+ QStringList args = QCoreApplication::arguments();
+ int w_pos = args.indexOf("-width");
+ int h_pos = args.indexOf("-height");
+ if (w_pos >= 0 && h_pos >= 0)
+ {
+ bool ok = true;
+ int w = args.at(w_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse width argument:" << args;
+ return 1;
+ }
+ int h = args.at(h_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse height argument:" << args;
+ return 1;
+ }
+ view.resize(w, h);
+ }
else
- view.show();
+ {
+ view.resize(800, 600);
+ }
+ view.show();
return app.exec();
}
diff --git a/examples/qt3d/nesting/cubeview.cpp b/examples/qt3d/nesting/cubeview.cpp
index d14b5048e..f3c1e3d6e 100644
--- a/examples/qt3d/nesting/cubeview.cpp
+++ b/examples/qt3d/nesting/cubeview.cpp
@@ -41,11 +41,13 @@
#include "cubeview.h"
#include "qglcube.h"
#include "qglteapot.h"
-#include <QtOpenGL/qglframebufferobject.h>
+
#include <QtCore/qpropertyanimation.h>
+#include <QtGui/QOpenGLFramebufferObject>
+
//! [1]
-CubeView::CubeView(QWidget *parent)
+CubeView::CubeView(QWindow *parent)
: QGLView(parent)
, fbo(0)
, tangle(0.0f)
@@ -105,7 +107,7 @@ CubeView::~CubeView()
//! [4]
void CubeView::initializeGL(QGLPainter *)
{
- fbo = new QGLFramebufferObject(512, 512, QGLFramebufferObject::Depth);
+ fbo = new QOpenGLFramebufferObject(512, 512, QOpenGLFramebufferObject::Depth);
fboSurface.setFramebufferObject(fbo);
//! [4]
diff --git a/examples/qt3d/nesting/cubeview.h b/examples/qt3d/nesting/cubeview.h
index 1fae5de4d..0ce1f4646 100644
--- a/examples/qt3d/nesting/cubeview.h
+++ b/examples/qt3d/nesting/cubeview.h
@@ -45,7 +45,7 @@
#include "qglbuilder.h"
#include "qglframebufferobjectsurface.h"
-class QGLFramebufferObject;
+class QOpenGLFramebufferObject;
class QGLCamera;
class CubeView : public QGLView
@@ -55,7 +55,7 @@ class CubeView : public QGLView
Q_PROPERTY(qreal cubeAngle READ cubeAngle WRITE setCubeAngle)
Q_PROPERTY(qreal orbitAngle READ orbitAngle WRITE setOrbitAngle)
public:
- CubeView(QWidget *parent = 0);
+ CubeView(QWindow *parent = 0);
~CubeView();
qreal teapotAngle() const { return tangle; }
@@ -76,7 +76,7 @@ private:
QGLSceneNode *cube;
QGLSceneNode *teapot;
QGLTexture2D qtlogo;
- QGLFramebufferObject *fbo;
+ QOpenGLFramebufferObject *fbo;
QGLFramebufferObjectSurface fboSurface;
QGLCamera *innerCamera;
qreal tangle;
diff --git a/examples/qt3d/nesting/main.cpp b/examples/qt3d/nesting/main.cpp
index abb38f0f7..f5201ebb8 100644
--- a/examples/qt3d/nesting/main.cpp
+++ b/examples/qt3d/nesting/main.cpp
@@ -46,12 +46,31 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
CubeView view;
- if (QApplication::arguments().contains(QLatin1String("-maximize")))
- view.showMaximized();
- else if (QApplication::arguments().contains(QLatin1String("-fullscreen")))
- view.showFullScreen();
+ QStringList args = QCoreApplication::arguments();
+ int w_pos = args.indexOf("-width");
+ int h_pos = args.indexOf("-height");
+ if (w_pos >= 0 && h_pos >= 0)
+ {
+ bool ok = true;
+ int w = args.at(w_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse width argument:" << args;
+ return 1;
+ }
+ int h = args.at(h_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse height argument:" << args;
+ return 1;
+ }
+ view.resize(w, h);
+ }
else
- view.show();
+ {
+ view.resize(800, 600);
+ }
+ view.show();
return app.exec();
}
diff --git a/examples/qt3d/solarsystem/main.cpp b/examples/qt3d/solarsystem/main.cpp
index 49c7cfb17..d36bf95e4 100644
--- a/examples/qt3d/solarsystem/main.cpp
+++ b/examples/qt3d/solarsystem/main.cpp
@@ -47,12 +47,31 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
SolarSystemView view;
- if (QApplication::arguments().contains(QLatin1String("-maximize")))
- view.showMaximized();
- else if (QApplication::arguments().contains(QLatin1String("-fullscreen")))
- view.showFullScreen();
+ QStringList args = QCoreApplication::arguments();
+ int w_pos = args.indexOf("-width");
+ int h_pos = args.indexOf("-height");
+ if (w_pos >= 0 && h_pos >= 0)
+ {
+ bool ok = true;
+ int w = args.at(w_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse width argument:" << args;
+ return 1;
+ }
+ int h = args.at(h_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse height argument:" << args;
+ return 1;
+ }
+ view.resize(w, h);
+ }
else
- view.show();
+ {
+ view.resize(800, 600);
+ }
+ view.show();
return app.exec();
}
diff --git a/examples/qt3d/solarsystem/solarsystem.cpp b/examples/qt3d/solarsystem/solarsystem.cpp
index 25b0f7699..ad29c3911 100644
--- a/examples/qt3d/solarsystem/solarsystem.cpp
+++ b/examples/qt3d/solarsystem/solarsystem.cpp
@@ -56,7 +56,7 @@
#include <QtCore/qmath.h>
-SolarSystemView::SolarSystemView(QWidget *parent)
+SolarSystemView::SolarSystemView(QWindow *parent)
: QGLView(parent)
, spaceScene(new QGLSceneNode(this))
, sunEffect(0)
diff --git a/examples/qt3d/solarsystem/solarsystem.h b/examples/qt3d/solarsystem/solarsystem.h
index aa166e726..372d1985b 100644
--- a/examples/qt3d/solarsystem/solarsystem.h
+++ b/examples/qt3d/solarsystem/solarsystem.h
@@ -56,7 +56,7 @@ class SolarSystemView : public QGLView
Q_PROPERTY(qreal angle3 READ angle3 WRITE setAngle3)
Q_PROPERTY(qreal glowFactor READ glowFactor WRITE setGlowFactor)
public:
- SolarSystemView(QWidget *parent = 0);
+ SolarSystemView(QWindow *parent = 0);
~SolarSystemView();
qreal angle1() const { return m_angle1; }
diff --git a/examples/qt3d/tank/main.cpp b/examples/qt3d/tank/main.cpp
index ad97805eb..5254b05d2 100644
--- a/examples/qt3d/tank/main.cpp
+++ b/examples/qt3d/tank/main.cpp
@@ -53,12 +53,31 @@ int main(int argc, char *argv[])
if (view.stereoType() != QGLView::RedCyanAnaglyph)
view.camera()->setEyeSeparation(0.3f);
- if (QApplication::arguments().contains(QLatin1String("-maximize")))
- view.showMaximized();
- else if (QApplication::arguments().contains(QLatin1String("-fullscreen")))
- view.showFullScreen();
+ QStringList args = QCoreApplication::arguments();
+ int w_pos = args.indexOf("-width");
+ int h_pos = args.indexOf("-height");
+ if (w_pos >= 0 && h_pos >= 0)
+ {
+ bool ok = true;
+ int w = args.at(w_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse width argument:" << args;
+ return 1;
+ }
+ int h = args.at(h_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse height argument:" << args;
+ return 1;
+ }
+ view.resize(w, h);
+ }
else
- view.show();
+ {
+ view.resize(800, 600);
+ }
+ view.show();
return a.exec();
}
diff --git a/examples/qt3d/tank/tankview.cpp b/examples/qt3d/tank/tankview.cpp
index 1c2e706d0..6adc25edc 100644
--- a/examples/qt3d/tank/tankview.cpp
+++ b/examples/qt3d/tank/tankview.cpp
@@ -48,7 +48,7 @@
#include <QMouseEvent>
-TankView::TankView(QWidget *parent)
+TankView::TankView(QWindow *parent)
: QGLView(parent)
, m_tankScene(new QGLSceneNode)
, m_count(0)
@@ -60,7 +60,8 @@ TankView::TankView(QWidget *parent)
Tank *tank = addTank();
connect(tank, SIGNAL(updated()), this, SLOT(update()));
- setToolTip(tr("Double-click to add more tanks"));
+ // TODO: setToolTip not implemented in QWindow
+ // setToolTip(tr("Double-click to add more tanks"));
setWindowTitle(tr("Double-click Me!"));
}
diff --git a/examples/qt3d/tank/tankview.h b/examples/qt3d/tank/tankview.h
index 38b966158..112598ad2 100644
--- a/examples/qt3d/tank/tankview.h
+++ b/examples/qt3d/tank/tankview.h
@@ -49,7 +49,7 @@ class Tank;
class TankView : public QGLView
{
public:
- TankView(QWidget *parent = 0);
+ TankView(QWindow *parent = 0);
~TankView();
protected:
void initializeGL(QGLPainter *painter);
diff --git a/examples/qt3d/teapot/main.cpp b/examples/qt3d/teapot/main.cpp
index f98693f3c..d79340be1 100644
--- a/examples/qt3d/teapot/main.cpp
+++ b/examples/qt3d/teapot/main.cpp
@@ -50,12 +50,31 @@ int main(int argc, char *argv[])
if (view.stereoType() != QGLView::RedCyanAnaglyph)
view.camera()->setEyeSeparation(0.3f);
- if (QApplication::arguments().contains(QLatin1String("-maximize")))
- view.showMaximized();
- else if (QApplication::arguments().contains(QLatin1String("-fullscreen")))
- view.showFullScreen();
+ QStringList args = QCoreApplication::arguments();
+ int w_pos = args.indexOf("-width");
+ int h_pos = args.indexOf("-height");
+ if (w_pos >= 0 && h_pos >= 0)
+ {
+ bool ok = true;
+ int w = args.at(w_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse width argument:" << args;
+ return 1;
+ }
+ int h = args.at(h_pos + 1).toInt(&ok);
+ if (!ok)
+ {
+ qWarning() << "Could not parse height argument:" << args;
+ return 1;
+ }
+ view.resize(w, h);
+ }
else
- view.show();
+ {
+ view.resize(800, 600);
+ }
+ view.show();
//! [main-args-end]
return app.exec();
diff --git a/examples/qt3d/teapot/teapotview.h b/examples/qt3d/teapot/teapotview.h
index d251f990a..e2ba50b05 100644
--- a/examples/qt3d/teapot/teapotview.h
+++ b/examples/qt3d/teapot/teapotview.h
@@ -51,7 +51,7 @@ class TeapotView : public QGLView
{
Q_OBJECT
public:
- TeapotView(QWidget *parent = 0) : QGLView(parent), teapot(0) {}
+ TeapotView(QWindow *parent = 0) : QGLView(parent), teapot(0) {}
~TeapotView();
protected:
diff --git a/examples/quick3d/basket/qml/Basket.qml b/examples/quick3d/basket/qml/Basket.qml
index 60a0e2f9e..aa81de493 100644
--- a/examples/quick3d/basket/qml/Basket.qml
+++ b/examples/quick3d/basket/qml/Basket.qml
@@ -44,7 +44,7 @@ import Qt3D 1.0
Viewport {
width: parent.width; height: parent.height
-
+ renderMode: "DirectRender"
fillColor: "#000000"
camera: Camera {
diff --git a/pkg.pri b/pkg.pri
index c82266cbf..540da7e0e 100644
--- a/pkg.pri
+++ b/pkg.pri
@@ -218,7 +218,7 @@ defineTest(qtcAddDeployment) {
!isEqual(source,$$targetFullPath) {
!isEmpty(copyCommand):copyCommand += &&
copyCommand += $(MKDIR) \"$$target\"
- copyCommand += && $(COPY_DIR) \"$$source\" \"$$target\"
+ copyCommand += && $(COPY_DIR) -v \"$$source\" \"$$target\"
}
}
!isEmpty(copyCommand) {
diff --git a/src/imports/threed/viewport.cpp b/src/imports/threed/viewport.cpp
index a747c97e9..31e14c0a4 100644
--- a/src/imports/threed/viewport.cpp
+++ b/src/imports/threed/viewport.cpp
@@ -52,13 +52,13 @@
#include "skybox.h"
#include <QtGui/QOpenGLContext>
+#include <QtGui/QOpenGLFramebufferObject>
#include <QtGui/qpainter.h>
#include <QtWidgets/qgraphicsview.h>
#include <QtWidgets/qgraphicsscene.h>
#include <QtWidgets/qgraphicssceneevent.h>
#include <QtGui/qevent.h>
-#include <QtOpenGL/qglframebufferobject.h>
#include <QtCore/qtimer.h>
#include <QtCore/qcoreapplication.h>
#include <QtDeclarative/qdeclarativeinfo.h>
@@ -230,7 +230,7 @@ public:
QGLLightModel *lightModel;
QWidget *viewWidget;
int pickId;
- QGLFramebufferObject *pickFbo;
+ QOpenGLFramebufferObject *pickFbo;
QMap<int, QObject *> objects;
QObject *pressedObject;
Qt::MouseButton pressedButton;
@@ -1140,8 +1140,8 @@ void Viewport::objectForPoint()
if (!d->pickFbo)
{
- d->pickFbo = new QGLFramebufferObject(fbosize,
- QGLFramebufferObject::CombinedDepthStencil);
+ d->pickFbo = new QOpenGLFramebufferObject(fbosize,
+ QOpenGLFramebufferObject::CombinedDepthStencil);
}
int objectId = -1;
QScopedPointer<QGLAbstractSurface> fboSurf(new QGLFramebufferObjectSurface(d->pickFbo));
diff --git a/src/quick3d/quick3d.pro b/src/quick3d/quick3d.pro
index c73c51119..04761d26d 100644
--- a/src/quick3d/quick3d.pro
+++ b/src/quick3d/quick3d.pro
@@ -8,7 +8,7 @@ gcov {
CONFIG += dll warn_on
}
-QT += declarative qtquick1
+QT += declarative
include(../../pkg.pri)
diff --git a/src/threed/painting/qglpainter.cpp b/src/threed/painting/qglpainter.cpp
index 1d2edb28c..76eeff765 100644
--- a/src/threed/painting/qglpainter.cpp
+++ b/src/threed/painting/qglpainter.cpp
@@ -43,6 +43,8 @@
#include "qglpainter_p.h"
#include "qglabstracteffect.h"
#include "qglext_p.h"
+#include <QtGui/QOpenGLContext>
+
#include <QtOpenGL/qglpixelbuffer.h>
#include <QtOpenGL/qglshaderprogram.h>
#include <QtOpenGL/qglframebufferobject.h>
@@ -52,6 +54,7 @@
#include <QtCore/qmap.h>
#if !defined(QT_NO_THREAD)
#include <QtCore/qthreadstorage.h>
+#include <QtCore/QThread>
#endif
#include "qglflatcoloreffect_p.h"
#include "qglflattextureeffect_p.h"
@@ -63,7 +66,7 @@
#include "qgeometrydata.h"
#include "qglvertexbundle_p.h"
#include "qmatrix4x4stack_p.h"
-#include "qglwidgetsurface.h"
+#include "qglwindowsurface.h"
#include "qglpixelbuffersurface.h"
#include "qglpaintersurface_p.h"
@@ -185,22 +188,25 @@ Q_GLOBAL_STATIC(QGLPainterPrivateCache, painterPrivateCache)
QGLPainterPrivateCache::QGLPainterPrivateCache()
{
- connect(QGLSignalProxy::instance(),
- SIGNAL(aboutToDestroyContext(const QGLContext *)),
- this,
- SLOT(contextDestroyed(const QGLContext *)));
}
QGLPainterPrivateCache::~QGLPainterPrivateCache()
{
}
-QGLPainterPrivate *QGLPainterPrivateCache::fromContext
- (const QGLContext *context)
+QGLPainterPrivate *QGLPainterPrivateCache::fromContext(QOpenGLContext *context)
{
QGLPainterPrivate *priv = cache.value(context, 0);
if (priv)
return priv;
+#ifndef QT_NO_THREAD
+ Q_ASSERT_X(context->thread() == QThread::currentThread(),
+ Q_FUNC_INFO,
+ "Attempt to fetch painter state for context outside contexts thread");
+#endif
+ // since we assert this is the same thread then this is bound to be a direct
+ // connection, not a queued (asynchronous) connection
+ connect(context, SIGNAL(destroyed()), this, SLOT(contextDestroyed()));
priv = new QGLPainterPrivate();
priv->context = context;
cache.insert(context, priv);
@@ -212,8 +218,9 @@ QGLPainterPrivateCache *QGLPainterPrivateCache::instance()
return painterPrivateCache();
}
-void QGLPainterPrivateCache::contextDestroyed(const QGLContext *context)
+void QGLPainterPrivateCache::contextDestroyed()
{
+ QOpenGLContext *context = qobject_cast<QOpenGLContext *>(sender());
QGLPainterPrivate *priv = cache.value(context, 0);
if (priv) {
priv->context = 0;
@@ -241,7 +248,7 @@ QGLPainter::QGLPainter()
\sa begin()
*/
-QGLPainter::QGLPainter(const QGLContext *context)
+QGLPainter::QGLPainter(QOpenGLContext *context)
: d_ptr(0)
{
begin(context);
@@ -249,15 +256,15 @@ QGLPainter::QGLPainter(const QGLContext *context)
/*!
Constructs a new GL painter and attaches it to the GL
- context associated with \a widget. It is not necessary to
+ context associated with \a window. It is not necessary to
call begin() after construction.
\sa begin(), isActive()
*/
-QGLPainter::QGLPainter(QGLWidget *widget)
+QGLPainter::QGLPainter(QWindow *window)
: d_ptr(0)
{
- begin(widget);
+ begin(window);
}
/*!
@@ -301,14 +308,14 @@ QGLPainter::~QGLPainter()
}
/*!
- Begins painting on QGLContext::currentContext(). Returns false
+ Begins painting on the current GL context. Returns false
if there is no GL context current.
\sa end()
*/
bool QGLPainter::begin()
{
- return begin(QGLContext::currentContext());
+ return begin(QOpenGLContext::currentContext());
}
/*!
@@ -325,7 +332,7 @@ bool QGLPainter::begin()
\sa end(), isActive()
*/
-bool QGLPainter::begin(const QGLContext *context)
+bool QGLPainter::begin(QOpenGLContext *context)
{
if (!context)
return false;
@@ -337,13 +344,13 @@ bool QGLPainter::begin(const QGLContext *context)
\internal
*/
bool QGLPainter::begin
- (const QGLContext *context, QGLAbstractSurface *surface,
+ (QOpenGLContext *context, QGLAbstractSurface *surface,
bool destroySurface)
{
// If we don't have a context specified, then use the one
// that the surface just made current.
if (!context)
- context = QGLContext::currentContext();
+ context = QOpenGLContext::currentContext();
// Find the QGLPainterPrivate for the context, or create a new one.
d_ptr = painterPrivateCache()->fromContext(context);
@@ -395,17 +402,19 @@ bool QGLPainter::begin
}
/*!
- Begins painting on the GL context associated with \a widget.
- Returns false if \a widget is null.
+ Begins GL painting on \a widget. Returns false if \a widget is null.
\sa end()
*/
-bool QGLPainter::begin(QGLWidget *widget)
+bool QGLPainter::begin(QWindow *window)
{
- if (!widget)
- return false;
- end();
- return begin(widget->context(), new QGLWidgetSurface(widget));
+ bool result = false;
+ if (window)
+ {
+ end();
+ result = begin(0, new QGLWindowSurface(window));
+ }
+ return result;
}
/*!
@@ -535,7 +544,7 @@ bool QGLPainter::isActive() const
Returns the GL context that is bound to this painter, or null
if it is not currently bound.
*/
-const QGLContext *QGLPainter::context() const
+QOpenGLContext *QGLPainter::context() const
{
if (d_ptr)
return d_ptr->context;
diff --git a/src/threed/painting/qglpainter.h b/src/threed/painting/qglpainter.h
index 75146f69d..eaa8907f1 100644
--- a/src/threed/painting/qglpainter.h
+++ b/src/threed/painting/qglpainter.h
@@ -83,21 +83,21 @@ class Q_QT3D_EXPORT QGLPainter : public QOpenGLFunctions
{
public:
QGLPainter();
- explicit QGLPainter(const QGLContext *context);
- explicit QGLPainter(QGLWidget *widget);
+ explicit QGLPainter(QOpenGLContext *context);
+ explicit QGLPainter(QWindow *widget);
explicit QGLPainter(QPainter *painter);
explicit QGLPainter(QGLAbstractSurface *surface);
virtual ~QGLPainter();
bool begin();
- bool begin(const QGLContext *context);
- bool begin(QGLWidget *widget);
+ bool begin(QOpenGLContext *context);
+ bool begin(QWindow *window);
bool begin(QPainter *painter);
bool begin(QGLAbstractSurface *surface);
bool end();
bool isActive() const;
- const QGLContext *context() const;
+ QOpenGLContext *context() const;
bool isFixedFunction() const;
@@ -212,7 +212,7 @@ private:
friend class QGLAbstractEffect;
- bool begin(const QGLContext *context, QGLAbstractSurface *surface,
+ bool begin(QOpenGLContext *context, QGLAbstractSurface *surface,
bool destroySurface = true);
};
diff --git a/src/threed/painting/qglpainter_p.h b/src/threed/painting/qglpainter_p.h
index bd1a0c6bf..510a136ef 100644
--- a/src/threed/painting/qglpainter_p.h
+++ b/src/threed/painting/qglpainter_p.h
@@ -94,7 +94,7 @@ public:
~QGLPainterPrivate();
QAtomicInt ref;
- const QGLContext *context;
+ QOpenGLContext *context;
QMatrix4x4Stack projectionMatrix;
QMatrix4x4Stack modelViewMatrix;
QMatrix4x4 inverseEyeMatrix;
@@ -137,17 +137,17 @@ public:
QGLPainterPrivateCache();
~QGLPainterPrivateCache();
- QMap<const QGLContext *, QGLPainterPrivate *> cache;
+ QMap<const QOpenGLContext *, QGLPainterPrivate *> cache;
- QGLPainterPrivate *fromContext(const QGLContext *context);
+ QGLPainterPrivate *fromContext(QOpenGLContext *context);
static QGLPainterPrivateCache *instance();
public Q_SLOTS:
- void contextDestroyed(const QGLContext *context);
+ void contextDestroyed();
Q_SIGNALS:
- void destroyedContext(const QGLContext *context);
+ void destroyedContext(const QOpenGLContext *context);
};
QT_END_NAMESPACE
diff --git a/src/threed/surfaces/qglabstractsurface.cpp b/src/threed/surfaces/qglabstractsurface.cpp
index f903ac047..6ea1f4b6b 100644
--- a/src/threed/surfaces/qglabstractsurface.cpp
+++ b/src/threed/surfaces/qglabstractsurface.cpp
@@ -44,9 +44,14 @@
#include "qglframebufferobjectsurface.h"
#include "qglpixelbuffersurface.h"
#include "qglsubsurface.h"
-#include "qglwidgetsurface.h"
-#include <QtGui/qpaintdevice.h>
-#include <QtDebug>
+#include "qglwindowsurface.h"
+
+#include <QtCore/QtDebug>
+#include <QtGui/QWindow>
+#include <QtGui/QOpenGLFramebufferObject>
+#include <QtOpenGL/QGLPixelBuffer>
+#include <QtGui/QOpenGLContext>
+#include <QtGui/QSurface>
QT_BEGIN_NAMESPACE
@@ -97,7 +102,7 @@ QT_BEGIN_NAMESPACE
When QGLPainter::popSurface() is called, the previous surface
is re-activated and the \c{glViewport()} changed accordingly.
- \sa QGLFramebufferObjectSurface, QGLWidgetSurface, QGLSubsurface
+ \sa QGLFramebufferObjectSurface, QGLWindowSurface, QGLSubsurface
\sa QGLPixelBufferSurface, QGLPainter::pushSurface()
*/
@@ -105,7 +110,7 @@ QT_BEGIN_NAMESPACE
\enum QGLAbstractSurface::SurfaceType
This enum defines the type of a QGLAbstractSurface.
- \value Widget Instance of QGLWidgetSurface.
+ \value Window Instance of QGLWindowSurface.
\value FramebufferObject Instance of QGLFramebufferObjectSurface.
\value PixelBuffer Instance of QGLPixelBufferSurface.
\value Subsurface Instance of QGLSubsurface.
@@ -117,6 +122,14 @@ QT_BEGIN_NAMESPACE
Constructs an OpenGL drawing surface of the specified \a surfaceType.
*/
+QGLAbstractSurface::QGLAbstractSurface(int surfaceType)
+ : m_context(0)
+ , m_window(0)
+ , m_fbo(0)
+ , m_pb(0)
+ , m_type(surfaceType)
+{
+}
/*!
Destroys this OpenGL drawing surface.
@@ -132,28 +145,38 @@ QGLAbstractSurface::~QGLAbstractSurface()
*/
/*!
- \fn QPaintDevice *QGLAbstractSurface::device() const
+ \fn QOpenGLContext *context() const
- Returns the raw device that this surface will draw on.
+ Returns the OpenGL context which is associated with this surface, if any.
+ When this surface is first activated, if this value is null then it will be
+ set to the context current at that time.
- If the surface is an instance of QGLSubsurface, then this will
- return the device of the surface that underlies the subsurface.
- The viewportRect() defines the region to render into.
+ The default value is null.
- \sa viewportRect()
+ \sa setContext()
*/
/*!
- \fn bool QGLAbstractSurface::activate(QGLAbstractSurface *prevSurface)
+ \fn void context(QOpenGLContext *context)
- Activate this surface by making its context current, and binding
- the associated framebuffer object, if any.
+ Sets the OpenGL context which is to be associated with this surface.
+ When this surface is first activated, if this value is null then it will be
+ set to the context current at that time.
+
+ \sa context()
+*/
+
+/*!
+ \fn void QGLAbstractSurface::activate(QGLAbstractSurface *prevSurface)
+
+ Activate this surface.
If \a prevSurface is null, then that surface has just been deactivated
in the process of switching to this surface. This may allow activate()
to optimize the transition to avoid unnecessary state changes.
- Returns true if the surface was activated; false otherwise.
+ Typically implementations should assert if this fails in debug mode,
+ since no rendering into the surface is possible.
\sa deactivate(), switchTo()
*/
@@ -165,7 +188,7 @@ QGLAbstractSurface::~QGLAbstractSurface()
context current. Typically this will release the framebuffer
object associated with the surface.
- If \a nextSurface is null, then that surface will be activated next
+ If \a nextSurface is not-null, then that surface will be activated next
in the process of switching away from this surface. This may allow
deactivate() to optimize the transition to avoid unnecessary state
changes.
@@ -185,13 +208,26 @@ QGLAbstractSurface::~QGLAbstractSurface()
*/
QRect QGLAbstractSurface::viewportRect() const
{
+ Q_ASSERT(isValid());
+
QRect view = viewportGL();
- QPaintDevice *dev = device();
int height;
- if (dev->devType() == QInternal::Widget)
- height = static_cast<QWidget *>(dev)->height();
- else
- height = dev->height();
+ if (m_type == Window)
+ {
+ Q_ASSERT(m_window);
+ height = m_window->height();
+ }
+ else if (m_type == FramebufferObject)
+ {
+ Q_ASSERT(m_fbo);
+ height = m_fbo->size().height();
+ }
+ else if (m_type == PixelBuffer)
+ {
+ Q_ASSERT(m_pb);
+ height = m_pb->size().height();
+ }
+
return QRect(view.x(), height - (view.y() + view.height()),
view.width(), view.height());
}
@@ -199,7 +235,7 @@ QRect QGLAbstractSurface::viewportRect() const
/*!
\fn QRect QGLAbstractSurface::viewportGL() const
- Returns the rectangle of the surface device() that is occupied by
+ Returns the rectangle of the surface that is occupied by
the viewport for this surface. The origin is at the bottom-left,
which makes the value suitable for passing to \c{glViewport()}:
@@ -214,42 +250,35 @@ QRect QGLAbstractSurface::viewportRect() const
and right stereo eye images into the two halves of a QGLWidget.
The eye surfaces would typically be instances of QGLSubsurface.
+ Note that the value returned from this function is not defined before
+ the activate() function has been called at least once.
+
\sa viewportRect(), device()
*/
/*!
- Returns the aspect ratio of viewportGL() after correcting for the
- DPI of device().
+ Returns the aspect ratio of viewportGL().
The return value is used to correct perspective and orthographic
- projections for the aspect ratio of the drawing surface. Subclasses
- may override this function to adjust the return value if the DPI of
- device() is not sufficient to determine the aspect ratio.
+ projections for the aspect ratio of the drawing surface.
+
+ No adjustments are made for DPI.
+
+ Subclasses may override this function to further adjust the return value
+ if the DPI in the horizontal vs vertical direction is not the same,
+ that is, the pixels are not square.
*/
qreal QGLAbstractSurface::aspectRatio() const
{
+ Q_ASSERT(isValid());
+
// Get the size of the current viewport.
QSize size = viewportGL().size();
- if (size.width() == 0 || size.height() == 0 ||
- size.width() == size.height())
+ if (size.width() == size.height())
return 1.0f;
- // Use the device's DPI setting to determine the pixel aspect ratio.
- QPaintDevice *device = this->device();
-
- int dpiX = 0;
- int dpiY = 0;
- if(device)
- {
- dpiX = device->logicalDpiX();
- dpiY = device->logicalDpiY();
- } else
- qWarning() << "null device in QGLAbstractSurface::aspectRatio()";
- if (dpiX <= 0 || dpiY <= 0)
- dpiX = dpiY = 1;
-
- // Return the final aspect ratio based on viewport and pixel size.
- return ((qreal)(size.width() * dpiY)) / ((qreal)(size.height() * dpiX));
+ // Return the final aspect ratio based on viewport.
+ return (qreal)size.width() / (qreal)size.height();
}
/*!
@@ -277,54 +306,46 @@ bool QGLAbstractSurface::switchTo(QGLAbstractSurface *nextSurface)
}
/*!
- Creates an OpenGL drawing surface for the specified paint \a device.
- Returns null if it is not possible to create a surface for \a device.
+ Returns true if this surface is valid and ready to be drawn into with OpenGL
+ commands. Typically it will be true if the surface has been associated with
+ an opengl context and a supported painting context such as a window or fbo.
- \sa createSurfaceForContext()
+ Sub-class implementations can use this fall-back, which simply checks for
+ a valid viewport rectangle.
+
+ Note that the surface may only become valid during activate() calls.
*/
-QGLAbstractSurface *QGLAbstractSurface::createSurfaceForDevice
- (QPaintDevice *device)
+bool QGLAbstractSurface::isValid() const
{
- if(!device)
- {
- qWarning() << "Unable to create a surface for device " << device;
- return 0;
- }
- switch (device->devType()) {
- case QInternal::Widget: {
- QGLWidget *glw = qobject_cast<QGLWidget *>
- (static_cast<QWidget *>(device));
- if (glw)
- return new QGLWidgetSurface(glw);
- else
- return 0;
- }
- case QInternal::Pbuffer:
- return new QGLPixelBufferSurface(static_cast<QGLPixelBuffer *>(device));
- case QInternal::FramebufferObject:
- return new QGLFramebufferObjectSurface
- (static_cast<QGLFramebufferObject *>(device));
- default:
- return 0;
- }
+ return viewportGL().isValid();
}
/*!
- Creates an OpenGL drawing surface for the paint device
- underlying \a context. If the paint device is not recognized,
- then a generic surface will be created that makes \a context
- current when the surface is activated.
+ Creates an OpenGL drawing surface using the given \a context. This relies on
+ the \a context having a valid surface which is a QWindow in which case the
+ surface returned is a QGLWindowSurface.
- \sa createSurfaceForDevice()
+ If not, then a generic surface based on the OpenGL context is returned. In this
+ case the generic surface will fail unless an underlying rendering surface becomes
+ available prior to attempting to activate the surface.
*/
-QGLAbstractSurface *QGLAbstractSurface::createSurfaceForContext
- (const QGLContext *context)
+QGLAbstractSurface *QGLAbstractSurface::createSurfaceForContext(QOpenGLContext *context)
{
Q_ASSERT(context);
- QGLAbstractSurface *surface = createSurfaceForDevice(context->device());
- if (!surface)
- surface = new QGLContextSurface(context);
- return surface;
+#ifndef QT_NO_DEBUG_STREAM
+ if (context->surface() && context->surface()->surfaceType() != QSurface::Window)
+ qWarning() << "Attempt to cast non-window surface";
+#endif
+ QWindow *win = static_cast<QWindow*>(context->surface());
+ if (win)
+ {
+ return new QGLWindowSurface(win);
+ }
+ else
+ {
+ return new QGLContextSurface(context);
+ }
+ return 0;
}
QT_END_NAMESPACE
diff --git a/src/threed/surfaces/qglabstractsurface.h b/src/threed/surfaces/qglabstractsurface.h
index 715abb471..6e70e9be3 100644
--- a/src/threed/surfaces/qglabstractsurface.h
+++ b/src/threed/surfaces/qglabstractsurface.h
@@ -43,6 +43,7 @@
#define QGLABSTRACTSURFACE_H
#include "qt3dglobal.h"
+
#include <QtOpenGL/qgl.h>
QT_BEGIN_HEADER
@@ -51,6 +52,10 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Qt3D)
+class QWindow;
+class QOpenGLFramebufferObject;
+class QGLPixelBuffer;
+
class Q_QT3D_EXPORT QGLAbstractSurface
{
public:
@@ -58,7 +63,7 @@ public:
enum SurfaceType
{
- Widget,
+ Window,
FramebufferObject,
PixelBuffer,
Subsurface,
@@ -67,7 +72,16 @@ public:
int surfaceType() const { return m_type; }
- virtual QPaintDevice *device() const = 0;
+ QOpenGLContext *context() const
+ {
+ return m_context;
+ }
+
+ void setContext(QOpenGLContext *context)
+ {
+ m_context = context;
+ }
+
virtual bool activate(QGLAbstractSurface *prevSurface = 0) = 0;
virtual void deactivate(QGLAbstractSurface *nextSurface = 0) = 0;
virtual QRect viewportGL() const = 0;
@@ -75,12 +89,17 @@ public:
virtual qreal aspectRatio() const;
bool switchTo(QGLAbstractSurface *nextSurface);
+ virtual bool isValid() const;
- static QGLAbstractSurface *createSurfaceForDevice(QPaintDevice *device);
- static QGLAbstractSurface *createSurfaceForContext(const QGLContext *context);
+ static QGLAbstractSurface *createSurfaceForContext(QOpenGLContext *context);
protected:
- QGLAbstractSurface(int surfaceType) : m_type(surfaceType) {}
+ QGLAbstractSurface(int surfaceType);
+
+ QOpenGLContext *m_context;
+ QWindow *m_window;
+ QOpenGLFramebufferObject *m_fbo;
+ QGLPixelBuffer *m_pb;
private:
int m_type;
diff --git a/src/threed/surfaces/qglcontextsurface.cpp b/src/threed/surfaces/qglcontextsurface.cpp
index f5bb272d0..bbd34a31a 100644
--- a/src/threed/surfaces/qglcontextsurface.cpp
+++ b/src/threed/surfaces/qglcontextsurface.cpp
@@ -39,22 +39,50 @@
**
****************************************************************************/
-#include <QtDebug>
#include "qglcontextsurface_p.h"
-QT_BEGIN_NAMESPACE
+#include <QtCore/QtDebug>
+#include <QtGui/QWindow>
+#include <QtGui/QOpenGLContext>
-QPaintDevice *QGLContextSurface::device() const
-{
- return m_context->device();
-}
+QT_BEGIN_NAMESPACE
bool QGLContextSurface::activate(QGLAbstractSurface *prevSurface)
{
Q_UNUSED(prevSurface);
- if (QGLContext::currentContext() != m_context)
- const_cast<QGLContext *>(m_context)->makeCurrent();
- return true;
+ Q_ASSERT_X(QOpenGLContext::currentContext() || m_context,
+ Q_FUNC_INFO,
+ "Activating GL contex surface without GL context");
+ if (m_context)
+ {
+ if (m_context != QOpenGLContext::currentContext())
+ {
+ m_context->makeCurrent(m_window);
+ }
+ }
+ else
+ {
+ m_context = QOpenGLContext::currentContext();
+ }
+ // Once we have used this context with a window remember that window and
+ // complain if it is used with another window, since that will affect the
+ // viewport and other rendering assumptions.
+ if (!m_window)
+ {
+#ifndef QT_NO_DEBUG_STREAM
+ if (!m_context->surface() || m_context->surface()->surfaceType() == QSurface::Window)
+ qWarning() << "Attempt to access context without GL window";
+#endif
+ m_window = static_cast<QWindow*>(m_context->surface());
+ }
+#ifndef QT_NO_DEBUG_STREAM
+ else
+ {
+ if (m_context->surface() != m_window)
+ qWarning() << "Attempt to render in wrong window for context";
+ }
+#endif
+ return isValid();
}
void QGLContextSurface::deactivate(QGLAbstractSurface *nextSurface)
@@ -64,13 +92,27 @@ void QGLContextSurface::deactivate(QGLAbstractSurface *nextSurface)
QRect QGLContextSurface::viewportGL() const
{
- QPaintDevice *device = m_context->device();
- if(!device)
+ QRect r;
+ if (m_window)
+ {
+ r = m_window->geometry();
+ }
+#ifndef QT_NO_DEBUG_STREAM
+ else
{
- qWarning() << "Null paint device in QGLContextSurface::viewportGL()";
- return QRect(0,0,0,0);
+ qWarning() << "Attempt to get viewport rect with no window\n"
+ << "Call activate() first";
}
- return QRect(0, 0, device->width(), device->height());
+#endif
+ return r;
+}
+
+bool QGLContextSurface::isValid() const
+{
+ bool winOK = true;
+ if (m_window)
+ winOK = m_window->surfaceType() == QWindow::OpenGLSurface;
+ return isValid() && winOK;
}
QT_END_NAMESPACE
diff --git a/src/threed/surfaces/qglcontextsurface_p.h b/src/threed/surfaces/qglcontextsurface_p.h
index 6c1a8beba..4c75b3507 100644
--- a/src/threed/surfaces/qglcontextsurface_p.h
+++ b/src/threed/surfaces/qglcontextsurface_p.h
@@ -62,19 +62,21 @@ QT_BEGIN_NAMESPACE
class QGLContextSurface : public QGLAbstractSurface
{
public:
- explicit QGLContextSurface(const QGLContext *context)
- : QGLAbstractSurface(502)
- , m_context(context) {}
+ static const int QGLCONTEXT_SURFACE_ID = 502;
+
+ explicit QGLContextSurface(QOpenGLContext *context)
+ : QGLAbstractSurface(QGLCONTEXT_SURFACE_ID)
+ {
+ m_context = context;
+ }
~QGLContextSurface() {}
- QPaintDevice *device() const;
bool activate(QGLAbstractSurface *prevSurface);
void deactivate(QGLAbstractSurface *nextSurface);
QRect viewportGL() const;
+ bool isValid() const;
private:
- const QGLContext *m_context;
-
Q_DISABLE_COPY(QGLContextSurface)
};
diff --git a/src/threed/surfaces/qgldrawbuffersurface.cpp b/src/threed/surfaces/qgldrawbuffersurface.cpp
index 11aaa6103..574b9a097 100644
--- a/src/threed/surfaces/qgldrawbuffersurface.cpp
+++ b/src/threed/surfaces/qgldrawbuffersurface.cpp
@@ -43,11 +43,6 @@
QT_BEGIN_NAMESPACE
-QPaintDevice *QGLDrawBufferSurface::device() const
-{
- return m_surface->device();
-}
-
bool QGLDrawBufferSurface::activate(QGLAbstractSurface *prevSurface)
{
if (!m_surface->activate(prevSurface))
@@ -68,4 +63,9 @@ QRect QGLDrawBufferSurface::viewportGL() const
return m_surface->viewportGL();
}
+bool QGLDrawBufferSurface::isValid() const
+{
+ return QGLAbstractSurface::isValid();
+}
+
QT_END_NAMESPACE
diff --git a/src/threed/surfaces/qgldrawbuffersurface_p.h b/src/threed/surfaces/qgldrawbuffersurface_p.h
index 9fe6c2ccc..cae0fbe4e 100644
--- a/src/threed/surfaces/qgldrawbuffersurface_p.h
+++ b/src/threed/surfaces/qgldrawbuffersurface_p.h
@@ -71,6 +71,7 @@ public:
bool activate(QGLAbstractSurface *prevSurface);
void deactivate(QGLAbstractSurface *nextSurface);
QRect viewportGL() const;
+ bool isValid() const;
private:
QGLAbstractSurface *m_surface;
diff --git a/src/threed/surfaces/qglframebufferobjectsurface.cpp b/src/threed/surfaces/qglframebufferobjectsurface.cpp
index 99551c269..9811d9722 100644
--- a/src/threed/surfaces/qglframebufferobjectsurface.cpp
+++ b/src/threed/surfaces/qglframebufferobjectsurface.cpp
@@ -41,6 +41,9 @@
#include "qglframebufferobjectsurface.h"
+#include <QtGui/QOpenGLContext>
+#include <QtCore/QDebug>
+
QT_BEGIN_NAMESPACE
/*!
@@ -51,15 +54,14 @@ QT_BEGIN_NAMESPACE
\ingroup qt3d::painting
*/
+// This exists solely for future expansion
class QGLFramebufferObjectSurfacePrivate
{
public:
- QGLFramebufferObjectSurfacePrivate
- (QGLFramebufferObject *fbo, const QGLContext *ctx)
- : framebufferObject(fbo), context(ctx) {}
+ QGLFramebufferObjectSurfacePrivate()
+ : forExpansion(0) {}
- QGLFramebufferObject *framebufferObject;
- const QGLContext *context;
+ int forExpansion;
};
/*!
@@ -68,7 +70,7 @@ public:
*/
QGLFramebufferObjectSurface::QGLFramebufferObjectSurface()
: QGLAbstractSurface(QGLAbstractSurface::FramebufferObject)
- , d_ptr(new QGLFramebufferObjectSurfacePrivate(0, 0))
+ , d_ptr(new QGLFramebufferObjectSurfacePrivate)
{
}
@@ -78,10 +80,12 @@ QGLFramebufferObjectSurface::QGLFramebufferObjectSurface()
current context when activate() is called.
*/
QGLFramebufferObjectSurface::QGLFramebufferObjectSurface
- (QGLFramebufferObject *fbo, const QGLContext *context)
+ (QOpenGLFramebufferObject *fbo, QOpenGLContext *context)
: QGLAbstractSurface(QGLAbstractSurface::FramebufferObject)
- , d_ptr(new QGLFramebufferObjectSurfacePrivate(fbo, context))
+ , d_ptr(new QGLFramebufferObjectSurfacePrivate)
{
+ m_fbo = fbo;
+ m_context = context;
}
/*!
@@ -92,47 +96,14 @@ QGLFramebufferObjectSurface::~QGLFramebufferObjectSurface()
}
/*!
- Returns the context that owns framebufferObject(); or null
- if the framebufferObject() should be assumed to be owned by
- the current context when activate() is called.
-
- \sa setContext(), framebufferObject()
-*/
-const QGLContext *QGLFramebufferObjectSurface::context() const
-{
- Q_D(const QGLFramebufferObjectSurface);
- return d->context;
-}
-
-/*!
- Sets the \a context that owns framebufferObject().
-
- When activate() is called, it checks to see if \a context is sharing
- with the current context. If it is, then the framebufferObject()
- is directly bound to the current context. Otherwise, \a context
- is made current and then framebufferObject() is bound.
-
- If \a context is null, then framebufferObject() will be bound
- to whatever the current context is when activate() is called.
-
- \sa context()
-*/
-void QGLFramebufferObjectSurface::setContext(const QGLContext *context)
-{
- Q_D(QGLFramebufferObjectSurface);
- d->context = context;
-}
-
-/*!
Returns the framebuffer object for this surface, or null if
it has not been set yet.
- \sa setFramebufferObject(), context()
+ \sa setFramebufferObject()
*/
-QGLFramebufferObject *QGLFramebufferObjectSurface::framebufferObject() const
+QOpenGLFramebufferObject *QGLFramebufferObjectSurface::framebufferObject() const
{
- Q_D(const QGLFramebufferObjectSurface);
- return d->framebufferObject;
+ return m_fbo;
}
/*!
@@ -141,19 +112,9 @@ QGLFramebufferObject *QGLFramebufferObjectSurface::framebufferObject() const
\sa framebufferObject()
*/
void QGLFramebufferObjectSurface::setFramebufferObject
- (QGLFramebufferObject *fbo)
-{
- Q_D(QGLFramebufferObjectSurface);
- d->framebufferObject = fbo;
-}
-
-/*!
- \reimp
-*/
-QPaintDevice *QGLFramebufferObjectSurface::device() const
+ (QOpenGLFramebufferObject *fbo)
{
- Q_D(const QGLFramebufferObjectSurface);
- return d->framebufferObject;
+ m_fbo = fbo;
}
/*!
@@ -162,17 +123,27 @@ QPaintDevice *QGLFramebufferObjectSurface::device() const
bool QGLFramebufferObjectSurface::activate(QGLAbstractSurface *prevSurface)
{
Q_UNUSED(prevSurface);
- Q_D(QGLFramebufferObjectSurface);
- if (d->context) {
- if (!QGLContext::areSharing(QGLContext::currentContext(), d->context))
- const_cast<QGLContext *>(d->context)->makeCurrent();
+ bool success = false;
+ if (m_context) {
+ if (!QOpenGLContext::areSharing(QOpenGLContext::currentContext(), m_context))
+ {
+ m_context->makeCurrent(m_context->surface());
+ }
} else {
- // If we don't have a current context, then something is wrong.
- Q_ASSERT(QGLContext::currentContext());
+ m_context = QOpenGLContext::currentContext();
+ }
+
+ if (isValid())
+ {
+ success = m_fbo->bind();
}
- if (d->framebufferObject)
- return d->framebufferObject->bind();
- return false;
+#ifndef QT_NO_DEBUG_STREAM
+ else
+ {
+ qWarning() << "Attempt to activate invalid fbo surface";
+ }
+#endif
+ return success;
}
/*!
@@ -180,17 +151,16 @@ bool QGLFramebufferObjectSurface::activate(QGLAbstractSurface *prevSurface)
*/
void QGLFramebufferObjectSurface::deactivate(QGLAbstractSurface *nextSurface)
{
- Q_D(QGLFramebufferObjectSurface);
- if (d->framebufferObject) {
+ if (m_fbo) {
if (nextSurface && nextSurface->surfaceType() == FramebufferObject) {
// If we are about to switch to another fbo that is on the
// same context, then don't bother doing the release().
// This saves an unnecessary glBindFramebuffer(0) call.
if (static_cast<QGLFramebufferObjectSurface *>(nextSurface)
- ->context() == d->context)
+ ->context() == m_context)
return;
}
- d->framebufferObject->release();
+ m_fbo->release();
}
}
@@ -199,11 +169,18 @@ void QGLFramebufferObjectSurface::deactivate(QGLAbstractSurface *nextSurface)
*/
QRect QGLFramebufferObjectSurface::viewportGL() const
{
- Q_D(const QGLFramebufferObjectSurface);
- if (d->framebufferObject)
- return QRect(QPoint(0, 0), d->framebufferObject->size());
+ if (m_fbo)
+ return QRect(QPoint(0, 0), m_fbo->size());
else
return QRect();
}
+/*!
+ \reimp
+*/
+bool QGLFramebufferObjectSurface::isValid() const
+{
+ return QGLAbstractSurface::isValid() && m_fbo && m_context;
+}
+
QT_END_NAMESPACE
diff --git a/src/threed/surfaces/qglframebufferobjectsurface.h b/src/threed/surfaces/qglframebufferobjectsurface.h
index 3135e81f9..ed699da55 100644
--- a/src/threed/surfaces/qglframebufferobjectsurface.h
+++ b/src/threed/surfaces/qglframebufferobjectsurface.h
@@ -43,7 +43,8 @@
#define QGLFRAMEBUFFEROBJECTSURFACE_H
#include "qglabstractsurface.h"
-#include <QtOpenGL/qglframebufferobject.h>
+
+#include <QtGui/QOpenGLFramebufferObject>
QT_BEGIN_HEADER
@@ -58,19 +59,16 @@ class Q_QT3D_EXPORT QGLFramebufferObjectSurface : public QGLAbstractSurface
public:
QGLFramebufferObjectSurface();
explicit QGLFramebufferObjectSurface
- (QGLFramebufferObject *fbo, const QGLContext *context = 0);
+ (QOpenGLFramebufferObject *fbo, QOpenGLContext *context = 0);
~QGLFramebufferObjectSurface();
- const QGLContext *context() const;
- void setContext(const QGLContext *context);
-
- QGLFramebufferObject *framebufferObject() const;
- void setFramebufferObject(QGLFramebufferObject *fbo);
+ QOpenGLFramebufferObject *framebufferObject() const;
+ void setFramebufferObject(QOpenGLFramebufferObject *fbo);
- QPaintDevice *device() const;
bool activate(QGLAbstractSurface *prevSurface = 0);
void deactivate(QGLAbstractSurface *nextSurface = 0);
QRect viewportGL() const;
+ bool isValid() const;
private:
QScopedPointer<QGLFramebufferObjectSurfacePrivate> d_ptr;
diff --git a/src/threed/surfaces/qglmaskedsurface.cpp b/src/threed/surfaces/qglmaskedsurface.cpp
index d2d46237f..a987df40d 100644
--- a/src/threed/surfaces/qglmaskedsurface.cpp
+++ b/src/threed/surfaces/qglmaskedsurface.cpp
@@ -164,15 +164,6 @@ void QGLMaskedSurface::setMask(QGLMaskedSurface::BufferMask mask)
/*!
\reimp
*/
-QPaintDevice *QGLMaskedSurface::device() const
-{
- Q_D(const QGLMaskedSurface);
- return d->surface ? d->surface->device() : 0;
-}
-
-/*!
- \reimp
-*/
bool QGLMaskedSurface::activate(QGLAbstractSurface *prevSurface)
{
Q_D(const QGLMaskedSurface);
@@ -211,4 +202,9 @@ QRect QGLMaskedSurface::viewportGL() const
return d->surface ? d->surface->viewportGL() : QRect();
}
+bool QGLMaskedSurface::isValid() const
+{
+ return QGLAbstractSurface::isValid();
+}
+
QT_END_NAMESPACE
diff --git a/src/threed/surfaces/qglmaskedsurface_p.h b/src/threed/surfaces/qglmaskedsurface_p.h
index b2b0c61d0..650a6ff6e 100644
--- a/src/threed/surfaces/qglmaskedsurface_p.h
+++ b/src/threed/surfaces/qglmaskedsurface_p.h
@@ -84,10 +84,10 @@ public:
QGLMaskedSurface::BufferMask mask() const;
void setMask(QGLMaskedSurface::BufferMask mask);
- QPaintDevice *device() const;
bool activate(QGLAbstractSurface *prevSurface = 0);
void deactivate(QGLAbstractSurface *nextSurface = 0);
QRect viewportGL() const;
+ bool isValid() const;
private:
QScopedPointer<QGLMaskedSurfacePrivate> d_ptr;
diff --git a/src/threed/surfaces/qglpaintersurface.cpp b/src/threed/surfaces/qglpaintersurface.cpp
index 98e9d4364..76fd65f24 100644
--- a/src/threed/surfaces/qglpaintersurface.cpp
+++ b/src/threed/surfaces/qglpaintersurface.cpp
@@ -41,17 +41,25 @@
#include "qglpaintersurface_p.h"
-QT_BEGIN_NAMESPACE
+#include <QtGui/QOpenGLContext>
-QPaintDevice *QGLPainterSurface::device() const
-{
- return m_painter->device();
-}
+QT_BEGIN_NAMESPACE
bool QGLPainterSurface::activate(QGLAbstractSurface *prevSurface)
{
- if (m_painterContext != QGLContext::currentContext())
- const_cast<QGLContext *>(m_painterContext)->makeCurrent();
+ Q_ASSERT_X(QOpenGLContext::currentContext() || m_context, Q_FUNC_INFO,
+ "Activating GL painter surface without GL context");
+ if (m_context)
+ {
+ if (m_context != QOpenGLContext::currentContext())
+ {
+ m_context->makeCurrent(m_context->surface());
+ }
+ }
+ else
+ {
+ m_context = QOpenGLContext::currentContext();
+ }
if (!prevSurface)
m_painter->beginNativePainting();
return true;
@@ -69,4 +77,9 @@ QRect QGLPainterSurface::viewportGL() const
return QRect(0, 0, device->width(), device->height());
}
+bool QGLPainterSurface::isValid() const
+{
+ return QGLAbstractSurface::isValid();
+}
+
QT_END_NAMESPACE
diff --git a/src/threed/surfaces/qglpaintersurface_p.h b/src/threed/surfaces/qglpaintersurface_p.h
index 0dc49161a..bf289a661 100644
--- a/src/threed/surfaces/qglpaintersurface_p.h
+++ b/src/threed/surfaces/qglpaintersurface_p.h
@@ -62,19 +62,22 @@ QT_BEGIN_NAMESPACE
class QGLPainterSurface : public QGLAbstractSurface
{
public:
+ static const int QGLPAINTER_SURFACE_ID = 503;
+
explicit QGLPainterSurface(QPainter *painter)
- : QGLAbstractSurface(503)
- , m_painter(painter), m_painterContext(QGLContext::currentContext()) {}
+ : QGLAbstractSurface(QGLPAINTER_SURFACE_ID)
+ , m_painter(painter)
+ {
+ }
~QGLPainterSurface() {}
- QPaintDevice *device() const;
bool activate(QGLAbstractSurface *prevSurface);
void deactivate(QGLAbstractSurface *nextSurface);
QRect viewportGL() const;
+ bool isValid() const;
private:
QPainter *m_painter;
- const QGLContext *m_painterContext;
Q_DISABLE_COPY(QGLPainterSurface)
};
diff --git a/src/threed/surfaces/qglpixelbuffersurface.cpp b/src/threed/surfaces/qglpixelbuffersurface.cpp
index 45735cc36..c70b878ff 100644
--- a/src/threed/surfaces/qglpixelbuffersurface.cpp
+++ b/src/threed/surfaces/qglpixelbuffersurface.cpp
@@ -57,7 +57,6 @@ QT_BEGIN_NAMESPACE
*/
QGLPixelBufferSurface::QGLPixelBufferSurface()
: QGLAbstractSurface(QGLAbstractSurface::PixelBuffer)
- , m_pbuffer(0)
{
}
@@ -66,8 +65,8 @@ QGLPixelBufferSurface::QGLPixelBufferSurface()
*/
QGLPixelBufferSurface::QGLPixelBufferSurface(QGLPixelBuffer *pbuffer)
: QGLAbstractSurface(QGLAbstractSurface::PixelBuffer)
- , m_pbuffer(pbuffer)
{
+ m_pb = pbuffer;
}
/*!
@@ -85,7 +84,7 @@ QGLPixelBufferSurface::~QGLPixelBufferSurface()
*/
QGLPixelBuffer *QGLPixelBufferSurface::pixelBuffer() const
{
- return m_pbuffer;
+ return m_pb;
}
/*!
@@ -96,15 +95,7 @@ QGLPixelBuffer *QGLPixelBufferSurface::pixelBuffer() const
void QGLPixelBufferSurface::setPixelBuffer
(QGLPixelBuffer *pbuffer)
{
- m_pbuffer = pbuffer;
-}
-
-/*!
- \reimp
-*/
-QPaintDevice *QGLPixelBufferSurface::device() const
-{
- return m_pbuffer;
+ m_pb = pbuffer;
}
/*!
@@ -113,8 +104,8 @@ QPaintDevice *QGLPixelBufferSurface::device() const
bool QGLPixelBufferSurface::activate(QGLAbstractSurface *prevSurface)
{
Q_UNUSED(prevSurface);
- if (m_pbuffer)
- return m_pbuffer->makeCurrent();
+ if (m_pb)
+ return m_pb->makeCurrent();
else
return false;
}
@@ -133,10 +124,15 @@ void QGLPixelBufferSurface::deactivate(QGLAbstractSurface *nextSurface)
*/
QRect QGLPixelBufferSurface::viewportGL() const
{
- if (m_pbuffer)
- return QRect(0, 0, m_pbuffer->width(), m_pbuffer->height());
+ if (m_pb)
+ return QRect(0, 0, m_pb->width(), m_pb->height());
else
return QRect();
}
+bool QGLPixelBufferSurface::isValid() const
+{
+ return QGLAbstractSurface::isValid() && m_pb;
+}
+
QT_END_NAMESPACE
diff --git a/src/threed/surfaces/qglpixelbuffersurface.h b/src/threed/surfaces/qglpixelbuffersurface.h
index 22dac86c5..edeb0901c 100644
--- a/src/threed/surfaces/qglpixelbuffersurface.h
+++ b/src/threed/surfaces/qglpixelbuffersurface.h
@@ -61,14 +61,12 @@ public:
QGLPixelBuffer *pixelBuffer() const;
void setPixelBuffer(QGLPixelBuffer *pbuffer);
- QPaintDevice *device() const;
bool activate(QGLAbstractSurface *prevSurface = 0);
void deactivate(QGLAbstractSurface *nextSurface = 0);
QRect viewportGL() const;
+ bool isValid() const;
private:
- QGLPixelBuffer *m_pbuffer;
-
Q_DISABLE_COPY(QGLPixelBufferSurface)
};
diff --git a/src/threed/surfaces/qglsubsurface.cpp b/src/threed/surfaces/qglsubsurface.cpp
index 367dd6218..04804cab6 100644
--- a/src/threed/surfaces/qglsubsurface.cpp
+++ b/src/threed/surfaces/qglsubsurface.cpp
@@ -143,18 +143,6 @@ void QGLSubsurface::setRegion(const QRect &region)
/*!
\reimp
*/
-QPaintDevice *QGLSubsurface::device() const
-{
- Q_D(const QGLSubsurface);
- if (d->surface)
- return d->surface->device();
- else
- return 0;
-}
-
-/*!
- \reimp
-*/
bool QGLSubsurface::activate(QGLAbstractSurface *prevSurface)
{
Q_D(QGLSubsurface);
@@ -196,4 +184,9 @@ QRect QGLSubsurface::viewportGL() const
}
}
+bool QGLSubsurface::isValid() const
+{
+ return QGLAbstractSurface::isValid();
+}
+
QT_END_NAMESPACE
diff --git a/src/threed/surfaces/qglsubsurface.h b/src/threed/surfaces/qglsubsurface.h
index 69904a195..f416fd128 100644
--- a/src/threed/surfaces/qglsubsurface.h
+++ b/src/threed/surfaces/qglsubsurface.h
@@ -65,10 +65,10 @@ public:
QRect region() const;
void setRegion(const QRect &region);
- QPaintDevice *device() const;
bool activate(QGLAbstractSurface *prevSurface = 0);
void deactivate(QGLAbstractSurface *nextSurface = 0);
QRect viewportGL() const;
+ bool isValid() const;
private:
QScopedPointer<QGLSubsurfacePrivate> d_ptr;
diff --git a/src/threed/surfaces/qglwidgetsurface.cpp b/src/threed/surfaces/qglwidgetsurface.cpp
deleted file mode 100644
index 7d137eb67..000000000
--- a/src/threed/surfaces/qglwidgetsurface.cpp
+++ /dev/null
@@ -1,146 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtQuick3D module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** GNU Lesser General Public License Usage
-** This file may be used under the terms of the GNU Lesser General Public
-** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this
-** file. Please review the following information to ensure the GNU Lesser
-** General Public License version 2.1 requirements will be met:
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU General
-** Public License version 3.0 as published by the Free Software Foundation
-** and appearing in the file LICENSE.GPL included in the packaging of this
-** file. Please review the following information to ensure the GNU General
-** Public License version 3.0 requirements will be met:
-** http://www.gnu.org/copyleft/gpl.html.
-**
-** Other Usage
-** Alternatively, this file may be used in accordance with the terms and
-** conditions contained in a signed written agreement between you and Nokia.
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qglwidgetsurface.h"
-#include <QtGui/qpainter.h>
-#include <QtGui/qpaintengine.h>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QGLWidgetSurface
- \brief The QGLWidgetSurface class represents a QGLWidget that is begin used as an OpenGL drawing surface.
- \since 4.8
- \ingroup qt3d
- \ingroup qt3d::painting
-*/
-
-/*!
- Constructs a widget surface. This constructor should be followed
- by a call to setWidget().
-*/
-QGLWidgetSurface::QGLWidgetSurface()
- : QGLAbstractSurface(QGLAbstractSurface::Widget)
- , m_widget(0)
-{
-}
-
-/*!
- Constructs a widget surface for \a widget.
-*/
-QGLWidgetSurface::QGLWidgetSurface(QGLWidget *widget)
- : QGLAbstractSurface(QGLAbstractSurface::Widget)
- , m_widget(widget)
-{
-}
-
-/*!
- Destroys this widget surface.
-*/
-QGLWidgetSurface::~QGLWidgetSurface()
-{
-}
-
-/*!
- Returns the widget that is underlying this surface.
-
- \sa setWidget()
-*/
-QGLWidget *QGLWidgetSurface::widget() const
-{
- return m_widget;
-}
-
-/*!
- Sets the \a widget that is underlying this surface.
-
- \sa widget()
-*/
-void QGLWidgetSurface::setWidget(QGLWidget *widget)
-{
- m_widget = widget;
-}
-
-/*!
- \reimp
-*/
-QPaintDevice *QGLWidgetSurface::device() const
-{
- return m_widget;
-}
-
-/*!
- \reimp
-*/
-bool QGLWidgetSurface::activate(QGLAbstractSurface *prevSurface)
-{
- Q_UNUSED(prevSurface);
- if (m_widget) {
- const QGLContext *context = m_widget->context();
- if (QGLContext::currentContext() != context)
- const_cast<QGLContext *>(context)->makeCurrent();
- return true;
- } else {
- return false;
- }
-}
-
-/*!
- \reimp
-*/
-void QGLWidgetSurface::deactivate(QGLAbstractSurface *nextSurface)
-{
- // Nothing to do here - leave the context current.
- Q_UNUSED(nextSurface);
-}
-
-/*!
- \reimp
-*/
-QRect QGLWidgetSurface::viewportGL() const
-{
- if (m_widget)
- return m_widget->rect(); // Origin assumed to be (0, 0).
- else
- return QRect();
-}
-
-QT_END_NAMESPACE
diff --git a/src/threed/surfaces/qglwindowsurface.cpp b/src/threed/surfaces/qglwindowsurface.cpp
new file mode 100644
index 000000000..c49ee2656
--- /dev/null
+++ b/src/threed/surfaces/qglwindowsurface.cpp
@@ -0,0 +1,175 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtQuick3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qglwindowsurface.h"
+#include <QtGui/qpainter.h>
+#include <QtGui/qpaintengine.h>
+#include <QtGui/QOpenGLContext>
+#include <QtCore/QDebug>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QGLWindowSurface
+ \brief The QGLWindowSurface class represents a QGLwindow that is begin used as an OpenGL drawing surface.
+ \since 4.8
+ \ingroup qt3d
+ \ingroup qt3d::painting
+*/
+
+/*!
+ Constructs a window surface, with a null window. This constructor should be
+ followed by a call to setWindow().
+*/
+QGLWindowSurface::QGLWindowSurface()
+ : QGLAbstractSurface(QGLAbstractSurface::Window)
+{
+}
+
+/*!
+ Constructs a window surface for \a window. If \a window is null,
+ then this surface is invalid, that is isValid() will return null.
+*/
+QGLWindowSurface::QGLWindowSurface(QWindow *window)
+ : QGLAbstractSurface(QGLAbstractSurface::Window)
+{
+ setWindow(window);
+}
+
+/*!
+ Destroys this window surface.
+*/
+QGLWindowSurface::~QGLWindowSurface()
+{
+ // we don't own the window - don't destroy it here
+}
+
+/*!
+ Returns the window that is underlying this surface. By default this
+ value is null.
+
+ \sa setWindow()
+*/
+QWindow *QGLWindowSurface::window() const
+{
+ return m_window;
+}
+
+/*!
+ Sets the \a window that is underlying this surface. If \a window is null,
+ then this surface is invalid, that is isValid() will return null.
+
+ The window should have a surfaceType() of QWindow::OpenGLSurface.
+ \sa window()
+*/
+void QGLWindowSurface::setWindow(QWindow *window)
+{
+ m_window = window;
+}
+
+/*!
+ \reimp
+*/
+bool QGLWindowSurface::activate(QGLAbstractSurface *prevSurface)
+{
+ Q_UNUSED(prevSurface);
+ Q_ASSERT_X(QOpenGLContext::currentContext() || m_context, Q_FUNC_INFO,
+ "Activating GL window surface without GL context");
+ if (m_context)
+ {
+ if (m_context != QOpenGLContext::currentContext())
+ {
+ m_context->makeCurrent(m_window);
+ }
+ }
+ else
+ {
+ m_context = QOpenGLContext::currentContext();
+ }
+ if (m_window)
+ {
+#ifndef QT_NO_DEBUG_STREAM
+ if (m_context->surface() != m_window)
+ qWarning() << "Attempt to activate GL window surface on wrong context";
+#endif
+ }
+ else
+ {
+ m_window = static_cast<QWindow*>(m_context->surface());
+ }
+#ifndef QT_NO_DEBUG_STREAM
+ if (!m_context->surface() || m_context->surface()->surfaceType() != QSurface::Window)
+ qWarning() << "Attempt to activate GL window surface on bad context";
+ if (!isValid())
+ qWarning() << "Attempt to activate invalid window surface";
+#endif
+ return isValid();
+}
+
+/*!
+ \reimp
+*/
+void QGLWindowSurface::deactivate(QGLAbstractSurface *nextSurface)
+{
+ // Nothing to do here - leave the context current.
+ Q_UNUSED(nextSurface);
+}
+
+/*!
+ \reimp
+*/
+QRect QGLWindowSurface::viewportGL() const
+{
+ if (m_window)
+ return m_window->geometry(); // Origin assumed to be (0, 0).
+ else
+ return QRect();
+}
+
+/*!
+ \reimp
+*/
+bool QGLWindowSurface::isValid() const
+{
+ return QGLAbstractSurface::isValid() && m_window;
+}
+
+QT_END_NAMESPACE
diff --git a/src/threed/surfaces/qglwidgetsurface.h b/src/threed/surfaces/qglwindowsurface.h
index e0ce8e277..569a36cdf 100644
--- a/src/threed/surfaces/qglwidgetsurface.h
+++ b/src/threed/surfaces/qglwindowsurface.h
@@ -50,27 +50,25 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Qt3D)
-class QGLWidgetSurfacePrivate;
+class QWindow;
-class Q_QT3D_EXPORT QGLWidgetSurface : public QGLAbstractSurface
+class Q_QT3D_EXPORT QGLWindowSurface : public QGLAbstractSurface
{
public:
- QGLWidgetSurface();
- explicit QGLWidgetSurface(QGLWidget *widget);
- ~QGLWidgetSurface();
+ QGLWindowSurface();
+ explicit QGLWindowSurface(QWindow *window);
+ ~QGLWindowSurface();
- QGLWidget *widget() const;
- void setWidget(QGLWidget *widget);
+ QWindow *window() const;
+ void setWindow(QWindow *window);
- QPaintDevice *device() const;
bool activate(QGLAbstractSurface *prevSurface = 0);
void deactivate(QGLAbstractSurface *nextSurface = 0);
QRect viewportGL() const;
+ bool isValid() const;
private:
- QGLWidget *m_widget;
-
- Q_DISABLE_COPY(QGLWidgetSurface)
+ Q_DISABLE_COPY(QGLWindowSurface)
};
QT_END_NAMESPACE
diff --git a/src/threed/surfaces/surfaces.pri b/src/threed/surfaces/surfaces.pri
index 8ce35fb6a..f8095e780 100644
--- a/src/threed/surfaces/surfaces.pri
+++ b/src/threed/surfaces/surfaces.pri
@@ -5,7 +5,7 @@ HEADERS += \
surfaces/qglframebufferobjectsurface.h \
surfaces/qglpixelbuffersurface.h \
surfaces/qglsubsurface.h \
- surfaces/qglwidgetsurface.h
+ surfaces/qglwindowsurface.h
SOURCES += \
qglabstractsurface.cpp \
qglcontextsurface.cpp \
@@ -15,9 +15,12 @@ SOURCES += \
qglpaintersurface.cpp \
qglpixelbuffersurface.cpp \
qglsubsurface.cpp \
- qglwidgetsurface.cpp
+ qglwindowsurface.cpp
PRIVATE_HEADERS += \
qglcontextsurface_p.h \
qgldrawbuffersurface_p.h \
qglmaskedsurface_p.h \
qglpaintersurface_p.h
+
+
+
diff --git a/src/threed/textures/qgltextureutils_p.h b/src/threed/textures/qgltextureutils_p.h
index 8077bb119..dfcfa7662 100644
--- a/src/threed/textures/qgltextureutils_p.h
+++ b/src/threed/textures/qgltextureutils_p.h
@@ -118,7 +118,7 @@ public:
static QGLTextureExtensions *extensions();
void invalidateResource() {}
- void freeResource(QOpenGLContext *context) {}
+ void freeResource(QOpenGLContext *) {}
};
diff --git a/src/threed/viewing/qglview.cpp b/src/threed/viewing/qglview.cpp
index 7e6b739e3..50f5cb49a 100644
--- a/src/threed/viewing/qglview.cpp
+++ b/src/threed/viewing/qglview.cpp
@@ -43,7 +43,7 @@
#include "qglframebufferobject.h"
#include "qglsubsurface.h"
#include "qglmaskedsurface_p.h"
-#include "qglwidgetsurface.h"
+#include "qglwindowsurface.h"
#include "qgldrawbuffersurface_p.h"
#include "qray3d.h"
#include <QtGui/qevent.h>
@@ -53,6 +53,9 @@
#include <QtCore/qdatetime.h>
#include <QtCore/qdebug.h>
+#include <QtGui/QOpenGLContext>
+#include <QtGui/QSurfaceFormat>
+
QT_BEGIN_NAMESPACE
/*!
@@ -211,7 +214,11 @@ class QGLViewPrivate
{
public:
QGLViewPrivate(QGLView *parent)
- : view(parent), mainSurface(parent)
+ : view(parent)
+ , context(0)
+ , initialized(false)
+ , mainSurface(parent)
+ , visible(false)
{
options = QGLView::CameraNavigation;
fbo = 0;
@@ -257,10 +264,14 @@ public:
}
QGLView *view;
+ QOpenGLContext *context;
+ QSurfaceFormat format;
+ bool initialized;
QGLView::Options options;
QGLView::StereoType stereoType;
QGLFramebufferObject *fbo;
- QGLWidgetSurface mainSurface;
+ QGLWindowSurface mainSurface;
+ bool visible;
QGLAbstractSurface *leftSurface;
QGLAbstractSurface *rightSurface;
bool pickBufferForceUpdate;
@@ -292,6 +303,8 @@ public:
QGLAbstractSurface *leftEyeSurface(const QSize &size);
QGLAbstractSurface *rightEyeSurface(const QSize &size);
QGLAbstractSurface *bothEyesSurface();
+
+ void ensureContext();
};
inline void QGLViewPrivate::logEnter(const char *message)
@@ -317,6 +330,30 @@ inline void QGLViewPrivate::logLeave(const char *message)
(ms / 1000) % 60, ms % 1000, message, duration);
}
+inline void QGLViewPrivate::ensureContext()
+{
+ if (!context)
+ {
+ context = new QOpenGLContext();
+ context->setFormat(format);
+#ifndef QT_NO_DEBUG_STREAM
+ QSurfaceFormat oldFormat = format;
+#endif
+ bool success = context->create();
+ // TODO: is it possible that the platform will downgrade the actual
+ // format, or will it just fail if it can't deliver the actual format
+ format = context->format();
+#ifndef QT_NO_DEBUG_STREAM
+ if (!success)
+ qWarning() << "Context was not successfully created";
+ if (oldFormat.swapBehavior() != format.swapBehavior())
+ qWarning() << "Could not create requested format"
+ << oldFormat.swapBehavior();
+#endif
+ }
+ context->makeCurrent(view);
+}
+
static QString qt_gl_stereo_arg()
{
QStringList args = QApplication::arguments();
@@ -394,10 +431,12 @@ QGLAbstractSurface *QGLViewPrivate::leftEyeSurface(const QSize &size)
switch (stereoType) {
case QGLView::Hardware:
#if defined(GL_BACK_LEFT) && defined(GL_BACK_RIGHT)
- if (!leftSurface) {
- leftSurface = new QGLDrawBufferSurface
- (&mainSurface,
- view->doubleBuffer() ? GL_BACK_LEFT : GL_FRONT_LEFT);
+ if (!leftSurface)
+ {
+ if (format.swapBehavior() == QSurfaceFormat::DoubleBuffer)
+ leftSurface = new QGLDrawBufferSurface(&mainSurface, GL_BACK_LEFT);
+ else
+ leftSurface = new QGLDrawBufferSurface(&mainSurface, GL_FRONT_LEFT);
}
return leftSurface;
#endif
@@ -459,7 +498,7 @@ QGLAbstractSurface *QGLViewPrivate::rightEyeSurface(const QSize &size)
if (!rightSurface) {
rightSurface = new QGLDrawBufferSurface
(&mainSurface,
- view->doubleBuffer() ? GL_BACK_RIGHT : GL_FRONT_RIGHT);
+ format.swapBehavior() == QSurfaceFormat::DoubleBuffer ? GL_BACK_RIGHT : GL_FRONT_RIGHT);
}
return rightSurface;
#endif
@@ -527,31 +566,35 @@ QGLAbstractSurface *QGLViewPrivate::bothEyesSurface()
}
}
-static QGLFormat makeStereoGLFormat(const QGLFormat& format)
+static QSurfaceFormat makeStereoGLFormat(const QSurfaceFormat& format)
{
+ QSurfaceFormat fmt(format);
#if defined(GL_BACK_LEFT) && defined(GL_BACK_RIGHT)
- QGLFormat fmt(format);
if (qt_gl_stereo_arg() == QLatin1String("-stereo-hw"))
- fmt.setOption(QGL::StereoBuffers);
- return fmt;
+ fmt.setOption(QSurfaceFormat::StereoBuffers);
#else
- QGLFormat fmt(format);
- fmt.setOption(QGL::NoStereoBuffers);
- return fmt;
+ qWarning("No option to clear stereo buffers");
#endif
+ return fmt;
}
/*!
Constructs a new view widget and attaches it to \a parent.
This constructor will request a stereo rendering context if
- the hardware supports it.
+ the hardware supports it (and the -stereo-hw option is set).
*/
-QGLView::QGLView(QWidget *parent)
- : QGLWidget(makeStereoGLFormat(QGLFormat::defaultFormat()), parent)
+QGLView::QGLView(QWindow *parent)
+ : QWindow(parent)
{
d = new QGLViewPrivate(this);
- setMouseTracking(true);
+ d->format = makeStereoGLFormat(QSurfaceFormat());
+ d->format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
+ d->format.setDepthBufferSize(24);
+ setSurfaceType(QWindow::OpenGLSurface);
+ setFormat(d->format);
+ // TODO: No mouse tracking available
+ // setMouseTracking(true);
if (!parent)
d->processStereoOptions(this);
}
@@ -563,12 +606,19 @@ QGLView::QGLView(QWidget *parent)
If \a format does not include the stereo option, then a stereo
viewing context will not be requested.
+
+ The format will be set onto the window, and also onto the underlying
+ OpenGL context.
*/
-QGLView::QGLView(const QGLFormat& format, QWidget *parent)
- : QGLWidget(format, parent)
+QGLView::QGLView(const QSurfaceFormat& format, QWindow *parent)
+ : QWindow(parent)
{
d = new QGLViewPrivate(this);
- setMouseTracking(true);
+ d->format = format;
+ setSurfaceType(QWindow::OpenGLSurface);
+ setFormat(d->format);
+ // TODO: No mouse tracking available
+ // setMouseTracking(true);
if (!parent)
d->processStereoOptions(this);
}
@@ -742,17 +792,13 @@ QVector3D QGLView::mapPoint(const QPoint &point) const
int width = viewportSize.width();
int height = viewportSize.height();
- // Use the device's DPI setting to determine the pixel aspect ratio.
- int dpiX = logicalDpiX();
- int dpiY = logicalDpiY();
- if (dpiX <= 0 || dpiY <= 0)
- dpiX = dpiY = 1;
+ // TODO: previous implementations catered for non-square pixels
- // Derive the aspect ratio based on window and pixel size.
+ // Derive the aspect ratio based on window size.
if (width <= 0 || height <= 0)
aspectRatio = 1.0f;
else
- aspectRatio = ((qreal)(width * dpiY)) / ((qreal)(height * dpiX));
+ aspectRatio = (qreal)width / (qreal)height;
// Map the point into eye co-ordinates.
return d->camera->mapPoint(point, aspectRatio, viewportSize);
@@ -764,9 +810,41 @@ void QGLView::cameraChanged()
d->pickBufferForceUpdate = true;
// Queue an update for the next event loop.
+
update();
}
+void QGLView::showEvent(QShowEvent *e)
+{
+ Q_UNUSED(e);
+ d->visible = true;
+}
+
+void QGLView::hideEvent(QHideEvent *e)
+{
+ Q_UNUSED(e);
+ d->visible = false;
+}
+
+void QGLView::exposeEvent(QExposeEvent *e)
+{
+ Q_UNUSED(e);
+
+ d->updateQueued = false;
+ d->ensureContext();
+
+ QRect rect = geometry();
+ resizeGL(rect.width(), rect.height());
+
+ if (!d->initialized)
+ initializeGL();
+
+ paintGL();
+
+ if (d->format.swapBehavior() == QSurfaceFormat::DoubleBuffer)
+ d->context->swapBuffers(this);
+}
+
/*!
\internal
*/
@@ -797,6 +875,7 @@ void QGLView::initializeGL()
glDisable(GL_CULL_FACE);
initializeGL(&painter);
+ d->initialized = true;
d->logLeave("QGLView::initializeGL");
}
@@ -870,6 +949,15 @@ void QGLView::paintGL()
d->logLeave("QGLView::paintGL");
}
+void QGLView::update()
+{
+ if (!d->updateQueued)
+ {
+ d->updateQueued = true;
+ QApplication::postEvent(this, new QExposeEvent(geometry()));
+ }
+}
+
/*!
Initializes the current GL context represented by \a painter.
@@ -914,8 +1002,15 @@ void QGLView::earlyPaintGL(QGLPainter *painter)
may wish to render a simpler scene that omits unselectable
objects and uses simpler meshes for the selectable objects.
+ The base default implementation does nothing. Sub-classes should
+ re-implement this function to paint GL content.
+
\sa earlyPaintGL()
*/
+void QGLView::paintGL(QGLPainter *painter)
+{
+ Q_UNUSED(painter);
+}
/*!
Processes the mouse press event \a e.
@@ -956,10 +1051,11 @@ void QGLView::mousePressEvent(QMouseEvent *e)
d->startUpVector = d->camera->upVector();
d->panModifiers = e->modifiers();
#ifndef QT_NO_CURSOR
- setCursor(Qt::ClosedHandCursor);
+ // TODO: not supported under QWindow
+ //setCursor(Qt::ClosedHandCursor);
#endif
}
- QGLWidget::mousePressEvent(e);
+ QWindow::mousePressEvent(e);
}
/*!
@@ -970,7 +1066,8 @@ void QGLView::mouseReleaseEvent(QMouseEvent *e)
if (d->panning && e->button() == Qt::LeftButton) {
d->panning = false;
#ifndef QT_NO_CURSOR
- unsetCursor();
+ // TODO: unsetCursor not support with QWindow
+ //unsetCursor();
#endif
}
if (d->pressedObject) {
@@ -1007,7 +1104,7 @@ void QGLView::mouseReleaseEvent(QMouseEvent *e)
QCoreApplication::sendEvent(pressed, &event);
}
}
- QGLWidget::mouseReleaseEvent(e);
+ QWindow::mouseReleaseEvent(e);
}
/*!
@@ -1025,7 +1122,7 @@ void QGLView::mouseDoubleClickEvent(QMouseEvent *e)
QCoreApplication::sendEvent(object, &event);
}
}
- QGLWidget::mouseDoubleClickEvent(e);
+ QWindow::mouseDoubleClickEvent(e);
}
/*!
@@ -1081,19 +1178,7 @@ void QGLView::mouseMoveEvent(QMouseEvent *e)
d->enteredObject = 0;
}
}
- QGLWidget::mouseMoveEvent(e);
-}
-
-/*!
- Processes the leave event \a e.
-*/
-void QGLView::leaveEvent(QEvent *e)
-{
- if (!d->pressedObject && d->enteredObject) {
- sendLeaveEvent(d->enteredObject);
- d->enteredObject = 0;
- }
- QGLWidget::leaveEvent(e);
+ QWindow::mouseMoveEvent(e);
}
#ifndef QT_NO_WHEELEVENT
@@ -1105,7 +1190,7 @@ void QGLView::wheelEvent(QWheelEvent *e)
{
if ((d->options & QGLView::CameraNavigation) != 0)
wheel(e->delta());
- QGLWidget::wheelEvent(e);
+ QWindow::wheelEvent(e);
}
#endif
@@ -1119,7 +1204,7 @@ void QGLView::keyPressEvent(QKeyEvent *e)
qreal sep;
if ((d->options & QGLView::CameraNavigation) == 0) {
- QGLWidget::keyPressEvent(e);
+ QWindow::keyPressEvent(e);
return;
}
switch (e->key()) {
@@ -1127,7 +1212,7 @@ void QGLView::keyPressEvent(QKeyEvent *e)
case Qt::Key_Escape:
case Qt::Key_Q:
{
- if (parentWidget() == 0)
+ if (parent() == 0)
close();
}
@@ -1189,7 +1274,7 @@ void QGLView::keyPressEvent(QKeyEvent *e)
}
break;
}
- QGLWidget::keyPressEvent(e);
+ QWindow::keyPressEvent(e);
}
class QGLViewPickSurface : public QGLAbstractSurface
@@ -1218,11 +1303,6 @@ QGLViewPickSurface::QGLViewPickSurface
{
}
-QPaintDevice *QGLViewPickSurface::device() const
-{
- return m_view;
-}
-
bool QGLViewPickSurface::activate(QGLAbstractSurface *prevSurface)
{
Q_UNUSED(prevSurface);
@@ -1306,7 +1386,7 @@ QObject *QGLView::objectForPoint(const QPoint &point)
// Create a framebuffer object as big as the window to act
// as the pick buffer if we are single buffered. If we are
// double-buffered, then use the window back buffer.
- bool useBackBuffer = doubleBuffer();
+ bool useBackBuffer = d->format.swapBehavior() == QSurfaceFormat::DoubleBuffer;
if (!useBackBuffer) {
QSize fbosize = QGL::nextPowerOfTwo(areaSize);
if (!d->fbo) {
@@ -1343,7 +1423,6 @@ QObject *QGLView::objectForPoint(const QPoint &point)
// Release the framebuffer object and return.
painter.end();
- doneCurrent();
return object;
}
@@ -1492,5 +1571,24 @@ QPointF QGLView::viewDelta(int deltax, int deltay) const
the percentage values, typically between -1 and 1.
*/
+/*!
+ Returns the OpenGL context object associated with this view, or null
+ if one has not been associated yet. The default is null.
+*/
+QOpenGLContext *QGLView::context()
+{
+ return d->context;
+}
+
+/*!
+ Returns true if the view is visible, that is its show event has been called
+ and was not followed by a hide event. Note that this cannot be relied apon
+ for the visibility of the window, as it depends on whether hide and show
+ events are triggered, which is platform dependent.
+*/
+bool QGLView::isVisible() const
+{
+ return d->visible;
+}
QT_END_NAMESPACE
diff --git a/src/threed/viewing/qglview.h b/src/threed/viewing/qglview.h
index 444854d99..52345c651 100644
--- a/src/threed/viewing/qglview.h
+++ b/src/threed/viewing/qglview.h
@@ -45,6 +45,8 @@
#include "qglpainter.h"
#include "qglcamera.h"
+#include <QtGui/QWindow>
+
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
@@ -53,12 +55,12 @@ QT_MODULE(Qt3D)
class QGLViewPrivate;
-class Q_QT3D_EXPORT QGLView : public QGLWidget
+class Q_QT3D_EXPORT QGLView : public QWindow
{
Q_OBJECT
public:
- explicit QGLView(QWidget *parent=0);
- explicit QGLView(const QGLFormat& format, QWidget *parent=0);
+ explicit QGLView(QWindow *parent = 0);
+ explicit QGLView(const QSurfaceFormat &format, QWindow *parent=0);
~QGLView();
enum Option
@@ -100,25 +102,34 @@ public:
void setCamera(QGLCamera *camera);
QVector3D mapPoint(const QPoint &point) const;
+ QOpenGLContext *context();
+ bool isVisible() const;
+
+public Q_SLOTS:
+ void update();
protected:
void initializeGL();
void resizeGL(int w, int h);
void paintGL();
+
virtual void initializeGL(QGLPainter *painter);
virtual void earlyPaintGL(QGLPainter *painter);
- virtual void paintGL(QGLPainter *painter) = 0;
+ virtual void paintGL(QGLPainter *painter);
void mousePressEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
void mouseDoubleClickEvent(QMouseEvent *e);
void mouseMoveEvent(QMouseEvent *e);
- void leaveEvent(QEvent *e);
#ifndef QT_NO_WHEELEVENT
void wheelEvent(QWheelEvent *e);
#endif
void keyPressEvent(QKeyEvent *e);
+ void showEvent(QShowEvent *e);
+ void hideEvent(QHideEvent *e);
+ void exposeEvent(QExposeEvent *e);
+
QPointF viewDelta(int deltax, int deltay) const;
QPointF viewDelta(const QPoint &delta) const
{ return viewDelta(delta.x(), delta.y()); }
diff --git a/tests/auto/threed/qgeometrydata/qgeometrydata.pro b/tests/auto/threed/qgeometrydata/qgeometrydata.pro
index e88dcac46..7d55ab1f9 100644
--- a/tests/auto/threed/qgeometrydata/qgeometrydata.pro
+++ b/tests/auto/threed/qgeometrydata/qgeometrydata.pro
@@ -8,3 +8,5 @@ INCLUDEPATH += ../../../../src/threed/geometry
SOURCES += tst_qgeometrydata.cpp
QT+=widgets
+
+CONFIG+=insignificant_test
diff --git a/tests/auto/threed/qgeometrydata/tst_qgeometrydata.cpp b/tests/auto/threed/qgeometrydata/tst_qgeometrydata.cpp
index 7dd77956e..0dfac0788 100644
--- a/tests/auto/threed/qgeometrydata/tst_qgeometrydata.cpp
+++ b/tests/auto/threed/qgeometrydata/tst_qgeometrydata.cpp
@@ -46,6 +46,7 @@
#include "qvector_utils_p.h"
#include "qtest_helpers.h"
#include "qglpainter.h"
+#include "qglview.h"
#include <QtCore/qdebug.h>
@@ -618,7 +619,7 @@ void tst_QGeometryData::draw()
data.appendVertex(a, b, c, d);
data.appendNormal(an, bn, cn, dn);
- QGLWidget w;
+ QGLView w;
QGLPainter p(&w);
data.draw(&p, 0, 4);
}
diff --git a/tests/auto/threed/qglabstractsurface/qglabstractsurface.pro b/tests/auto/threed/qglabstractsurface/qglabstractsurface.pro
index c47d4fbd4..a7d3c3cf1 100644
--- a/tests/auto/threed/qglabstractsurface/qglabstractsurface.pro
+++ b/tests/auto/threed/qglabstractsurface/qglabstractsurface.pro
@@ -5,3 +5,5 @@ CONFIG += unittest warn_on qt3d
SOURCES += tst_qglabstractsurface.cpp
QT+=widgets
+
+CONFIG+=insignificant_test
diff --git a/tests/auto/threed/qglabstractsurface/tst_qglabstractsurface.cpp b/tests/auto/threed/qglabstractsurface/tst_qglabstractsurface.cpp
index 66a6dafc1..217724d86 100644
--- a/tests/auto/threed/qglabstractsurface/tst_qglabstractsurface.cpp
+++ b/tests/auto/threed/qglabstractsurface/tst_qglabstractsurface.cpp
@@ -41,12 +41,14 @@
#include <QtTest/QtTest>
#include "qglabstractsurface.h"
-#include "qglwidgetsurface.h"
+#include "qglwindowsurface.h"
#include "qglframebufferobjectsurface.h"
#include "qglpixelbuffersurface.h"
#include "qglsubsurface.h"
#include "qopenglfunctions.h"
+#include <QtGui/QOpenGLContext>
+
class tst_QGLAbstractSurface : public QObject
{
Q_OBJECT
@@ -55,16 +57,16 @@ public:
~tst_QGLAbstractSurface() {}
private slots:
- void glWidgetSurface();
+ void glWindowSurface();
void fboSurface();
- void pbufferSurface();
+ // TODO: void pbufferSurface();
void subSurface();
private:
- bool isFboCurrent(QGLFramebufferObject *fbo);
+ bool isFboCurrent(QOpenGLFramebufferObject *fbo);
};
-bool tst_QGLAbstractSurface::isFboCurrent(QGLFramebufferObject *fbo)
+bool tst_QGLAbstractSurface::isFboCurrent(QOpenGLFramebufferObject *fbo)
{
GLint currentFbo = -1;
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &currentFbo);
@@ -76,92 +78,121 @@ bool tst_QGLAbstractSurface::isFboCurrent(QGLFramebufferObject *fbo)
return currentFbo == 0;
}
-void tst_QGLAbstractSurface::glWidgetSurface()
+static void ensureContext(QWindow &win, QOpenGLContext &ctx)
{
- QGLWidget glw;
- if (!glw.isValid())
- QSKIP("GL Implementation not valid", SkipSingle);
+ QSurfaceFormat format;
+ format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
+ ctx.setFormat(format);
+#ifndef QT_NO_DEBUG_STREAM
+ QSurfaceFormat oldFormat = format;
+#endif
+ ctx.create();
+ // TODO: is it possible that the platform will downgrade the actual
+ // format, or will it just fail if it can't deliver the actual format
+ format = ctx.format();
+#ifndef QT_NO_DEBUG_STREAM
+ if (oldFormat.swapBehavior() != format.swapBehavior())
+ qWarning() << "Could not create context for swap behavior"
+ << oldFormat.swapBehavior();
+#endif
+ ctx.makeCurrent(&win);
+}
+void tst_QGLAbstractSurface::glWindowSurface()
+{
+ QWindow glw;
+ glw.setSurfaceType(QWindow::OpenGLSurface);
+ QOpenGLContext ctx;
+ ensureContext(glw, ctx);
+ if (!ctx.isValid())
+ QSKIP("GL Implementation not valid", SkipSingle);
- QGLWidgetSurface surface1;
- QVERIFY(surface1.surfaceType() == QGLAbstractSurface::Widget);
- QVERIFY(surface1.widget() == 0);
- surface1.setWidget(&glw);
- QVERIFY(surface1.widget() == &glw);
- QVERIFY(surface1.device() == &glw);
- QCOMPARE(surface1.viewportRect(), glw.rect());
+ QGLWindowSurface surface1;
+ QVERIFY(surface1.surfaceType() == QGLAbstractSurface::Window);
+ QVERIFY(surface1.window() == 0);
+ surface1.setWindow(&glw);
+ QVERIFY(surface1.window() == &glw);
+ QCOMPARE(surface1.viewportRect(), glw.geometry());
QVERIFY(surface1.activate());
- QVERIFY(QGLContext::currentContext() == glw.context());
+ QVERIFY(QOpenGLContext::currentContext() == &ctx);
QCOMPARE(surface1.viewportGL(), QRect(0, 0, glw.width(), glw.height()));
surface1.deactivate();
- QVERIFY(QGLContext::currentContext() == glw.context()); // Left current.
+ QVERIFY(QOpenGLContext::currentContext() == &ctx); // Left current.
- QGLWidget glw2;
+ QWindow glw2;
+ glw2.setSurfaceType(QWindow::OpenGLSurface);
+ QOpenGLContext ctx2;
+ ensureContext(glw2, ctx2);
- QGLWidgetSurface surface2(&glw2);
- QVERIFY(surface2.surfaceType() == QGLAbstractSurface::Widget);
- QVERIFY(surface2.widget() == &glw2);
- QVERIFY(surface2.device() == &glw2);
+ QGLWindowSurface surface2(&glw2);
+ QVERIFY(surface2.surfaceType() == QGLAbstractSurface::Window);
+ QVERIFY(surface2.window() == &glw2);
QVERIFY(surface1.activate());
QVERIFY(surface1.switchTo(&surface2));
- QVERIFY(QGLContext::currentContext() == glw2.context());
+ QVERIFY(QOpenGLContext::currentContext() == &ctx2);
QVERIFY(surface2.switchTo(&surface1));
- QVERIFY(QGLContext::currentContext() == glw.context());
+ QVERIFY(QOpenGLContext::currentContext() == &ctx);
}
void tst_QGLAbstractSurface::fboSurface()
{
- if (!QGLFramebufferObject::hasOpenGLFramebufferObjects())
+ if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects())
QSKIP("fbo's are not supported", SkipSingle);
- QGLWidget glw;
- if (!glw.isValid())
+ QWindow glw;
+ glw.setSurfaceType(QWindow::OpenGLSurface);
+ QOpenGLContext ctx;
+ ensureContext(glw, ctx);
+ if (!ctx.isValid())
QSKIP("GL Implementation not valid", SkipSingle);
- QGLWidgetSurface surface1(&glw);
+ QGLWindowSurface surface1(&glw);
QVERIFY(surface1.activate());
QCOMPARE(surface1.viewportGL(), QRect(0, 0, glw.width(), glw.height()));
- QGLFramebufferObject fbo1(128, 128);
+ QOpenGLFramebufferObject fbo1(128, 128);
QVERIFY(fbo1.handle() != 0);
QGLFramebufferObjectSurface surface2(&fbo1);
QVERIFY(surface2.surfaceType() == QGLAbstractSurface::FramebufferObject);
QVERIFY(surface2.framebufferObject() == &fbo1);
- QVERIFY(surface2.device() == &fbo1);
QVERIFY(isFboCurrent(0));
QVERIFY(surface2.activate());
- QVERIFY(QGLContext::currentContext() == glw.context());
+ QVERIFY(QOpenGLContext::currentContext() == &ctx);
QVERIFY(isFboCurrent(&fbo1));
QCOMPARE(surface2.viewportGL(), QRect(QPoint(0, 0), fbo1.size()));
surface2.deactivate();
QVERIFY(isFboCurrent(0));
- QVERIFY(QGLContext::currentContext() == glw.context());
+ QVERIFY(QOpenGLContext::currentContext() == &ctx);
- surface2.setContext(glw.context());
+ surface2.setContext(&ctx);
- QGLWidget glw2;
- QGLWidgetSurface surface3(&glw2);
+ QWindow glw2;
+ glw2.setSurfaceType(QWindow::OpenGLSurface);
+ QOpenGLContext ctx2;
+ ensureContext(glw2, ctx2);
+
+ QGLWindowSurface surface3(&glw2);
QVERIFY(surface3.activate());
- QVERIFY(QGLContext::currentContext() == glw2.context());
+ QVERIFY(QOpenGLContext::currentContext() == &ctx2);
QCOMPARE(surface3.viewportGL(), QRect(0, 0, glw2.width(), glw2.height()));
QVERIFY(surface3.switchTo(&surface2));
QVERIFY(isFboCurrent(&fbo1));
- QVERIFY(QGLContext::currentContext() == glw.context());
+ QVERIFY(QOpenGLContext::currentContext() == &ctx);
QCOMPARE(surface2.viewportGL(), QRect(QPoint(0, 0), fbo1.size()));
QVERIFY(surface2.switchTo(&surface3));
QVERIFY(isFboCurrent(0));
- QVERIFY(QGLContext::currentContext() == glw2.context());
+ QVERIFY(QOpenGLContext::currentContext() == &ctx2);
QCOMPARE(surface3.viewportGL(), QRect(0, 0, glw2.width(), glw2.height()));
surface3.deactivate();
@@ -169,41 +200,40 @@ void tst_QGLAbstractSurface::fboSurface()
surface1.activate();
QCOMPARE(surface1.viewportGL(), QRect(0, 0, glw.width(), glw.height()));
- QGLFramebufferObject fbo2(256, 256);
+ QOpenGLFramebufferObject fbo2(256, 256);
QVERIFY(fbo2.handle() != 0);
QGLFramebufferObjectSurface surface4;
QVERIFY(surface4.surfaceType() == QGLAbstractSurface::FramebufferObject);
QVERIFY(surface4.framebufferObject() == 0);
- QVERIFY(surface4.device() == 0);
QVERIFY(!surface4.activate(0));
QVERIFY(surface4.viewportGL().isNull());
surface4.setFramebufferObject(&fbo2);
QVERIFY(surface4.framebufferObject() == &fbo2);
- QVERIFY(surface4.device() == &fbo2);
- surface4.setContext(glw.context());
+ surface4.setContext(&ctx);
QVERIFY(surface1.switchTo(&surface2));
- QVERIFY(QGLContext::currentContext() == glw.context());
+ QVERIFY(QOpenGLContext::currentContext() == &ctx);
QVERIFY(isFboCurrent(&fbo1));
QCOMPARE(surface2.viewportGL(), QRect(QPoint(0, 0), fbo1.size()));
QVERIFY(surface2.switchTo(&surface4));
- QVERIFY(QGLContext::currentContext() == glw.context());
+ QVERIFY(QOpenGLContext::currentContext() == &ctx);
QVERIFY(isFboCurrent(&fbo2));
QCOMPARE(surface4.viewportGL(), QRect(QPoint(0, 0), fbo2.size()));
QVERIFY(surface3.switchTo(&surface2));
- QVERIFY(QGLContext::currentContext() == glw.context());
+ QVERIFY(QOpenGLContext::currentContext() == &ctx);
QVERIFY(isFboCurrent(&fbo1));
QCOMPARE(surface2.viewportGL(), QRect(QPoint(0, 0), fbo1.size()));
QVERIFY(surface2.switchTo(&surface1));
- QVERIFY(QGLContext::currentContext() == glw.context());
+ QVERIFY(QOpenGLContext::currentContext() == &ctx);
QVERIFY(isFboCurrent(0));
QCOMPARE(surface1.viewportGL(), QRect(0, 0, glw.width(), glw.height()));
}
+/*
void tst_QGLAbstractSurface::pbufferSurface()
{
if (!QGLPixelBuffer::hasOpenGLPbuffers())
@@ -213,7 +243,7 @@ void tst_QGLAbstractSurface::pbufferSurface()
if (!glw.isValid())
QSKIP("GL Implementation not valid", SkipSingle);
- QGLWidgetSurface surface1(&glw);
+ QGLWindowSurface surface1(&glw);
QVERIFY(surface1.activate());
QCOMPARE(surface1.viewportGL(), QRect(0, 0, glw.width(), glw.height()));
@@ -234,7 +264,7 @@ void tst_QGLAbstractSurface::pbufferSurface()
QVERIFY(QGLContext::currentContext() == surface2ctx); // Left current.
QGLWidget glw2;
- QGLWidgetSurface surface3(&glw2);
+ QGLWindowSurface surface3(&glw2);
QVERIFY(surface3.activate());
QVERIFY(QGLContext::currentContext() == glw2.context());
QCOMPARE(surface3.viewportGL(), QRect(0, 0, glw2.width(), glw2.height()));
@@ -283,23 +313,25 @@ void tst_QGLAbstractSurface::pbufferSurface()
QVERIFY(QGLContext::currentContext() == glw.context());
QCOMPARE(surface1.viewportGL(), QRect(0, 0, glw.width(), glw.height()));
}
-
+*/
void tst_QGLAbstractSurface::subSurface()
{
- QGLWidget glw;
- if (!glw.isValid())
+ QWindow glw;
+ glw.setSurfaceType(QWindow::OpenGLSurface);
+ QOpenGLContext ctx;
+ ensureContext(glw, ctx);
+ if (!ctx.isValid())
QSKIP("GL Implementation not valid", SkipSingle);
- QGLWidgetSurface surface1(&glw);
+ QGLWindowSurface surface1(&glw);
QGLSubsurface surface2(&surface1, QRect(0, 0, 32, 16));
QVERIFY(surface2.surfaceType() == QGLAbstractSurface::Subsurface);
QVERIFY(surface2.surface() == &surface1);
- QVERIFY(surface2.device() == &glw);
QCOMPARE(surface2.region(), QRect(0, 0, 32, 16));
QVERIFY(surface2.activate());
- QVERIFY(QGLContext::currentContext() == glw.context());
+ QVERIFY(QOpenGLContext::currentContext() == &ctx);
QCOMPARE(surface2.viewportGL(), QRect(0, glw.height() - 16, 32, 16));
QGLSubsurface surface3(&surface1, QRect(16, 8, 32, 16));
@@ -308,13 +340,12 @@ void tst_QGLAbstractSurface::subSurface()
QCOMPARE(surface3.region(), QRect(16, 8, 32, 16));
QVERIFY(surface2.switchTo(&surface3));
- QVERIFY(QGLContext::currentContext() == glw.context());
+ QVERIFY(QOpenGLContext::currentContext() == &ctx);
QCOMPARE(surface3.viewportGL(), QRect(16, glw.height() - (8 + 16), 32, 16));
QGLSubsurface surface4;
QVERIFY(surface4.surfaceType() == QGLAbstractSurface::Subsurface);
QVERIFY(surface4.surface() == 0);
- QVERIFY(surface4.device() == 0);
QVERIFY(surface4.region().isNull());
QVERIFY(!surface4.activate(0));
surface4.setRegion(QRect(4, 6, 12, 8));
@@ -324,7 +355,7 @@ void tst_QGLAbstractSurface::subSurface()
QCOMPARE(surface4.region(), QRect(4, 6, 12, 8));
QVERIFY(surface2.switchTo(&surface4));
- QVERIFY(QGLContext::currentContext() == glw.context());
+ QVERIFY(QOpenGLContext::currentContext() == &ctx);
QCOMPARE(surface4.viewportGL(), QRect(16 + 4, glw.height() - (6 + 8 + 8), 12, 8));
}
diff --git a/tests/auto/threed/qglmaterial/qglmaterial.pro b/tests/auto/threed/qglmaterial/qglmaterial.pro
index 3531334e9..479f38886 100644
--- a/tests/auto/threed/qglmaterial/qglmaterial.pro
+++ b/tests/auto/threed/qglmaterial/qglmaterial.pro
@@ -5,3 +5,5 @@ CONFIG += unittest warn_on qt3d
SOURCES += tst_qglmaterial.cpp
QT+=widgets
+
+CONFIG+=insignificant_test
diff --git a/tests/auto/threed/qglmaterial/tst_qglmaterial.cpp b/tests/auto/threed/qglmaterial/tst_qglmaterial.cpp
index cfb9687f3..ab5259e2c 100644
--- a/tests/auto/threed/qglmaterial/tst_qglmaterial.cpp
+++ b/tests/auto/threed/qglmaterial/tst_qglmaterial.cpp
@@ -55,6 +55,9 @@
#include <QtGui/qvector3d.h>
#include <QtGui/qvector4d.h>
+#include "qglframebufferobjectsurface.h"
+#include "qglview.h"
+
class TestWidget;
class tst_QGLMaterial : public QObject
@@ -81,11 +84,11 @@ private:
TestWidget *widget;
};
-class TestWidget : public QGLWidget
+class TestWidget : public QGLView
{
Q_OBJECT
public:
- TestWidget(QWidget *parent = 0);
+ TestWidget(QWindow *parent = 0);
~TestWidget();
bool runTest(QGLAbstractMaterial *mat, int timeout = 5000);
@@ -107,8 +110,8 @@ private:
QColor clearColor;
};
-TestWidget::TestWidget(QWidget *parent)
- : QGLWidget(parent)
+TestWidget::TestWidget(QWindow *parent)
+ : QGLView(parent)
, material(0)
, eventLoop(0)
, paintDone(false)
@@ -155,7 +158,7 @@ bool TestWidget::runTest(QGLAbstractMaterial *mat, int timeout)
qt_x11_wait_for_window_manager(this);
#endif
} else {
- updateGL();
+ update();
}
if (!paintDone)
eventLoop->exec();
@@ -197,6 +200,11 @@ void TestWidget::initializeGL()
void TestWidget::paintGL()
{
QGLPainter painter(this);
+ QOpenGLFramebufferObject fbo(512, 512);
+ QGLFramebufferObjectSurface surf(&fbo);
+
+ surf.activate();
+
painter.setClearColor(clearColor);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -212,7 +220,10 @@ void TestWidget::paintGL()
material->release(&painter, 0);
}
- QImage capture = grabFrameBuffer();
+ surf.deactivate();
+
+ QImage capture = fbo.toImage();
+
if (capture.width() > 0 && capture.height() > 0)
pixel = QColor(capture.pixel(capture.width() / 2, capture.height() / 2));
@@ -689,7 +700,7 @@ static QColor litColor(const QGLMaterial &material)
void tst_QGLMaterial::standardMaterialDraw()
{
- if (!widget->isValid())
+ if (!widget->context()->isValid())
QSKIP("GL Implementation not valid", SkipSingle);
QGLMaterial mat1;
@@ -699,7 +710,7 @@ void tst_QGLMaterial::standardMaterialDraw()
void tst_QGLMaterial::colorMaterialDraw()
{
- if (!widget->isValid())
+ if (!widget->context()->isValid())
QSKIP("GL Implementation not valid", SkipSingle);
QGLColorMaterial mat1;
diff --git a/tests/auto/threed/qglpainter/qglpainter.pro b/tests/auto/threed/qglpainter/qglpainter.pro
index a4b2e2127..a521ab775 100644
--- a/tests/auto/threed/qglpainter/qglpainter.pro
+++ b/tests/auto/threed/qglpainter/qglpainter.pro
@@ -14,3 +14,5 @@ HEADERS += qgltestwidget.h \
compareimage.h \
qglsimulator.h
QT+=widgets
+
+CONFIG+=insignificant_test
diff --git a/tests/auto/threed/qglpainter/qgltestwidget.cpp b/tests/auto/threed/qglpainter/qgltestwidget.cpp
index b54976df7..892d32a9b 100644
--- a/tests/auto/threed/qglpainter/qgltestwidget.cpp
+++ b/tests/auto/threed/qglpainter/qgltestwidget.cpp
@@ -42,12 +42,14 @@
#include <QtTest/QtTest>
#include "qgltestwidget.h"
#include "compareimage.h"
+#include "qglframebufferobjectsurface.h"
+
#include <QtCore/qeventloop.h>
#include <QtCore/qtimer.h>
#include <QtGui/qpainter.h>
-QGLTestWidget::QGLTestWidget(QWidget *parent)
- : QGLWidget(parent)
+QGLTestWidget::QGLTestWidget(QWindow *parent)
+ : QGLView(parent)
{
eventLoop = 0;
paintDone = false;
@@ -77,7 +79,7 @@ bool QGLTestWidget::runTest(QObject *target, const char *method, int timeout)
qt_x11_wait_for_window_manager(this);
#endif
} else {
- updateGL();
+ update();
}
if (!paintDone)
eventLoop->exec();
@@ -100,7 +102,11 @@ void QGLTestWidget::paintGL()
{
if (target && method)
QMetaObject::invokeMethod(target, method, Qt::DirectConnection);
- capture = grabFrameBuffer();
+ QOpenGLFramebufferObject fbo(512, 512);
+ QGLFramebufferObjectSurface surf(&fbo);
+
+ capture = fbo.toImage();
+
if (target && method) {
QSize sz = size();
simulated = QImage(sz, QImage::Format_RGB32);
diff --git a/tests/auto/threed/qglpainter/qgltestwidget.h b/tests/auto/threed/qglpainter/qgltestwidget.h
index e4967e058..1095e77d6 100644
--- a/tests/auto/threed/qglpainter/qgltestwidget.h
+++ b/tests/auto/threed/qglpainter/qgltestwidget.h
@@ -43,14 +43,15 @@
#define QGLTESTWIDGET_H
#include <QtOpenGL/qgl.h>
+#include "qglview.h"
class QEventLoop;
-class QGLTestWidget : public QGLWidget
+class QGLTestWidget : public QGLView
{
Q_OBJECT
public:
- QGLTestWidget(QWidget *parent = 0);
+ QGLTestWidget(QWindow *parent = 0);
~QGLTestWidget();
bool runTest(QObject *target, const char *method, int timeout = 5000);
diff --git a/tests/auto/threed/qglpainter/tst_qglpainter.cpp b/tests/auto/threed/qglpainter/tst_qglpainter.cpp
index ccb530660..7be78ef27 100644
--- a/tests/auto/threed/qglpainter/tst_qglpainter.cpp
+++ b/tests/auto/threed/qglpainter/tst_qglpainter.cpp
@@ -96,7 +96,7 @@ void tst_QGLPainter::cleanupTestCase()
void tst_QGLPainter::clear()
{
- if (!widget->isValid())
+ if (!widget->context()->isValid())
QSKIP("GL Implementation not valid", SkipSingle);
QVERIFY(widget->runTest(this, "clearPaint"));
@@ -120,7 +120,7 @@ void tst_QGLPainter::clearPaintQ(QPainter *painter, const QSize& size)
void tst_QGLPainter::drawTriangle()
{
QSKIP("Fails under qt5", SkipSingle);
- if (!widget->isValid())
+ if (!widget->context()->isValid())
QSKIP("GL Implementation not valid", SkipSingle);
QVERIFY(widget->runTest(this, "drawTrianglePaint"));
@@ -134,7 +134,7 @@ void tst_QGLPainter::drawTrianglePaint()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
QMatrix4x4 projm;
- projm.ortho(widget->rect());
+ projm.ortho(widget->geometry());
painter.projectionMatrix() = projm;
painter.modelViewMatrix().setToIdentity();
@@ -158,7 +158,7 @@ void tst_QGLPainter::drawTrianglePaintQ(QPainter *painter, const QSize& size)
sim.setColor(Qt::green);
QMatrix4x4 proj;
- proj.ortho(widget->rect());
+ proj.ortho(widget->geometry());
sim.setProjectionMatrix(proj);
QVector2DArray vertices;
@@ -187,7 +187,7 @@ void tst_QGLPainter::scissor()
{
QSKIP("Does not pass on Qt5", SkipSingle);
- if (!widget->isValid())
+ if (!widget->context()->isValid())
QSKIP("GL Implementation not valid", SkipSingle);
// Run a painting test to check that the scissor works.
@@ -197,7 +197,7 @@ void tst_QGLPainter::scissor()
// GL state is updated properly as the scissor changes.
QGLPainter painter;
painter.begin(widget);
- QRect windowRect = widget->rect();
+ QRect windowRect = widget->geometry();
QVERIFY(!glIsEnabled(GL_SCISSOR_TEST));
@@ -226,7 +226,7 @@ void tst_QGLPainter::scissorPaint()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
QMatrix4x4 projm;
- projm.ortho(widget->rect());
+ projm.ortho(widget->geometry());
painter.projectionMatrix() = projm;
painter.modelViewMatrix().setToIdentity();
@@ -279,7 +279,7 @@ void tst_QGLPainter::scissorPaintQ(QPainter *painter, const QSize& size)
sim.clear();
QMatrix4x4 proj;
- proj.ortho(widget->rect());
+ proj.ortho(widget->geometry());
sim.setProjectionMatrix(proj);
QVector2DArray vertices;
@@ -451,7 +451,7 @@ static bool checkGLMatrix(GLenum, const QMatrix4x4&) { return true; }
void tst_QGLPainter::projectionMatrixStack()
{
- if (!widget->isValid())
+ if (!widget->context()->isValid())
QSKIP("GL Implementation not valid", SkipSingle);
QGLPainter painter(widget);
@@ -481,7 +481,7 @@ void tst_QGLPainter::projectionMatrixStack()
void tst_QGLPainter::modelViewMatrixStack()
{
- if (!widget->isValid())
+ if (!widget->context()->isValid())
QSKIP("GL Implementation not valid", SkipSingle);
QGLPainter painter(widget);
@@ -554,10 +554,36 @@ void tst_QGLPainter::worldMatrix()
QVERIFY(fuzzyCompare(painter.worldMatrix(), world));
}
+static void ensureContext(QWindow &win, QOpenGLContext &ctx)
+{
+ QSurfaceFormat format;
+ format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
+ ctx.setFormat(format);
+#ifndef QT_NO_DEBUG_STREAM
+ QSurfaceFormat oldFormat = format;
+#endif
+ ctx.create();
+ // TODO: is it possible that the platform will downgrade the actual
+ // format, or will it just fail if it can't deliver the actual format
+ format = ctx.format();
+#ifndef QT_NO_DEBUG_STREAM
+ if (oldFormat.swapBehavior() != format.swapBehavior())
+ qWarning() << "Could not create context for swap behavior"
+ << oldFormat.swapBehavior();
+#endif
+ ctx.makeCurrent(&win);
+}
+
void tst_QGLPainter::basicCullable()
{
- QGLWidget w;
- QGLPainter painter(&w);
+ QWindow glw;
+ glw.setSurfaceType(QWindow::OpenGLSurface);
+ QOpenGLContext ctx;
+ ensureContext(glw, ctx);
+ if (!ctx.isValid())
+ QSKIP("GL Implementation not valid", SkipSingle);
+
+ QGLPainter painter(&glw);
painter.modelViewMatrix().setToIdentity();
// Default values for the camera have
@@ -676,8 +702,14 @@ void tst_QGLPainter::isCullable_data()
void tst_QGLPainter::isCullable()
{
- QGLWidget w;
- QGLPainter painter(&w);
+ QWindow glw;
+ glw.setSurfaceType(QWindow::OpenGLSurface);
+ QOpenGLContext ctx;
+ ensureContext(glw, ctx);
+ if (!ctx.isValid())
+ QSKIP("GL Implementation not valid", SkipSingle);
+
+ QGLPainter painter(&glw);
painter.modelViewMatrix().setToIdentity();
QGLCamera camera;
@@ -736,8 +768,14 @@ void tst_QGLPainter::isCullableVert()
// and back instead of rotating it from side to side
// since the view frustum is typically not square in section
// as it depends on the surface, this will give different results.
- QGLWidget w;
- QGLPainter painter(&w);
+ QWindow glw;
+ glw.setSurfaceType(QWindow::OpenGLSurface);
+ QOpenGLContext ctx;
+ ensureContext(glw, ctx);
+ if (!ctx.isValid())
+ QSKIP("GL Implementation not valid", SkipSingle);
+
+ QGLPainter painter(&glw);
painter.modelViewMatrix().setToIdentity();
QGLCamera camera;
diff --git a/tests/auto/threed/qglrender/qglrender.pro b/tests/auto/threed/qglrender/qglrender.pro
index 3358af59f..e259cf303 100644
--- a/tests/auto/threed/qglrender/qglrender.pro
+++ b/tests/auto/threed/qglrender/qglrender.pro
@@ -5,3 +5,5 @@ CONFIG += unittest warn_on qt3d
SOURCES += tst_qglrender.cpp
QT+=widgets
+
+CONFIG+=insignificant_test
diff --git a/tests/auto/threed/qglrender/tst_qglrender.cpp b/tests/auto/threed/qglrender/tst_qglrender.cpp
index 150396d5e..8a87b2bb2 100644
--- a/tests/auto/threed/qglrender/tst_qglrender.cpp
+++ b/tests/auto/threed/qglrender/tst_qglrender.cpp
@@ -146,7 +146,7 @@ void tst_QGLRender::repo()
class TestPainter : public QGLPainter
{
public:
- TestPainter(QGLWidget *w) : QGLPainter(w) {}
+ TestPainter(QWindow *w) : QGLPainter(w) {}
void draw(QGL::DrawingMode mode, const QGLIndexBuffer& indices,
int offset, int count)
{
@@ -239,7 +239,7 @@ void tst_QGLRender::sequence()
cl->setEffect(QGL::LitDecalTexture2D);
TestView widget(scene);
- if (!widget.isValid())
+ if (!widget.context()->isValid())
QSKIP("GL Implementation not valid", SkipSingle);
TestPainter *ptr = new TestPainter(&widget);
diff --git a/tests/auto/threed/qglscenenode/qglscenenode.pro b/tests/auto/threed/qglscenenode/qglscenenode.pro
index 7ee6830ec..77ac01701 100644
--- a/tests/auto/threed/qglscenenode/qglscenenode.pro
+++ b/tests/auto/threed/qglscenenode/qglscenenode.pro
@@ -6,3 +6,5 @@ CONFIG += unittest warn_on qt3d
INCLUDEPATH += ../../../shared
SOURCES += tst_qglscenenode.cpp
QT+=widgets
+
+CONFIG+=insignificant_test
diff --git a/tests/auto/threed/qglscenenode/tst_qglscenenode.cpp b/tests/auto/threed/qglscenenode/tst_qglscenenode.cpp
index f87f77b5f..c9152517d 100644
--- a/tests/auto/threed/qglscenenode/tst_qglscenenode.cpp
+++ b/tests/auto/threed/qglscenenode/tst_qglscenenode.cpp
@@ -695,6 +695,26 @@ protected:
};
+static void ensureContext(QWindow &win, QOpenGLContext &ctx)
+{
+ QSurfaceFormat format;
+ format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
+ ctx.setFormat(format);
+#ifndef QT_NO_DEBUG_STREAM
+ QSurfaceFormat oldFormat = format;
+#endif
+ ctx.create();
+ // TODO: is it possible that the platform will downgrade the actual
+ // format, or will it just fail if it can't deliver the actual format
+ format = ctx.format();
+#ifndef QT_NO_DEBUG_STREAM
+ if (oldFormat.swapBehavior() != format.swapBehavior())
+ qWarning() << "Could not create context for swap behavior"
+ << oldFormat.swapBehavior();
+#endif
+ ctx.makeCurrent(&win);
+}
+
void tst_QGLSceneNode::position_QTBUG_17279()
{
QGeometryData geom;
@@ -713,8 +733,14 @@ void tst_QGLSceneNode::position_QTBUG_17279()
QVERIFY(node->localTransform().isIdentity());
QCOMPARE(node->position().z(), -5.0);
- QGLWidget w;
- QGLPainter p(&w);
+ QWindow glw;
+ glw.setSurfaceType(QWindow::OpenGLSurface);
+ QOpenGLContext ctx;
+ ensureContext(glw, ctx);
+ if (!ctx.isValid())
+ QSKIP("GL Implementation not valid", SkipSingle);
+
+ QGLPainter p(&glw);
QGLCamera cam;
p.setCamera(&cam);
diff --git a/tests/manual/displaymodel/qml/tst_displaymodel.qml b/tests/manual/displaymodel/qml/tst_displaymodel.qml
index e514471c8..219d69936 100644
--- a/tests/manual/displaymodel/qml/tst_displaymodel.qml
+++ b/tests/manual/displaymodel/qml/tst_displaymodel.qml
@@ -39,7 +39,7 @@
**
****************************************************************************/
-import QtQuick 1.0
+import QtQuick 2.0
import Qt3D 1.0
import Qt3D.Shapes 1.0
diff --git a/tests/shared/qmlres.h b/tests/shared/qmlres.h
index df2737906..231a6b469 100644
--- a/tests/shared/qmlres.h
+++ b/tests/shared/qmlres.h
@@ -135,7 +135,7 @@ int main(int argc, char *argv[])
f.setSamples(16); \
QSGView view; \
view.setFormat(f); \
- QString qml = q_get_qmldir(QLatin1String("qml/desktop.qml")); \
+ QString qml = q_get_qmldir(QLatin1String( file )); \
view.setSource(QUrl::fromLocalFile(qml)); \
if (QGuiApplication::arguments().contains(QLatin1String("-maximize"))) \
view.showMaximized(); \
diff --git a/tutorials/qt3d/cube1/cubeview.cpp b/tutorials/qt3d/cube1/cubeview.cpp
index 51e074f62..add9bb401 100644
--- a/tutorials/qt3d/cube1/cubeview.cpp
+++ b/tutorials/qt3d/cube1/cubeview.cpp
@@ -43,7 +43,7 @@
#include "qglcube.h"
//! [1]
-CubeView::CubeView(QWidget *parent)
+CubeView::CubeView(QWindow *parent)
: QGLView(parent)
{
QGLBuilder builder;
diff --git a/tutorials/qt3d/cube1/cubeview.h b/tutorials/qt3d/cube1/cubeview.h
index 04238f58d..77b5d2b9a 100644
--- a/tutorials/qt3d/cube1/cubeview.h
+++ b/tutorials/qt3d/cube1/cubeview.h
@@ -50,7 +50,7 @@ class CubeView : public QGLView
{
Q_OBJECT
public:
- CubeView(QWidget *parent = 0);
+ CubeView(QWindow *parent = 0);
~CubeView();
protected:
diff --git a/tutorials/qt3d/cube2/cubeview.cpp b/tutorials/qt3d/cube2/cubeview.cpp
index 1dca459a8..5140b233f 100644
--- a/tutorials/qt3d/cube2/cubeview.cpp
+++ b/tutorials/qt3d/cube2/cubeview.cpp
@@ -42,7 +42,7 @@
#include "qglbuilder.h"
#include "qglcube.h"
-CubeView::CubeView(QWidget *parent)
+CubeView::CubeView(QWindow *parent)
: QGLView(parent)
{
QGLBuilder builder;
diff --git a/tutorials/qt3d/cube2/cubeview.h b/tutorials/qt3d/cube2/cubeview.h
index 04238f58d..77b5d2b9a 100644
--- a/tutorials/qt3d/cube2/cubeview.h
+++ b/tutorials/qt3d/cube2/cubeview.h
@@ -50,7 +50,7 @@ class CubeView : public QGLView
{
Q_OBJECT
public:
- CubeView(QWidget *parent = 0);
+ CubeView(QWindow *parent = 0);
~CubeView();
protected:
diff --git a/tutorials/qt3d/cube3/cubeview.cpp b/tutorials/qt3d/cube3/cubeview.cpp
index 80c3e0f1a..412cffbde 100644
--- a/tutorials/qt3d/cube3/cubeview.cpp
+++ b/tutorials/qt3d/cube3/cubeview.cpp
@@ -42,7 +42,7 @@
#include "qglbuilder.h"
#include "qglcube.h"
-CubeView::CubeView(QWidget *parent)
+CubeView::CubeView(QWindow *parent)
: QGLView(parent)
{
QGLBuilder builder;
diff --git a/tutorials/qt3d/cube3/cubeview.h b/tutorials/qt3d/cube3/cubeview.h
index 04238f58d..77b5d2b9a 100644
--- a/tutorials/qt3d/cube3/cubeview.h
+++ b/tutorials/qt3d/cube3/cubeview.h
@@ -50,7 +50,7 @@ class CubeView : public QGLView
{
Q_OBJECT
public:
- CubeView(QWidget *parent = 0);
+ CubeView(QWindow *parent = 0);
~CubeView();
protected:
diff --git a/tutorials/qt3d/cube4/cubeview.cpp b/tutorials/qt3d/cube4/cubeview.cpp
index e3045292b..a6f9a00ec 100644
--- a/tutorials/qt3d/cube4/cubeview.cpp
+++ b/tutorials/qt3d/cube4/cubeview.cpp
@@ -43,7 +43,7 @@
#include "qglcube.h"
//! [1]
-CubeView::CubeView(QWidget *parent)
+CubeView::CubeView(QWindow *parent)
: QGLView(parent)
{
//! [1]
diff --git a/tutorials/qt3d/cube4/cubeview.h b/tutorials/qt3d/cube4/cubeview.h
index 4f00216ca..fd5937b25 100644
--- a/tutorials/qt3d/cube4/cubeview.h
+++ b/tutorials/qt3d/cube4/cubeview.h
@@ -52,7 +52,7 @@ class CubeView : public QGLView
//! [1]
Q_OBJECT
public:
- CubeView(QWidget *parent = 0);
+ CubeView(QWindow *parent = 0);
~CubeView();
protected:
diff --git a/tutorials/qt3d/penguin/modelview.h b/tutorials/qt3d/penguin/modelview.h
index 978b185f8..dc1f75a51 100644
--- a/tutorials/qt3d/penguin/modelview.h
+++ b/tutorials/qt3d/penguin/modelview.h
@@ -51,7 +51,7 @@ class ModelView : public QGLView
{
Q_OBJECT
public:
- ModelView(QWidget *parent = 0) : QGLView(parent) {}
+ ModelView(QWindow *parent = 0) : QGLView(parent) {}
~ModelView();
protected:
diff --git a/tutorials/qt3d/penguin_advanced/modelview.cpp b/tutorials/qt3d/penguin_advanced/modelview.cpp
index a72495331..c42763c2d 100644
--- a/tutorials/qt3d/penguin_advanced/modelview.cpp
+++ b/tutorials/qt3d/penguin_advanced/modelview.cpp
@@ -42,7 +42,7 @@
#include "qglabstractscene.h"
#include "qglscenenode.h"
-ModelView::ModelView(QWidget *parent)
+ModelView::ModelView(QWindow *parent)
: QGLView(parent)
, m_scene(0)
, m_main(0)
diff --git a/tutorials/qt3d/penguin_advanced/modelview.h b/tutorials/qt3d/penguin_advanced/modelview.h
index 38b4340cc..c6a23ed13 100644
--- a/tutorials/qt3d/penguin_advanced/modelview.h
+++ b/tutorials/qt3d/penguin_advanced/modelview.h
@@ -50,7 +50,7 @@ class ModelView : public QGLView
{
Q_OBJECT
public:
- ModelView(QWidget *parent = 0);
+ ModelView(QWindow *parent = 0);
~ModelView() {}
protected: