Make sure the Image texture provider does not return an atlassed texture
authorGunnar Sletta <gunnar.sletta@nokia.com>
Wed, 5 Oct 2011 07:38:32 +0000 (09:38 +0200)
committerQt by Nokia <qt-info@nokia.com>
Wed, 5 Oct 2011 10:36:15 +0000 (12:36 +0200)
This has the implication that textures from texture providers are always
the complete texture with coordinates from 0-1, which is means we get
a copy for atlas textures which may end up affecting performance.

Alternatives are:
 - ShaderEffect does this, which means texture providers can provide
   atlas textures.
 - We expose the subrect to ShaderEffect, which means an API
   change in all shader effect classes, and let the vertex shader
   solve this. Worst API, fastest and most memory efficient.

Change-Id: Id58eb866f315012637345a6f731626abf4a7a86c
Reviewed-on: http://codereview.qt-project.org/6029
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Kim M. Kalland <kim.kalland@nokia.com>

src/declarative/items/qsgimage.cpp
src/declarative/scenegraph/util/qsgtexture.cpp
src/declarative/scenegraph/util/qsgtexture.h

index 92b454b..a23d9ed 100644 (file)
@@ -63,6 +63,10 @@ public:
     }
 
     QSGTexture *texture() const {
+
+        if (m_texture->isAtlasTexture())
+            const_cast<QSGImageTextureProvider *>(this)->m_texture = m_texture->removedFromAtlas();
+
         if (m_texture) {
             m_texture->setFiltering(m_smooth ? QSGTexture::Linear : QSGTexture::Nearest);
             m_texture->setMipmapFiltering(QSGTexture::Nearest);
index 4e208c0..7cd398d 100644 (file)
@@ -193,11 +193,33 @@ QSGTexture::~QSGTexture()
 
     Binding a texture may also include uploading the texture data from
     a previously set QImage.
+
+    \warning This function can only be called from the rendering thread.
+ */
+
+/*!
+    This function returns a copy of the current texture which is removed
+    from its atlas.
+
+    The current texture remains unchanged, so texture coordinates do not
+    need to be updated.
+
+    Removing a texture from an atlas is primarily useful when passing
+    it to a shader that operates on the texture coordinates 0-1 instead
+    of the texture subrect inside the atlas.
+
+    If the texture is not part of a texture atlas, this function returns 0.
+
+    Implementations of this function are recommended to return the same instance
+    for multiple calls to limit memory usage.
+
+    \warning This function can only be called from the rendering thread.
  */
 
-void QSGTexture::removeFromAtlas()
+QSGTexture *QSGTexture::removedFromAtlas() const
 {
-    // default textures are not in atlasses, so do nothing...
+    Q_ASSERT_X(!isAtlasTexture(), "QSGTexture::removedFromAtlas()", "Called on a non-atlas texture");
+    return 0;
 }
 
 /*!
index 5506042..135c5e4 100644 (file)
@@ -80,7 +80,8 @@ public:
     virtual QRectF textureSubRect() const;
 
     virtual bool isAtlasTexture() const;
-    virtual void removeFromAtlas();
+
+    virtual QSGTexture *removedFromAtlas() const;
 
     virtual void bind() = 0;
     void updateBindOptions(bool force = false);