Public API for creating atlas textures, when available.
authorGunnar Sletta <gunnar.sletta@digia.com>
Fri, 2 Aug 2013 13:18:32 +0000 (15:18 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 12 Aug 2013 15:03:15 +0000 (17:03 +0200)
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>
src/quick/items/qquickwindow.cpp
src/quick/items/qquickwindow.h
src/quick/scenegraph/qsgcontext.cpp
src/quick/scenegraph/qsgcontext_p.h

index c34bad5..c785405 100644 (file)
@@ -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.
index a0bc832..fad67e9 100644 (file)
@@ -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);
index a142a23..cb0a6d5 100644 (file)
@@ -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;
+}
 
 
 /*!
index bbc4267..3d5fc00 100644 (file)
@@ -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();