From 326ed5767e5d09ed3bf2177d5de17d4e07edf226 Mon Sep 17 00:00:00 2001 From: Kim Motoyoshi Kalland Date: Mon, 15 Aug 2011 14:46:23 +0200 Subject: Implemented minimum FBO size on the ShaderEffectSource. Task-number: QTBUG-20193 Change-Id: I45020c094c4a4892c055700f084fde7b219cdc10 Reviewed-on: http://codereview.qt.nokia.com/2972 Reviewed-by: Qt Sanity Bot Reviewed-by: Gunnar Sletta --- src/declarative/items/qsgshadereffectsource.cpp | 21 +++++++++++++++++---- src/declarative/scenegraph/qsgcontext.cpp | 15 +++++++++++++++ src/declarative/scenegraph/qsgcontext_p.h | 1 + 3 files changed, 33 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/declarative/items/qsgshadereffectsource.cpp b/src/declarative/items/qsgshadereffectsource.cpp index 5114d8c042..d7653b578b 100644 --- a/src/declarative/items/qsgshadereffectsource.cpp +++ b/src/declarative/items/qsgshadereffectsource.cpp @@ -558,8 +558,12 @@ void QSGShaderEffectSource::setSourceRect(const QRectF &rect) /*! \qmlproperty size ShaderEffectSource::textureSize - This property holds the size of the texture. If it is empty, which is the - default, the size of the source rectangle is used. + This property holds the requested size of the texture. If it is empty, + which is the default, the size of the source rectangle is used. + + \note Some platforms have a limit on how small framebuffer objects can be, + which means the actual texture size might be larger than the requested + size. */ QSize QSGShaderEffectSource::textureSize() const @@ -762,7 +766,7 @@ QSGTexture *QSGShaderEffectSource::texture() const QSGNode *QSGShaderEffectSource::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) { - if (!m_sourceItem) { + if (!m_sourceItem || m_sourceItem->width() == 0 || m_sourceItem->height() == 0) { delete oldNode; return 0; } @@ -782,13 +786,22 @@ QSGNode *QSGShaderEffectSource::updatePaintNode(QSGNode *oldNode, UpdatePaintNod tex->setLive(m_live); tex->setItem(QSGItemPrivate::get(m_sourceItem)->itemNode()); - QRectF sourceRect = m_sourceRect.isNull() + QRectF sourceRect = m_sourceRect.width() == 0 || m_sourceRect.height() == 0 ? QRectF(0, 0, m_sourceItem->width(), m_sourceItem->height()) : m_sourceRect; tex->setRect(sourceRect); QSize textureSize = m_textureSize.isEmpty() ? QSize(qCeil(qAbs(sourceRect.width())), qCeil(qAbs(sourceRect.height()))) : m_textureSize; + Q_ASSERT(!textureSize.isEmpty()); + QSGItemPrivate *d = static_cast(QObjectPrivate::get(this)); + const QSize minTextureSize = d->sceneGraphContext()->minimumFBOSize(); + // Keep power-of-two by doubling the size. + while (textureSize.width() < minTextureSize.width()) + textureSize.rwidth() *= 2; + while (textureSize.height() < minTextureSize.height()) + textureSize.rheight() *= 2; + tex->setSize(textureSize); tex->setRecursive(m_recursive); tex->setFormat(GLenum(m_format)); diff --git a/src/declarative/scenegraph/qsgcontext.cpp b/src/declarative/scenegraph/qsgcontext.cpp index 1f6f6e1e2a..2a9e007264 100644 --- a/src/declarative/scenegraph/qsgcontext.cpp +++ b/src/declarative/scenegraph/qsgcontext.cpp @@ -397,6 +397,21 @@ QSGTexture *QSGContext::createTexture(const QImage &image) const +/*! + Returns the minimum supported framebuffer object size. + */ + +QSize QSGContext::minimumFBOSize() const +{ +#ifdef Q_WS_MAC + return QSize(33, 33); +#else + return QSize(1, 1); +#endif +} + + + /*! Returns a material shader for the given material. */ diff --git a/src/declarative/scenegraph/qsgcontext_p.h b/src/declarative/scenegraph/qsgcontext_p.h index be7dff880a..29a5aac4b9 100644 --- a/src/declarative/scenegraph/qsgcontext_p.h +++ b/src/declarative/scenegraph/qsgcontext_p.h @@ -102,6 +102,7 @@ public: QSize *size, const QSize &requestSize); virtual QSGTexture *createTexture(const QImage &image = QImage()) const; + virtual QSize minimumFBOSize() const; static QSGContext *createDefaultContext(); -- cgit v1.2.3