diff options
author | Laszlo Agocs <laszlo.agocs@digia.com> | 2014-03-17 15:30:49 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-18 20:59:55 +0100 |
commit | 337524714cad51934879d817564c5d58e6dbd0c0 (patch) | |
tree | 8c5edc5f456566897c2d9a1a72e4d99b88e63116 /src/quickwidgets | |
parent | 2a39fa47c26453fbc6d200dce7eb01d40cdf259a (diff) |
Add surface format to QQuickWidget.
Change-Id: Id72a042588e37832a0d3757bad935c531ef8275a
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
Diffstat (limited to 'src/quickwidgets')
-rw-r--r-- | src/quickwidgets/qquickwidget.cpp | 54 | ||||
-rw-r--r-- | src/quickwidgets/qquickwidget.h | 3 | ||||
-rw-r--r-- | src/quickwidgets/qquickwidget_p.h | 1 |
3 files changed, 55 insertions, 3 deletions
diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index 6484bf2fd2..d8b00a71c0 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -97,6 +97,9 @@ void QQuickWidgetPrivate::handleWindowChange() QQuickWidgetPrivate::QQuickWidgetPrivate() : root(0) , component(0) + , offscreenWindow(0) + , offscreenSurface(0) + , renderControl(0) , fbo(0) , context(0) , resizeMode(QQuickWidget::SizeViewToRootObject) @@ -110,9 +113,7 @@ QQuickWidgetPrivate::QQuickWidgetPrivate() offscreenWindow = new QQuickWindow(renderControl); offscreenWindow->setTitle(QString::fromLatin1("Offscreen")); // Do not call create() on offscreenWindow. - offscreenSurface = new QOffscreenSurface; - offscreenSurface->setFormat(offscreenWindow->requestedFormat()); - offscreenSurface->create(); + createOffscreenSurface(); } QQuickWidgetPrivate::~QQuickWidgetPrivate() @@ -125,6 +126,15 @@ QQuickWidgetPrivate::~QQuickWidgetPrivate() delete fbo; } +void QQuickWidgetPrivate::createOffscreenSurface() +{ + delete offscreenSurface; + offscreenSurface = 0; + offscreenSurface = new QOffscreenSurface; + offscreenSurface->setFormat(offscreenWindow->requestedFormat()); + offscreenSurface->create(); +} + void QQuickWidgetPrivate::execute() { Q_Q(QQuickWidget); @@ -941,4 +951,42 @@ void QQuickWidget::triggerUpdate() } } +/*! + Sets the surface \a format for the context and offscreen surface used + by this widget. + + Call this function when there is a need to request a context for a + given OpenGL version or profile. The sizes for depth, stencil and + alpha buffers are taken care of automatically and there is no need + to request those explicitly. + + \sa QWindow::setFormat(), QWindow::format(), format() +*/ +void QQuickWidget::setFormat(const QSurfaceFormat &format) +{ + Q_D(QQuickWidget); + QSurfaceFormat currentFormat = d->offscreenWindow->format(); + QSurfaceFormat newFormat = format; + newFormat.setDepthBufferSize(qMax(newFormat.depthBufferSize(), currentFormat.depthBufferSize())); + newFormat.setStencilBufferSize(qMax(newFormat.stencilBufferSize(), currentFormat.stencilBufferSize())); + newFormat.setAlphaBufferSize(qMax(newFormat.alphaBufferSize(), currentFormat.alphaBufferSize())); + if (currentFormat != newFormat) { + d->offscreenWindow->setFormat(newFormat); + d->createOffscreenSurface(); + } +} + +/*! + Returns the actual surface format. + + If the widget has not yet been shown, the requested format is returned. + + \sa setFormat() +*/ +QSurfaceFormat QQuickWidget::format() const +{ + Q_D(const QQuickWidget); + return d->offscreenWindow->format(); +} + QT_END_NAMESPACE diff --git a/src/quickwidgets/qquickwidget.h b/src/quickwidgets/qquickwidget.h index 2c021c85fb..81e9af02fb 100644 --- a/src/quickwidgets/qquickwidget.h +++ b/src/quickwidgets/qquickwidget.h @@ -89,6 +89,9 @@ public: QSize sizeHint() const; QSize initialSize() const; + void setFormat(const QSurfaceFormat &format); + QSurfaceFormat format() const; + public Q_SLOTS: void setSource(const QUrl&); void setContent(const QUrl& url, QQmlComponent *component, QObject *item); diff --git a/src/quickwidgets/qquickwidget_p.h b/src/quickwidgets/qquickwidget_p.h index 1ba06162f9..6a822ffba0 100644 --- a/src/quickwidgets/qquickwidget_p.h +++ b/src/quickwidgets/qquickwidget_p.h @@ -87,6 +87,7 @@ public: void createContext(); void destroyContext(); void handleContextCreationFailure(const QSurfaceFormat &format, bool isEs); + void createOffscreenSurface(); GLuint textureId() const Q_DECL_OVERRIDE; |