Add surface format to QQuickWidget.

Change-Id: Id72a042588e37832a0d3757bad935c531ef8275a
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
This commit is contained in:
Laszlo Agocs 2014-03-17 15:30:49 +01:00 committed by The Qt Project
parent 2a39fa47c2
commit 337524714c
4 changed files with 62 additions and 3 deletions

View File

@ -58,6 +58,13 @@ private:
MainWindow::MainWindow()
: m_quickWidget(new QQuickWidget)
{
if (QCoreApplication::arguments().contains(QStringLiteral("--coreprofile"))) {
QSurfaceFormat format;
format.setVersion(4, 4);
format.setProfile(QSurfaceFormat::CoreProfile);
m_quickWidget->setFormat(format);
}
QMdiArea *centralWidget = new QMdiArea;
QLCDNumber *lcd = new QLCDNumber;

View File

@ -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

View File

@ -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);

View File

@ -87,6 +87,7 @@ public:
void createContext();
void destroyContext();
void handleContextCreationFailure(const QSurfaceFormat &format, bool isEs);
void createOffscreenSurface();
GLuint textureId() const Q_DECL_OVERRIDE;