aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar.sletta@digia.com>2013-08-02 15:18:32 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-12 17:03:15 +0200
commit3ed9f1f4b6f9e17943fe8f756e1ff9d6ba2b6479 (patch)
treed9998b8110eecee82e1c6de3b585d72760f13bff
parent0bf62bd47bfda33305153a808619550e6a5b896f (diff)
Public API for creating atlas textures, when available.
Atlas textures are currently only used when scenegraph is combined with the customcontext from the playground/scenegraph module. Change-Id: I42f62abdad42e97cc1dcdc05bfb16ecf2839dc0e Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
-rw-r--r--src/quick/items/qquickwindow.cpp32
-rw-r--r--src/quick/items/qquickwindow.h4
-rw-r--r--src/quick/scenegraph/qsgcontext.cpp7
-rw-r--r--src/quick/scenegraph/qsgcontext_p.h3
4 files changed, 36 insertions, 10 deletions
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp
index c34bad5430..c785405231 100644
--- a/src/quick/items/qquickwindow.cpp
+++ b/src/quick/items/qquickwindow.cpp
@@ -2805,6 +2805,8 @@ QQmlIncubationController *QQuickWindow::incubationController() const
\value TextureOwnsGLTexture The texture object owns the texture id and
will delete the GL texture when the texture object is deleted.
+
+ \value TextureCanUseAtlas The image can be uploaded into a texture atlas.
*/
/*!
@@ -2897,6 +2899,14 @@ bool QQuickWindow::clearBeforeRendering() const
return d->clearBeforeRendering;
}
+/*!
+ \overload
+ */
+
+QSGTexture *QQuickWindow::createTextureFromImage(const QImage &image) const
+{
+ return createTextureFromImage(image, 0);
+}
/*!
@@ -2906,10 +2916,11 @@ bool QQuickWindow::clearBeforeRendering() const
The caller of the function is responsible for deleting the returned texture.
The actual GL texture will be deleted when the texture object is deleted.
- Depending on the underlying implementation of the scene graph, the returned
- texture may be part of an atlas. For code to be portable across implementations
- one should always use the texture coordinates returned from
- QSGTexture::normalizedTextureSubRect() when building geometry.
+ When \a options contains TextureCanUseAtlas the engine may put the image
+ into a texture atlas. Textures in an atlas need to rely on
+ QSGTexture::normalizedTextureSubRect() for their geometry and will not
+ support QSGTexture::Repeat. Other values from CreateTextureOption are
+ ignored.
\warning This function will return 0 if the scene graph has not yet been
initialized.
@@ -2925,11 +2936,15 @@ bool QQuickWindow::clearBeforeRendering() const
\sa sceneGraphInitialized()
*/
-QSGTexture *QQuickWindow::createTextureFromImage(const QImage &image) const
+QSGTexture *QQuickWindow::createTextureFromImage(const QImage &image, CreateTextureOptions options) const
{
Q_D(const QQuickWindow);
- if (d->context && d->context->isReady())
- return d->context->createTexture(image);
+ if (d->context && d->context->isReady()) {
+ if (options & TextureCanUseAtlas)
+ return d->context->createTexture(image);
+ else
+ return d->context->createTextureNoAtlas(image);
+ }
else
return 0;
}
@@ -2941,7 +2956,8 @@ QSGTexture *QQuickWindow::createTextureFromImage(const QImage &image) const
The caller of the function is responsible for deleting the returned texture.
- Use \a options to customize the texture attributes.
+ Use \a options to customize the texture attributes. The TextureUsesAtlas
+ option is ignored.
\warning This function will return 0 if the scenegraph has not yet been
initialized.
diff --git a/src/quick/items/qquickwindow.h b/src/quick/items/qquickwindow.h
index a0bc832334..fad67e9734 100644
--- a/src/quick/items/qquickwindow.h
+++ b/src/quick/items/qquickwindow.h
@@ -72,7 +72,8 @@ public:
enum CreateTextureOption {
TextureHasAlphaChannel = 0x0001,
TextureHasMipmaps = 0x0002,
- TextureOwnsGLTexture = 0x0004
+ TextureOwnsGLTexture = 0x0004,
+ TextureCanUseAtlas = 0x0008
};
Q_DECLARE_FLAGS(CreateTextureOptions, CreateTextureOption)
@@ -107,6 +108,7 @@ public:
// Scene graph specific functions
QSGTexture *createTextureFromImage(const QImage &image) const;
+ QSGTexture *createTextureFromImage(const QImage &image, CreateTextureOptions options) const;
QSGTexture *createTextureFromId(uint id, const QSize &size, CreateTextureOptions options = CreateTextureOption(0)) const;
void setClearBeforeRendering(bool enabled);
diff --git a/src/quick/scenegraph/qsgcontext.cpp b/src/quick/scenegraph/qsgcontext.cpp
index a142a23c67..cb0a6d5afc 100644
--- a/src/quick/scenegraph/qsgcontext.cpp
+++ b/src/quick/scenegraph/qsgcontext.cpp
@@ -447,6 +447,13 @@ QSGTexture *QSGContext::createTexture(const QImage &image) const
return t;
}
+QSGTexture *QSGContext::createTextureNoAtlas(const QImage &image) const
+{
+ QSGPlainTexture *t = new QSGPlainTexture();
+ if (!image.isNull())
+ t->setImage(image);
+ return t;
+}
/*!
diff --git a/src/quick/scenegraph/qsgcontext_p.h b/src/quick/scenegraph/qsgcontext_p.h
index bbc42674c6..3d5fc00de3 100644
--- a/src/quick/scenegraph/qsgcontext_p.h
+++ b/src/quick/scenegraph/qsgcontext_p.h
@@ -103,7 +103,8 @@ public:
virtual QSGGlyphNode *createNativeGlyphNode();
virtual QSGRenderer *createRenderer();
- virtual QSGTexture *createTexture(const QImage &image = QImage()) const;
+ virtual QSGTexture *createTexture(const QImage &image) const;
+ virtual QSGTexture *createTextureNoAtlas(const QImage &image) const;
virtual QSize minimumFBOSize() const;
virtual QSharedPointer<QSGDepthStencilBuffer> depthStencilBufferForFbo(QOpenGLFramebufferObject *fbo);
QSGDepthStencilBufferManager *depthStencilBufferManager();